:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef1f6; --text: #16202e; --muted: #5d6878; --border: #dde2ea;
  --primary: #00205b; --primary-ink: #ffffff; --accent: #ba0c2f; --good: #1b7f3b; --warn: #b4501a; --link: #1d4ed8;
  --a1: #2e7d32; --a2: #0277bd; --b1: #6a1b9a; --b2: #ba0c2f; --c1: #37474f;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-w: 220px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --surface-2: #202937; --text: #e6ebf2; --muted: #9aa6b6; --border: #2c3747;
    --primary: #7aa2ff; --primary-ink: #0b1220; --accent: #ff5c7a; --good: #4ade80; --warn: #fdba74; --link: #93b4ff;
    --a1: #66bb6a; --a2: #4fc3f7; --b1: #ce93d8; --b2: #ff6f8a; --c1: #b0bec5; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e28; --surface-2: #202937; --text: #e6ebf2; --muted: #9aa6b6; --border: #2c3747;
  --primary: #7aa2ff; --primary-ink: #0b1220; --accent: #ff5c7a; --good: #4ade80; --warn: #fdba74; --link: #93b4ff;
  --a1: #66bb6a; --a2: #4fc3f7; --b1: #ce93d8; --b2: #ff6f8a; --c1: #b0bec5; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); background: var(--bg); color: var(--text); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--link); }
h1 { font-size: 1.55rem; margin: .2em 0 .4em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 1em 0 .4em; }
h4 { margin: .8em 0 .3em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }
.good { color: var(--good); } .warn { color: var(--warn); } .danger { color: var(--accent); }
.hidden { display: none !important; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
.spacer { flex: 1; }

/* Shell */
.top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .5rem; padding: .55rem 1rem; background: var(--primary); color: var(--primary-ink); padding-top: calc(.55rem + env(safe-area-inset-top)); }
:root[data-theme="dark"] .top { background: #0b1830; color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .top { background: #0b1830; color: #fff; } }
.top .icon-btn { color: inherit; }
.brand { color: inherit; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; }
.brand small { font-weight: 400; opacity: .8; font-size: .8rem; }
.flag { width: 26px; height: 19px; border-radius: 3px; background:
  linear-gradient(90deg, transparent 8px, #00205b 8px, #00205b 11px, transparent 11px),
  linear-gradient(0deg, transparent 8px, #00205b 8px, #00205b 11px, transparent 11px),
  linear-gradient(90deg, transparent 6px, #fff 6px, #fff 13px, transparent 13px),
  linear-gradient(0deg, transparent 6px, #fff 6px, #fff 13px, transparent 13px), #ba0c2f; box-shadow: 0 0 0 1px rgba(255,255,255,.4); }
.banner { background: #fff4e5; color: #6b3a00; padding: .5rem 1rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.layout { display: flex; max-width: 1200px; margin: 0 auto; }
.nav { width: var(--nav-w); flex: none; padding: 1rem .6rem; position: sticky; top: 52px; align-self: flex-start; max-height: calc(100vh - 52px); overflow: auto; }
.nav a { display: flex; gap: .6rem; align-items: center; padding: .5rem .7rem; border-radius: 10px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.nav-foot { padding: .6rem; }
main { flex: 1; min-width: 0; padding: 1rem 1.2rem 2rem; outline: none; }
.menu-btn { display: none; }
.bottom { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .nav { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; background: var(--surface); transform: translateX(-105%); transition: transform .2s; max-height: none; padding-top: calc(1rem + env(safe-area-inset-top)); box-shadow: 2px 0 12px rgba(0,0,0,.2); width: 250px; }
  body.menu-open .nav { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  main { padding: .9rem 1rem 2rem; }
  .bottom { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: .4rem 0 .45rem; font-size: .72rem; color: var(--muted); text-decoration: none; }
  .bottom a span { font-size: 1.25rem; line-height: 1.2; }
  .bottom a.active { color: var(--primary); font-weight: 600; }
}
@media (min-width: 861px) { body { padding-bottom: 0; } }

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.card.note, .note { background: var(--surface-2); }
.card.center { text-align: center; }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid.two > .card { margin: 0; } .grid.two { margin-bottom: 1rem; }
@media (max-width: 760px) { .grid.two { grid-template-columns: 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.row.center { justify-content: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .55rem .9rem; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .35rem .7rem; font-size: .9rem; min-height: 34px; }
.btn.big { font-size: 1.1rem; padding: .8rem 1.4rem; }
.btn.danger { color: var(--accent); border-color: var(--accent); }
.btn.rec, .icon-btn.rec { background: var(--accent) !important; color: #fff !important; border-color: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 1.05rem; padding: .25rem .4rem; border-radius: 8px; color: var(--text); min-width: 34px; min-height: 34px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.on { color: #d4a000; }
.btn.icon { min-width: 44px; font-size: 1.2rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem; max-width: 100%; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
.form input, .form select { width: 100%; }
.chk { display: inline-flex; gap: .4rem; align-items: center; cursor: pointer; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .45rem; border-radius: 999px; border: 1px solid currentColor; line-height: 1.3; margin-right: .2rem; vertical-align: middle; }
.lvl-A1 { color: var(--a1); } .lvl-A2 { color: var(--a2); } .lvl-B1 { color: var(--b1); } .lvl-B2 { color: var(--b2); } .lvl-C1 { color: var(--c1); }
.badge.cost-free { color: var(--good); } .badge.cost-freemium { color: var(--a2); } .badge.cost-paid { color: var(--warn); }
.badge.now { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge.new { color: var(--accent); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; flex: 1; min-width: 60px; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.bar.lvl-A1 span { background: var(--a1); } .bar.lvl-A2 span { background: var(--a2); } .bar.lvl-B1 span { background: var(--b1); } .bar.lvl-B2 span { background: var(--b2); }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #1f2937; color: #fff; padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: .25s; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.tabs { display: flex; gap: .3rem; overflow-x: auto; margin: .5rem 0 1rem; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs a { padding: .5rem .8rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: .3rem .75rem; font-size: .85rem; text-decoration: none; color: var(--text); background: var(--surface); cursor: pointer; font-family: inherit; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: .3rem; }
details summary { cursor: pointer; padding: .3rem 0; }

/* Today */
.hero { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-end; margin-bottom: 1rem; }
.hero h1 .small { font-weight: 400; display: block; margin-top: .2rem; }
.stats { display: flex; gap: .6rem; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .8rem; min-width: 92px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }
.small-stats { justify-content: center; margin-bottom: 1rem; }
.plan { list-style: none; padding: 0; margin: .8rem 0; }
.plan li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .45rem 0; border-bottom: 1px dashed var(--border); }
.plan li label { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; }
.plan li.done span { text-decoration: line-through; color: var(--muted); }
.plan input, .checklist input { width: 18px; height: 18px; margin-top: .2rem; flex: none; }
.timer-box { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.manual-log .row input[type=number] { width: 100px; }
.manual-log .row input:not([type]) { flex: 1; min-width: 150px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin: .5rem 0 1rem; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.chart .col span { width: 100%; background: var(--a2); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .7; }
.chart .col span.met { background: var(--good); opacity: 1; }
.chart .col i { font-style: normal; font-size: .7rem; color: var(--muted); }
.lvl-row { display: flex; gap: .5rem; align-items: center; margin: .4rem 0; }
.lvl-row .muted { width: 90px; }

/* Course */
.unit-list { display: grid; gap: .5rem; }
.unit-item { display: flex; align-items: center; gap: .8rem; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text); background: var(--surface); }
.unit-item:hover { border-color: var(--primary); }
.unit-item.now { border-color: var(--accent); border-width: 2px; }
.unit-item.done { opacity: .75; }
.unit-n { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; flex: none; }
.unit-t { flex: 1; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.unit-t small { color: var(--muted); }
.tick { color: var(--good); font-weight: 700; }
.unit-head { margin-bottom: 1rem; }
ul.grammar li { margin: .35rem 0; }
table { border-collapse: collapse; width: 100%; }
table.ex td, table.vocab td { padding: .35rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.ex td:first-child, table.vocab td:first-child { width: 40px; }
table.vocab td:nth-child(2) { width: 45%; }
.reading { background: var(--surface-2); border-radius: 12px; padding: .9rem 1rem; font-size: 1.08rem; line-height: 1.75; margin: .5rem 0; white-space: normal; }
.drills { display: grid; gap: .7rem; }
.drill { padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px; }
.drill.ok { border-color: var(--good); }
.drill label { display: block; margin-bottom: .2rem; }
.drill input { flex: 1; min-width: 140px; }
.fb { font-weight: 600; font-size: .9rem; }
.special .btn { min-width: 40px; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: .3rem 0; }
.checklist label { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; }
.unit-foot { display: flex; gap: .5rem; justify-content: space-between; flex-wrap: wrap; margin: 1rem 0; }
.ai-out { margin-top: .6rem; }
.ai-out:empty { display: none; }

/* Resources */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .7rem; }
.res { border: 1px solid var(--border); border-radius: 12px; padding: .7rem .8rem; background: var(--surface); display: flex; flex-direction: column; gap: .35rem; }
.res-head { display: flex; gap: .5rem; align-items: flex-start; }
.res-name { font-weight: 600; text-decoration: none; }
.res-name:hover { text-decoration: underline; }
.res-desc { margin: 0; font-size: .9rem; color: var(--muted); flex: 1; }
.res-meta { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem; }
.filters input[type=search] { width: 100%; margin-bottom: .3rem; }

/* Flashcards */
.flash { max-width: 520px; margin: 0 auto 1rem; padding: 1.2rem; border-radius: 16px; background: var(--surface-2); outline: none; }
.flash .front { font-size: 1.8rem; font-weight: 700; margin: 1rem 0 .5rem; }
.flash .back { font-size: 1.3rem; margin: .5rem 0 1rem; color: var(--muted); }
.flash-meta { display: flex; justify-content: space-between; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.grades .btn { flex-direction: column; gap: 0; }
.grades small { font-size: .7rem; opacity: .6; }
.g0 { border-color: var(--accent) !important; } .g1 { border-color: var(--warn) !important; } .g2 { border-color: var(--a2) !important; } .g3 { border-color: var(--good) !important; }
.big-text { font-size: 1.4rem; font-weight: 700; }
.decks { display: grid; gap: .35rem; max-height: 560px; overflow: auto; }
.deck { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .5rem; align-items: center; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-size: .9rem; }
.deck .bar { grid-column: 2 / 4; }
.deck.on { border-color: var(--primary); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.opts .btn.right { background: var(--good); color: #fff; border-color: var(--good); }
.opts .btn.wrong { background: var(--accent); color: #fff; border-color: var(--accent); }
.quiz { margin-top: 1rem; }

/* Pharmacy */
.dialogue .line { margin: .3rem 0; padding: .4rem .6rem; border-radius: 10px; }
.dialogue .line.F { background: var(--surface-2); }
.dialogue .line.playing { outline: 2px solid var(--accent); }
.dialogue.practice .line.F span[lang] { filter: blur(6px); }
.dialogue.practice .line.F:hover span[lang] { filter: none; }
.scen { display: grid; gap: .4rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-bottom: 1rem; }
.scen-item { padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: var(--text); background: var(--surface); }
.scen-item.on, .scen-item:hover { border-color: var(--accent); }
ol.steps li { margin-bottom: .6rem; }
ol.steps h3 { margin: .2rem 0; }
table.timeline td { padding: .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.timeline td:first-child { font-weight: 700; white-space: nowrap; width: 90px; }
ul.phr { list-style: none; padding: 0; } ul.phr li { padding: .15rem 0; }

/* AI chat */
.chat { display: flex; flex-direction: column; }
.chat-tools label { display: inline-flex; gap: .3rem; align-items: center; }
.msgs { min-height: 240px; max-height: 60vh; overflow-y: auto; padding: .5rem 0; display: flex; flex-direction: column; gap: .6rem; }
.msg { display: flex; gap: .3rem; align-items: flex-start; max-width: 92%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.bubble { padding: .6rem .85rem; border-radius: 14px; background: var(--surface-2); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--primary); color: var(--primary-ink); }
.bubble p { margin: .3em 0; } .bubble ul, .bubble ol { margin: .3em 0; padding-left: 1.3em; } .bubble h4 { margin: .6em 0 .2em; }
.composer { display: flex; gap: .5rem; align-items: flex-end; border-top: 1px solid var(--border); padding-top: .6rem; }
.composer textarea { flex: 1; }
.composer-btns { display: flex; flex-direction: column; gap: .4rem; }

/* Speaking */
.shadow { text-align: center; padding: 1rem 0; }
.target { font-size: 1.5rem; font-weight: 600; margin: .5rem 0 1rem; min-height: 2em; }
.heard { min-height: 3em; }
.cmp .ok { color: var(--good); font-weight: 600; } .cmp .miss { color: var(--accent); text-decoration: underline wavy; }
.cmp { font-size: 1.3rem; }
audio { width: 100%; margin: .5rem 0; }

/* Writing */
.title-input { width: 100%; font-size: 1.2rem; font-weight: 600; margin-bottom: .5rem; }
.journal { list-style: none; padding: 0; }
.journal li a { display: block; padding: .55rem 0; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.folder-box { background: var(--surface-2); border-radius: 12px; padding: .2rem .9rem; margin: .5rem 0; }
.file-btn { cursor: pointer; }

@media (max-width: 520px) {
  h1 { font-size: 1.3rem; }
  .stat { min-width: 0; flex: 1 1 40%; }
  .grades { grid-template-columns: repeat(2, 1fr); }
  .opts { grid-template-columns: 1fr; }
  table.vocab td:nth-child(2) { width: auto; }
  .flash .front { font-size: 1.5rem; }
}

/* Fixes */
.banner[hidden] { display: none; }
.plan .btn { white-space: nowrap; }
table.ex td, table.vocab td { overflow-wrap: anywhere; hyphens: auto; }
.card { min-width: 0; }
