/* =========================================================================
   QUEST — Perception Training scenario engine.
   Dark mono terminal. JetBrains Mono. No color. Light on darkness.
   ========================================================================= */

:root {
  --bg:           #0a0a0a;
  --bg-elev:      #111111;
  --fg:           #e8e8e8;
  --fg-dim:       #a0a0a0;
  --fg-faint:     #6a6a6a;
  --border:       #262626;
  --border-soft:  #1a1a1a;
  --accent:       #f5f5f5;
  --selection:    #2a2a2a;

  --font-mono:    'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.65;
  font-weight: 400;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

::selection {
  background: var(--selection);
  color: var(--fg);
}

/* ---------- CRT / Scanlines ---------- */
.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 0%, transparent 60%, rgba(0,0,0,0.35) 100%);
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.00) 0px,
    rgba(255,255,255,0.00) 2px,
    rgba(255,255,255,0.012) 3px,
    rgba(255,255,255,0.00) 4px
  );
  mix-blend-mode: overlay;
}

/* ---------- Container ---------- */
.quest-container {
  position: relative;
  z-index: 3;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.quest-header {
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.quest-header-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--fg-faint);
  text-transform: uppercase;
}

/* ---------- Progress ---------- */
.quest-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--fg-faint);
}

.quest-progress-bar {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
}

.quest-progress-fill {
  height: 100%;
  background: var(--fg-dim);
  border-radius: 1px;
  width: 0%;
  transition: width 400ms ease;
}

.quest-progress-label {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ---------- Content ---------- */
.quest-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 32px 0 40px;
}

/* ---------- Scenario ---------- */
.quest-scenario {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.quest-scenario-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--fg-faint);
  text-transform: uppercase;
}

.quest-scenario-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
  max-width: 580px;
}

/* ---------- Entry homepage ---------- */
.quest-hero {
  padding: 12px 0 10px;
}

.quest-kicker {
  margin: 0 0 18px;
  color: var(--fg-faint);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.quest-hero-title {
  margin: 0;
  max-width: 620px;
  color: var(--fg);
  font-size: clamp(42px, 11vw, 72px);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.quest-hero-copy {
  margin: 28px 0 0;
  max-width: 580px;
  color: var(--fg);
  font-size: 17px;
  line-height: 1.65;
}

.quest-hero-subcopy {
  margin: 16px 0 0;
  max-width: 580px;
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.75;
}

.quest-proof-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 30px 0 0;
}

.quest-proof-card {
  min-height: 174px;
  padding: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.quest-proof-label {
  display: block;
  margin-bottom: 18px;
  color: var(--fg-faint);
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.quest-proof-card strong {
  display: block;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 500;
}

.quest-proof-card p {
  margin: 12px 0 0;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.65;
}

.quest-start-block {
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
}

.quest-start-label {
  display: block;
  margin-bottom: 16px;
  color: var(--fg);
  font-size: 15px;
  line-height: 1.7;
}

/* ---------- Answer Buttons ---------- */
.quest-answer-btns {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.quest-answer-btn {
  flex: 1;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-answer-btn:hover {
  border-color: var(--fg-dim);
  background: var(--bg-elev);
}

.quest-answer-btn:active {
  transform: scale(0.98);
}

.quest-answer-btn[disabled] {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.quest-answer-btn.is-correct {
  border-color: var(--fg);
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
}

.quest-answer-btn.is-wrong {
  border-color: var(--fg-faint);
  color: var(--fg-faint);
  opacity: 0.5;
}

/* ---------- Explanation ---------- */
.quest-explanation {
  margin-top: 20px;
  padding: 16px 18px;
  background: var(--bg-elev);
  border-left: 2px solid var(--border);
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg-dim);
  animation: quest-fade-in 300ms ease;
}

.quest-explanation-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--fg-faint);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ---------- Primary Button ---------- */
.quest-btn {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg-faint);
  border-radius: 2px;
  padding: 12px 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-btn:hover {
  border-color: var(--fg);
  background: var(--bg-elev);
}

.quest-btn:active {
  transform: scale(0.98);
}

.quest-btn[disabled] {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ---------- Secondary Button ---------- */
.quest-btn-secondary {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 10px 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-btn-secondary:hover {
  border-color: var(--fg-dim);
  color: var(--fg);
}

/* ---------- Input ---------- */
.quest-input {
  width: 100%;
  min-height: 56px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.06em;
  outline: none;
  resize: none;
  overflow: hidden;
  transition: border-color 150ms ease;
}

.quest-input::placeholder {
  color: var(--fg-faint);
  letter-spacing: 0.1em;
}

.quest-input:focus {
  border-color: var(--fg-dim);
}

/* ---------- Timer ---------- */
.quest-timer {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  text-align: right;
  padding: 8px 0;
}

/* ---------- Stats ---------- */
.quest-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 0;
  border-top: 1px solid var(--border-soft);
}

.quest-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.quest-stats-label {
  color: var(--fg-faint);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.14em;
}

.quest-stats-value {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.quest-stats-highlight {
  color: var(--accent);
  font-weight: 500;
}

/* ---------- Pattern chips ---------- */
.quest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quest-chip {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-chip:hover {
  border-color: var(--fg-dim);
  color: var(--fg);
}

.quest-chip.is-selected {
  border-color: var(--fg);
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
}

/* ---------- Voice-first input ---------- */
.quest-voice-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 0 12px;
}

.quest-voice-btn {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--fg-faint);
  color: var(--fg-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 200ms ease, border-color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-voice-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.quest-voice-btn.is-recording {
  color: var(--fg);
  border-color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
}

.quest-voice-btn[disabled] {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.quest-voice-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid var(--fg-faint);
  opacity: 0;
  pointer-events: none;
}

.quest-voice-btn.is-recording .quest-voice-ring {
  animation: quest-ring-pulse 1.5s ease-out infinite;
}

@keyframes quest-ring-pulse {
  0%   { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.4); }
}

.quest-voice-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.quest-voice-status {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--fg-faint);
  text-align: center;
  text-transform: uppercase;
}

.quest-voice-timer {
  color: var(--fg);
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.quest-voice-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.quest-voice-control {
  min-width: 92px;
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-voice-control:hover {
  border-color: var(--fg-dim);
  color: var(--fg);
}

.quest-voice-control-primary {
  color: var(--fg);
  border-color: var(--fg-faint);
}

.quest-mode-toggle {
  background: none;
  border: none;
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  cursor: pointer;
  padding: 8px 0;
  margin-top: 8px;
  transition: color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.quest-mode-switch {
  display: block;
  margin: 6px auto 0;
  text-align: center;
}

.quest-mode-toggle:hover {
  color: var(--fg-dim);
}

/* ---------- PWA update modal ---------- */
.pwa-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}

.pwa-modal.is-open {
  display: flex;
}

.pwa-modal-card {
  width: min(100%, 360px);
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 22px;
}

.pwa-modal-title {
  color: var(--fg);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.pwa-modal-body {
  margin: 16px 0 0;
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1.65;
}

.pwa-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.pwa-btn {
  background: var(--fg);
  color: var(--bg);
  border: 1px solid var(--fg);
  border-radius: 2px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.pwa-btn-ghost {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border);
}

/* Legacy input row (kept for textarea styling) */
.quest-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.quest-input-row .quest-input {
  flex: 1;
  resize: none;
}

/* ---------- Loading scan line ---------- */
.quest-scan {
  padding: 24px 0;
  width: 100%;
}

.quest-scan-track {
  height: 1px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.quest-scan-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: var(--fg-faint);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
  animation: quest-scan-sweep 3s ease-in-out infinite;
}

@keyframes quest-scan-sweep {
  0%   { left: 0; width: 0%; }
  50%  { left: 0; width: 60%; }
  100% { left: 100%; width: 0%; }
}

/* ---------- Animations ---------- */
@keyframes quest-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes quest-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

.quest-fade-in {
  animation: quest-fade-in 300ms ease;
}

.quest-loading {
  animation: quest-pulse 1.4s ease-in-out infinite;
}

/* ---------- State: empty / loading ---------- */
.quest-empty {
  text-align: center;
  padding: 48px 0;
  color: var(--fg-faint);
  font-size: 12px;
  letter-spacing: 0.1em;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .quest-container {
    padding: 0 16px;
  }
  .quest-content {
    padding-top: 24px;
  }
  .quest-hero-title {
    font-size: 42px;
  }
  .quest-hero-copy {
    font-size: 15px;
    line-height: 1.7;
  }
  .quest-proof-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 24px;
  }
  .quest-proof-card {
    min-height: 0;
    padding: 14px;
  }
  .quest-proof-label {
    margin-bottom: 10px;
  }
  .quest-scenario-text {
    font-size: 14px;
  }
  .quest-answer-btn {
    padding: 12px 14px;
    font-size: 12px;
  }
  .quest-btn {
    padding: 11px 20px;
    font-size: 11px;
    width: 100%;
  }
  .quest-btn-secondary {
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 374px) {
  body {
    font-size: 14px;
  }
  .quest-answer-btns {
    flex-direction: column;
    gap: 8px;
  }
}

/* ---------- Reduce motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .quest-progress-fill {
    transition: none;
  }
}
