:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1d1d1f; --muted: #5f6368; --border: #e5e7eb;
  --accent: #2563eb; --on-accent: #ffffff;
  --badge-bg: #fee2e2; --badge-fg: #b91c1c; --badge-ok-bg: #dcfce7; --badge-ok-fg: #15803d;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --hero-from: #2563eb; --hero-to: #4f46e5; --hero-fg: #ffffff; --hero-btn-bg: #ffffff; --hero-btn-fg: #2563eb;
  --wrong: #b91c1c; --card-border: #cbd5e1;
  --right-bg: #dcfce7; --right-fg: #166534; --almost-bg: #fef3c7; --almost-fg: #854d0e; --wrong-bg: #fee2e2; --wrong-fg: #991b1b;
  --track: #e5e7eb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --surface: #1c1f26; --text: #f1f2f4; --muted: #a0a6b1; --border: #2c303a;
    --accent: #6b9bff; --on-accent: #0b1020;
    --badge-bg: #4a1d1d; --badge-fg: #fca5a5; --badge-ok-bg: #14341f; --badge-ok-fg: #86efac;
    --wrong: #fca5a5; --card-border: #3b4150;
    --right-bg: #14341f; --right-fg: #86efac; --almost-bg: #3b2a0a; --almost-fg: #fcd34d; --wrong-bg: #4a1d1d; --wrong-fg: #fca5a5;
    --track: #2c303a;
    --shadow: none;
    --hero-from: #1d4ed8; --hero-to: #4338ca; --hero-fg: #ffffff; --hero-btn-bg: #ffffff; --hero-btn-fg: #1d4ed8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --surface: #1c1f26; --text: #f1f2f4; --muted: #a0a6b1; --border: #2c303a;
  --accent: #6b9bff; --on-accent: #0b1020;
  --badge-bg: #4a1d1d; --badge-fg: #fca5a5; --badge-ok-bg: #14341f; --badge-ok-fg: #86efac;
  --wrong: #fca5a5; --card-border: #3b4150;
  --right-bg: #14341f; --right-fg: #86efac; --almost-bg: #3b2a0a; --almost-fg: #fcd34d; --wrong-bg: #4a1d1d; --wrong-fg: #fca5a5;
  --track: #2c303a;
  --shadow: none;
  --hero-from: #1d4ed8; --hero-to: #4338ca; --hero-fg: #ffffff; --hero-btn-bg: #ffffff; --hero-btn-fg: #1d4ed8;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: 160px; scroll-padding-top: 72px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}
/* paints the phone's status-bar band above the sticky top bar (zero height in a browser) */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px 32px; }
.topbar {
  display: flex; justify-content: flex-end; align-items: center; gap: 8px;
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); padding: 12px 0 6px;
}
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.lang-toggle button {
  font: inherit; font-weight: 600; min-height: 44px; min-width: 56px; padding: 0 12px;
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
}
.lang-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.hi { font-size: 22px; font-weight: 700; margin: 8px 0 2px; }
.hero { background: linear-gradient(135deg, var(--hero-from), var(--hero-to)); color: var(--hero-fg); border-radius: 18px; padding: 16px; }
.hero .k { opacity: .85; }
.hero .go {
  display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 12px; min-height: 48px;
  border-radius: 12px; text-decoration: none;
  background: var(--hero-btn-bg); color: var(--hero-btn-fg); font: inherit; font-weight: 700; cursor: pointer;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.tile {
  display: block; background: var(--surface); color: var(--text); text-decoration: none;
  border-radius: 14px; padding: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); min-width: 0;
}
.tile .i { font-size: 24px; }
.tile .n { font-weight: 700; margin-top: 4px; overflow-wrap: anywhere; }
.tile .s { color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.badge { display: inline-block; background: var(--badge-bg); color: var(--badge-fg); border-radius: 8px; padding: 1px 8px; font-weight: 700; margin-top: 6px; }
.badge.g { background: var(--badge-ok-bg); color: var(--badge-ok-fg); }
.placeholder { padding-top: 24px; }
.placeholder a { color: var(--accent); font-weight: 600; display: inline-block; min-height: 44px; line-height: 44px; }

.btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); min-height: 48px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.logout { margin-top: 20px; }
.logout-ask { margin: 20px 0 8px; font-weight: 600; }
.logout-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.login { padding-top: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 24px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.field input {
  font: inherit; font-weight: 400; min-height: 48px; padding: 0 12px; border-radius: 12px; width: 100%;
  background: var(--surface); color: var(--text); border: 1px solid var(--card-border);
}
.field input:focus-visible, .btn:focus-visible, .tile:focus-visible, .hero .go:focus-visible, .lang-toggle button:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.form-error { margin: 0; color: var(--wrong); font-weight: 600; }
.form-error:empty { display: none; }
.badge[hidden] { display: none; }

/* words drill */
.words { padding-top: 8px; }
.back { color: var(--accent); font-weight: 600; display: inline-block; min-height: 44px; line-height: 44px; text-decoration: none; }
.prog { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; margin-top: 8px; }
.bar .fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .2s; }
.ask { margin: 20px 0 6px; color: var(--muted); }
.prompt { font-size: 26px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; margin-bottom: 16px; }
.answer-form { display: flex; flex-direction: column; gap: 12px; }
.answer {
  font: inherit; font-size: 18px; min-height: 52px; padding: 0 14px; border-radius: 12px; width: 100%;
  background: var(--surface); color: var(--text); border: 1px solid var(--card-border);
}
.answer:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.answer[readonly] { opacity: .85; }
.res { border-radius: 12px; padding: 12px 14px; border: 1px solid transparent; overflow-wrap: anywhere; }
.res .verdict { font-weight: 700; font-size: 18px; }
.res .note { margin-top: 2px; }
.res .correct { margin-top: 4px; }
.res.right { background: var(--right-bg); color: var(--right-fg); border-color: var(--right-fg); }
.res.almost { background: var(--almost-bg); color: var(--almost-fg); border-color: var(--almost-fg); }
.res.wrong { background: var(--wrong-bg); color: var(--wrong-fg); border-color: var(--wrong-fg); }
.words-note { font-size: 18px; margin: 20px 0; overflow-wrap: anywhere; }
.btn.gap { margin-top: 12px; }
.words a.btn { text-decoration: none; }
