/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --border: #e2e0d8;
  --grid: #e8e6df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #c93c3b;
  --ok: #1a8a5f;
  --warn: #a86f00;
  --tooltip-bg: #1f1f1d;
  --tooltip-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);

  /* student colours, fixed order */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  /* word stages: one hue, light -> dark */
  --st1: #d5ebdd; --st2: #94cfa9; --st3: #4ca66f; --st4: #1d6b3e;
  /* answers: red side = forgot, green side = knew it */
  --ans1: #e34948; --ans2: #f2a9a8; --ans3: #93d3b7; --ans4: #1baf7a;

  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --grid: #2a2a28;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --danger: #e66767; --ok: #3cc28e; --warn: #e0a33a;
    --tooltip-bg: #f2f1ec; --tooltip-ink: #111;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #2f9a2f;
    --st1: #23422f; --st2: #2f6b45; --st3: #46a066; --st4: #8fd6a8;
    --ans1: #e66767; --ans2: #8a4544; --ans3: #2c6e55; --ans4: #3cc28e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --grid: #2a2a28;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --danger: #e66767; --ok: #3cc28e; --warn: #e0a33a;
  --tooltip-bg: #f2f1ec; --tooltip-ink: #111;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #2f9a2f;
  --st1: #23422f; --st2: #2f6b45; --st3: #46a066; --st4: #8fd6a8;
  --ans1: #e66767; --ans2: #8a4544; --ans3: #2c6e55; --ans4: #3cc28e;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .9rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.grow { flex: 1 1 auto; }
.spacer { flex: 1; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
body.narrow .wrap { max-width: 440px; padding-top: 10vh; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text-2); }
.topbar nav a.on, .topbar nav a:hover { background: var(--surface-2); color: var(--text); }

.card-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }

.row { display: flex; gap: 10px; align-items: center; }
.row > label { flex: 1; }
.wrap-row { flex-wrap: wrap; }
.center { justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; align-items: start; }
.grid-2 > .card-panel { margin-bottom: 0; }
section.grid-2 { margin-bottom: 18px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); font-weight: 500; }
label.check, .row > label.check { flex: none; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--text); }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.big-input { font-size: 1.15rem; font-weight: 600; }
input[type=search] { width: auto; min-width: 160px; }
.flash-in { animation: flashin .8s ease; }
@keyframes flashin { from { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); } to { background: var(--surface); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: .9rem; font-weight: 600; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ai { background: linear-gradient(135deg, #7b5cff, #d95ca8); color: #fff; border-color: transparent; }
.btn.ai:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.subtle { color: var(--text-2); }
.btn.small { padding: 4px 9px; font-size: .8rem; border-radius: 8px; }
.btn.big { font-size: 1.1rem; padding: 14px 28px; border-radius: 14px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; background: color-mix(in srgb, var(--ok) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.err-msg { color: var(--danger); margin: 0; }
.ok-msg { color: var(--ok); font-weight: 600; }

/* student colour slots */
.slot-1 { --sc: var(--s1); } .slot-2 { --sc: var(--s2); } .slot-3 { --sc: var(--s3); }
.slot-4 { --sc: var(--s4); } .slot-5 { --sc: var(--s5); } .slot-6 { --sc: var(--s6); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--sc, var(--muted)); margin-right: 7px; flex: none; }
.student-box { border-top: 4px solid var(--sc); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.st-new { background: var(--surface-2); }
.pill.st-learning { background: color-mix(in srgb, var(--ans1) 16%, var(--surface)); color: var(--text); }
.pill.st-familiar { background: color-mix(in srgb, var(--st3) 22%, var(--surface)); color: var(--text); }
.pill.st-mastered { background: var(--st4); color: #fff; }

/* tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; padding: 8px 16px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); font-weight: 600; }
.tab.on { border-color: var(--sc); box-shadow: inset 0 0 0 1px var(--sc); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-size: .88rem; font-weight: 600; }
.segmented a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.head-row { margin-bottom: 16px; }
.head-row h1 { margin: 0; }

/* words page */
.words-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.words-layout > .card-panel { margin-bottom: 18px; }
@media (max-width: 860px) { .words-layout { grid-template-columns: 1fr; } }
.bulk-log { list-style: none; padding: 0; margin: 10px 0 0; font-size: .88rem; max-height: 260px; overflow: auto; }
.bulk-log li { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.bulk-log li.ok { color: var(--ok); }
.bulk-log li.bad { color: var(--danger); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.words-table td.actions { white-space: nowrap; text-align: right; }
form.inline { display: inline; }

/* dashboard */
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 18px; margin-bottom: 18px; }
.hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); border-left: 5px solid var(--sc); }
.hero-name { font-weight: 700; display: flex; align-items: center; gap: 4px; }
.hero-num { font-size: 2.6rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.hero-num .unit { font-size: 1rem; font-weight: 500; color: var(--text-2); }
.hero-sub { color: var(--text-2); }
.crown { font-size: 1.2rem; }
table.versus th[scope=row] { font-weight: 500; color: var(--text-2); }
table.versus td, table.versus thead th { text-align: center; font-variant-numeric: tabular-nums; }
table.versus thead th { color: var(--text); text-transform: none; letter-spacing: 0; font-size: .95rem; }
table.versus td.win { font-weight: 750; color: var(--text); background: color-mix(in srgb, var(--ok) 12%, transparent); }
table.versus td.win::after { content: " ★"; color: var(--warn); }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.chart-grid .card-panel { margin-bottom: 0; }
.chart-card.wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .chart-grid { grid-template-columns: minmax(0, 1fr); } }
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 200px; }
.hard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.hard-grid h3 { display: flex; align-items: center; }
.hard-list { margin: 0; padding-left: 20px; }
.hard-list li { margin-bottom: 4px; }
table.simple td:first-child { white-space: nowrap; }

/* ---------- student study page ---------- */
body.study { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.study-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.today-stats { color: var(--text-2); font-size: .9rem; }
.study-main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 16px 32px; width: 100%; max-width: 620px; margin: 0 auto; }
.screen { width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
#screen-start, #screen-done, #screen-loading { padding-top: 6vh; }
.done-emoji { font-size: 3.5rem; }
.board-box { width: 100%; margin-top: 18px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.board-row { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 4px 12px; align-items: center; padding: 8px 0; }
.board-row + .board-row { border-top: 1px solid var(--border); }
.board-row.me .board-name { font-weight: 750; }
.board-name { display: flex; align-items: center; }
.board-bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.board-bar span { display: block; height: 100%; background: var(--sc); border-radius: 99px; transition: width .6s ease; }
.board-nums { grid-column: 1 / -1; font-size: .85rem; color: var(--text-2); }

.progress { width: 100%; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.progress-label { align-self: flex-end; margin-top: -6px; }

.flashcard { position: relative; width: 100%; min-height: 360px; perspective: 1400px; cursor: pointer; outline: none; }
.flashcard .face { position: absolute; inset: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 2px 4px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.08); padding: 28px 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; backface-visibility: hidden; -webkit-backface-visibility: hidden; transition: transform .45s cubic-bezier(.2,.7,.3,1); overflow-y: auto; }
.flashcard .back { transform: rotateY(180deg); justify-content: flex-start; padding-top: 34px; }
.flashcard.flipped .front { transform: rotateY(-180deg); }
.flashcard.flipped .back { transform: rotateY(0); }
.flashcard:focus-visible .face { outline: 2px solid var(--accent); }
.word { font-size: clamp(2rem, 8vw, 3rem); font-weight: 750; letter-spacing: -.02em; line-height: 1.15; word-break: break-word; }
.small-word { font-size: 1.3rem; color: var(--text-2); }
.meta { color: var(--text-2); font-size: 1rem; }
.meta #c-ipa { font-family: "Lucida Sans Unicode", "Arial Unicode MS", system-ui, sans-serif; }
.hint { position: absolute; bottom: 16px; }
.badge-new { position: absolute; top: 16px; left: 16px; background: var(--s4); color: #1a1300; font-size: .72rem; font-weight: 800; padding: 3px 9px; border-radius: 99px; letter-spacing: .05em; }
.speak { position: absolute; top: 12px; right: 12px; border: 0; background: var(--surface-2); border-radius: 50%; width: 42px; height: 42px; font-size: 1.15rem; cursor: pointer; }
.speak:hover { filter: brightness(.95); }
.translation { font-size: 1.7rem; font-weight: 700; color: var(--accent); line-height: 1.25; }
.definition { font-size: 1.05rem; color: var(--text); max-width: 46ch; }
.examples { list-style: none; padding: 0; margin: 4px 0 0; text-align: left; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.examples li { background: var(--surface-2); padding: 10px 14px; border-radius: 12px; font-style: italic; color: var(--text-2); }
.examples mark { background: transparent; color: var(--text); font-weight: 700; font-style: normal; }
.note { font-size: .92rem; background: color-mix(in srgb, var(--s4) 16%, var(--surface)); border-radius: 12px; padding: 9px 14px; width: 100%; text-align: left; }
.note::before { content: "💡 "; }

.show-btn { width: 100%; margin-top: 6px; }
.answer-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; margin-top: 6px; }
.ans { font: inherit; border: 0; border-radius: 14px; padding: 12px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #fff; font-weight: 700; font-size: 1rem; transition: transform .08s; }
.ans:active { transform: scale(.96); }
.ans .when { font-size: .75rem; font-weight: 500; opacity: .9; min-height: 1em; }
.ans.again { background: #d64545; }
.ans.hard { background: #c98500; }
.ans.good { background: #1f9a6b; }
.ans.easy { background: #2a78d6; }

@media (max-width: 480px) {
  .flashcard { min-height: 58vh; }
  h1 { font-size: 1.35rem; }
  .card-panel { padding: 16px; }
  .words-table th:nth-child(4), .words-table td:nth-child(4),
  .words-table th:nth-child(6), .words-table td:nth-child(6) { display: none; }
}
