/* VocaBrain — "Vỏ não đang lớn"
   Paper + ink notebook; one hot pink for activity, highlighter yellow only for achievements.
   English headwords in Fraunces (collected specimens), interface in Be Vietnam Pro. */

:root {
  --paper: #eef0f5;
  --sheet: #fafbfd;
  --ink: #1c1b3a;
  --ink-2: #4a4968;
  --ink-3: #80859f;
  --rule: #d6d9e4;
  --pulse: #e8336d;
  --pulse-soft: #fbd5e1;
  --unknown: #9aa0b4;
  --glow: #ffe45c;
  --shadow: 0 1px 2px rgba(28, 27, 58, .06), 0 8px 24px rgba(28, 27, 58, .08);

  --f-word: "Fraunces", Georgia, serif;
  --f-ui: "Be Vietnam Pro", system-ui, sans-serif;
  --rail: 84px;
  --top: 64px;
  --nav: 0px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15142b;
    --sheet: #1f1e3b;
    --ink: #eceef6;
    --ink-2: #b9bbd0;
    --ink-3: #7f82a3;
    --rule: #302f52;
    --pulse: #ff4d85;
    --pulse-soft: #4a1f3a;
    --unknown: #696d8e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink); font: 400 16px/1.5 var(--f-ui);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--pulse); outline-offset: 2px; }

button {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px;
  padding: 9px 16px; cursor: pointer; font-weight: 500; transition: border-color .15s, background .15s;
}
button:hover { border-color: var(--ink-3); }
button.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
button.primary:hover { background: var(--ink-2); }
button.ghost { background: none; border-color: transparent; color: var(--ink-2); }
button.ghost:hover { color: var(--ink); border-color: var(--rule); }
button.danger { color: var(--pulse); }
button.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }

input, select, textarea {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 9px 12px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
textarea { width: 100%; resize: vertical; }
code { background: var(--paper); padding: 1px 5px; border-radius: 4px; font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.word { font-family: var(--f-word); font-variation-settings: "SOFT" 100, "WONK" 1; }

/* ---------- navigation rail (desktop) / bottom bar (mobile) ---------- */
.rail {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail); z-index: 30;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 0;
  background: var(--sheet); border-right: 1px solid var(--rule);
}
.rail .mark { width: 40px; height: 40px; margin-bottom: 18px; }
.rail button {
  width: 68px; border: 0; background: none; border-radius: 14px; padding: 10px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; color: var(--ink-3); position: relative;
}
.rail button svg { width: 24px; height: 24px; }
.rail button:hover { color: var(--ink); background: var(--paper); }
.rail button.active { color: var(--ink); background: var(--paper); }
.rail button.active svg { color: var(--pulse); }
.rail .add-btn {
  width: 52px; height: 52px; padding: 0; border-radius: 50%; background: var(--ink); color: var(--paper);
  font-size: 28px; font-weight: 300; margin: 10px 0; justify-content: center;
}
.rail .add-btn:hover { background: var(--pulse); color: #fff; }
.badge-n {
  position: absolute; top: 4px; right: 10px; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--pulse); color: #fff; font-size: 11px; line-height: 18px; font-weight: 600;
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: var(--rail); right: 0; height: var(--top); z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px);
}
.today { flex: none; display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.ring { width: 40px; height: 40px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring .track { stroke: var(--rule); }
.ring .fill { stroke: var(--pulse); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring.done .fill { stroke: var(--ink); }
.today b { color: var(--ink); font-weight: 600; }
.streak { background: var(--glow); color: #1c1b3a; border-radius: 4px; padding: 1px 8px; font-weight: 600; font-size: 13px; }
.search { position: relative; flex: 1; max-width: 520px; margin-left: auto; }
.search input { width: 100%; padding: 11px 16px; border-radius: 999px; background: var(--sheet); }
.suggest {
  position: absolute; top: 50px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; z-index: 40;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
  max-height: 340px; overflow: auto;
}
.suggest li { padding: 8px 12px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.suggest li:hover, .suggest li.sel { background: var(--paper); }
.suggest li .word { font-size: 17px; }
.suggest li .muted { margin-left: auto; font-size: 13px; }
#profile { border-radius: 999px; max-width: 160px; }

main { position: fixed; top: var(--top); left: var(--rail); right: 0; bottom: var(--nav); }
.view { display: none; position: absolute; inset: 0; overflow: auto; }
.view.active { display: block; }
.page { max-width: 780px; margin: 0 auto; padding: 20px 20px 60px; }
.page h1 { font: 600 28px/1.2 var(--f-ui); margin: 8px 0 6px; letter-spacing: -.01em; }
.page .lede { color: var(--ink-2); margin: 0 0 22px; max-width: 60ch; }

/* status dots, shared */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.known { background: var(--ink); }
.dot.learning { background: var(--pulse); }
.dot.ghost { border: 1.5px solid var(--unknown); }

/* ---------- brain ---------- */
#view-brain { overflow: hidden; }
#graph { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#graph.dragging { cursor: grabbing; }
.graph-tools { position: absolute; top: 8px; left: 20px; right: 20px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.graph-tools > * { flex: none; white-space: nowrap; }
.graph-tools button, .graph-tools select { padding: 6px 12px; font-size: 14px; border-radius: 999px; }
.graph-tools button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.legend {
  position: absolute; left: 20px; bottom: 16px; display: flex; flex-wrap: wrap; gap: 6px 16px; max-width: calc(100% - 40px);
  font-size: 13px; color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 22px; height: 8px; }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; pointer-events: none;
}
.empty h2 { font: 400 40px/1.15 var(--f-word); font-variation-settings: "SOFT" 100, "WONK" 1; margin: 0 0 12px; max-width: 16ch; }
.empty p { color: var(--ink-2); max-width: 46ch; margin: 0 0 22px; }
.empty .row { pointer-events: auto; justify-content: center; }

/* ---------- word sheet ---------- */
.sheet {
  position: fixed; top: calc(var(--top) + 8px); right: 12px; bottom: calc(var(--nav) + 12px); width: min(420px, calc(100% - 24px));
  z-index: 25; background: var(--sheet); border: 1px solid var(--rule); border-radius: 20px; box-shadow: var(--shadow);
  overflow: auto; padding: 24px 24px 28px; transform: translateX(calc(100% + 24px)); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet-close { position: absolute; top: 14px; right: 14px; padding: 4px 10px; border-radius: 999px; }
.w-head { padding-right: 40px; }
.w-head h2 { font: 400 44px/1.05 var(--f-word); font-variation-settings: "SOFT" 100, "WONK" 1; margin: 0; overflow-wrap: anywhere; }
.w-sub { display: flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--ink-3); flex-wrap: wrap; }
.speak { padding: 4px 10px; border-radius: 999px; font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.tag { font-size: 13px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-2); }
.tag.known { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tag.learning { background: var(--pulse); color: #fff; border-color: var(--pulse); }
.segmented { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; padding: 3px; margin-top: 14px; }
.segmented button { border: 0; border-radius: 999px; padding: 6px 14px; background: none; font-size: 14px; color: var(--ink-2); }
.segmented button.on-learning { background: var(--pulse); color: #fff; }
.segmented button.on-known { background: var(--ink); color: var(--paper); }
.sec { margin-top: 22px; }
.sec-h { display: flex; align-items: baseline; gap: 8px; margin: 0 0 8px; }
.sec-h h3 { margin: 0; font-size: 15px; font-weight: 600; }
.sec-h .count { font-size: 13px; color: var(--ink-3); }
.sec-h button { margin-left: auto; }
.vi-input { width: 100%; font-size: 17px; }
.defs { margin: 0; padding-left: 20px; }
.defs li { margin-bottom: 10px; line-height: 1.5; max-width: 62ch; }
.defs .pos { color: var(--ink-3); font-style: italic; font-size: 14px; margin-right: 4px; }
.defs .ex { display: block; color: var(--ink-2); font-family: var(--f-word); font-style: italic; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--f-word); font-size: 15px; padding: 3px 12px; border-radius: 999px; cursor: pointer;
  border: 1px dashed var(--unknown); color: var(--ink-2); background: none; font-weight: 400;
}
.chip:hover { border-style: solid; border-color: var(--ink); color: var(--ink); }
.chip.known { border: 1px solid var(--ink); background: var(--ink); color: var(--paper); }
.chip.learning { border: 1px solid var(--pulse); background: var(--pulse); color: #fff; }
.chip small { font-family: var(--f-ui); font-size: 11px; opacity: .75; margin-left: 4px; }
.chip .x { margin-left: 6px; opacity: .6; font-family: var(--f-ui); }
.add-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.loading { color: var(--ink-3); padding: 40px 0; text-align: center; }
.branch-lit { background: var(--glow); color: #1c1b3a; border-radius: 4px; padding: 0 6px; font-size: 13px; font-weight: 600; }

/* ---------- add menu ---------- */
.add-menu {
  position: fixed; z-index: 35; left: calc(var(--rail) + 8px); top: 50%; transform: translateY(-50%);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 16px; box-shadow: var(--shadow); padding: 8px; width: 290px;
}
.add-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 10px; padding: 10px 12px; }
.add-menu button:hover { background: var(--paper); }
.add-menu b { display: block; font-weight: 600; }
.add-menu span { color: var(--ink-3); font-size: 13px; font-weight: 400; }

/* ---------- swipe ---------- */
.deck-switch { display: flex; gap: 6px; margin-bottom: 18px; }
.deck-switch button { border-radius: 999px; }
.deck-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.swipe-stage { position: relative; height: 340px; display: flex; align-items: center; justify-content: center; }
.swipe-card {
  position: absolute; width: min(420px, 100%); height: 300px; background: var(--sheet); border: 1px solid var(--rule);
  border-radius: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 24px; text-align: center; touch-action: none; user-select: none; cursor: grab;
}
.swipe-card.behind { transform: scale(.95) translateY(14px); opacity: .6; pointer-events: none; }
.swipe-card .word { font-size: 52px; line-height: 1.05; overflow-wrap: anywhere; }
.swipe-card .hint { color: var(--ink-3); font-size: 14px; }
.swipe-card .stamp {
  position: absolute; top: 22px; font-weight: 700; font-size: 15px; padding: 3px 12px; border-radius: 6px; border: 2px solid; opacity: 0;
}
.swipe-card .stamp.yes { right: 22px; color: var(--ink); transform: rotate(8deg); }
.swipe-card .stamp.no { left: 22px; color: var(--pulse); transform: rotate(-8deg); }
.swipe-actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; max-width: 420px; margin: 18px auto 0; }
.swipe-actions .no { border-color: var(--pulse); color: var(--pulse); }
.swipe-meter { max-width: 420px; margin: 26px auto 0; }
.estimate { font: 400 56px/1 var(--f-word); font-variation-settings: "SOFT" 100, "WONK" 1; }
.meter { height: 6px; background: var(--rule); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.meter i { display: block; height: 100%; background: var(--pulse); transition: width .3s; }
.result-list { margin-top: 18px; }

/* ---------- review ---------- */
.review-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.card {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 24px; box-shadow: var(--shadow);
  padding: 34px 28px; min-height: 280px; display: grid; gap: 10px; align-content: center; justify-items: center; text-align: center;
}
.card .word.big { font-size: 56px; line-height: 1.05; overflow-wrap: anywhere; }
.card .prompt-vi { font-size: 26px; font-weight: 500; max-width: 26ch; }
.card .answer { width: min(340px, 100%); text-align: center; font: 400 26px var(--f-word); border-radius: 14px; }
.card .answer.right { border-color: var(--ink); background: var(--paper); }
.card .answer.wrong { border-color: var(--pulse); color: var(--pulse); }
.card .back { justify-self: stretch; text-align: left; border-top: 1px solid var(--rule); padding-top: 18px; margin-top: 8px; display: grid; grid-template-columns: 1fr 150px; gap: 16px; }
.card .back p { margin: 0 0 8px; }
.card .back .vi { font-size: 19px; font-weight: 600; }
.minimap { width: 150px; height: 150px; }
.minimap text { font-family: var(--f-word); font-size: 11px; fill: var(--ink-2); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grades button { display: grid; gap: 2px; padding: 12px 6px; }
.grades small { color: var(--ink-3); font-size: 12px; font-weight: 400; }
.grades .again { border-color: var(--pulse); }
.done-card .word.big { font-size: 44px; }

/* ---------- progress ---------- */
.hero-stat { display: grid; grid-template-columns: auto 1fr; gap: 6px 28px; align-items: end; margin-bottom: 8px; }
.hero-stat .estimate { font-size: 88px; }
.hero-stat p { margin: 0; color: var(--ink-2); max-width: 44ch; }
.ladder { list-style: none; margin: 24px 0 0; padding: 0; border-left: 2px solid var(--rule); }
.ladder li { position: relative; padding: 6px 0 6px 22px; color: var(--ink-3); }
.ladder li::before {
  content: ""; position: absolute; left: -7px; top: 13px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--rule);
}
.ladder li.reached { color: var(--ink); }
.ladder li.reached::before { background: var(--ink); border-color: var(--ink); }
.ladder li.next::before { border-color: var(--pulse); }
.ladder li b { display: inline-block; width: 70px; font-weight: 600; }
.ladder .gap { color: var(--pulse); font-size: 13px; margin-left: 6px; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 28px 0 0; padding: 18px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.facts div b { display: block; font-size: 26px; font-weight: 600; }
.facts div span { color: var(--ink-3); font-size: 13px; }
.block { margin-top: 36px; }
.block h2 { font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.block > p { color: var(--ink-3); font-size: 14px; margin: 0 0 14px; max-width: 62ch; }
.bands { display: grid; gap: 8px; }
.band { display: grid; grid-template-columns: 160px 1fr 64px; gap: 12px; align-items: center; font-size: 14px; }
.band .bar { height: 10px; background: var(--rule); border-radius: 99px; overflow: hidden; display: flex; }
.band .bar i { height: 100%; }
.band .k { background: var(--ink); }
.band .l { background: var(--pulse); }
.band .n { text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.days { display: flex; align-items: flex-end; gap: 4px; height: 80px; }
.days div { flex: 1; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.days div.today { background: var(--pulse); opacity: 1; }
.days-labels { display: flex; gap: 4px; font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.days-labels span { flex: 1; text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input { flex: 1; min-width: 160px; }
.words-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.words-list li {
  display: grid; grid-template-columns: 10px minmax(110px, 1fr) 2fr auto; gap: 14px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--rule); cursor: pointer;
}
.words-list li:hover { background: var(--sheet); }
.words-list .word { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.words-list .vi { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.words-list .meta { font-size: 12px; color: var(--ink-3); }

/* ---------- dialog / toast ---------- */
dialog {
  background: var(--sheet); color: var(--ink); border: 1px solid var(--rule); border-radius: 20px;
  width: min(560px, calc(100% - 32px)); padding: 24px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(21, 20, 43, .45); }
dialog h3 { margin: 0 0 6px; font-size: 20px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + 24px); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; max-width: calc(100% - 32px);
  box-shadow: var(--shadow); font-size: 15px;
}
.toast.win { background: var(--glow); color: #1c1b3a; font-weight: 600; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  :root { --rail: 0px; --nav: 68px; --top: 60px; }
  .rail {
    top: auto; right: 0; width: auto; height: calc(var(--nav) + env(safe-area-inset-bottom)); flex-direction: row;
    justify-content: space-around; padding: 4px 6px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--rule);
  }
  .rail .mark { display: none; }
  .rail button { width: auto; flex: 1; padding: 8px 0 6px; }
  .rail .add-btn { flex: none; width: 50px; height: 50px; margin: -18px 4px 0; box-shadow: var(--shadow); }
  .topbar { padding: 0 12px; gap: 10px; }
  .today .label { display: none; }
  .ring { width: 34px; height: 34px; }
  #profile { max-width: 92px; }
  .add-menu { left: 50%; top: auto; bottom: calc(var(--nav) + 12px); transform: translateX(-50%); }
  .sheet {
    top: auto; left: 0; right: 0; bottom: var(--nav); width: 100%; max-height: 60vh; border-radius: 22px 22px 0 0;
    transform: translateY(105%); padding: 22px 18px 28px;
  }
  .sheet.open { transform: none; }
  .w-head h2 { font-size: 36px; }
  .legend { display: none; }
  .graph-tools { left: 12px; right: 12px; }
  .graph-tools button, .graph-tools select { font-size: 13px; padding: 5px 10px; }
  .empty h2 { font-size: 30px; }
  .swipe-card .word { font-size: 42px; }
  .page { padding: 14px 16px 40px; }
  .page h1 { font-size: 23px; }
  .page .lede { font-size: 14px; margin-bottom: 14px; }
  .deck-switch button { font-size: 13px; padding: 6px 12px; }
  .swipe-stage { height: 260px; }
  .swipe-card { height: 230px; }
  .swipe-actions button { padding: 10px 8px; font-size: 14px; white-space: nowrap; }
  .card .word.big { font-size: 42px; }
  .card .back { grid-template-columns: 1fr; }
  .minimap { justify-self: center; }
  .hero-stat { grid-template-columns: 1fr; }
  .hero-stat .estimate { font-size: 64px; }
  .band { grid-template-columns: 110px 1fr 54px; font-size: 13px; }
  .words-list li { grid-template-columns: 10px 1fr auto; }
  .words-list .vi { grid-column: 2 / 4; grid-row: 2; }
  .grades { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
