:root {
  --bg: #f5f2ea;
  --surface: #fffdf8;
  --ink: #1c2230;
  --muted: #5d6676;
  --line: #ddd6c8;
  --accent: #5b3fd6;
  --accent-ink: #ffffff;
  --said: #1b8a4b;
  --recalled: #1f6fd0;
  --revealed: #b26a00;
  --wrong: #c9342a;
  --missing: #a3a8b3;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1d2029;
    --ink: #eceef3;
    --muted: #a1a8b6;
    --line: #313543;
    --accent: #a08bff;
    --accent-ink: #14161c;
    --said: #4cc884;
    --recalled: #6aa8ff;
    --revealed: #e2a23c;
    --wrong: #ff7468;
    --missing: #5f6675;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ink);
  font: 700 22px/1 var(--display);
  cursor: pointer;
}
.brand em { color: var(--accent); }

.steps { display: flex; gap: 6px; font-size: 13px; color: var(--muted); }
.steps li { padding: 5px 12px; border-radius: 99px; border: 1px solid transparent; white-space: nowrap; }
.steps li.current { color: var(--ink); border-color: var(--ink); font-weight: 600; }
.steps li.done { color: var(--said); }

.account { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 14px; }
.account .link-button { margin: 0; }
.auth-card { max-width: 420px; margin: 0 auto; }
.auth-card h2 { font: 700 22px var(--display); }
.auth-card .hint { margin-top: 6px; }
.auth-switch { margin-top: 18px; font-size: 14px; color: var(--muted); }
.auth-switch .link-button { margin: 0; color: var(--accent); }

.banner {
  padding: 10px 24px;
  background: color-mix(in srgb, var(--revealed) 14%, var(--bg));
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

main { max-width: 1320px; margin: 0 auto; padding: 28px 24px 64px; }

/* ---------- shared pieces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.eyebrow {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.hint { color: var(--muted); font-size: 14px; }
.optional { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
code { font-size: 0.92em; padding: 1px 5px; border-radius: 5px; background: color-mix(in srgb, var(--ink) 8%, transparent); }

label { display: block; font-weight: 600; font-size: 14.5px; margin: 16px 0 6px; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; min-height: 96px; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: 600 15px var(--font);
  cursor: pointer;
  margin: 0;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.quiet { border-color: var(--line); font-weight: 500; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button:not(:disabled):hover { filter: brightness(1.08); }

.link-button {
  border: 0;
  background: none;
  padding: 0;
  margin-top: 18px;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 18px; }
.actions.centered { justify-content: center; margin-top: 28px; }
.status { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: flex-end; gap: 12px; }
.grow { flex: 1; min-width: 0; }

/* ---------- choose screen ---------- */

.hero { max-width: 760px; margin: 12px auto 26px; text-align: center; }
.hero h1 { font: 700 clamp(30px, 5vw, 46px)/1.12 var(--display); letter-spacing: -0.01em; }
.hero h1 span { color: var(--accent); }
.hero p { margin-top: 14px; color: var(--muted); font-size: 17px; }

.source-card { max-width: 760px; margin: 0 auto; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.tabs button {
  flex: 1;
  padding: 9px 8px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--muted);
  font: 600 14.5px var(--font);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); }

.tab-panel { padding-top: 4px; }
.tab-panel > p:first-child, .tab-panel > div > p:first-child { margin-top: 16px; }
.tab-panel .hint { margin-top: 8px; }
.tab-panel h3 { font-size: 14.5px; margin: 20px 0 8px; }
.tab-panel h3 .hint { font-weight: 400; margin-left: 6px; }
.plain { margin: 10px 0 16px; color: var(--muted); font-size: 14.5px; }
.plain li { padding-left: 18px; position: relative; }
.plain li::before { content: "·"; position: absolute; left: 6px; font-weight: 700; }

.file-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.file-row label { margin: 0; }
.file-row .hint { margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 13.5px;
  max-width: 100%;
}
.chips li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; }

.pick-list { border: 1px solid var(--line); border-radius: 10px; max-height: 232px; overflow-y: auto; }
.pick-list li + li { border-top: 1px solid var(--line); }
.pick-list label { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 10px 12px; font-weight: 500; cursor: pointer; }
.pick-list input { margin-top: 4px; accent-color: var(--accent); }
.pick-list .meta { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.pick-list .empty { padding: 12px; color: var(--muted); font-size: 14px; }
.tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 11.5px; font-weight: 700; vertical-align: 1px; }

.history { max-width: 760px; margin: 30px auto 0; }
.history h2 { font-size: 15px; margin-bottom: 10px; }
.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.history .meta { color: var(--muted); font-size: 13.5px; }

.privacy { max-width: 760px; margin: 26px auto 0; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- explain / probe screen ---------- */

.work { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 20px; align-items: start; }

.map-card { padding: 16px 16px 12px; }
.map-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 2px 6px 10px; }
.map-head h2 { font: 700 20px/1.2 var(--display); }
.count { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.map-wrap { position: relative; }
.map { display: block; width: 100%; height: auto; border-radius: 10px; background: var(--bg); }
.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font: italic 18px var(--display);
  pointer-events: none;
  transition: opacity 0.4s;
}
.map-empty.gone { opacity: 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 12px 6px 2px; color: var(--muted); font-size: 13px; }
.legend.centered { justify-content: center; padding: 14px 0 0; }
.legend li { display: inline-flex; align-items: center; gap: 7px; }
.key { display: inline-block; width: 26px; height: 0; border-top: 3px solid; }
.key.said { border-color: var(--said); }
.key.recalled { border-color: var(--recalled); }
.key.revealed { border-color: var(--revealed); border-top-style: dashed; }
.key.wrong { border-color: var(--wrong); border-top-width: 4px; }
.key.missing { border-color: var(--missing); border-top-style: dotted; }

.panel h2 { font: 700 21px/1.25 var(--display); }
.panel .hint { margin-top: 8px; }

.mic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  border: 2px solid var(--accent);
  border-radius: 14px;
  background: transparent;
  color: var(--accent);
  font: 700 16px var(--font);
  cursor: pointer;
}
.mic svg { width: 26px; height: 26px; }
.mic.small { padding: 11px; font-size: 15px; }
.mic.listening { background: var(--accent); color: var(--accent-ink); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe {
  50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 22%, transparent); }
}

.interim { min-height: 21px; margin-top: 6px; color: var(--muted); font-style: italic; font-size: 14px; }

.feedback { margin-top: 16px; padding: 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); }
.feedback.good { border-color: var(--recalled); }
.feedback.shown { border-color: var(--revealed); }
.verdict { font-weight: 700; }
.feedback.good .verdict { color: var(--recalled); }
.feedback.shown .verdict { color: var(--revealed); }
.fact { font: 700 18px/1.3 var(--display); margin: 6px 0; }
.you-said { margin-top: 10px; padding-left: 12px; border-left: 3px solid var(--wrong); color: var(--muted); font-size: 14.5px; }

/* ---------- the map itself ---------- */

.node { opacity: 0; transition: opacity 0.45s; }
.node.show { opacity: 1; }
.node-inner { transform-box: fill-box; transform-origin: center; transform: scale(0.6); transition: transform 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }
.node.show .node-inner { transform: scale(1); }
.node rect { fill: var(--surface); stroke: var(--ink); stroke-width: 1.7; transition: stroke 0.3s; }
.node text { font: 600 15.5px var(--font); fill: var(--ink); }
.node.ghost rect { fill: var(--bg); stroke: var(--missing); stroke-dasharray: 4 4; }
.node.ghost text { fill: var(--missing); }
.node.focus rect { stroke: var(--accent); stroke-width: 2.8; }

.link { opacity: 0; transition: opacity 0.5s; }
.link.show { opacity: 1; }
.link path { stroke: var(--missing); stroke-width: 2.6; stroke-linecap: round; transition: stroke 0.4s; }
.link-label { font: 600 13.5px var(--font); paint-order: stroke; stroke: var(--bg); stroke-width: 6px; stroke-linejoin: round; fill: var(--muted); }
.link.said path { stroke: var(--said); }
.link.said .link-label { fill: var(--said); }
.link.recalled path { stroke: var(--recalled); }
.link.recalled .link-label { fill: var(--recalled); }
.link.revealed path { stroke: var(--revealed); stroke-dasharray: 10 6; }
.link.revealed .link-label { fill: var(--revealed); }
.link.wrong path { stroke: var(--wrong); stroke-width: 3.4; }
.link.wrong .link-label { fill: var(--wrong); font-weight: 800; }
.link.missing path { stroke-width: 1.7; stroke-dasharray: 2 7; }
.link.focus path { stroke: var(--accent); stroke-width: 3.2; stroke-dasharray: 8 7; animation: march 0.9s linear infinite; }
@keyframes march { to { stroke-dashoffset: -15; } }

.arrow-said { fill: var(--said); }
.arrow-recalled { fill: var(--recalled); }
.arrow-revealed { fill: var(--revealed); }
.arrow-wrong { fill: var(--wrong); }
.arrow-missing { fill: var(--missing); }
.arrow-focus { fill: var(--accent); }

/* ---------- review screen ---------- */

.summary-head { text-align: center; margin-bottom: 22px; }
.summary-head h1 { font: 700 clamp(28px, 4.4vw, 40px)/1.15 var(--display); }
.summary-head .hint { margin-top: 8px; font-size: 15px; }

.score-card { max-width: 1000px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; align-items: center; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 54px; align-items: center; gap: 12px; }
.bar-row + .bar-row { margin-top: 14px; }
.bar-label { font-size: 14.5px; font-weight: 600; }
.bar { height: 16px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 99px; transition: width 0.9s cubic-bezier(0.2, 0.8, 0.2, 1); }
.fill.before { background: var(--said); }
.fill.after { background: var(--recalled); }
.bar-value { font: 700 20px var(--display); text-align: right; font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tiles li { padding: 12px 8px; border-radius: 12px; background: var(--bg); text-align: center; border-top: 4px solid var(--missing); }
.tiles li.said { border-color: var(--said); }
.tiles li.recalled { border-color: var(--recalled); }
.tiles li.fixed { border-color: var(--accent); }
.tiles li.todo { border-color: var(--revealed); }
.tiles strong { display: block; font: 700 26px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.tiles span { font-size: 12.5px; color: var(--muted); }

.big-map { max-width: 1000px; margin: 20px auto 0; padding: 14px; }
.switch { display: flex; gap: 4px; padding: 4px; margin: 0 auto 12px; width: fit-content; max-width: 100%; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.switch button { padding: 8px 14px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: 600 14px var(--font); cursor: pointer; }
.switch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); }

.review { margin: 20px auto 0; max-width: 1000px; }
.review h2 { font: 700 20px var(--display); margin-bottom: 6px; }
.review li { padding: 14px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: start; }
.review li:first-child { border-top: 0; }
.review .fact { font-size: 17px; margin: 0 0 4px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; border: 1.5px solid; text-align: center; }
.chip.wrong { color: var(--wrong); }
.chip.revealed { color: var(--revealed); }
.chip.missing { color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14.5px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.28);
  z-index: 10;
}

/* ---------- small screens ---------- */

@media (max-width: 940px) {
  .work, .score-card { grid-template-columns: 1fr; }
  .steps li:not(.current) { display: none; }
  #maps-left { display: none; }
}
@media (max-width: 560px) {
  main { padding: 20px 16px 48px; }
  .top { padding: 12px 16px; }
  .card { padding: 16px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 1fr 48px; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .review li { grid-template-columns: 1fr; gap: 6px; }
  .tabs button { font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
