/* French study: mobile first, light and dark via prefers-color-scheme. System fonts only. */
:root {
  color-scheme: light dark;
  --bg: #f6f3ee; --surface: #fffdf9; --surface-2: #efeae1; --line: #ddd5c8;
  --ink: #1d2433; --muted: #5d6578;
  --accent: #2446a8; --accent-ink: #ffffff; --accent-soft: #e3e9fb;
  --good: #1f7a4d; --good-soft: #dff1e7; --bad: #b3261e; --bad-soft: #fbe4e1;
  --hl: #fff0bf; --warn-soft: #fdf0d3;
  --shadow: 0 1px 2px rgb(29 36 51 / .08), 0 4px 14px rgb(29 36 51 / .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --ipa: "Charis SIL", "Gentium Plus", "Noto Sans", "Segoe UI", "DejaVu Sans", system-ui, sans-serif;
  --arabic: "Geeza Pro", "Noto Naskh Arabic", "Amiri", "Scheherazade New", "Traditional Arabic", "Simplified Arabic", "Segoe UI", Tahoma, "DejaVu Sans", Arial, sans-serif;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --surface: #1b202b; --surface-2: #252c3a; --line: #343c4d;
    --ink: #ebe8e2; --muted: #a2a9b8;
    --accent: #8fa8ff; --accent-ink: #0d1330; --accent-soft: #232d52;
    --good: #6fd0a0; --good-soft: #1b3a2d; --bad: #ff948b; --bad-soft: #43201e;
    --hl: #4a3f12; --warn-soft: #3b3217;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font); overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Arabic ---- */
.ar, [lang="ar"] { font-family: var(--arabic); }
.ar { font-size: 1.3em; line-height: 2; }
.ar-lg { font-size: 1.55em; }

/* ---- layout ---- */
#app {
  max-width: 560px; margin: 0 auto; min-height: 100dvh; background: var(--bg);
  padding: 0 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) { #app { border-inline: 1px solid var(--line); } }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 0 6px; min-height: 56px; }
.topbar h1 { font: 700 1.25rem/1.2 var(--serif); letter-spacing: .01em; }
.stack { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
.center { display: flex; justify-content: center; }
.section { display: flex; flex-direction: column; gap: 10px; }
.section-title { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.icon { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* ---- tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, 560px); display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 20;
}
.tab {
  flex: 1; min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--muted); font-size: .78rem; font-weight: 600; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .icon { transform: scale(1.08); }
.tab:focus-visible { outline-offset: -4px; }

/* ---- buttons and inputs ---- */
.btn {
  min-height: 44px; min-width: 44px; padding: 8px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.btn.success { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 52px; width: 100%; font-size: 1.05rem; }
.btn.small { min-height: 44px; padding: 4px 14px; font-size: .9rem; }
.btn.icon { font-size: 1.4rem; padding: 0; width: 44px; }
.btn.round { border-radius: 50%; width: 56px; height: 56px; padding: 0; }
.btn.round.xl { width: 76px; height: 76px; }
.btn.round.xl .icon { width: 36px; height: 36px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

.field { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.label { font-size: .85rem; font-weight: 600; color: var(--muted); padding: 0; }
.input {
  width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 1rem;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--bad); font-size: .92rem; min-height: 0; }
.error:empty { display: none; }
.count { font-size: .95rem; font-weight: 600; color: var(--accent); }
.count.bad { color: var(--muted); font-weight: 500; }

.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px 10px; font-size: .92rem; font-weight: 600; cursor: pointer; color: var(--muted); border-inline-start: 1px solid var(--line);
}
.segmented label:first-of-type { border-inline-start: 0; }
.segmented input:checked + label { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: -3px; }
.segmented input:checked:focus-visible + label { outline-color: var(--ink); }

.steppers { gap: 14px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper-label { font-weight: 600; }
.stepper-ctl { display: flex; align-items: center; gap: 6px; }
.stepper-val { min-width: 3.6ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch-row label { font-weight: 600; flex: 1; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; cursor: pointer; flex: none; margin: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.range { width: 100%; min-height: 44px; accent-color: var(--accent); }
.range-row { display: flex; align-items: center; gap: 12px; }

.picker { display: flex; flex-direction: column; gap: 12px; }
.pane { display: flex; flex-direction: column; gap: 12px; }
.setup { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 0 16px 16px; display: block; }
.setup:not([open]) { padding-bottom: 0; }
.setup > summary { min-height: 52px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.setup > .section { margin-top: 14px; }
.setup .section + .section { padding-top: 14px; border-top: 1px solid var(--line); }
.queue-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-weight: 600; }

/* autocomplete */
.ac { position: relative; }
.ac-list {
  position: absolute; top: 100%; inset-inline: 0; z-index: 15; margin: 4px 0 0; padding: 4px; list-style: none; max-height: 280px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .18);
}
.ac-opt { min-height: 44px; padding: 6px 10px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.ac-opt:hover, .ac-opt[aria-selected="true"] { background: var(--accent-soft); }
.ac-opt .ar { font-size: 1.15em; line-height: 1.6; }
.ac-fr { font-weight: 600; }

/* ---- now playing ---- */
.now-playing { text-align: center; display: flex; flex-direction: column; gap: 10px; padding: 22px 16px; }
.now-playing.idle { opacity: .75; }
.np-headword { font: 700 2.1rem/1.15 var(--serif); overflow-wrap: anywhere; }
.np-meta { display: flex; gap: 10px; justify-content: center; align-items: baseline; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.ipa { font-family: var(--ipa); }
.np-ar { font: 400 2.1rem/2 var(--arabic); min-height: 2em; }
.np-ex { border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.np-ex:has(.np-ex-fr:empty) { display: none; }
.np-ex-fr { font-size: 1.05rem; font-style: italic; }
.np-ex-ar { font: 400 1.4rem/2 var(--arabic); }
.np-fr, .np-ar, .np-ex-fr, .np-ex-ar { border-radius: 10px; transition: background .15s; }
.now-playing[data-part="fr"] .np-fr,
.now-playing[data-part="ar"] .np-ar,
.now-playing[data-part="ex-fr"] .np-ex-fr,
.now-playing[data-part="ex-ar"] .np-ex-ar { background: var(--hl); }
.progress-line { text-align: center; font-weight: 600; font-size: .9rem; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.controls { display: flex; justify-content: center; align-items: center; gap: 28px; padding: 4px 0; }

/* ---- quiz ---- */
.q-card { display: flex; flex-direction: column; gap: 14px; }
.q-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.q-headword { font: 700 2rem/1.15 var(--serif); overflow-wrap: anywhere; }
.q-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.q-actions > .btn:only-child { grid-column: 1 / -1; }
.q-counts { text-align: center; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.keys { display: none; text-align: center; font-size: .82rem; color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .keys { display: block; } }
.meaning { display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--line); padding-top: 14px; outline: none; }
.senses { display: flex; flex-direction: column; gap: 16px; }
.sense { display: flex; flex-direction: column; gap: 4px; }
.sense-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.sense-num { font-weight: 700; color: var(--accent); }
.sense-ind { font-style: italic; }
.tag { font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.tr { text-align: right; }
.mark { font: 700 .95rem var(--arabic); color: var(--accent); padding-inline: 2px; }
.gloss { text-align: right; color: var(--muted); }
.ex { margin-top: 4px; padding-inline-start: 10px; border-inline-start: 3px solid var(--line); }
.ex-fr { font-style: italic; }
.ex-ar { text-align: right; font: 400 1.25rem/2 var(--arabic); }
.summary-line { font-size: 1.1rem; margin-bottom: 12px; }
.missed { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; }
.missed li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border-top: 1px solid var(--line); }

/* ---- progress ---- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile-num { font: 700 2.2rem/1.1 var(--serif); font-variant-numeric: tabular-nums; color: var(--accent); }
.tile-label { font-weight: 700; margin-top: 2px; }
.tile-sub { font-size: .8rem; color: var(--muted); }

/* ---- notices, toast, login, sheet ---- */
.notice { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; margin-top: 8px; font-size: .92rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card { width: min(100%, 380px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.login-card h2 { font: 700 1.6rem var(--serif); }
.sheet { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 0; width: min(92vw, 440px); max-height: 90dvh; }
.sheet::backdrop { background: rgb(0 0 0 / .5); }
.sheet-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.sheet-body h2 { font: 700 1.3rem var(--serif); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 380px) {
  .progress-line { font-size: .82rem; }
  .np-headword { font-size: 1.8rem; }
  .np-ar { font-size: 1.8rem; }
  .controls { gap: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
