:root {
  --ink: #10161C;
  --ink-raised: #161E27;
  --ink-card: #1B2530;
  --border: #2A3644;
  --paper: #F7F8FA;
  --steel: #8C97A6;
  --signal: #2DD4A7;
  --signal-dim: #1B4A40;
  --noise: #FF6B5C;
  --noise-dim: #4A2622;
  --mixed: #E8B84B;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

/* Bulletproof hide — guarantees the hidden attribute always wins over any
   class (like .gate) that sets display on the same element. Without this,
   toggling .hidden in JS can silently fail to actually hide the element,
   causing multiple screens to render stacked on top of each other. */
[hidden] {
  display: none !important;
}

* { box-sizing: border-box; }

html { background: var(--ink); }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  opacity: 0.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 900px 600px at 50% 0%, rgba(45, 212, 167, 0.10), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 100%, rgba(255, 107, 92, 0.06), transparent 60%);
  pointer-events: none;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

a { color: var(--signal); }

/* ---------- Access gate ---------- */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  background: rgba(27, 37, 48, 0.55);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 32px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.gate-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--signal), var(--mixed));
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 20px;
  box-shadow: 0 0 32px rgba(45, 212, 167, 0.35);
}

.gate-card h1 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0 0 8px;
}

.gate-sub {
  color: var(--steel);
  font-size: 14px;
  margin: 0 0 24px;
}

#access-code-input, #api-key-input {
  width: 100%;
  background: var(--ink-raised);
  border: 1px solid var(--border);
  color: var(--paper);
  padding: 13px 14px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

#access-code-input:focus, #api-key-input:focus {
  border-color: var(--signal);
}

.code-input-row {
  position: relative;
  margin-bottom: 12px;
}

.code-input-row #access-code-input {
  margin-bottom: 0;
  padding-right: 44px;
}

.code-visibility-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--steel);
  font-size: 15px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.code-visibility-toggle:hover { color: var(--signal); }

#access-code-submit {
  width: 100%;
  background: var(--signal);
  color: var(--ink);
  border: none;
  padding: 13px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
}

.gate-error {
  color: var(--noise);
  font-size: 13px;
  margin-top: 12px;
}

.gate-note {
  color: var(--signal);
  font-size: 13px;
  margin: 4px 0 14px;
  line-height: 1.5;
}

.gate-buy {
  display: block;
  margin-top: 20px;
  font-size: 13px;
  color: var(--steel);
  text-decoration: none;
}
.gate-buy:hover { color: var(--signal); }

/* ---------- App shell ---------- */
.app { max-width: 640px; margin: 0 auto; padding: 0 20px 60px; position: relative; }

@media (min-width: 900px) {
  .app { max-width: 720px; padding-top: 20px; }
  .intro h1 { font-size: 38px; }
  .eyebrow { font-size: 13px; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--signal), var(--mixed));
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--steel);
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 15px;
}
.icon-btn:hover { border-color: var(--signal); color: var(--signal); }

.intro { padding: 20px 0 28px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--signal);
  margin: 0 0 10px;
}

.intro h1 {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.25;
  margin: 0;
  font-weight: 600;
}

.input-panel {
  background: var(--ink-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

#headline-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
  resize: none;
  outline: none;
}

#headline-input::placeholder { color: var(--steel); }

.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.char-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--steel);
}

.analyze-btn {
  background: var(--signal);
  color: var(--ink);
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.analyze-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--ink);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-btn {
  background: none;
  border: none;
  color: var(--steel);
  font-size: 14px;
}

/* ---------- Result ---------- */
.result-panel {
  margin-top: 28px;
  animation: rise 0.35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.meter-wrap { margin-bottom: 22px; }

.meter-track {
  position: relative;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
}

.meter-zone { flex: 1; }
.noise-zone { background: var(--noise); opacity: 0.55; }
.mixed-zone { background: var(--mixed); opacity: 0.55; }
.signal-zone { background: var(--signal); opacity: 0.55; }

.meter-needle {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 18px;
  background: var(--paper);
  border-radius: 2px;
  left: 50%;
  transform: translateX(-50%);
  transition: left 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 8px rgba(247,248,250,0.6);
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--steel);
  margin-top: 6px;
}

.verdict-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.verdict-label {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
}
.verdict-label.signal { color: var(--signal); }
.verdict-label.noise { color: var(--noise); }
.verdict-label.mixed { color: var(--mixed); }

.verdict-score {
  font-family: var(--font-mono);
  color: var(--steel);
  font-size: 14px;
}

.verdict-summary {
  color: var(--paper);
  font-size: 15px;
  line-height: 1.55;
  margin: 8px 0 12px;
}

.verdict-disclaimer {
  color: var(--steel);
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 24px;
  padding: 10px 12px;
  background: var(--ink-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pillars { display: flex; flex-direction: column; gap: 12px; }

.pillar {
  background: var(--ink-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.pillar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.pillar-name {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--steel);
}

.pillar-score {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--paper);
}

.pillar-bar-track {
  height: 5px;
  background: var(--ink-raised);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.pillar-bar-fill {
  height: 100%;
  background: var(--signal);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.pillar-note {
  font-size: 13.5px;
  color: var(--steel);
  line-height: 1.5;
  margin: 0;
}

.flags-panel {
  margin-top: 20px;
  background: var(--noise-dim);
  border: 1px solid rgba(255,107,92,0.3);
  border-radius: 10px;
  padding: 14px 16px;
}

.flags-title {
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--noise);
  margin: 0 0 8px;
}

.flags-list { margin: 0; padding-left: 18px; color: var(--paper); font-size: 13.5px; }
.flags-list li { margin-bottom: 4px; }

.error-panel {
  margin-top: 20px;
  background: var(--noise-dim);
  border: 1px solid rgba(255,107,92,0.3);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--paper);
  font-size: 14px;
}

.footer {
  text-align: center;
  color: var(--steel);
  font-size: 12px;
  font-family: var(--font-mono);
  margin-top: 40px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal-card {
  background: var(--ink-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
}

.modal-card h2 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 20px;
}

.modal-sub {
  color: var(--steel);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}

@media (max-width: 480px) {
  .intro h1 { font-size: 24px; }
}
