/* Quizbox — styles. System fonts, no frameworks, cheap effects (no blur) for older hardware. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #14171c;
  --muted: #5d6573;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-ink: #ffffff;
  --accent-soft: #e3f4f1;
  --accent-wash: rgba(15, 118, 110, .12);
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --ok-line: #86d19f;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --bad-line: #f0a3a3;
  --flag: #b45309;
  --flag-soft: #fdf3e2;
  /* Logo colours (same in both themes, like the favicon); overridden by a custom accent */
  --brand: #0f766e;
  --brand-light: #14b8a6;
  --brand-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 8px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e8eaef; --muted: #9aa3b2;
    --border: #2a2f3a; --border-strong: #3a404d; --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #0f1115;
    --accent-soft: #102d2a; --ok: #4ade80; --ok-soft: #12271a; --ok-line: #2f7a4b; --bad: #f87171; --bad-soft: #2c1618;
    --bad-line: #8a3a3a; --flag: #fbbf24; --flag-soft: #2b2312;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e8eaef; --muted: #9aa3b2;
  --border: #2a2f3a; --border-strong: #3a404d; --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #0f1115;
  --accent-soft: #102d2a; --ok: #4ade80; --ok-soft: #12271a; --ok-line: #2f7a4b; --bad: #f87171; --bad-soft: #2c1618;
  --bad-line: #8a3a3a; --flag: #fbbf24; --flag-soft: #2b2312;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; justify-content: center; }
.grow { flex: 1 1 auto; }
.text-bad { color: var(--bad) !important; }
.text-ok { color: var(--ok); }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.wrap.narrow { max-width: 680px; }
main.wrap { padding-top: 18px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
main > * + * { margin-top: 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top);
}
.topbar-in { max-width: 860px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 16px; }
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h1 { font-size: 18px; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.brand-mark { width: 36px; height: 36px; flex: none; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding-top: 4px; }
.tabs a {
  padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { font-size: 12px; background: var(--surface-2); border-radius: 99px; padding: 1px 8px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, transform .05s; user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-sm .ico { width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-icon {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: var(--radius-sm); flex: none;
  border: 1px solid transparent; background: transparent; color: var(--muted); transition: background-color .15s, color .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.sm { width: 34px; height: 34px; }
.btn-icon.sm .ico { width: 17px; height: 17px; }
.btn-icon.on-flag { color: var(--flag); background: var(--flag-soft); }
.btn-icon.on-flag .ico { fill: currentColor; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--accent); font-weight: 600; font-size: 14px; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 550;
}
.chip-btn .ico { width: 14px; height: 14px; }
.chip-btn:hover { color: var(--text); border-color: var(--border-strong); }
.chip-btn.on { color: var(--flag); background: var(--flag-soft); border-color: transparent; }
.chip-btn.on .ico { fill: currentColor; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg-btn { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-size: 14px; font-weight: 550; color: var(--muted); white-space: nowrap; }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-sm .seg-btn { padding: 4px 10px; font-size: 12.5px; }

/* ---------- Toolbar, search, chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search {
  flex: 1 1 220px; display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); height: 100%; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 13.5px; font-weight: 550;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Cards & panels ---------- */
.card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 18px; }
.panel > * + * { margin-top: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { font-size: 16px; font-weight: 650; }
.h3 { font-size: 15px; margin: 14px 0 6px; }
.badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--flag-soft); color: var(--flag); }

.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.bar-lg { height: 10px; }
.bar-ok > span { background: var(--ok); }
.bar-bad > span { background: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat b small { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat span { font-size: 12.5px; color: var(--muted); }

.pips { display: inline-flex; gap: 4px; flex: none; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.pips i.on { background: var(--ok); }

/* ---------- Home ---------- */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.set-card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.set-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.set-card-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.set-card h3 { font-size: 16px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.set-card-foot { display: flex; justify-content: space-between; color: var(--muted); }
.set-card-foot span { display: inline-flex; align-items: center; gap: 4px; }
.set-card-foot .ico { width: 14px; height: 14px; }

.empty { padding: 36px 22px; text-align: center; }
.empty > * + * { margin-top: 12px; }
.empty h2 { font-size: 20px; }
.empty .muted { max-width: 440px; margin-left: auto; margin-right: auto; }
.empty-ico { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty-ico .ico { width: 28px; height: 28px; }
.format { text-align: left; margin-top: 22px !important; border-top: 1px solid var(--border); padding-top: 14px; }
.format summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.format > * + * { margin-top: 10px; }
pre.code, textarea.code {
  font: 13px/1.5 var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; overflow: auto; white-space: pre; width: 100%; color: var(--text);
}
textarea.code { resize: vertical; }
.drop-hint { margin-top: 24px; }
@media (hover: none) { .drop-hint { display: none; } }

/* ---------- Set overview ---------- */
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mode-card {
  display: flex; flex-direction: column; gap: 12px; padding: 16px; color: var(--text); position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s;
}
a.mode-card:hover { border-color: var(--accent); }
.mode-card h3 { font-size: 16px; font-weight: 650; }
.mode-card .btn-row { margin-top: 10px; }
.mode-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; }
.mode-ico .ico { width: 21px; height: 21px; }
.mode-ico.study { background: var(--accent-soft); color: var(--accent); }
.mode-ico.quiz { background: var(--ok-soft); color: var(--ok); }
.mode-ico.browse { background: var(--flag-soft); color: var(--flag); }
.mode-go { position: absolute; top: 16px; right: 16px; color: var(--muted); }

.runs { list-style: none; margin: 0; padding: 0; }
.run {
  width: 100%; display: grid; grid-template-columns: 1fr 52px 1fr 44px 44px; align-items: center; gap: 10px;
  padding: 9px 4px; border: 0; border-top: 1px solid var(--border); background: none; text-align: left; font-size: 14px;
}
.run:hover { background: var(--surface-2); }
.run-score, .run-pct, .run-time { font-variant-numeric: tabular-nums; text-align: right; }
.run-pct { font-weight: 650; }

/* ---------- Question browser ---------- */
.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.qitem { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.qitem.is-flagged { border-left: 3px solid var(--flag); }
.qitem > * + * { margin-top: 10px; }
.qitem-head { display: flex; gap: 10px; align-items: flex-start; }
.qitem-head .pips { margin-top: 8px; }
.qnum { font-size: 12.5px; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 7px; padding: 2px 8px; flex: none; margin-top: 1px; }
.qitem-q { flex: 1; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.qitem-a { display: flex; gap: 8px; align-items: flex-start; background: var(--ok-soft); color: var(--text); border-radius: var(--radius-sm); padding: 9px 12px; }
.qitem-a .ico { color: var(--ok); margin-top: 3px; }
.qitem-a span { overflow-wrap: anywhere; white-space: pre-wrap; }
.qitem-back { color: var(--muted); font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 3px solid var(--border); padding-left: 12px; }
.qitem-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- Study & quiz card ---------- */
.meta > * + * { margin-top: 8px; }
.meta-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.meta-row b { color: var(--text); }
.scene { perspective: 1400px; }
.qcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 18px; transition: transform .16s ease-in; transform-origin: 50% 50%; will-change: transform;
}
.qcard.turn-out { transform: rotateY(90deg); }
.qcard.turn-in { transform: rotateY(-90deg); transition: none; }
.qcard > * + * { margin-top: 14px; }
.qcard.is-back { background: linear-gradient(180deg, var(--accent-soft), var(--surface) 140px); }
.qcard-top { display: flex; align-items: center; gap: 10px; margin: -6px -6px 0 0; }
.qcard-top .qnum { margin: 0; }
.qcard-q { font-size: 20px; line-height: 1.4; font-weight: 650; letter-spacing: -.01em; white-space: pre-wrap; overflow-wrap: anywhere; }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 10px 14px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; font-size: 16px; line-height: 1.4;
  transition: border-color .12s, background-color .12s, opacity .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt:disabled { cursor: default; color: var(--text); }
.opt-key {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 8px;
  background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 14px;
}
.opt-text { flex: 1; overflow-wrap: anywhere; white-space: pre-wrap; }
.opt.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.is-correct .opt-key { background: var(--ok); color: var(--surface); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.is-wrong .opt-key { background: var(--bad); color: var(--surface); }
.opt.is-dim { opacity: .55; }
.feedback { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.back-q { font-size: 15px; white-space: pre-wrap; }
.back-answer { background: var(--ok-soft); border: 1px solid var(--ok-line); border-radius: 12px; padding: 12px 14px; }
.back-answer .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ok); margin-bottom: 2px; }
.back-answer p { font-size: 17px; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.back-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; font-size: 15.5px; }
.qcard .back-text:not(:first-child) { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.qcard.done { text-align: center; padding: 34px 20px; }
.qcard.done h2 { font-size: 22px; }
.done-ico { width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.done-ico .ico { width: 30px; height: 30px; }

.action-bar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-height: 44px; }
.action-bar .btn { min-width: 120px; }
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; } }
.score-pill { font-weight: 700; font-size: 14px; background: var(--ok-soft); color: var(--ok); padding: 5px 11px; border-radius: 99px; font-variant-numeric: tabular-nums; }

/* ---------- Quiz result ---------- */
.result { padding: 28px 20px; text-align: center; }
.result > * + * { margin-top: 10px; }
.result h2 { font-size: 22px; }
.result .btn-row { margin-top: 18px; }
.ring {
  --p: 0; width: 120px; height: 120px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
}
.ring span { width: 96px; height: 96px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 26px; font-weight: 750; }
.review { margin: 0; padding: 0 0 0 20px; }
.review li { padding: 12px 0; border-top: 1px solid var(--border); }
.review li:first-child { border-top: 0; }
.review li > * + * { margin-top: 6px; }
.review-q { font-weight: 600; white-space: pre-wrap; }
.review-a { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; }
.review-a .ico { margin-top: 3px; }
.review-a.ok { color: var(--ok); }
.review-a.bad { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.review-a span { color: var(--text); white-space: pre-wrap; }
.review-back { font-size: 14px; color: var(--muted); white-space: pre-wrap; }

/* ---------- Forms ---------- */
.field { display: block; border: 0; padding: 0; margin: 0; }
.field + .field, .field + .check, .check + .field { margin-top: 16px; }
.field > span { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.field > span em { font-style: normal; font-weight: 400; color: var(--muted); }
.field input[type=text], .field input[type=password], .field input[type=number], .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); outline: 0;
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .btn { min-width: 42px; min-height: 42px; justify-content: center; font-size: 18px; }
.field .stepper input[type=number] { width: 72px; text-align: center; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 15px; }
.field-row input[type=color] {
  width: 42px; height: 42px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.field-sub { margin-top: 14px; }
.field-sub > p { margin: 0 0 6px; font-size: 14px; }
.field-sub > p label { font-weight: 600; }
.field > .check { margin-top: 2px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.ans-list { display: grid; gap: 8px; }
.ans-row { display: flex; align-items: center; gap: 8px; }
.ans-row input[type=text] {
  flex: 1; min-width: 0; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); outline: 0;
}
.ans-row input[type=text]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ans-pick { position: relative; cursor: pointer; }
.ans-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ans-pick .opt-key { width: 42px; height: 42px; border: 1.5px solid var(--border); transition: all .12s; }
.ans-pick input:checked + .opt-key { background: var(--ok); color: var(--surface); border-color: var(--ok); }
.ans-pick input:focus-visible + .opt-key { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Import dialog ---------- */
.imp-list { display: grid; gap: 12px; }
.imp-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.imp-row > * + * { margin-top: 10px; }
.imp-row.is-fail { border-color: var(--bad-line); background: var(--bad-soft); }
.imp-file { display: flex; align-items: center; gap: 8px; font-weight: 600; overflow-wrap: anywhere; }
.imp-file .ico { color: var(--muted); }
.imp-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.imp-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.imp-fields .field + .field { margin-top: 0; }
.imp-errors summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.imp-errors ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--bad); max-height: 180px; overflow: auto; }
.imp-warnings summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.imp-warnings ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--flag); max-height: 180px; overflow: auto; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; background: rgba(10, 12, 18, .5); display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fade .15s ease;
}
.modal-overlay.out { opacity: 0; transition: opacity .12s; }
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop .18s ease;
}
.modal-wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 6px 20px; }
.modal-head h2 { font-size: 17px; font-weight: 650; }
.modal-body { padding: 8px 20px 16px; overflow: auto; -webkit-overflow-scrolling: touch; }
.modal-body > p + * { margin-top: 12px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toasts & drag overlay ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; font-weight: 550;
  box-shadow: var(--shadow-lg); max-width: 100%; animation: pop .18s ease; transition: opacity .3s, transform .3s;
}
.toast-ok { background: var(--ok); color: #fff; }
.toast-bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }
.unsaved-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 190; background: var(--bad); color: #fff; font-weight: 600; text-align: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.saving-indicator {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); z-index: 95;
  font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.saving-indicator[hidden] { display: none; }
.signin-again {
  position: fixed; bottom: calc(8px + env(safe-area-inset-bottom)); right: 12px; z-index: 191;
  background: #fff; color: var(--bad); font-weight: 600;
}
.signin-again[hidden] { display: none; }
body.has-unsaved { padding-bottom: 64px; }
body.has-unsaved .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); }
.drop-overlay { display: none; }
body.dragging .drop-overlay {
  display: grid; place-items: center; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 150; pointer-events: none;
  background: var(--accent-wash); border: 3px dashed var(--accent);
}
.drop-overlay div { background: var(--surface); color: var(--accent); padding: 14px 22px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow-lg); }

/* ---------- Flashcards & libraries ---------- */
.show-xs { display: none; }
.seg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg-btn .ico { width: 16px; height: 16px; }
.seg-full { display: flex; width: 100%; }
.seg-full .seg-btn { flex: 1 1 auto; min-width: 0; padding-top: 9px; padding-bottom: 9px; }
.seg-full .seg-btn span { overflow: hidden; text-overflow: ellipsis; }
.seg-count { font-size: 12px; font-variant-numeric: tabular-nums; background: var(--surface-2); color: var(--muted); border-radius: 99px; padding: 0 7px; line-height: 18px; flex: none; }
.seg-btn:not(.on) .seg-count { background: var(--border); }
.lib-bar { max-width: 620px; }
.badge .ico { width: 14px; height: 14px; margin-right: 5px; }
.badge-cards { background: var(--accent-soft); color: var(--accent); }
code { font: 13px var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.qcard-label { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.qcard.is-term { border-top: 3px solid var(--accent); }
.term-face { min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 12px 4px; }
.term { font-size: 28px; line-height: 1.3; font-weight: 700; letter-spacing: -.015em; white-space: pre-wrap; overflow-wrap: anywhere; }
.qcard .back-text.meaning { font-size: 17px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.qitem-term { font-size: 17px; }
.qitem-meaning { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--accent-soft); border-radius: var(--radius-sm); padding: 9px 12px; }
.btn-grade-ok { background: var(--ok); color: var(--surface); }
.btn-grade-ok:hover { filter: brightness(1.08); }
.btn-grade-bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.btn-grade-bad:hover { border-color: var(--bad); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .modes { grid-template-columns: 1fr; }
  .mode-card { flex-direction: row; align-items: center; }
  .mode-card .mode-go { position: static; margin-left: auto; }
  .mode-card .btn-row { margin-top: 8px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .lib-bar .seg-btn { padding-left: 8px; padding-right: 8px; font-size: 13.5px; }
  .lib-bar .seg-btn .ico { display: none; }
  .topbar-in { min-height: 56px; padding: 6px 12px; }
  .qcard { padding: 16px 14px; border-radius: 16px; }
  .qcard-q { font-size: 18px; }
  .opt { min-height: 52px; padding: 10px 12px; font-size: 15.5px; }
  .imp-fields { grid-template-columns: 1fr; }
  .run { grid-template-columns: 1fr 48px 40px 44px; }
  .run-bar { display: none; }
  .hide-xs { display: none; } .show-xs { display: inline; }
  .toolbar .btn { flex: 1 1 auto; }
  .toolbar .search + .btn { flex: none; }
  /* Sticky action bar at the thumb */
  .action-bar {
    position: sticky; bottom: 0; z-index: 10; margin-left: -16px; margin-right: -16px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--border);
  }
  .action-bar .btn { flex: 1; min-width: 0; }
  main.wrap { padding-bottom: 24px; }
  /* Dialogs become bottom sheets */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
}

/* ---------- Auth screens (setup, sign-in, server unreachable) ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}
.auth-card { width: 100%; max-width: 420px; padding: 28px 24px; }
.auth-card h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.auth-card > * + *, .auth-card form > * + * { margin-top: 14px; }
.auth-card .btn-primary { width: 100%; }
.auth-card [role=alert]:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
