:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1b26;
  --muted: #625f70;
  --line: #dedbd3;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --primary-soft: #e8e6fd;
  --ok: #17803d;
  --ok-soft: #dff5e6;
  --bad: #c0262d;
  --bad-soft: #fde3e3;
  --warn: #9a5b00;
  --warn-soft: #fdefcf;
  --flame: #e2620d;
  --radius: 14px;
  --nav-h: 60px;
  --shadow: 0 1px 2px rgb(20 18 40 / 6%), 0 4px 14px rgb(20 18 40 / 5%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131a;
    --surface: #1e1d27;
    --surface-2: #292734;
    --text: #edebf5;
    --muted: #a4a0b6;
    --line: #353344;
    --primary: #8b84ff;
    --primary-text: #12102a;
    --primary-soft: #2a2850;
    --ok: #4ccb7a;
    --ok-soft: #173524;
    --bad: #ff7b7f;
    --bad-soft: #40191c;
    --warn: #f2b84b;
    --warn-soft: #3b2c0c;
    --flame: #ff8a3d;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100dvh; }
h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
.icon { flex: none; width: 24px; height: 24px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.es { font-family: Georgia, "Times New Roman", serif; font-size: 1.06em; }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ── shell ─────────────────────────────────────────── */
#app { min-height: 100dvh; }
#view { max-width: 820px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); outline: none; }
#nav {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
#nav .brand { display: none; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600; min-height: 48px;
}
#nav a[aria-current="page"] { color: var(--primary); }
body.in-session #nav { display: none; }
body.in-session #view { padding-bottom: 0; max-width: none; padding: 0; }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 232px 1fr; }
  #nav {
    /* inset first: it would otherwise reset the top offset and the rail would scroll away with the page */
    position: sticky; inset: auto; top: 0; align-self: start; height: 100dvh; overflow-y: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  #nav .brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; font-weight: 800; font-size: 1.1rem; }
  #nav .brand span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-text); font-family: Georgia, serif; }
  #nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
  #nav a:hover { background: var(--surface-2); }
  #nav a[aria-current="page"] { background: var(--primary-soft); }
  #view { padding: 32px 32px 64px; width: 100%; }
  body.in-session #app { display: block; }
}

/* ── building blocks ───────────────────────────────── */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.stack-lg { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.accent { background: var(--primary-soft); border-color: transparent; box-shadow: none; }
.eyebrow { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 20px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; text-decoration: none; color: var(--text);
  transition: transform .08s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 6px 14px; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.speak { color: var(--primary); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .3s; }
.bar.ok > i { background: var(--ok); }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list a.item, .list button.item, .list div.item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
  background: none; border: 0; color: inherit; text-decoration: none;
}
.list a.item:hover, .list button.item:hover { background: var(--surface-2); }
.list .item .title { font-weight: 600; }
.list .item .meta { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.num { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); font-weight: 800; flex: none; }
.num.done { background: var(--ok-soft); color: var(--ok); }
.num.current { background: var(--primary); color: var(--primary-text); }

.thumb { position: relative; flex: none; width: 56px; height: 56px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; display: block; }
.thumb .num { position: absolute; right: -6px; bottom: -6px; width: 26px; height: 26px; border-radius: 50%; font-size: .8rem; border: 2px solid var(--surface); }
.thumb .num .icon { width: 14px !important; height: 14px !important; }
.thumb.no-cover { width: 36px; height: 36px; }
.thumb.no-cover .num { position: static; width: 36px; height: 36px; border-radius: 10px; font-size: 1rem; border: 0; }
.thumb.no-cover .num .icon { width: 20px !important; height: 20px !important; }
.hero { border-radius: var(--radius); overflow: hidden; }
.hero img { width: 100%; height: clamp(140px, 28vw, 220px); object-fit: cover; display: block; }
.hero.no-cover { display: none; }

.page-head { display: flex; align-items: flex-start; gap: 8px; }
.page-head .icon-btn { margin: -6px 0 0 -10px; }

/* ── home ─────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat .row { gap: 6px; color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat .icon { width: 18px; height: 18px; }
.flame { color: var(--flame); }
.days { display: flex; align-items: flex-end; gap: 6px; height: 96px; }
.days > div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; font-size: .7rem; color: var(--muted); }
.days i { display: block; width: 100%; max-width: 28px; border-radius: 6px 6px 2px 2px; background: var(--primary); min-height: 3px; }
.days i.zero { background: var(--surface-2); }

/* ── grammar topic ────────────────────────────────── */
.prose { display: grid; gap: 14px; }
.prose p { max-width: 68ch; }
.prose ul { margin: 0; padding-left: 22px; display: grid; gap: 6px; max-width: 68ch; }
.prose .es-inline { font-family: Georgia, serif; font-weight: 600; color: var(--primary); cursor: pointer; border-radius: 4px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
caption { text-align: left; padding: 10px 12px 4px; font-weight: 700; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-size: .85rem; }
tr:last-child > td { border-bottom: 0; }
.examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.examples li { display: flex; align-items: center; gap: 4px; padding: 6px 12px 6px 4px; }
.examples li + li { border-top: 1px solid var(--line); }
.examples .uk { color: var(--muted); font-size: .9rem; }
.note { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); }
.note .icon { color: var(--warn); }
.sticky-cta { position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); margin-top: 8px; }
@media (min-width: 900px) { .sticky-cta { bottom: 16px; } }

/* ── vocabulary ───────────────────────────────────── */
.word { display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 4px; }
.word .uk { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.dot.learning { background: var(--warn); border-color: transparent; }
.dot.known { background: var(--ok); border-color: transparent; }

/* ── session ──────────────────────────────────────── */
.session { display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh; }
.s-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; max-width: 760px; width: 100%; margin: 0 auto; }
.s-top .bar { flex: 1; height: 12px; }
.s-body { padding: 12px 16px 24px; max-width: 680px; width: 100%; margin: 0 auto; display: grid; align-content: start; gap: 18px; }
.s-foot { border-top: 1px solid var(--line); background: var(--surface); padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
.s-foot.ok { background: var(--ok-soft); border-color: transparent; }
.s-foot.bad { background: var(--bad-soft); border-color: transparent; }
.s-foot.near { background: var(--warn-soft); border-color: transparent; }
.s-foot > div { max-width: 680px; margin: 0 auto; display: grid; gap: 12px; }
.verdict { display: flex; gap: 10px; align-items: flex-start; }
.verdict b { display: block; }
.s-foot.ok .verdict { color: var(--ok); }
.s-foot.bad .verdict { color: var(--bad); }
.s-foot.near .verdict { color: var(--warn); }
.verdict .detail { color: var(--text); }
.task { font-size: .85rem; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.prompt { font-size: clamp(1.25rem, 1.05rem + 1vw, 1.6rem); font-weight: 700; line-height: 1.35; }
.prompt .hint { font-weight: 500; color: var(--muted); font-size: .8em; }
.sub { color: var(--muted); }

.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px; text-align: left; width: 100%;
  border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 600;
}
.option kbd { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); font: 700 .8rem system-ui; color: var(--muted); flex: none; }
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; }
@media (pointer: coarse) { .option kbd { display: none; } }

.field {
  width: 100%; min-height: 52px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.15rem; font-family: Georgia, serif;
}
.field:focus { border-color: var(--primary); outline: none; }
.field.inline { width: auto; min-width: 7ch; max-width: 100%; min-height: 44px; padding: 4px 10px; margin: 0 4px; text-align: center; font-size: 1em; font-weight: 700; }
.field.right { border-color: var(--ok); background: var(--ok-soft); }
.field.wrong { border-color: var(--bad); background: var(--bad-soft); }
.accents { display: flex; flex-wrap: wrap; gap: 6px; }
.accents button { min-width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font: 600 1.05rem Georgia, serif; }
.accents button:hover { background: var(--surface-2); }

.bank-answer { display: flex; flex-wrap: wrap; gap: 8px; min-height: 60px; padding: 8px; border-radius: 12px; border: 2px dashed var(--line); align-content: flex-start; }
.bank-answer.word { gap: 4px; justify-content: center; }
.bank-answer.right { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.bank-answer.wrong { border-style: solid; border-color: var(--bad); background: var(--bad-soft); }
.bank { display: flex; flex-wrap: wrap; gap: 8px; }
.tile { min-height: 44px; padding: 6px 14px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font: 600 1.05rem Georgia, serif; }
.tile.used { visibility: hidden; }
.tile:hover { border-color: var(--primary); }

.conj { display: grid; gap: 8px; }
.conj label { display: grid; grid-template-columns: minmax(96px, 30%) 1fr; align-items: center; gap: 10px; }
.conj span { color: var(--muted); font-weight: 600; font-size: .9rem; }
.conj .field { min-height: 46px; font-size: 1.05rem; }
.conj small { grid-column: 2; color: var(--ok); font-weight: 700; font-family: Georgia, serif; font-size: .95rem; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match > div { display: grid; gap: 10px; align-content: start; }
.match button { min-height: 52px; padding: 8px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 600; }
.match button.sel { border-color: var(--primary); background: var(--primary-soft); }
.match button.done { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.match button.miss { border-color: var(--bad); background: var(--bad-soft); animation: shake .3s; }

.syllables { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.syllables button { min-width: 56px; min-height: 60px; padding: 6px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font: 700 1.5rem Georgia, serif; }
.syllables button:hover:not(:disabled) { border-color: var(--primary); }
.syllables button.right { border-color: var(--ok); background: var(--ok-soft); }
.syllables button.wrong { border-color: var(--bad); background: var(--bad-soft); }

.intro { text-align: center; padding: 28px 18px; display: grid; gap: 10px; justify-items: center; }
.intro .big { font: 700 clamp(1.8rem, 1.4rem + 2vw, 2.6rem) Georgia, serif; }
.intro .tr { font-size: 1.25rem; }
.intro .ex { margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--line); width: 100%; }
.listen-btn { width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; margin: 0 auto; }
.listen-btn .icon { width: 44px; height: 44px; }

.result { text-align: center; display: grid; gap: 18px; justify-items: center; padding-top: 8vh; }
.result .icon { width: 72px; height: 72px; color: var(--flame); }
.result .stats { width: 100%; }

/* ── reader ───────────────────────────────────────── */
.reader-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.reader-bar input { width: 84px; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-align: center; }
.page-img { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: block; }

/* ── settings ─────────────────────────────────────── */
.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 600; }
.form .check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.form .check input { width: 22px; height: 22px; }
.form select, .form input[type="number"] { min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); max-width: 340px; }
.form small { font-weight: 400; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); z-index: 40; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (forced-colors: active) { .bar > i, .dot.known, .dot.learning { background: Highlight; } }
