:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --ink: #1d2320;
  --ink-2: #56605a;
  --ink-3: #8a918c;
  --line: #e2dcd0;
  --green: #1f6f54;
  --green-soft: #dcebe4;
  --red: #b8412f;
  --red-soft: #f6e0db;
  --gold: #c8912a;
  --gold-soft: #f5e8cc;
  --shadow: 0 1px 2px rgba(30,35,32,.06), 0 6px 20px rgba(30,35,32,.06);
  --radius: 16px;
  --on-green: #ffffff;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --surface: #1c2220; --surface-2: #252c29; --ink: #eef0ec; --ink-2: #b3bab5; --ink-3: #7d857f;
    --line: #2f3834; --green: #5fbf98; --green-soft: #1f3a30; --red: #e27a67; --red-soft: #3d2521;
    --gold: #e0b35a; --gold-soft: #3a3020; --on-green: #0f1a15; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --surface: #1c2220; --surface-2: #252c29; --ink: #eef0ec; --ink-2: #b3bab5; --ink-3: #7d857f;
  --line: #2f3834; --green: #5fbf98; --green-soft: #1f3a30; --red: #e27a67; --red-soft: #3d2521;
  --gold: #e0b35a; --gold-soft: #3a3020; --on-green: #0f1a15; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 30px; } h2 { font-size: 22px; } h3 { font-size: 18px; }
.muted { color: var(--ink-2); } .small { font-size: 14px; } .tiny { font-size: 12px; color: var(--ink-3); }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 21px; font-weight: 700; text-decoration: none; }
.flag { display: inline-flex; width: 22px; height: 16px; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.flag i { flex: 1; } .flag i:nth-child(1) { background: #1f8a5b; } .flag i:nth-child(2) { background: #fff; } .flag i:nth-child(3) { background: #cf3a2c; }
.top-r { display: flex; align-items: center; gap: 6px; }
.ico { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; }
.ico:hover { background: var(--surface-2); }
.ico svg, .tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sync { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 10px; font-size: 12px; color: var(--ink-2); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.sync[data-s="ok"] .dot { background: var(--green); }
.sync[data-s="busy"] .dot { background: var(--gold); animation: pulse 1s infinite; }
.sync[data-s="off"] .dot, .sync[data-s="auth"] .dot { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { position: relative; flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 500; color: var(--ink-3); text-decoration: none; border-radius: 10px; }
.tabs a.on { color: var(--green); }
.tabs a.on svg { stroke-width: 2.2; }
.badge { position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 96px; }
  .tabs { top: 0; bottom: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start; gap: 6px; border-top: 0; border-right: 1px solid var(--line); padding-top: 80px; }
  .tabs a { flex: none; width: 80px; margin: 0 auto; padding: 10px 0; }
  .tabs a:hover { background: var(--surface-2); }
  .top { margin-left: -96px; padding-left: 20px; z-index: 11; }
}

/* layout */
main { max-width: 760px; margin: 0 auto; padding: 20px 16px 32px; outline: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.sp { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:hover { background: var(--surface-2); }
.btn.pri { background: var(--green); border-color: var(--green); color: var(--on-green); }
.btn.pri:hover { filter: brightness(1.07); background: var(--green); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.big { min-height: 56px; font-size: 17px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }

.say { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); }
.say:hover { background: var(--green-soft); border-color: var(--green); }
.say svg { width: 17px; height: 17px; fill: none; stroke: var(--green); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.say.lg { width: 52px; height: 52px; } .say.lg svg { width: 24px; height: 24px; }

/* home */
.hero { background: linear-gradient(135deg, #1f6f54 0%, #0f3d2e 100%); color: #fff; border: 0; }
.hero h1 { color: #fff; margin-bottom: 4px; }
.hero .muted { color: rgba(255,255,255,.8); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat { background: rgba(255,255,255,.12); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--serif); font-size: 26px; line-height: 1.1; }
.stat span { font-size: 12px; opacity: .85; }
.goal { height: 8px; background: rgba(255,255,255,.2); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.goal i { display: block; height: 100%; background: #fff; border-radius: 4px; transition: width .4s; }
.phrase .it { font-family: var(--serif); font-size: 22px; }

/* units */
.unit { display: block; text-decoration: none; transition: transform .1s, border-color .15s; }
.unit:hover { border-color: var(--green); transform: translateY(-1px); }
.unit .num { font-family: var(--serif); color: var(--gold); font-size: 14px; font-weight: 700; }
.unit h3 { margin: 2px 0; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--green-soft); color: var(--green); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.grammar p { margin: 0 0 10px; }
.gt { border-collapse: collapse; margin: 6px 0 12px; font-size: 15px; width: 100%; }
.gt td, .gt th { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.gt th { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.gt tr:last-child td { border-bottom: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .it { font-weight: 600; }
.list .hu { color: var(--ink-2); font-size: 15px; }
.lv { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--surface-2); border: 1px solid var(--line); }
.lv.l1 { background: var(--red-soft); border-color: var(--red); }
.lv.l2 { background: var(--gold-soft); border-color: var(--gold); }
.lv.l3 { background: var(--green-soft); border-color: var(--green); }
.lv.l4 { background: var(--green); border-color: var(--green); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: 14px; margin-bottom: 8px; }

/* flashcard */
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-bottom: 14px; }
.progress i { display: block; height: 100%; background: var(--green); transition: width .3s; }
.fc { min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 28px 18px; }
.fc .dir { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.fc .q { font-family: var(--serif); font-size: clamp(28px, 7vw, 40px); line-height: 1.15; }
.fc .a { font-size: 22px; color: var(--green); font-weight: 600; }
.fc .ex { font-size: 15px; color: var(--ink-2); max-width: 460px; }
.fc hr { width: 60px; border: 0; border-top: 2px solid var(--line); margin: 4px 0; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grades .btn { flex-direction: column; gap: 0; min-height: 60px; padding: 6px 4px; font-size: 15px; }
.grades .btn small { font-weight: 500; font-size: 11px; color: var(--ink-3); }
.g0 { border-color: var(--red) !important; color: var(--red); }
.g1 { border-color: var(--gold) !important; color: var(--gold); }
.g2 { border-color: var(--green) !important; color: var(--green); }
.g3 { border-color: var(--green) !important; background: var(--green-soft) !important; color: var(--green); }
.kbd { display: none; }
@media (hover: hover) { .kbd { display: inline; font-size: 11px; color: var(--ink-3); } }

/* quiz */
.opts { display: grid; gap: 10px; }
.opt { text-align: left; min-height: 54px; padding: 12px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-size: 17px; }
.opt:hover { border-color: var(--green); }
.opt.ok { border-color: var(--green); background: var(--green-soft); }
.opt.bad { border-color: var(--red); background: var(--red-soft); }
.opt[disabled] { cursor: default; }
.inp { width: 100%; min-height: 54px; padding: 0 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font: 19px var(--sans); }
.inp:focus { outline: none; border-color: var(--green); }
.inp.ok { border-color: var(--green); background: var(--green-soft); }
.inp.bad { border-color: var(--red); background: var(--red-soft); }
.fb { padding: 12px 14px; border-radius: 12px; font-weight: 500; }
.fb.ok { background: var(--green-soft); color: var(--green); }
.fb.bad { background: var(--red-soft); color: var(--red); }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 54px; padding: 8px; border-radius: 12px; }
.tiles.ans { border: 1.5px dashed var(--line); background: var(--surface-2); }
.tile { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; box-shadow: 0 1px 0 var(--line); }
.tile.used { visibility: hidden; }
select.inp { font-size: 16px; }

/* speak */
.target { font-family: var(--serif); font-size: clamp(24px, 6vw, 32px); line-height: 1.25; }
.target .w.hit { color: var(--green); }
.target .w.miss { color: var(--red); text-decoration: underline wavy; text-underline-offset: 5px; }
.mic { width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--green); color: var(--on-green); display: grid; place-items: center; box-shadow: var(--shadow); }
.mic svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.mic.rec { background: var(--red); animation: pulse 1.2s infinite; }
.score { font-family: var(--serif); font-size: 44px; line-height: 1; }

/* settings */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; }
input[type=range] { width: 180px; accent-color: var(--green); }

/* modal & toast */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(10,15,12,.55); padding: 16px; }
.modal .card { width: 100%; max-width: 400px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.center { text-align: center; }
.empty { text-align: center; padding: 36px 16px; }
.empty .big { font-size: 44px; margin-bottom: 6px; }
