:root {
  --accent: #7c5cff; --accent-2: #5b8cff; --accent-soft: rgba(124, 92, 255, .12);
  --bg: #f4f4f8; --card: #ffffff; --text: #17171f; --muted: #6e6e82; --line: rgba(20, 20, 40, .08);
  --ok: #18a058; --ok-soft: rgba(24, 160, 88, .12); --bad: #e5484d; --bad-soft: rgba(229, 72, 77, .12);
  --warn: #f5a524; --hard: #f08c00;
  --radius: 18px; --tab-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e0e14; --card: #1b1b25; --text: #f0f0f6; --muted: #9a9ab0; --line: rgba(255, 255, 255, .08); --accent-soft: rgba(124, 92, 255, .22); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--accent); text-decoration: none; }

#app { min-height: 100%; padding: calc(var(--safe-top) + 8px) 16px calc(var(--tab-h) + var(--safe-bottom) + 24px); max-width: 720px; margin: 0 auto; }
body.no-tabs #app { padding-bottom: calc(var(--safe-bottom) + 24px); }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; min-height: 52px; margin-bottom: 6px; }
.top h1 { font-size: 28px; line-height: 1.1; margin: 0; flex: 1; letter-spacing: -.02em; }
.top h2 { font-size: 18px; margin: 0; flex: 1; text-align: center; }
.icon-btn { border: none; background: var(--card); width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; flex: none; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.ghost { background: transparent; box-shadow: none; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: 1px solid var(--line); }
body.no-tabs .tabs { display: none; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabs a svg { width: 24px; height: 24px; }
.tabs a.on { color: var(--accent); }

/* cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card h3 { margin: 0 0 4px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.hero { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.hero .muted { color: rgba(255,255,255,.8); }
.big-num { font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 22px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); color: var(--text); }
.list .item:last-child { border-bottom: none; }
.list .item .chev { color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.s0 { background: var(--accent-2); } .dot.s1, .dot.s3 { background: var(--warn); } .dot.s2 { background: var(--ok); }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 20px 4px 8px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: none; border-radius: 14px; padding: 13px 18px; font-weight: 600; background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 18px rgba(124,92,255,.3); }
.btn.white { background: #fff; color: var(--accent); box-shadow: none; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.btn.white:disabled { opacity: 1; background: rgba(255,255,255,.18); color: #fff; }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.fab { position: fixed; right: 20px; bottom: calc(var(--tab-h) + var(--safe-bottom) + 18px); width: 56px; height: 56px; border-radius: 18px; border: none; z-index: 15;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 8px 22px rgba(124,92,255,.4); display: flex; align-items: center; justify-content: center; }
.fab svg { width: 26px; height: 26px; }

/* forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 5px 2px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 13px; outline: none; font-size: 16px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: none; padding: 7px 13px; border-radius: 999px; background: var(--card); color: var(--muted); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--text); color: var(--bg); }
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; gap: 12px; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch:checked { background: var(--ok); } .switch:checked::after { left: 22px; }

/* review */
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; transition: width .3s; }
.flash { background: var(--card); border-radius: 24px; padding: 26px 22px; min-height: 52vh; display: flex; flex-direction: column; box-shadow: 0 6px 24px rgba(0,0,0,.06); margin-top: 14px; }
.flash .front { font-size: 32px; font-weight: 700; text-align: center; letter-spacing: -.01em; word-break: break-word; }
.flash .phon { text-align: center; color: var(--muted); margin-top: 4px; }
.flash .ctx { margin-top: 18px; padding: 12px 14px; background: var(--bg); border-radius: 14px; font-size: 15px; }
.flash .ctx mark { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.flash .answer { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.flash .tr { font-size: 24px; font-weight: 700; text-align: center; color: var(--accent); }
.flash .meta { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.flash .def { margin-top: 14px; font-size: 15px; }
.flash .ex { margin-top: 10px; font-size: 15px; }
.flash .ex div { margin-bottom: 8px; }
.flash .note { margin-top: 12px; font-size: 14px; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; }
.tap-hint { margin-top: auto; padding-top: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; position: sticky; bottom: 0; padding: 10px 0 calc(var(--safe-bottom) + 10px); background: var(--bg); box-shadow: 0 -14px 14px -6px var(--bg); }
.rate button { border: none; border-radius: 14px; padding: 10px 4px; font-weight: 700; font-size: 14px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rate button small { font-weight: 500; font-size: 11.5px; opacity: .9; }
.r1 { background: var(--bad); } .r2 { background: var(--hard); } .r3 { background: var(--ok); } .r4 { background: var(--accent-2); }
.speak { border: none; background: var(--accent-soft); color: var(--accent); width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; flex: none; }
.speak svg { width: 17px; height: 17px; }

/* lesson */
.lesson h2 { font-size: 24px; margin: 4px 0 6px; letter-spacing: -.01em; }
.lesson .body { white-space: pre-wrap; }
.lesson .body ul { margin: 6px 0; padding-left: 20px; white-space: normal; }
.lesson .exs { margin-top: 10px; }
.lesson .exs .e { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.mistake { padding: 10px 0; border-top: 1px solid var(--line); }
.mistake:first-of-type { border-top: none; }
.wrong { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.right { color: var(--ok); font-weight: 600; }
.exercise .q { font-size: 20px; font-weight: 600; margin: 8px 0 16px; line-height: 1.35; }
.opt { display: block; width: 100%; text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 13px 15px; margin-bottom: 10px; font-size: 17px; }
.opt.sel { border-color: var(--accent); }
.opt.good { border-color: var(--ok); background: var(--ok-soft); }
.opt.badc { border-color: var(--bad); background: var(--bad-soft); }
.feedback { border-radius: 14px; padding: 12px 14px; margin: 6px 0 14px; font-size: 15px; }
.feedback.ok { background: var(--ok-soft); } .feedback.bad { background: var(--bad-soft); }
.feedback b { display: block; margin-bottom: 3px; }
.words { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 10px; border-radius: 14px; background: var(--card); margin-bottom: 12px; border: 2px dashed var(--line); }
.words.pool { border-style: solid; background: transparent; }
.word { border: none; background: var(--card); box-shadow: inset 0 0 0 1px var(--line), 0 2px 0 var(--line); border-radius: 10px; padding: 8px 12px; font-size: 16px; }
.words:not(.pool) .word { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.score-ring { width: 140px; height: 140px; border-radius: 50%; margin: 10px auto 16px; display: flex; align-items: center; justify-content: center; font-size: 38px; font-weight: 800; }
.lvl-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 28px; padding: 0 8px; border-radius: 8px; font-weight: 800; font-size: 14px; background: var(--accent-soft); color: var(--accent); }
.check { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex: none; background: var(--line); color: var(--muted); }
.check.done { background: var(--ok); color: #fff; }

/* misc */
.spinner { width: 28px; height: 28px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 50px 20px; text-align: center; color: var(--muted); }
.loading .spinner { margin-bottom: 14px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 46px; margin-bottom: 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-bottom) + 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 10px 16px calc(var(--safe-bottom) + 20px); animation: up .22s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 60px; margin-top: 10px; }
.bars div { flex: 1; text-align: center; font-size: 10px; color: var(--muted); }
.bars i { display: block; background: var(--accent-soft); border-radius: 5px; margin-bottom: 4px; min-height: 3px; }
.bars i.today { background: var(--accent); }
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: inline; opacity: .6; font-size: 11px; } }
