:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #1c2430;
  --muted: #5b6776;
  --border: #dde2e8;
  --accent: #0f766e;
  --accent-soft: #d5f0ec;
  --accent-text: #ffffff;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn-soft: #fef3c7;
  --warn-border: #f59e0b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #182029;
    --surface-2: #212b36;
    --text: #e6ebf0;
    --muted: #97a3b0;
    --border: #2c3845;
    --accent: #2dd4bf;
    --accent-soft: #123b37;
    --accent-text: #06201d;
    --good: #4ade80;
    --good-soft: #13331f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --warn-soft: #3a2e0c;
    --warn-border: #d97706;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #182029;
  --surface-2: #212b36;
  --text: #e6ebf0;
  --muted: #97a3b0;
  --border: #2c3845;
  --accent: #2dd4bf;
  --accent-soft: #123b37;
  --accent-text: #06201d;
  --good: #4ade80;
  --good-soft: #13331f;
  --bad: #f87171;
  --bad-soft: #3a1717;
  --warn-soft: #3a2e0c;
  --warn-border: #d97706;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px;
}

main { padding-top: 20px; padding-bottom: 40px; outline: none; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 560px) {
  .brand span { display: none; }
  .nav a { padding: 6px 9px; font-size: 15px; }
}

/* ---------- typography ---------- */
h1 { font-size: 28px; line-height: 1.2; margin: 8px 0 6px; }
h2 { font-size: 21px; margin: 28px 0 12px; }
h3 { font-size: 18px; margin: 26px 0 8px; color: var(--accent); }
.lead { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.btn.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }

/* ---------- cards / grid ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0 8px;
}
.stat .num { font-size: 28px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}
.topic-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  transition: transform .12s ease, border-color .12s ease;
}
.topic-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.topic-card .head { display: flex; align-items: center; gap: 10px; }
.topic-card .ico { font-size: 26px; }
.topic-card .title { font-weight: 700; font-size: 17px; line-height: 1.25; }
.topic-card .sum { color: var(--muted); font-size: 14px; flex: 1; }
.topic-card .meta { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- notes ---------- */
.notes .table-wrap { overflow-x: auto; margin: 10px 0; }
.notes table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.notes th, .notes td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.notes th { background: var(--surface-2); font-weight: 600; }
.notes ul, .notes ol { padding-left: 22px; }
.notes li { margin: 3px 0; }
.notes ul.cols { columns: 2 220px; }
.notes .tip {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
}
.notes pre.ascii {
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.35;
}
.notes .two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 20px; }
.notes mark { background: #fde68a; color: #1c2430; border-radius: 3px; padding: 0 2px; }

.flow { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.flow span {
  flex: 1 1 150px;
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
}
.flow small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.flow.vertical { flex-direction: column; }
.flow.vertical span { flex: none; }

.traps {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: 26px;
}
.traps h3 { margin-top: 0; color: inherit; }
.traps ul { margin: 0; padding-left: 20px; }
.traps li { margin: 4px 0; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; flex-wrap: wrap; }

.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 18px; }
.toc a {
  font-size: 13px;
  padding: 4px 10px;
  background: var(--surface-2);
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
}
.toc a:hover { color: var(--accent); }

/* ---------- chips (topic filters) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  border: 0;
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  min-height: 40px;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.field { margin: 14px 0; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }

/* ---------- flashcards ---------- */
.fc-wrap { max-width: 640px; margin: 0 auto; }
.fc-progress { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.flashcard {
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.flashcard .inner {
  position: relative;
  min-height: 260px;
  transition: transform .45s ease;
  transform-style: preserve-3d;
}
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.flashcard .face.back { transform: rotateY(180deg); background: var(--accent-soft); }
.flashcard .face .txt { font-size: 22px; font-weight: 600; line-height: 1.35; }
.flashcard .face.back .txt { font-size: 19px; font-weight: 500; }
.flashcard .face .tag { position: absolute; top: 12px; left: 14px; font-size: 12px; color: var(--muted); }
.flashcard .face .hint { position: absolute; bottom: 12px; font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .flashcard .inner { transition: none; }
}
.kbd-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }
kbd {
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 12px;
  background: var(--surface);
}
.fc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

/* ---------- quiz ---------- */
.quiz-wrap { max-width: 720px; margin: 0 auto; }
.q-topic { font-size: 13px; color: var(--muted); }
.q-text { font-size: 21px; font-weight: 650; margin: 6px 0 16px; line-height: 1.35; }
.options { display: grid; gap: 10px; }
.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  min-height: 48px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .k {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.opt.correct { background: var(--good-soft); border-color: var(--good); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.opt:disabled { cursor: default; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 10px; }
.feedback.ok { background: var(--good-soft); color: var(--good); }
.feedback.ko { background: var(--bad-soft); color: var(--bad); }
.feedback .ex { color: var(--text); display: block; margin-top: 4px; }
.score-big { font-size: 54px; font-weight: 800; text-align: center; margin: 8px 0 0; }
.review-item { border-top: 1px solid var(--border); padding: 12px 0; }
.review-item .your { color: var(--bad); }
.review-item .right { color: var(--good); }

/* ---------- search ---------- */
.search-input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 17px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.result { border-bottom: 1px solid var(--border); padding: 10px 0; }
.result .t { font-weight: 600; }
.result .src { font-size: 13px; color: var(--muted); }
.result mark { background: #fde68a; color: #1c2430; border-radius: 3px; padding: 0 2px; }

.footer { color: var(--muted); font-size: 13px; padding-top: 10px; padding-bottom: 30px; text-align: center; }

@media print {
  .topbar, .footer, .btn-row, .pager, .toc { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; }
}

/* ---------- drobnosti ---------- */
.notes > :first-child { margin-top: 0; }
@media (max-width: 560px) {
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1 1 auto; }
  h1 { font-size: 24px; }
  .q-text { font-size: 19px; }
}
