/* base.css — design tokens, app bar, layout primitives, forms, buttons, toasts, error pages.
   Page-specific styles live in auth.css / practice.css / history.css. No inline styles anywhere (CSP). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #1f6feb;
  --accent-contrast: #ffffff;
  --danger: #c93c37;
  --ok: #1f8a4c;
  --bubble-tutor: #e9eef7;
  --bubble-learner: #dff3e6;
  /* dialogue speakers (SPEC-IS2 §10.3): six tints, fg >= 4.5:1 on --surface, bubble text stays --text */
  --speaker-1-fg: #1d5fb8; --speaker-1-bg: #e6eefb;
  --speaker-2-fg: #1f7a3f; --speaker-2-bg: #e3f4e8;
  --speaker-3-fg: #9a3f8f; --speaker-3-bg: #f6e6f4;
  --speaker-4-fg: #9a4a06; --speaker-4-bg: #fdeede;
  --speaker-5-fg: #0f6f78; --speaker-5-bg: #e0f4f6;
  --speaker-6-fg: #b3263c; --speaker-6-bg: #fbe6ea;
  --mark: #fff1a8;
  --border: #d9dee6;
  --radius: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --appbar-h: 56px;
  --bar-h: 88px;
  --shadow: 0 1px 2px rgba(16, 20, 24, 0.08), 0 4px 16px rgba(16, 20, 24, 0.06);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent);
  color-scheme: light;

  /* ---- IS2 tokens (SPEC-IS2 §10.3; every colour ≥ 4.5:1 on --bg and --surface as text) ---- */
  --almost: #a05e00;            /* ≈ feedback: amber, never red */
  --notyet: #5f6b7a;            /* ✗ feedback: neutral grey, never red */
  --gender-m: #0b7285;          /* ● masculine */
  --gender-f: #c2410c;          /* ▲ feminine */
  --gender-n: #6d28d9;          /* ■ neuter */
  --case-nom: #1d62d6;          /* nominative: blue */
  --case-acc: #c93c37;          /* accusative: red */
  --case-dat: #197a42;          /* dative: green */
  --case-gen: #626a78;          /* genitive: grey */
  --verb-slot: 2px solid currentColor;   /* the "hinge": finite verb box (+ 1px underline bracket, see .verb-slot) */
  --slot-front: #e7eefc;
  --slot-v: #fdebd0;
  --slot-subj: #e3f5ea;
  --slot-ekki: #f3e8ff;
  --slot-rest: #eef0f3;
  --tile-bg: #ffffff;
  --tile-bg-active: #dbe7fb;
  --tile-shadow: 0 1px 2px rgba(16, 20, 24, 0.12), 0 2px 6px rgba(16, 20, 24, 0.08);
  --pip: #cfd6e0;
  --pip-on: var(--accent);
  --heat-0: #eef1f5;            /* heatmap ○ */
  --heat-1: #cfe3fb;            /* ◔ */
  --heat-2: #9cc4f5;            /* ◑ */
  --heat-3: #5f9bea;            /* ◕ */
  --heat-4: #1f6feb;            /* ● */
  --ex-max-w: 720px;            /* engine task column */
  --bar-h-ex: 128px;            /* engine bottom bar (Check/Continue + tiles + letter bar) */
  --tabbar-h: 56px;             /* mobile bottom tab bar (+ safe area) */
}

[data-theme="dark"] {
  --bg: #101418;
  --surface: #181d23;
  --text: #e6e9ee;
  --muted: #9aa5b4;
  --accent: #6ea8ff;
  --accent-contrast: #0b1220;
  --danger: #ff6b66;
  --ok: #4cc27a;
  --bubble-tutor: #1f2a3a;
  --bubble-learner: #1b3326;
  --speaker-1-fg: #8ab4ff; --speaker-1-bg: #1e2a40;
  --speaker-2-fg: #7fd39a; --speaker-2-bg: #1c3326;
  --speaker-3-fg: #e0a6e0; --speaker-3-bg: #33223a;
  --speaker-4-fg: #f0b26a; --speaker-4-bg: #3a2a1a;
  --speaker-5-fg: #7fd6de; --speaker-5-bg: #1a3335;
  --speaker-6-fg: #ff9aa8; --speaker-6-bg: #3a1f26;
  --mark: #5d4d00;
  --border: #2a323c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35);
  color-scheme: dark;

  --almost: #ffb454;
  --notyet: #9aa5b4;
  --gender-m: #4fc3d9;
  --gender-f: #ff9466;
  --gender-n: #c4a6ff;
  --case-nom: #6ea8ff;
  --case-acc: #ff6b66;
  --case-dat: #4cc27a;
  --case-gen: #9aa5b4;
  --slot-front: #1b2a44;
  --slot-v: #3a2a10;
  --slot-subj: #15301f;
  --slot-ekki: #2a1f3d;
  --slot-rest: #222831;
  --tile-bg: #1f262e;
  --tile-bg-active: #243a5e;
  --tile-shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  --pip: #3a4452;
  --heat-0: #1d242c;
  --heat-1: #1b3350;
  --heat-2: #22497e;
  --heat-3: #3268b4;
  --heat-4: #6ea8ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418;
    --surface: #181d23;
    --text: #e6e9ee;
    --muted: #9aa5b4;
    --accent: #6ea8ff;
    --accent-contrast: #0b1220;
    --danger: #ff6b66;
    --ok: #4cc27a;
    --bubble-tutor: #1f2a3a;
    --bubble-learner: #1b3326;
    --speaker-1-fg: #8ab4ff; --speaker-1-bg: #1e2a40;
    --speaker-2-fg: #7fd39a; --speaker-2-bg: #1c3326;
    --speaker-3-fg: #e0a6e0; --speaker-3-bg: #33223a;
    --speaker-4-fg: #f0b26a; --speaker-4-bg: #3a2a1a;
    --speaker-5-fg: #7fd6de; --speaker-5-bg: #1a3335;
    --speaker-6-fg: #ff9aa8; --speaker-6-bg: #3a1f26;
    --mark: #5d4d00;
    --border: #2a323c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35);
    color-scheme: dark;

    --almost: #ffb454;
    --notyet: #9aa5b4;
    --gender-m: #4fc3d9;
    --gender-f: #ff9466;
    --gender-n: #c4a6ff;
    --case-nom: #6ea8ff;
    --case-acc: #ff6b66;
    --case-dat: #4cc27a;
    --case-gen: #9aa5b4;
    --slot-front: #1b2a44;
    --slot-v: #3a2a10;
    --slot-subj: #15301f;
    --slot-ekki: #2a1f3d;
    --slot-rest: #222831;
    --tile-bg: #1f262e;
    --tile-bg-active: #243a5e;
    --tile-shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
    --pip: #3a4452;
    --heat-0: #1d242c;
    --heat-1: #1b3350;
    --heat-2: #22497e;
    --heat-3: #3268b4;
    --heat-4: #6ea8ff;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-3);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 var(--space-3); }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

pre {
  overflow: auto;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.muted { color: var(--muted); }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -100px;
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-radius: var(--radius);
}

.skip-link:focus { top: var(--space-2); }

/* ---- Icons (inline SVG sprite) ---- */
.icon {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.3em;
  flex: none;
}

/* ---- App bar ---- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--appbar-h);
  padding: 0 var(--space-3);
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.appbar__logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  min-height: 44px;
}

.appbar__toggle {
  margin-left: auto;
}

.appbar__toggle .icon { transition: transform 0.2s; }
.appbar__toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }

.appbar__nav {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.appbar__nav.is-open { display: flex; }

.appbar__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.appbar__link:hover { background: var(--bubble-tutor); }
.appbar__link.is-active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.appbar__form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
}

@media (min-width: 640px) {
  /* `.appbar` prefix: the generic `.btn { display: inline-flex }` rule is declared later with the same specificity and would otherwise win. */
  .appbar .appbar__toggle { display: none; }
  .appbar__nav {
    display: flex;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-left: auto;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
  }
  .appbar__link span { display: none; }
  .appbar__link { padding: 0 var(--space-2); }
}

/* 640–1439 px: the nav row (8 links + 2 secondary + language/theme chips + logout) must fit — tighter gaps, icon-only
   logout. Below 1024 px learners navigate with the bottom tab bar, so their page links are hidden here (see .tabbar). */
@media (min-width: 640px) and (max-width: 1439px) {
  .appbar__nav { gap: var(--space-1); }
  .appbar__logout { padding: 0; width: 44px; }
  .appbar__logout .appbar__link-text { display: none; }
}

/* ≥ 1440 px: text labels on the primary links (icon-only with title tooltips between 1024 and 1439 px — measured:
   eight labelled links + two secondary icons + language/theme chips + logout need ≈ 1180 px). */
@media (min-width: 1440px) {
  .appbar__link:not(.appbar__link--secondary) span { display: inline; }
}

@media (min-width: 1600px) {
  .appbar__link { padding: 0 var(--space-3); }
}

/* History and Search: secondary links next to Practice (SPEC-IS2 §9.1), always icon-only. */
.appbar__link--secondary { color: var(--muted); }
.appbar__link--secondary.is-active { color: var(--accent); }

/* ---- Main / footer ---- */
.main {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-3);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
}

@media (min-width: 640px) {
  .main { padding: var(--space-4); }
}

.footer {
  display: none;
  padding: var(--space-3) var(--space-4);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

@media (min-width: 640px) {
  .footer { display: block; }
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

@media (hover: hover) {
  .btn:hover { background: var(--bubble-tutor); }
}
/* Pressed feedback (touch and mouse): a visible, immediate change without the OS tap highlight. */
.btn { -webkit-tap-highlight-color: transparent; transition: transform 80ms ease, background-color 120ms ease, filter 120ms ease; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.96); background: var(--bubble-tutor); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

@media (hover: hover) {
  .btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
}
.btn--primary:active:not(:disabled) { filter: brightness(0.88); background: var(--accent); }
.btn--chip.is-active:active:not(:disabled) { background: var(--accent); }

.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--icon { padding: 0; width: 44px; }
.btn--chip { min-height: 36px; min-width: 36px; padding: 0 var(--space-2); border-radius: 999px; font-size: 0.9rem; }
.btn--chip.btn--icon { width: 36px; }
.btn--chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
/* SPEC §11.1: touch targets >= 44 px — chips stay compact (36 px) only for mouse pointers. */
@media (pointer: coarse) {
  .btn--chip { min-height: 44px; min-width: 44px; }
  .btn--chip.btn--icon { width: 44px; }
}
.btn--round { border-radius: 50%; width: 64px; height: 64px; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }
.field label { font-weight: 500; }
.field .hint { color: var(--muted); font-size: 0.9rem; }
.field .error { color: var(--danger); font-size: 0.9rem; }

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { min-height: 96px; resize: vertical; }

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] { border-color: var(--danger); }

/* ---- Flash / toasts ---- */
.flash {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.flash--success { border-color: var(--ok); }
.flash--error { border-color: var(--danger); }

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}

.toast--error { background: var(--danger); color: #fff; }
.toast--success { background: var(--ok); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---- Error pages ---- */
.error-page {
  max-width: 640px;
  margin: 10vh auto 0;
  text-align: center;
}

.error-page__status {
  font-size: 4rem;
  font-weight: 800;
  color: var(--muted);
  margin: 0;
  line-height: 1;
}

.error-page__debug { text-align: left; margin: var(--space-3) 0; }
.error-page__debug pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- Mascot: Ulla, the IS2 sheep (assets/img/mascot.svg · mascot-head.svg · components/mascot.js) ----
   Sizes come from the width/height attributes (no layout shift); the classes below only pin the placements of
   SPEC-IS2 §10.3 (brand mark 30 px, note 64 px, panel 48 px, hero 160/120 px). Light/dark contrast is inside the SVGs. */
.mascot {
  display: inline-block;
  flex: none;
  vertical-align: middle;
  user-select: none;
  -webkit-user-drag: none;
}

.appbar__mark { width: 30px; height: 30px; }

/* head 64 px + one short line (error pages, lesson-locked) */
.mascot-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  color: var(--muted);
  text-align: left;
}

.mascot-note .mascot { width: 64px; height: 64px; }
.mascot-note span { max-width: 32ch; }

/* Today: the "all done" card and the finish-onboarding banner get the 48 px head (today.js) */
.today-plan .today-plan__alldone--mascot {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  column-gap: var(--space-3);
  row-gap: var(--space-1);
  align-items: start;
}

.today-plan .today-plan__alldone--mascot > .mascot { grid-row: 1 / span 3; }
.today__banner > .mascot { align-self: center; }
.today__banner > .mascot + div { flex-basis: 200px; }  /* keeps the head beside the text on a 375 px phone */

/* ---- Utilities ---- */
.stack > * + * { margin-top: var(--space-3); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.grow { flex: 1 1 auto; }
.text-is { font-weight: 500; overflow-wrap: anywhere; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ====================================================================================================
   IS2 shared pieces (SPEC-IS2 §9.1, §10.2, §10.3). Page/component styles live in is2.css and the page files.
   ==================================================================================================== */

/* ---- Shared aria-live region (ui.announce) ---- */
.live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Gender marks: colour + glyph, never colour alone (● masculine, ▲ feminine, ■ neuter) ---- */
.gender-m,
.gender-f,
.gender-n { font-weight: 600; white-space: nowrap; }
.gender-m { color: var(--gender-m); }
.gender-f { color: var(--gender-f); }
.gender-n { color: var(--gender-n); }
.gender-m::after { content: " \25CF"; }
.gender-f::after { content: " \25B2"; }
.gender-n::after { content: " \25A0"; }
.gender-m::after,
.gender-f::after,
.gender-n::after { font-size: 0.75em; vertical-align: 0.1em; }

/* ---- Case colour code (inventory §C.1): nominative blue · accusative red · dative green · genitive grey ---- */
.case-nom { color: var(--case-nom); }
.case-acc { color: var(--case-acc); }
.case-dat { color: var(--case-dat); }
.case-gen { color: var(--case-gen); }

/* ---- The finite-verb "hinge": a 2 px box with a 1 px underline bracket, same on cards, tiles, feedback, slot diagram ---- */
.verb-slot {
  display: inline-block;
  padding: 0 0.2em;
  border: var(--verb-slot);
  border-radius: 4px;
  box-shadow: 0 3px 0 -2px currentColor;
  font-weight: 600;
  line-height: 1.3;
}

/* ---- Emoji pictures (components/emoji.js); the width/height attributes set the size ---- */
.ex-emoji {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  user-select: none;
  -webkit-user-drag: none;
}

.ex-emoji--text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 64px;
  padding: var(--space-1) var(--space-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
  overflow-wrap: anywhere;
}

/* ---- Pips (ui.pips) and segmented progress bar (ui.segmentedBar) ---- */
.pips { display: inline-flex; gap: 6px; vertical-align: middle; }
.pip { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--pip); }
.pip.is-on { background: var(--pip-on); }

.segbar { display: flex; gap: 4px; width: 100%; height: 6px; }
.segbar__seg { flex: 1 1 0; min-width: 4px; border-radius: 3px; background: var(--pip); transition: background-color 0.3s; }
.segbar__seg[data-state="done"] { background: var(--ok); }
.segbar__seg[data-state="active"] { background: var(--accent); }
.segbar__seg[data-state="almost"] { background: var(--almost); }
.segbar__seg[data-state="wrong"],
.segbar__seg[data-state="skipped"] { background: var(--notyet); }

/* ---- Icelandic letter bar (letterbar.js): 44 px keys, 8 px gaps, collapsible ---- */
.letterbar {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.letterbar__keys {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.letterbar__key {
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--tile-bg);
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--tile-shadow);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.letterbar__key:active { background: var(--tile-bg-active); }
.letterbar__shift.is-active { border-color: var(--accent); background: var(--tile-bg-active); color: var(--accent); }
.letterbar__shift.is-locked { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast); }
.letterbar.is-collapsed { justify-content: flex-end; }
.letterbar__toggle { flex: none; }
.letterbar__toggle .icon { transition: transform 0.2s; }
.letterbar__toggle[aria-expanded="false"] .icon { transform: rotate(180deg); }

/* ---- Bottom sheet on <dialog> (ui.sheet). Same values as the practice word sheet so both can share the class. ---- */
.sheet {
  border: 0;
  padding: 0;
  margin: auto 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 85dvh;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet__panel { padding: var(--space-3); padding-bottom: max(var(--space-3), env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--space-2); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.sheet__title { margin: 0; font-size: 1.5rem; }
.sheet__actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }

/* The "More" navigation sheet (views/partials/tabbar.php) */
.sheet--nav { margin: auto auto 0; max-width: 480px; }
.sheet--nav .sheet__title { font-size: 1.2rem; }
.sheet__list { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }

.sheet__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: 0 var(--space-3);
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

.sheet__link:hover { background: var(--bubble-tutor); }
.sheet__link.is-active,
.sheet__link[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---- Mobile bottom tab bar (views/partials/tabbar.php): Today · Learn · Cards · Practice · Progress · More ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  min-height: var(--tabbar-h);
  padding: 0 max(var(--space-1), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--space-1), env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  min-height: var(--tabbar-h);
  margin: 0;
  padding: var(--space-1) 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tabbar__item .icon { width: 24px; height: 24px; }
.tabbar__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar__item:active { background: var(--bubble-tutor); }
.tabbar__item[aria-current="page"],
.tabbar__item.is-active,
.tabbar__item[aria-expanded="true"] { color: var(--accent); }

@media (min-width: 1024px) {
  .tabbar { display: none; }
}

@media (max-width: 1023px) {
  /* room for the fixed bar; sticky bottoms (toasts, the profile Save bar) move above it */
  .has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .has-tabbar .toasts { bottom: calc(var(--tabbar-h) + var(--space-3) + env(safe-area-inset-bottom)); }
  .has-tabbar .form-actions--sticky { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  /* full-screen shells with their own bottom bar (live practice, exercise engine: add `no-tabbar` to body_class) */
  .has-tabbar.page-practice,
  .has-tabbar.no-tabbar { padding-bottom: 0; }
  .has-tabbar.page-practice .toasts,
  .has-tabbar.no-tabbar .toasts { bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .page-practice .tabbar,
  .no-tabbar .tabbar { display: none; }
  /* learners reach every page from the tab bar + More sheet; the app bar keeps brand, language, theme, logout */
  .appbar__nav--learner .appbar__link { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Maintenance banner (admin settings `maintenance_banner`, docs/ADMIN-IS2.md §3) ---- */
.maintenance-banner {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  background: var(--almost);
  color: #fff;
  text-align: center;
  font-weight: 500;
}

/* ---- Footer with the legal links and the contact line (owner's requests of 2026-10-11) ----------------------------
   Guests and learners alike must reach Privacy / Terms / Contact on every width, so the footer is no longer hidden on
   phones; learners' bottom tab bar is cleared by `.has-tabbar { padding-bottom }` above. The practice shell keeps it off. */
.footer { display: block; padding: var(--space-3); }
.footer__line { margin: 0; }
.footer__line + .footer__line { margin-top: var(--space-1); }
.footer a { color: inherit; }

/* ---- Demo-mode notice on the landing page (home.landing.demo_notice) ---- */
.demo-notice {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid color-mix(in srgb, var(--almost) 45%, var(--border));
  border-left: 4px solid var(--almost);
  border-radius: 10px;
  background: color-mix(in srgb, var(--almost) 10%, var(--surface));
  color: var(--text);
  font-weight: 500;
}

.landing__seo { margin: 0 0 var(--space-3); }

/* ---- Terms acceptance on the register form ---- */
.choice--terms { align-items: flex-start; }
.choice--terms input[aria-invalid="true"] { outline: 2px solid var(--danger); outline-offset: 2px; }

/* ---- Cookie notice (partials/cookie-banner.php, consent.js): an informational bottom sheet ----
   Fixed above the tab bar / toasts order: toasts (200) > banner (150) > practice bar (10). Keyboard: the OK button is a
   native <button>, Escape dismisses too (consent.js). Works without JS: the form posts to /cookies/ack. */
.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 150;
  padding: var(--space-3);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(16, 20, 24, 0.12);
}

.cookie-banner__inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.cookie-banner__text {
  flex: 1 1 320px;
  margin: 0;
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-1);
}

.cookie-banner__text strong { flex-basis: 100%; }
.cookie-banner__text a { color: var(--accent); }
.cookie-banner__ok { flex: 0 0 auto; min-width: 120px; }

@media (max-width: 1023px) {
  .has-tabbar .cookie-banner { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .has-tabbar.page-practice .cookie-banner,
  .has-tabbar.no-tabbar .cookie-banner { bottom: 0; }
}

/* the live practice shell owns the whole viewport (sticky bar, mic): the notice waits for the next ordinary page */
.page-practice .cookie-banner { display: none; }
