:root {
  --blue: #0b5394;
  --blue-soft: #e8f0f9;
  --yellow: #fecc02;
  --yellow-soft: #fff6cc;
  --ink: #1d2733;
  --muted: #566170;
  --line: #e3e7ec;
  --bg: #f6f8fa;
  --card: #fff;
  --ok: #166534;
  --ok-soft: #e6f4ea;
  --bad: #c5221f;
  --bad-soft: #fce8e6;
  --warn: #b06000;
  --radius: 14px;
  --ls: 1; /* lesson font scale (1 = 100%), set from the account preference by app.js */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--blue); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: .2rem 0 .4rem; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; background: var(--blue); color: #fff;
  padding-top: max(.6rem, env(safe-area-inset-top));
}
#topbar .brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: .02em; }
#topbar nav { display: flex; gap: .2rem; overflow-x: auto; }
#topbar nav a {
  color: #dbe7f5; text-decoration: none; padding: .35rem .6rem; border-radius: 8px; white-space: nowrap;
}
#topbar nav a.active { background: rgba(255,255,255,.16); color: #fff; }

main { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 5rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 0 0 1rem;
}
.card.accent { border-color: var(--blue); box-shadow: 0 2px 10px rgba(11,83,148,.08); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7rem; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: .55rem .95rem; text-decoration: none;
  display: inline-flex; align-items: center; gap: .35rem;
}
button:hover { border-color: #c5ccd4; }
button.primary, .btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: #0a4a85; }
button.big { padding: .8rem 1.3rem; font-size: 1.05rem; }
button.ghost { background: transparent; border-color: transparent; color: var(--blue); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
button.icon { padding: .3rem .5rem; border-radius: 8px; }

input[type=text], input[type=password], input[type=number], textarea, select {
  font: inherit; width: 100%; padding: .6rem .7rem; border: 1px solid #cfd6de; border-radius: 10px;
  background: #fff; color: var(--ink);
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(11,83,148,.25); border-color: var(--blue); }
label { display: block; font-size: .9rem; color: var(--muted); margin: .6rem 0 .25rem; }

.login { max-width: 360px; margin: 12vh auto 0; }
.login .flag { width: 56px; height: 56px; border-radius: 14px; background: var(--blue); position: relative; margin: 0 auto 1rem; overflow: hidden; }
.login .flag::before { content: ""; position: absolute; left: 30%; top: 0; bottom: 0; width: 14%; background: var(--yellow); }
.login .flag::after { content: ""; position: absolute; top: 43%; left: 0; right: 0; height: 14%; background: var(--yellow); }

.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--blue-soft); color: var(--blue); }
.badge.new { background: var(--yellow-soft); color: #7a5b00; }
.badge.review { background: var(--blue-soft); color: var(--blue); }
.badge.recycle { background: #eef0f3; color: #4a5561; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.mastered { background: var(--ok-soft); color: var(--ok); }

.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: .2rem 0 1rem; }
.progress > div { height: 100%; background: var(--blue); transition: width .3s; }

.word-card .lemma { font-size: 1.35rem; font-weight: 700; }
.word-card .forms { color: var(--muted); font-size: .92rem; }
.word-card .tr { font-size: 1.05rem; margin: .3rem 0; }
.examples { margin: .5rem 0 0; padding: 0; list-style: none; }
.examples li { padding: .35rem 0; border-top: 1px dashed var(--line); }
.examples .native { color: var(--muted); font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: .15rem .6rem; font-size: .88rem; }

.lesson-text { font-size: 1.15rem; line-height: 1.75; white-space: pre-wrap; }
.lesson-text mark { background: var(--yellow-soft); border-radius: 4px; padding: 0 .1em; cursor: help; }
.lesson-text mark.review, .lesson-text mark.recycle { background: var(--blue-soft); }
.translation { color: var(--muted); white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: .8rem; }

.exercise .prompt { font-size: 1.2rem; margin: .4rem 0 .8rem; line-height: 1.5; }
.exercise .options { display: grid; gap: .5rem; }
.exercise .options button { justify-content: flex-start; text-align: left; }
.exercise .options button.right { background: var(--ok-soft); border-color: var(--ok); }
.exercise .options button.wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback { margin-top: .8rem; padding: .7rem .9rem; border-radius: 10px; }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback.info { background: var(--blue-soft); }
.sv-keys { display: flex; gap: .3rem; margin: .4rem 0; }
.sv-keys button { padding: .25rem .6rem; }

.speak { border: none; background: var(--blue-soft); color: var(--blue); border-radius: 999px; padding: .2rem .55rem; font-size: .9rem; }

.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: .5rem .4rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: .95rem; }
.table th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.bars { display: flex; gap: .4rem; align-items: flex-end; height: 70px; }
.bars div { flex: 1; background: var(--blue-soft); border-radius: 6px 6px 0 0; position: relative; min-height: 4px; }
.bars div span { position: absolute; bottom: -1.3rem; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--muted); }
.bars div b { position: absolute; top: -1.2rem; left: 0; right: 0; text-align: center; font-size: .75rem; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; z-index: 50;
  width: max-content; max-width: min(90vw, 26rem); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 max(.6rem, env(safe-area-inset-bottom)); display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .5rem; align-items: start; }
.sticky-actions > button { min-height: 44px; justify-content: center; }
/* On a lesson page the toast must not cover the footer (slider status and its retry/refresh action): lift it above. */
body:has(.sticky-actions) #toast { bottom: 11rem; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* Lesson text size: only learning content (.lesson-body) scales with --ls; header, footer and controls keep their size. */
.font-scale { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: .3rem; align-items: center; min-width: 0; }
.fs-a { font-weight: 700; color: var(--muted); line-height: 1; }
.fs-a.small-a { font-size: .8rem; }
.fs-a.large-a { font-size: 1.35rem; }
.fs-range { -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; height: 44px; margin: 0; background: transparent; cursor: pointer; touch-action: pan-y; }
.fs-range::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: #b9c3ce; }
.fs-range::-moz-range-track { height: 6px; border-radius: 99px; background: #b9c3ce; }
.fs-range::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--blue); }
.fs-range::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--blue); }
.fs-range:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 8px; }
.fs-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .1rem .4rem; font-size: .78rem; color: var(--muted); min-height: 1.1rem; }
.fs-val { font-weight: 600; }
.fs-stat.error, .fs-stat.stale, .fs-stat.resync_error { color: var(--bad); font-weight: 600; }
.fs-range:disabled { opacity: .45; cursor: not-allowed; }
.fs-stat.saved { color: var(--ok); }
.fs-retry { min-height: 44px; padding: .2rem .7rem; font-size: .85rem; }

.lesson-body { font-size: calc(1rem * var(--ls)); overflow-wrap: anywhere; min-width: 0; } /* long compound words (Swedish/Russian) must wrap, not widen the page */
.lesson-body .small { font-size: calc(.88rem * var(--ls)); }
.lesson-body h2 { font-size: calc(1.2rem * var(--ls)); }
.lesson-body h3 { font-size: calc(1.05rem * var(--ls)); }
.lesson-body .word-card .lemma { font-size: calc(1.35rem * var(--ls)); }
.lesson-body .word-card .forms { font-size: calc(.92rem * var(--ls)); }
.lesson-body .word-card .tr { font-size: calc(1.05rem * var(--ls)); }
.lesson-body .examples .native { font-size: calc(.9rem * var(--ls)); }
.lesson-body .chip { font-size: calc(.88rem * var(--ls)); }
.lesson-body .lesson-text { font-size: calc(1.15rem * var(--ls)); }
.lesson-body .exercise .prompt { font-size: calc(1.2rem * var(--ls)); }
.lesson-body .badge { font-size: calc(.75rem * var(--ls)); }
.lesson-body .speak { font-size: calc(.9rem * var(--ls)); }
.lesson-body button.big { font-size: calc(1.05rem * var(--ls)); }
.lesson-body .stat b { font-size: calc(1.5rem * var(--ls)); }
.lesson-body .stat span { font-size: calc(.85rem * var(--ls)); }
.lesson-body .table td, .lesson-body .table th { font-size: calc(.95rem * var(--ls)); }
.lesson-body .table th { font-size: calc(.85rem * var(--ls)); }

.table td.actions { white-space: nowrap; }
.table td, .table th { overflow-wrap: anywhere; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible, summary:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
h1:focus { outline: none; }
main, .card { min-width: 0; }

@media (max-width: 560px) {
  /* Tables become one stacked card per row: every cell and every action stays inside the viewport. */
  .table.stack, .table.stack tbody { display: block; width: 100%; }
  .table.stack tr { display: block; padding: .55rem 0; border-bottom: 1px solid var(--line); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { display: block; border: 0; padding: .15rem 0; }
  .table.stack td.actions { display: flex; flex-wrap: wrap; gap: .4rem; padding-top: .4rem; white-space: normal; }
  .table.stack td.actions button { min-width: 44px; min-height: 44px; justify-content: center; }
  .table.stack tr.stack-head { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); padding: 0; border: 0; }
  .row { min-width: 0; }
  #topbar { flex-direction: column; align-items: stretch; gap: .3rem; }
  main { padding: .8rem .75rem 5rem; }
  .lesson-text { font-size: 1.08rem; }
  .lesson-body .lesson-text { font-size: calc(1.08rem * var(--ls)); }
  .sticky-actions { gap: .35rem; }
  .sticky-actions > button { padding-left: .6rem; padding-right: .6rem; }
}
