/* ==========================================================================
   Zbrojní průkaz – testy
   Mobile-first; světlý i tmavý režim (prefers-color-scheme); safe-area pro iPhone.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #f3f1ea;
  --surface: #fffdf8;
  --ink: #1b201c;
  --muted: #656e63;
  --line: #ddd8ca;
  --chip: #e9e5d7;

  --bar: #1f2d25;            /* hlavička – tmavá v obou režimech (kvůli bílému textu stavového řádku iOS) */
  --bar-ink: #f4f1e6;
  --accent: #d9a441;         /* mosaz */
  --accent-ink: #1b201c;
  --primary: #22352b;
  --primary-ink: #ffffff;

  --ok: #1e8a4c;
  --ok-bg: #dcf2e4;
  --bad: #c23b32;
  --bad-bg: #fbe0dd;
  --sel-bg: #f7ebcf;
  --sel: #b98624;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .08), 0 4px 14px rgba(20, 30, 20, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101411;
    --surface: #1a201c;
    --ink: #e8ebe4;
    --muted: #97a294;
    --line: #2b342d;
    --chip: #2a332c;
    --bar: #16211a;
    --primary: #2f4a3a;
    --ok: #46c27b;
    --ok-bg: #163b27;
    --bad: #f0726a;
    --bad-bg: #431f1c;
    --sel-bg: #3a3018;
    --sel: #d9a441;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

body.modal-open { overflow: hidden; }

button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.loading { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

/* ---------- rozvržení obrazovky ---------- */

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px calc(16px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.has-footer .main { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }

/* ---------- horní lišta ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
  background: var(--bar);
  color: var(--bar-ink);
}

.bar-btn {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px 0 4px;
  font-weight: 600;
  color: var(--accent);
}

.bar-mid { text-align: center; min-width: 0; }
.bar-title { font-weight: 700; font-size: 17px; white-space: nowrap; }
.bar-sub { font-size: 13px; opacity: .75; font-variant-numeric: tabular-nums; }
.bar-sub .urgent { color: #ff8b80; opacity: 1; font-weight: 700; }
.bar-right { justify-self: end; }

.bar-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  color: var(--bar-ink);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.bar-pill.accent { background: var(--accent); color: var(--accent-ink); }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, .15);
}
.progress span { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }

/* ---------- karty a prvky ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; border: 0; padding: 0; background: transparent; }

.section-title { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  border: 2px solid transparent;
  border-radius: 14px;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  background: var(--surface);
}
.btn.block { width: 100%; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }

.textbtn {
  align-self: center;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.skip { background: var(--sel-bg); color: var(--sel); }

.notice { padding: 12px 14px; border-radius: 12px; background: var(--sel-bg); color: var(--ink); font-size: 15px; }
.empty { text-align: center; color: var(--muted); padding: 18px 0; }

/* ---------- úvodní obrazovka ---------- */

.hero {
  background: var(--bar);
  color: var(--bar-ink);
  padding: calc(env(safe-area-inset-top) + 12px) calc(20px + env(safe-area-inset-right)) 26px calc(20px + env(safe-area-inset-left));
}
.hero > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.hero-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.logo { width: 48px; height: 48px; border-radius: 12px; }
.hero h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.01em; }
.hero p { margin-top: 6px; opacity: .78; font-size: 15px; }

.home .main { margin-top: -14px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px 8px; text-align: center; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 0 4px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat strong { font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; line-height: 1.25; color: var(--muted); }

.bigbtn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 112px;
  padding: 18px 20px;
  border-radius: 20px;
  position: relative;
  box-shadow: var(--shadow);
}
.bigbtn::after { content: '›'; position: absolute; right: 20px; top: 50%; transform: translateY(-52%); font-size: 34px; opacity: .6; }
.bigbtn-title { font-size: 24px; font-weight: 800; letter-spacing: -.01em; padding-right: 28px; }
.bigbtn-sub { font-size: 14.5px; opacity: .85; padding-right: 32px; line-height: 1.3; }
.bigbtn.practice { background: var(--primary); color: #fff; }
.bigbtn.exam { background: var(--accent); color: var(--accent-ink); }
.bigbtn:active { transform: scale(.985); }

.history { margin-top: 6px; }
.hist-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.hist-list li + li { border-top: 1px solid var(--line); }
.hist-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "main badge" "sub badge";
  align-items: center;
  column-gap: 12px;
  padding: 12px 16px;
}
.hist-row.link { grid-template-columns: 1fr auto 16px; grid-template-areas: "main badge chev" "sub badge chev"; }
.hist-main { grid-area: main; font-size: 18px; }
.hist-sub { grid-area: sub; font-size: 13.5px; }
.hist-row .badge { grid-area: badge; }
.chev { grid-area: chev; color: var(--muted); font-size: 22px; }

/* ---------- otázka ---------- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.qmeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.qid { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qtext { font-size: 19px; line-height: 1.4; font-weight: 650; }
.qimg {
  display: block;
  max-width: 100%;
  max-height: 52vh;
  width: auto;
  height: auto;
  margin: 0 auto 14px;
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
}

.answers { display: flex; flex-direction: column; gap: 10px; }

.answer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 13px 14px;
  text-align: left;
  line-height: 1.4;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  cursor: pointer;
}
.answer:disabled { color: var(--ink); opacity: 1; cursor: default; }
.answer.static { cursor: default; min-height: 0; font-size: 16px; }
.answer:active:not(:disabled):not(.static) { transform: scale(.99); }
@media (hover: hover) { .answer:hover:not(:disabled):not(.static) { border-color: var(--sel); } }

.letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--chip);
  font-weight: 700;
  font-size: 15px;
}
.atext { flex: 1; min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.mark { flex: none; width: 22px; text-align: center; font-weight: 800; font-size: 20px; line-height: 32px; }
.tag { display: block; margin-top: 4px; font-style: normal; font-size: 12.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; opacity: .85; }

.answer.is-selected { border-color: var(--sel); background: var(--sel-bg); }
.answer.is-selected .letter { background: var(--sel); color: #fff; }
.answer.is-selected .mark { color: var(--sel); }

.answer.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.answer.is-correct .letter { background: var(--ok); color: #fff; }
.answer.is-correct .mark { color: var(--ok); }
.answer.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.answer.is-wrong .letter { background: var(--bad); color: #fff; }
.answer.is-wrong .mark { color: var(--bad); }
.answer.is-dim { opacity: .55; }
.answer.is-dim.static { opacity: .75; }

.feedback { padding: 12px 14px; border-radius: 12px; font-weight: 700; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- spodní lišta ---------- */

.footer-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid;
  gap: 10px;
  padding: 12px calc(16px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.footer-bar > * { width: 100%; max-width: 640px; }
.footer-bar { grid-template-columns: 1fr; justify-items: center; }
.footer-bar.two { grid-template-columns: 1fr 1fr; }
.footer-bar.three { grid-template-columns: 1fr 1.25fr 1fr; }
.footer-bar.two, .footer-bar.three { max-width: none; }
@media (min-width: 680px) {
  .footer-bar.two, .footer-bar.three { padding-left: calc(50vw - 320px); padding-right: calc(50vw - 320px); }
}
.footer-bar .btn { padding: 0 10px; min-width: 0; }

/* ---------- přepínač ---------- */

.switch { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.switch-label { font-size: 16px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  flex: none;
  order: -1;
  position: relative;
  width: 50px; height: 30px;
  border-radius: 999px;
  background: var(--line);
  transition: background .2s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch input:checked ~ .switch-track { background: var(--ok); }
.switch input:checked ~ .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible ~ .switch-track { outline: 3px solid var(--accent); outline-offset: 2px; }
.toolbar .switch-label { font-size: 15px; }

/* ---------- přehled testu ---------- */

.overview-sum { font-weight: 700; margin-bottom: 14px; }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 10px; }
.navchip {
  display: grid;
  place-items: center;
  min-height: 52px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--surface);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.navchip.done { background: var(--primary); border-color: var(--primary); color: #fff; }
.navchip.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.navchip.sm { display: inline-block; width: 16px; height: 16px; min-height: 0; border-radius: 5px; box-shadow: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.navchip.sm { border-width: 2px; }
.two-line { display: flex; flex-direction: column; line-height: 1.2; }
.two-line small { font-size: 12px; font-weight: 500; color: var(--muted); }

/* ---------- výsledky ---------- */

.score-card { text-align: center; }
.score { font-size: 22px; color: var(--muted); font-variant-numeric: tabular-nums; }
.score strong { font-size: 64px; line-height: 1.05; color: var(--ink); }
.verdict { display: inline-block; margin: 10px 0 14px; padding: 8px 22px; border-radius: 999px; font-weight: 800; letter-spacing: .06em; }
.verdict.pass { background: var(--ok-bg); color: var(--ok); }
.verdict.fail { background: var(--bad-bg); color: var(--bad); }
.verdicts { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 14px; }
.verdicts .verdict { margin: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 16px; border-radius: 14px; letter-spacing: .02em; }
.verdicts .v-label { font-size: 13px; font-weight: 600; opacity: .85; letter-spacing: 0; }
.verdicts .v-res { font-size: 16px; }
.badges { grid-area: badge; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.verdict.neutral { background: var(--chip); color: var(--muted); letter-spacing: 0; font-weight: 600; font-size: 15px; border-radius: 14px; }
.verdict small { display: block; font-weight: 400; font-size: 12.5px; }

.meta { display: grid; gap: 6px; margin: 0; text-align: left; }
.meta > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.meta.stacked > div { flex-direction: column; gap: 2px; }
.meta.stacked dd { text-align: left; font-weight: 500; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: var(--chip); gap: 4px; }
.segmented button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; cursor: pointer; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.review {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--line);
  border-radius: var(--radius);
}
.review.ok { border-left-color: var(--ok); }
.review.wrong { border-left-color: var(--bad); }
.review.skipped { border-left-color: var(--sel); }
.review-head { display: flex; justify-content: space-between; align-items: center; }
.review-n { font-weight: 700; color: var(--muted); font-size: 14px; }
.review .qtext { font-size: 17px; }
.review .answer { padding: 10px 12px; }
.review .letter { width: 28px; height: 28px; font-size: 14px; }
.review .mark { line-height: 28px; }

.danger-zone p { margin-bottom: 12px; }

/* ---------- dialog ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 14, 11, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 400px;
  padding: 22px 20px 18px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
}
.modal h2 { font-size: 20px; margin-bottom: 8px; }
.modal p { color: var(--muted); margin-bottom: 18px; }
.modal-actions { display: flex; flex-direction: column-reverse; gap: 10px; }
.modal-actions .btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
