:root {
  --teal: #0f766e;
  --teal-d: #0b5a54;      /* teal used as FOREGROUND text (tags/labels/pills) */
  --teal-ink: #0f766e;    /* teal used as text/border on card (.btn.sec, links) */
  --bg: #f4f7f6;
  --card: #ffffff;
  --ink: #16211f;
  --muted: #5c6b68;
  --line: #e0e7e5;
  --good: #17966b;        /* good used as FILL / border (letter chips, option border) */
  --good-ink: #0f7a58;    /* good used as TEXT on a card - AA-contrast variant */
  --good-bg: #e6f6ee;
  --bad: #c8442f;         /* bad used as FILL / border */
  --bad-ink: #c8442f;     /* bad used as TEXT on a card - AA-contrast variant */
  --bad-bg: #fbeae6;
  --gold: #b9871f;
  --shadow: 0 2px 10px rgba(16,40,36,.07);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1615; --card: #17211f; --ink: #e8efed; --muted: #9fb0ad;
    --line: #263230; --good-bg: #12332a; --bad-bg: #3a201b; --shadow: 0 2px 12px rgba(0,0,0,.4);
    /* teal + result text are unreadable at full saturation on dark tints;
       lighten just the text/border variants to keep >=4.5:1 on the dark card */
    --teal-d: #5fd3c4; --teal-ink: #4fc7b8;
    --good-ink: #57d6a6; --bad-ink: #ff9683;
  }
}
/* explicit theme toggle (artifact host stamps data-theme on root) wins both ways */
:root[data-theme="dark"] {
  --bg: #0f1615; --card: #17211f; --ink: #e8efed; --muted: #9fb0ad;
  --line: #263230; --good-bg: #12332a; --bad-bg: #3a201b; --shadow: 0 2px 12px rgba(0,0,0,.4);
  --teal-d: #5fd3c4; --teal-ink: #4fc7b8;
  --good-ink: #57d6a6; --bad-ink: #ff9683;
}
:root[data-theme="light"] {
  --bg: #f4f7f6; --card: #ffffff; --ink: #16211f; --muted: #5c6b68;
  --line: #e0e7e5; --good-bg: #e6f6ee; --bad-bg: #fbeae6; --shadow: 0 2px 10px rgba(16,40,36,.07);
  --teal-d: #0b5a54; --teal-ink: #0f766e;
  --good-ink: #0f7a58; --bad-ink: #c8442f;
}
* { box-sizing: border-box; }
/* keep type in rem so the user's browser / OS font-size preference scales the app */
html { font-size: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 1rem; line-height: 1.5; -webkit-text-size-adjust: 100%;
}
/* every bit of text picks its own direction from its first strong char,
   so Hebrew stays RTL while English/Latin terms stay LTR inside it */
.stem, .opt-text, .fact, .card p, .card li, h1, h2, h3 { unicode-bidi: plaintext; }

/* screen-reader-only live/announce region (visually hidden, still read aloud) */
.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;
}
/* programmatic focus (screen swaps) should not draw a ring; keyboard focus still does */
[tabindex="-1"]:focus { outline: none; }

#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--teal); color: #fff;
  padding-top: max(10px, env(safe-area-inset-top));
}
#brand { font-weight: 700; font-size: 0.9375rem; letter-spacing: .2px; }
.ghost {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px;
  background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px;
  padding: 7px 11px; font-size: 0.875rem; cursor: pointer; font-family: inherit;
}
.ghost:active { transform: scale(.97); }
.ghost:focus-visible { outline: 2.5px solid #fff; outline-offset: 2px; }
#app { max-width: 720px; margin: 0 auto; padding: 16px 14px 40px; }
#footer { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 18px; }

h1 { font-size: 1.375rem; margin: 4px 0 2px; }
.sub { color: var(--muted); font-size: 0.875rem; margin: 0 0 18px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}

/* menu tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; text-align: right; cursor: pointer;
  font-family: inherit; color: var(--ink); display: flex; flex-direction: column; gap: 4px;
  transition: transform .06s;
}
.tile:active { transform: scale(.98); }
.tile .emoji { font-size: 1.625rem; }
.tile .t { font-weight: 700; font-size: 1rem; }
.tile .d { color: var(--muted); font-size: 0.78rem; }
.tile.wide { grid-column: 1 / -1; }

/* chips (filters) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 7px 15px; font-size: 0.84rem; cursor: pointer; font-family: inherit;
}
.chip.on { background: var(--teal); color: #fff; border-color: var(--teal); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--teal); color: #fff; border: 0; border-radius: 12px;
  padding: 13px 18px; font-size: 1rem; font-weight: 600; cursor: pointer;
  font-family: inherit; width: 100%;
}
.btn:active { transform: scale(.99); }
.btn.sec { background: transparent; color: var(--teal-ink); border: 1.5px solid var(--teal-ink); }
.btn.sm { width: auto; min-height: 44px; padding: 9px 16px; font-size: 0.875rem; }
.btn:disabled { opacity: .5; }
.btn:focus-visible, .tile:focus-visible, .opt:focus-visible, .chip:focus-visible,
input.txt:focus-visible { outline: 2.5px solid var(--teal-ink); outline-offset: 2px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* quiz */
.qmeta { display: flex; align-items: center; justify-content: space-between; color: var(--muted);
  font-size: 0.8125rem; margin-bottom: 8px; }
/* keep the exam timer on screen on long questions (sits just under the sticky topbar) */
.qmeta.sticky { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 46px);
  z-index: 4; background: var(--bg); padding: 6px 0; margin-bottom: 6px; }
.progress { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .3s; }
.stem { font-size: 1.125rem; font-weight: 600; margin: 6px 0 16px; }
/* long single-token Latin terms must wrap, never force horizontal page scroll */
.stem, .opt-text, .name-en, .fline .val { overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: 0.72rem; color: var(--teal-d); background: var(--good-bg);
  border-radius: 6px; padding: 2px 8px; margin-inline-end: 6px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px; text-align: right;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 0.97rem; cursor: pointer; font-family: inherit; color: var(--ink);
  width: 100%; transition: border-color .1s, background .1s;
}
.opt .letter {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; background: var(--bg);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 0.8125rem; font-weight: 700;
}
.opt-text { flex: 1; }
.opt:active { transform: scale(.995); }
.opt.correct { border-color: var(--good); background: var(--good-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.correct .letter { background: var(--good); color: #fff; border-color: var(--good); }
.opt.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
/* exam/duel: mark the picked option without revealing whether it is correct */
.opt.chosen { border-color: var(--teal); }
.opt.chosen .letter { background: var(--teal); color: #fff; border-color: var(--teal); }
.opt[disabled] { cursor: default; }

.explain {
  margin-top: 14px; padding: 13px 14px; border-radius: 12px; font-size: 0.906rem;
  background: var(--good-bg); border: 1px solid var(--line);
}
.explain.bad { background: var(--bad-bg); }
.explain b { display: block; margin-bottom: 3px; }

.reveal-btn { margin: 8px 0 2px; }

/* flashcard */
.flash { text-align: center; padding: 22px 16px; }
.flash .name-en { font-size: 1.5rem; font-weight: 800; }
.flash .name-he { color: var(--muted); font-size: 1rem; margin-top: 2px; }
.flash .facegrid { text-align: right; margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.flash .fline { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.flash .fline .lbl { font-size: 0.75rem; color: var(--teal-d); font-weight: 700; }
.flash .fline .val { font-size: 0.9375rem; }
.selfrate { display: flex; gap: 10px; margin-top: 16px; }
.selfrate .btn { font-size: 0.9375rem; }

/* result / readiness */
.big { font-size: 2.5rem; font-weight: 800; text-align: center; }
.bar { height: 20px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--teal); }
.statline { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.statline .lbl { flex: 0 0 42%; font-size: 0.875rem; }
.statline .bar { flex: 1; }
.statline .pct { flex: 0 0 44px; text-align: left; font-size: 0.8125rem; color: var(--muted); }
.weak { color: var(--bad-ink); font-weight: 700; }

.note { color: var(--muted); font-size: 0.8125rem; }
.center { text-align: center; }
.mt { margin-top: 14px; }
a.link { color: var(--teal-ink); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.9375rem; color: var(--ink);
  background: var(--good-bg); border-radius: 8px; padding: 2px 10px; }
.timer.low { color: #fff; background: var(--bad); }
label.field { display: block; font-size: 0.875rem; margin-bottom: 6px; color: var(--muted); }
input.txt {
  width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 1rem; font-family: inherit;
}
.pill { display:inline-block; background: var(--good-bg); color: var(--teal-d); border-radius:999px;
  padding:3px 10px; font-size:0.75rem; font-weight:700; }

/* post-exam answer review (correct answer + explanation per missed question) */
.reviewq { border-top: 1px solid var(--line); padding: 10px 0; }
.reviewq:first-of-type { border-top: 0; padding-top: 4px; }
.rq-stem { font-weight: 600; font-size: 0.906rem; margin: 0 0 6px; }
.rq-line { font-size: 0.875rem; margin: 2px 0; font-weight: 600; }
.rq-good { color: var(--good-ink); }
.rq-bad { color: var(--bad-ink); }
.rq-exp { margin: 6px 0 0; }
