:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #77756f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --good: #0ca30c;
  --warn: #c98500;
  --bad: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e8e7e2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --accent-soft: #1d2b3d;
    --good: #2fbf2f;
    --warn: #fab219;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #2f2f2c;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #9a998f;
  --accent: #3987e5;
  --accent-soft: #1d2b3d;
  --good: #2fbf2f;
  --warn: #fab219;
  --bad: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2a2a27;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h3 { margin: 0 0 .6rem; font-size: 1.02rem; }
pre { background: var(--surface-2); padding: .6rem .8rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; white-space: pre-wrap; word-break: break-all; }
kbd { font-size: .72em; border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; margin-left: .3em; opacity: .8; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="number"], input:not([type]), select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .9rem;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
}
button:hover, .button:hover { filter: brightness(.97); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
button.link { background: none; border: none; color: var(--accent); padding: .2rem; }
.icon-btn { background: none; border: none; font-size: 1.2rem; padding: .3rem .5rem; }

.topbar { display: flex; align-items: center; gap: .8rem; padding: .7rem 16px; max-width: 980px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; white-space: nowrap; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-left: auto; justify-content: flex-end; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .15rem .6rem; font-size: .8rem; color: var(--text-2); white-space: nowrap; }
.chip b { color: var(--text); }

.tabs { display: flex; gap: .3rem; padding: 0 16px; max-width: 980px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: .55rem .7rem; white-space: nowrap; color: var(--text-2); gap: .3rem; position: relative; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .72rem; padding: 0 .45rem; margin-left: .2rem; }

main { max-width: 980px; margin: 0 auto; padding: 12px 16px 64px; }
.tab { display: none; }
.tab.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 12px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; }
.row.space { justify-content: space-between; }
.row.center, .center { justify-content: center; text-align: center; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.label { display: block; margin-bottom: .4rem; color: var(--text-2); }

/* dictation */
.dictation { text-align: center; padding: 1.4rem 1rem 1rem; }
.mode-switch { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; margin-bottom: 1rem; }
.mode-switch label { padding: .3rem .9rem; border-radius: 999px; cursor: pointer; font-size: .9rem; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch label:has(input:checked) { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.mic { width: 104px; height: 104px; border-radius: 50%; background: var(--accent); color: #fff; border: none; margin: 0 auto; display: flex; touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .12s; }
.mic.listening { background: var(--bad); transform: scale(1.06); animation: pulse 1.4s infinite; }
.mic.busy { opacity: .85; }
.mic.small { width: 64px; height: 64px; font-size: 1.6rem; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(208, 59, 59, .45); } 100% { box-shadow: 0 0 0 22px rgba(208, 59, 59, 0); } }
.meter { height: 4px; width: 160px; margin: .9rem auto .3rem; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--good); transition: width .06s; }
.interim { min-height: 1.5em; font-size: 1.3rem; font-weight: 600; margin: .2rem 0; }

.confirm-item { border: 1px solid var(--border); border-radius: 12px; padding: .7rem; margin-bottom: .6rem; }
.confirm-item .heard { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.confirm-item input { flex: 1; min-width: 8rem; font-size: 1.1rem; font-weight: 600; }
.confidence { font-size: .75rem; color: var(--muted); }
.alts { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; }
.alts button { padding: .2rem .65rem; border-radius: 999px; font-size: .9rem; }

.goal { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: .6rem; }
.goal div { height: 100%; width: 0; background: var(--good); border-radius: 3px; transition: width .3s; }

/* word lists */
.word-list { list-style: none; margin: 0; padding: 0; }
.word-list li { display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem; padding: .65rem 0; border-top: 1px solid var(--border); }
.word-list li:first-child { border-top: none; }
.word-list.compact li { padding: .45rem 0; }
.w-main { min-width: 0; }
.w-text { font-weight: 650; font-size: 1.05rem; }
.w-ph { color: var(--muted); font-size: .85rem; margin-left: .35rem; }
.w-tr { color: var(--text-2); }
.w-def, .w-ex { font-size: .88rem; color: var(--muted); }
.w-ex { font-style: italic; }
.w-side { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }
.w-actions { display: flex; gap: .2rem; }
.w-actions button { padding: .15rem .45rem; font-size: .85rem; background: none; border-color: transparent; }
.status { font-size: .72rem; border-radius: 999px; padding: .05rem .5rem; border: 1px solid var(--border); white-space: nowrap; }
.status.new { color: var(--series-1); }
.status.learning { color: var(--warn); }
.status.mastered { color: var(--good); }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1 1 14rem; }
.dict-layout { display: grid; grid-template-columns: 220px 1fr; gap: 12px; align-items: start; }
.days ul { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.days li button { width: 100%; justify-content: space-between; background: none; border: none; border-radius: 8px; padding: .35rem .5rem; }
.days li button.active { background: var(--accent-soft); font-weight: 600; }
.days li small { color: var(--muted); }

/* review */
.review-card { text-align: center; min-height: 260px; display: flex; flex-direction: column; justify-content: center; gap: .6rem; }
.front { font-size: 2rem; font-weight: 700; word-break: break-word; }
.front .sub { display: block; font-size: .95rem; font-weight: 400; color: var(--muted); }
.back { font-size: 1.15rem; }
.back .def, .back .ex { font-size: .95rem; color: var(--muted); }
.back .ex { font-style: italic; }
#review-input input { font-size: 1.3rem; text-align: center; width: min(100%, 22rem); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.grades button { flex-direction: column; padding: .55rem .3rem; }
.grades small { font-size: .72rem; color: var(--muted); }
.grades .g0 { border-color: var(--bad); }
.grades .g2 { border-color: var(--good); }
.correct { color: var(--good); font-weight: 700; }
.wrong { color: var(--bad); font-weight: 700; }

/* progress */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.tile .v { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.tile .k { color: var(--muted); font-size: .82rem; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--text-2); margin-top: .4rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.stack { display: flex; height: 18px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); }
.stack div { height: 100%; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--surface); font-size: .8rem; padding: .3rem .55rem; border-radius: 6px; white-space: nowrap; }

/* sync & audit */
#sync-btn.spinning svg { animation: spin 1s linear infinite; }
#sync-btn.error { color: var(--bad); }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-info { font-size: .92rem; }
.sync-info b { color: var(--text); }
.sync-info .err { color: var(--bad); }
.sync-info table { width: 100%; border-collapse: collapse; margin-top: .4rem; }
.sync-info td { padding: .25rem .3rem; border-top: 1px solid var(--border); }
.audit-list { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.audit-list li { padding: .4rem 0; border-top: 1px solid var(--border); display: flex; gap: .6rem; flex-wrap: wrap; }
.audit-list li:first-child { border-top: none; }
.audit-list time { color: var(--muted); font-size: .8rem; min-width: 7.5rem; }
.audit-list .actor { font-size: .72rem; border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; color: var(--text-2); }

/* agent */
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.plan-options { margin-top: .7rem; }
.plan-options input[type="text"] { flex: 1 1 14rem; }
.chat-log { max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; margin-bottom: .6rem; }
.msg { padding: .6rem .8rem; border-radius: 12px; max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg.assistant { align-self: flex-start; background: var(--surface-2); }
.msg.pending { color: var(--muted); font-style: italic; }
.msg .tools { font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.chat form input { flex: 1; }
.markdown table { border-collapse: collapse; width: 100%; font-size: .9rem; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: .3rem .5rem; text-align: left; vertical-align: top; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-size: 1rem; margin: .9rem 0 .4rem; }
.markdown p, .markdown ul, .markdown ol { margin: .4rem 0; }
.markdown code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: .6rem .9rem; border-radius: 12px; display: flex; gap: .8rem; align-items: center; z-index: 30; max-width: calc(100vw - 32px); }
.toast button { background: none; border: none; color: var(--surface); text-decoration: underline; padding: 0; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); padding: 1rem; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog label { display: block; margin: .4rem 0; color: var(--text-2); font-size: .9rem; }
dialog input, dialog textarea { width: 100%; margin-top: .15rem; }

@media (max-width: 700px) {
  /* bottom navigation on phones */
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--border); padding: 0 0 env(safe-area-inset-bottom); gap: 0; max-width: none; }
  .tabs button { flex: 1 1 0; flex-direction: column; gap: 0; padding: .4rem .1rem .45rem; font-size: .7rem; border-bottom: none; border-top: 2px solid transparent; min-width: 0; }
  .tabs button.active { border-top-color: var(--accent); }
  .tabs .ti { font-size: 1.15rem; line-height: 1.2; }
  .tabs .badge { position: absolute; top: 2px; right: calc(50% - 1.6rem); margin: 0; }
  main { padding-bottom: 90px; }
  .toast { bottom: 76px; }
  .dict-layout { grid-template-columns: 1fr; }
  .days ul { max-height: 9.5rem; }
  .chips .chip.opt { display: none; }
  .brand span { display: none; }
  .front { font-size: 1.6rem; }
}
