@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@300;400;500&display=swap');

:root {
  --bg: #0c0a14;
  --surface: #12101c;
  --surface2: #1a1726;
  --border: #2a2540;
  --text: rgba(255,255,255,0.75);
  --text-strong: rgba(255,255,255,0.88);
  --dim: rgba(255,255,255,0.28);  /* = --dim-2, kept for compat */
  --muted: rgba(255,255,255,0.12);
  --gold: #FFE8C8;
  --gold-soft: rgba(255,232,200,0.08);
  --signal: #A08CFF;
  --signal-soft: rgba(160,140,255,0.10);
  --cool: #8CB8FF;
  --cool-soft: rgba(140,184,255,0.08);
  --warm: #FFC88C;
  --pink: #C8A0FF;
  --purple: #7C6CF0;
  /* ── Type Scale (1.2 modular) ── */
  --fs-xs: 0.7em;      /* 11.2px — labels, meta */
  --fs-sm: 0.82em;     /* 13.1px — secondary copy */
  --fs-body: 0.89em;   /* 14.2px — body */
  --fs-base: 1em;      /* 16px   — default */
  --fs-md: 1.15em;     /* 18.4px — native text emphasis */
  --fs-lg: 1.3em;      /* 20.8px — headings */
  --fs-xl: 1.6em;      /* 25.6px — well distance */
  --fs-2xl: 2.4em;     /* 38.4px — detail hero */
  /* ── Dim Tiers ── */
  --dim-1: rgba(255,255,255,0.18);  /* faintest — labels, metadata */
  --dim-2: rgba(255,255,255,0.28);  /* mid — default secondary */
  --dim-3: rgba(255,255,255,0.42);  /* readable — card context, descriptions */
  /* Aliases for legacy JS color refs */
  --accent: var(--signal);
  --accent-soft: var(--signal-soft);
  --green: var(--gold);
  --green-soft: var(--gold-soft);
  --red: var(--cool);
  --red-soft: var(--cool-soft);
  --orange: var(--warm);
  --blue: var(--cool);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100dvh; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app { max-width: 520px; margin: 0 auto; padding: 0 20px 40px; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 8px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: var(--fs-xs); font-weight: 500; color: var(--dim-1); letter-spacing: 0.06em; }
.topbar-back {
  background: none; border: 1px solid var(--border); color: var(--dim);
  width: 30px; height: 30px; border-radius: 9px; font-size: 0.95em;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; font-family: inherit;
}
.topbar-back:hover { color: var(--text); border-color: var(--signal); }
.user-name { font-size: var(--fs-xs); color: var(--signal); font-weight: 500; }

/* ── Gravity Well ── */
.well-wrap {
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 0 8px;
  animation: fadeUp 0.5s ease-out;
  transition: padding 0.6s cubic-bezier(0.22, 1.15, 0.36, 1);
}
.well-entering {
  animation: well-enter 1.2s ease-out both;
}
@keyframes well-enter {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}
.well-wrap canvas {
  display: block;
  transition: width 0.6s cubic-bezier(0.22, 1.15, 0.36, 1),
              height 0.6s cubic-bezier(0.22, 1.15, 0.36, 1);
}
.well-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xl); font-weight: 300; color: var(--dim-3);
  margin-top: 6px; cursor: pointer;
  transition: color 0.2s, opacity 0.4s, max-height 0.4s, margin 0.4s;
  letter-spacing: -0.03em; max-height: 60px; overflow: hidden;
}
.well-dist:hover { color: var(--text); }
.well-dist:empty { display: none; }
.well-helper {
  font-size: var(--fs-xs); color: var(--dim-1); text-align: center;
  margin-top: 4px; opacity: 0.5;
  transition: opacity 0.4s, max-height 0.4s, margin 0.4s;
  max-height: 30px; overflow: hidden;
}
.well-helper:empty { display: none; }

/* Well compact state (persistent during exercise/landscape) */
.well-wrap.well-compact { padding: 10px 0 0; }
.well-wrap.well-compact canvas { width: 70px !important; height: 70px !important; }
.well-wrap.well-compact .well-dist { opacity: 0; max-height: 0; margin: 0; pointer-events: none; }
.well-wrap.well-compact .well-helper { opacity: 0; max-height: 0; margin: 0; pointer-events: none; }

/* ── Voice Drift Log ── */
.drift-log {
  text-align: center; font-size: var(--fs-sm); color: var(--dim-3);
  padding: 10px 20px; margin-bottom: 12px; line-height: 1.5;
  font-style: italic; animation: fadeUp 0.5s ease-out;
}

/* ── Hint ── */
.hint-bar {
  text-align: center; font-size: var(--fs-xs); color: var(--dim-1);
  padding: 8px; margin-bottom: 12px; letter-spacing: 0.02em;
}

/* ── Cards ── */
.browser { }
.pick-label {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--dim-1); margin-bottom: 12px; font-weight: 600;
}
.pick-grid { display: flex; flex-direction: column; gap: 10px; }

.card {
  padding: 16px 18px; border-radius: 14px; cursor: pointer;
  background: var(--surface); transition: all 0.25s;
  border-left: 2px solid transparent;
}
.card:hover { background: var(--surface2); transform: translateY(-1px); }
.card:active { transform: translateY(0); }

.card-rationale {
  font-size: var(--fs-xs); color: var(--dim-3); margin-bottom: 6px;
  font-style: italic; line-height: 1.4;
}
.card-region {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--dim-1); font-weight: 600; margin-bottom: 3px;
}
.card-intent { font-size: var(--fs-body); font-weight: 600; line-height: 1.35; color: var(--text-strong); }
.card-context { font-size: var(--fs-sm); color: var(--dim-3); margin-top: 4px; line-height: 1.4; }
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.card-dots { display: none; } /* killed */
.card-register { font-size: var(--fs-xs); color: var(--dim-1); font-weight: 500; }

.browse-link {
  text-align: center; font-size: var(--fs-xs); color: var(--dim-1);
  padding: 14px; cursor: pointer; margin-top: 8px;
  border-radius: 10px; transition: all 0.2s;
}
.browse-link:hover { color: var(--signal); background: var(--signal-soft); }

/* ── Landscape ── */
.landscape-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.region-cell {
  padding: 20px 16px; border-radius: 14px;
  background: var(--surface); cursor: pointer;
  transition: all 0.5s; border: 1px solid transparent;
}
.region-cell:hover { background: var(--surface2); }
.region-cell .region-name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-strong); margin-bottom: 4px; }
.region-cell .region-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs); color: var(--dim-1); font-weight: 300;
}
.clarity-0 { filter: blur(5px); opacity: 0.25; }
.clarity-1 { filter: blur(2px); opacity: 0.50; }
.clarity-2 { filter: blur(0.5px); opacity: 0.78; border-color: var(--border); }
.clarity-3 { filter: none; opacity: 1; border-color: var(--border); }
.clarity-3 .region-name { color: var(--gold); }
.landscape-back {
  font-size: var(--fs-xs); color: var(--dim-1); cursor: pointer;
  padding: 10px 0; margin-bottom: 12px;
}
.landscape-back:hover { color: var(--signal); }

/* ── Exercise ── */
.exercise { display: none; }
.exercise.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.scenario-header { margin-bottom: 28px; }
.scenario-context { font-size: var(--fs-sm); color: var(--dim-3); line-height: 1.5; margin-bottom: 6px; }
.scenario-intent { font-size: var(--fs-lg); font-weight: 700; line-height: 1.3; color: var(--text-strong); letter-spacing: -0.02em; }

/* Console-style input */
.write-area { position: relative; }
.ghost {
  display: none; padding: 12px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-sm); color: var(--dim-1); opacity: 0.35;
}
.coach-hint {
  display: none; font-size: var(--fs-sm); margin-bottom: 10px;
  padding: 6px 12px; border-radius: 8px;
  background: var(--signal-soft); color: var(--signal); font-weight: 500;
}
.write-area textarea {
  width: 100%; padding: 18px 0;
  background: transparent; color: var(--text-strong);
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-md); font-weight: 400;
  resize: none; line-height: 1.7; min-height: 76px;
  border: none; border-bottom: 1px solid var(--border);
  border-radius: 0; transition: border-color 0.3s;
}
.write-area textarea:focus { outline: none; border-bottom-color: var(--signal); }
.write-area textarea:disabled { opacity: 0.15; }
.write-area textarea::placeholder {
  color: var(--muted); font-family: 'DM Sans', sans-serif;
  font-style: italic; font-weight: 400;
}
.go-btn {
  display: block; margin: 18px auto 0; padding: 11px 36px;
  background: transparent; color: var(--dim-2);
  border: 1px solid var(--border); border-radius: 24px;
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
  font-family: 'DM Sans', sans-serif; transition: all 0.25s;
}
.go-btn:hover:not(:disabled) { color: var(--text); border-color: var(--signal); background: var(--signal-soft); }
.go-btn:disabled { opacity: 0.12; cursor: not-allowed; }

/* ── Feedback ── */
.feedback { display: none; margin-top: 0; }
.feedback.active { display: block; }

.fb-stage-1, .fb-stage-2, .fb-stage-3 { opacity: 0; }

/* Region header */
.fb-region {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--dim-1); font-weight: 600; margin-bottom: 16px; display: block;
}

/* Scenario recap in feedback */
.fb-recap-context { font-size: var(--fs-sm); color: var(--dim-3); line-height: 1.5; margin-bottom: 4px; }
.fb-recap-intent { font-size: var(--fs-base); font-weight: 700; color: var(--text-strong); line-height: 1.3; margin-bottom: 16px; }

/* User attempt display */
.fb-attempt {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-body); color: rgba(200,185,255,0.8);
  padding: 10px 0; margin-bottom: 12px; line-height: 1.5;
}
.fb-attempt.snapped { color: var(--gold); }

/* ── Terrain Canvas ── */
.fb-terrain-wrap {
  position: relative; margin-bottom: 16px;
  border-radius: 14px; overflow: hidden;
  background: rgba(255,255,255,0.012);
}
.fb-terrain-wrap canvas { display: block; width: 100%; cursor: pointer; }
.terrain-hint {
  text-align: center; font-size: var(--fs-xs); color: var(--dim-1);
  padding: 6px 0 10px; animation: shimmer 2.5s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.55; }
}

/* Native card */
.fb-native {
  padding: 16px; margin-bottom: 14px; border-radius: 14px; background: var(--surface);
}
.fb-native-label {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--dim-1); font-weight: 600; margin-bottom: 5px;
}
.fb-native-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-md); font-weight: 400; color: var(--gold); line-height: 1.5;
  letter-spacing: 0.01em;
}
.fb-native-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs); color: var(--dim-1); margin-top: 6px; font-weight: 300;
}

/* ── Progressive Cards ── */
.fb-progressive {
  display: flex; gap: 12px; margin: 16px 0; cursor: pointer;
}
.fb-prog-bars {
  display: flex; flex-direction: column; gap: 4px;
  width: 4px; flex-shrink: 0; padding-top: 12px;
}
.fb-prog-bar {
  width: 4px; height: 18px; border-radius: 2px;
  opacity: 0.15; transition: opacity 0.4s;
}
.fb-prog-bar.lit { opacity: 1; }
.fb-prog-cards { flex: 1; min-width: 0; }
.fb-pcard {
  display: none; font-size: var(--fs-sm); line-height: 1.55; color: var(--text);
  padding: 12px 14px; margin-bottom: 8px; border-radius: 10px;
  background: rgba(255,255,255,0.018); border-left: 2px solid transparent;
}
.fb-pcard.active { display: block; }
.pcard-prefix { color: var(--signal); font-weight: 600; }
.pcard-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.pcard-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs); font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--dim-2); padding: 3px 8px;
  border: 1px solid var(--border); border-radius: 5px;
}
.fb-tap-hint { font-size: var(--fs-xs); color: var(--dim-1); opacity: 0.35; margin-top: 2px; }

/* ── Drill CTA ── */
.drill-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px; background: transparent; color: var(--dim);
  border: 1px solid var(--border); border-radius: 14px;
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.25s; margin: 14px 0;
}
.drill-btn:hover { border-color: var(--gold); color: var(--gold); background: rgba(255,232,200,0.04); }
.drill-arrow { font-size: 1.1em; }

/* ── Snap Message ── */
.fb-snap-msg {
  text-align: center; padding: 24px 16px; margin: 16px 0; border-radius: 16px;
  background: linear-gradient(160deg, rgba(255,232,200,0.04) 0%, transparent 60%);
  border: 1px solid rgba(255,232,200,0.06);
}
.fb-snap-msg h3 { font-size: var(--fs-lg); font-weight: 700; color: var(--gold); margin-bottom: 4px; }
.fb-snap-msg p { font-size: var(--fs-sm); color: var(--dim-3); line-height: 1.5; }

/* Actions */
.fb-actions { display: flex; gap: 8px; margin-top: 18px; }
.btn-retry, .btn-next {
  flex: 1; padding: 12px; border-radius: 12px; font-size: var(--fs-sm);
  font-weight: 600; cursor: pointer; text-align: center;
  background: transparent; color: var(--dim);
  border: 1px solid var(--border); transition: all 0.2s; font-family: inherit;
}
.btn-retry:hover, .btn-next:hover { border-color: var(--signal); color: var(--text); background: var(--signal-soft); }

/* ── Detail Panel ── */
.detail-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px; max-width: 360px;
  width: 92%; text-align: center; animation: rise 0.3s ease-out;
}
.detail-close {
  position: absolute; top: 12px; right: 16px;
  font-size: 1.3em; color: var(--dim); cursor: pointer;
  width: 30px; height: 30px; display: flex; align-items: center;
  justify-content: center; border-radius: 8px;
}
.detail-close:hover { color: var(--text); background: var(--surface2); }
.detail-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-2xl); font-weight: 300; color: var(--gold);
  margin-bottom: 4px; letter-spacing: -0.03em;
}
.detail-label { font-size: var(--fs-xs); color: var(--dim-1); margin-bottom: 16px; }
.detail-bars {
  display: flex; align-items: flex-end; justify-content: center;
  gap: 8px; height: 60px; margin-bottom: 16px;
}
.detail-bar {
  width: 20px; border-radius: 4px 4px 0 0;
  background: var(--signal); opacity: 0.4;
  transition: height 0.3s, opacity 0.3s;
}
.detail-bar:last-child { opacity: 0.8; }
.detail-dims { text-align: left; }
.detail-dim { margin-bottom: 8px; }
.detail-dim-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs); font-weight: 500; color: var(--dim-2);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px;
}
.detail-dim-desc { font-size: var(--fs-xs); color: var(--dim-3); font-style: italic; }
.detail-scale {
  height: 3px; background: var(--surface2); border-radius: 2px;
  position: relative; margin-top: 4px;
}
.detail-mark {
  position: absolute; top: -2px; width: 7px; height: 7px;
  border-radius: 50%; transform: translateX(-50%);
  transition: left 0.3s;
}
.detail-center { position: absolute; top: -1px; left: 50%; width: 1px; height: 5px; background: var(--gold); opacity: 0.2; }
.detail-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--fs-xs); color: var(--dim-1); margin-top: 16px;
  padding-top: 12px; border-top: 1px solid var(--border); font-weight: 300;
}

/* ── Overlay ── */
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(6,4,10,0.85);
  z-index: 100; align-items: center; justify-content: center;
  backdrop-filter: blur(12px);
}
.overlay.active { display: flex; }
#name-modal { background: rgba(6,4,10,0.68); backdrop-filter: blur(10px); }
.dialog {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 28px; max-width: 300px;
  width: 90%; text-align: center;
}
.dialog-lead { font-size: var(--fs-body); font-weight: 700; margin-bottom: 4px; color: var(--text-strong); }
.dialog-sub { font-size: var(--fs-sm); color: var(--dim-3); margin-bottom: 18px; }
.dialog input {
  width: 100%; padding: 13px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); font-weight: 400;
  text-align: center; margin-bottom: 12px;
}
.dialog input:focus { outline: none; border-color: var(--signal); }
.dialog input::placeholder { color: var(--muted); }
.dialog-btn {
  width: 100%; padding: 13px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.2s;
}
.dialog-btn:hover:not(:disabled) { border-color: var(--signal); background: var(--signal-soft); }
.dialog-btn:disabled { opacity: 0.12; }

/* ── Loading ── */
.loading { text-align: center; padding: 36px; color: var(--dim-2); font-size: var(--fs-sm); }
.spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 1.5px solid var(--border); border-top-color: var(--signal);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Onboarding ── */
.ob-card {
  text-align: center; padding: 40px 24px 28px;
}
.ob-title {
  font-size: var(--fs-lg); font-weight: 700; color: var(--text-strong);
  line-height: 1.4; margin-bottom: 10px;
}
.ob-detail {
  font-size: var(--fs-body); color: var(--dim-3); line-height: 1.6;
}
.ob-dots {
  display: flex; justify-content: center; gap: 8px; margin-bottom: 20px;
}
.ob-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border); transition: all 0.3s;
}
.ob-dot.active {
  background: var(--signal); width: 20px; border-radius: 3px;
}
.ob-btn {
  display: block; margin: 0 auto; padding: 13px 44px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 24px;
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.25s;
}
.ob-btn:hover {
  border-color: var(--signal); background: var(--signal-soft);
}

/* ── Card Stagger (spring-driven from JS) ── */

/* ── Mobile ── */
@media (max-width: 480px) {
  :root {
    --fs-lg: 1.15em;
    --fs-xl: 1.4em;
    --fs-2xl: 2em;
    --fs-md: 1.05em;
  }
  .app { padding: 0 16px 32px; }
  .fb-actions { flex-direction: column; }
}
