/* =============================================================
   Teoria Prawa Jazdy — Kategoria B
   Główny arkusz styli (czysty, minimalistyczny)
   Sekcje:
     1. Zmienne kolorystyczne i reset
     2. Layout (sidebar + main)
     3. Wyszukiwarka i pasek postępu
     4. Tipografia i sekcje merytoryczne
     5. Komponenty (karty, tabele, hierarchia, dwie kolumny)
     6. Galeria znaków + schematy SVG
     7. Checklist egzaminacyjny
     8. Tryb skupienia, toolbar
     9. Highlight wyszukiwania (mark + flash sekcji)
    10. Szybki test (quiz)
    11. Mobile + print
   ============================================================= */

/* 1. Zmienne kolorystyczne ----------------------------------- */
/* Light Mode (domyślny) — wszystkie kolory tła/tekstów/komponentów
   spięte w zmiennych CSS. Dark Mode w bloku @media niżej tylko
   przesłania wartości; reguły komponentów pozostają wspólne. */
:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #555555;
  --border: #e5e5e5;
  --border-strong: #d0d0d0;
  --code-bg: #f6f6f6;
  --highlight: #fff3a3;
  --flash-bg: #fff7d4;
  --red: #c63030;
  --blue: #1f4ea1;
  --yellow: #d6a800;
  --green: #2f7a2f;

  /* Komponenty: tła kart i banerów */
  --card-info-bg: #f4f7fc;
  --card-alert-bg: #fffbe6;
  --quiz-bg: #f8f9fb;
  --quiz-correct-bg: #ecf7ec;
  --quiz-correct-text: #1e5e1e;
  --quiz-wrong-bg: #fdeeee;
  --quiz-wrong-text: #8b1f1f;
  --banner-bg: #fcfcfc;
  --btn-primary-bg: var(--text);
  --btn-primary-text: var(--bg);
  --btn-primary-hover-bg: #2a2a2a;
  --btn-primary-hover-border: #2a2a2a;

  /* Filtr stosowany do inline'owych schematów SVG (.svg-figure svg).
     W Light Mode = brak; w Dark Mode invert+hue-rotate utrzymuje
     hue (niebieski / czerwony / zielony) i odwraca jasność. */
  --schematic-filter: none;

  --max-width: 760px;
}

/* Dark Mode — automatyczne przełączenie na podstawie ustawień systemu.
   Brak JS, brak FOUC. Paleta: bardzo ciemne tło (#121212), jasnoszary
   tekst (#e0e0e0), subtelne ramki (#2d2d2d), nieco jaśniejsze sekcje
   (#1e1e1e). Akcenty rozjaśnione dla czytelności na ciemnym tle. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #e0e0e0;
    --muted: #9a9a9a;
    --border: #2d2d2d;
    --border-strong: #3d3d3d;
    --code-bg: #1e1e1e;
    --highlight: #5a4a00;
    --flash-bg: #3a3000;

    /* Akcenty „drogowe" — rozjaśnione warianty */
    --red: #ff6b6b;
    --blue: #6ea8ff;
    --yellow: #f0c84a;
    --green: #6ec96e;

    /* Tła kart – delikatne podbarwienie na bazie #1e1e1e */
    --card-info-bg: #182230;
    --card-alert-bg: #2a2410;
    --quiz-bg: #1a1d24;
    --quiz-correct-bg: #15291a;
    --quiz-correct-text: #9ed79e;
    --quiz-wrong-bg: #2a1717;
    --quiz-wrong-text: #ff9b9b;
    --banner-bg: #1a1a1a;

    /* Przycisk wsparcia w Dark Mode — subtelniejszy, z ramką, nie raniący wzroku.
       (Light: jasne tło z ciemnym tekstem; Dark: ciemnoszare tło + jasna ramka.) */
    --btn-primary-bg: #2a2a2a;
    --btn-primary-text: #f0f0f0;
    --btn-primary-hover-bg: #3a3a3a;
    --btn-primary-hover-border: #4a4a4a;

    /* Schematy poglądowe (rysowane inline w HTML) — invert+hue-rotate
       odwraca jasność (białe drogi → ciemne, czarny tekst → jasny),
       a hue-rotate(180deg) anuluje przesunięcie hue, więc niebieskie
       pojazdy zostają niebieskie, czerwone czerwone itd. */
    --schematic-filter: invert(0.92) hue-rotate(180deg);
  }

  /* Oficjalne znaki drogowe (assets/signs/*.svg) muszą zachować ścisłe
     kolory PoRD — opakowujemy je w jasne tło, żeby były czytelne na
     ciemnej stronie bez zmiany pliku SVG. Tekst meta na tym jasnym
     tle wymaga ciemnych kolorów (nie odziedziczonych z body). */
  .sign-card { background: #f5f5f5; }
  .sign-card .sign-name { color: #111; }
  .sign-card .sign-code,
  .sign-card .sign-desc { color: #555; }
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 2. Layout -------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  max-width: 1140px;
  margin: 0 auto;
  gap: 48px;
  padding: 32px 24px 96px;
}

.sidebar {
  position: sticky;
  top: 32px;
  align-self: start;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding-right: 8px;
  border-right: 1px solid var(--border);
}

.sidebar h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 12px;
}

.sidebar ol {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  counter-reset: section;
}

.sidebar li {
  counter-increment: section;
  margin: 0;
}

.sidebar a {
  display: block;
  padding: 6px 0;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 1px solid transparent;
}

.sidebar a::before {
  content: counter(section, decimal-leading-zero) ".  ";
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sidebar a:hover { border-bottom-color: var(--border-strong); }
.sidebar a.active { font-weight: 600; }

.sidebar-footer {
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Baner wsparcia (donacja) — między spisem treści a stopką sidebara
   Kolory dobrane do palety strony: tło ledwo odróżnialne od białego (#fcfcfc),
   przycisk używa var(--text) — tej samej "primary" co .quiz-btn.selected.
   Selektory scope'owane pod #support-banner, żeby nadpisać globalne reguły
   .sidebar a (counter w ::before, display: block, border-bottom). */
#support-banner {
  margin: 24px -8px 20px -8px;
  padding: 16px 14px;
  background: var(--banner-bg);
  border-top: 1px solid var(--border);
  text-align: center;
}
#support-banner p {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}
#support-banner .btn-coffee {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: 1px solid var(--btn-primary-bg);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
/* Wyłącz licznik z .sidebar a::before dla przycisku */
#support-banner .btn-coffee::before { content: none; }
#support-banner .btn-coffee:hover {
  background: var(--btn-primary-hover-bg);
  border-color: var(--btn-primary-hover-border);
}
#support-banner .btn-coffee:focus {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}
#support-banner .btn-coffee-icon { flex-shrink: 0; }

@media (max-width: 860px) {
  #support-banner {
    margin: 20px 0 16px;
    padding: 14px 12px;
  }
  #support-banner p { font-size: 13px; }
  #support-banner .btn-coffee { padding: 10px 16px; font-size: 14px; }
}

.content { min-width: 0; max-width: var(--max-width); }

/* 3. Wyszukiwarka i pasek postępu ---------------------------- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--text);
  z-index: 1000;
  transition: width 0.05s linear;
}

.search-wrap { margin-bottom: 20px; }

.search-input {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}

.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: 2px solid var(--text); outline-offset: 0; border-color: var(--text); }

.search-count {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 16px;
}

/* 4. Tipografia i sekcje ------------------------------------- */
.header {
  margin-bottom: 48px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.header .eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
}

.header h1 {
  font-size: 32px;
  line-height: 1.2;
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header p { margin: 0; color: var(--muted); font-size: 15px; }

section {
  margin: 0 0 64px;
  scroll-margin-top: 24px;
}

section h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.005em;
}

section .lead { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

h3 { font-size: 16px; font-weight: 600; margin: 32px 0 8px; }
h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 20px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

p { margin: 0 0 16px; }
ul, ol { padding-left: 22px; margin: 0 0 16px; }
li { margin-bottom: 6px; }
strong { font-weight: 600; }

/* 5. Komponenty: karty, tabele, hierarchia ------------------- */
.card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px 20px;
  margin: 16px 0;
  background: var(--bg);
}

.card.note { background: var(--code-bg); }
.card.warn { border-left: 3px solid var(--red); }
.card.info { border-left: 3px solid var(--blue); background: var(--card-info-bg); }
.card.tip  { border-left: 3px solid var(--green); }
.card.alert { border-left: 3px solid var(--yellow); background: var(--card-alert-bg); }

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px;
}

.card.warn .card-title { color: var(--red); }
.card.info .card-title { color: var(--blue); }
.card.tip  .card-title { color: var(--green); }
.card.alert .card-title { color: var(--yellow); }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 16px 0;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--code-bg);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.center { text-align: center; }

/* Numerowana lista hierarchii */
.hierarchy {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  counter-reset: hier;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.hierarchy li {
  counter-increment: hier;
  padding: 14px 16px 14px 56px;
  position: relative;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.hierarchy li:last-child { border-bottom: none; }

.hierarchy li::before {
  content: counter(hier);
  position: absolute;
  left: 16px;
  top: 14px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hierarchy strong { display: block; margin-bottom: 4px; }
.hierarchy small { color: var(--muted); font-size: 13px; line-height: 1.5; display: block; }

/* Dwie kolumny (allow / deny) */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.col-box {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 16px;
}

.col-box.allow { border-left: 3px solid var(--green); }
.col-box.deny  { border-left: 3px solid var(--red); }
.col-box h4 { margin-top: 0; }
.col-box ul { margin: 0; }

/* Siatka sytuacji wymagających szczególnej ostrożności */
.situations {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin: 16px 0;
  list-style: none;
  padding: 0;
}

.situations li {
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: 4px;
  padding: 12px 14px;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
}

.situations li strong { display: block; margin-bottom: 2px; font-size: 13px; }
.situations li small { color: var(--muted); font-size: 12px; line-height: 1.4; }

/* 6. Galeria znaków + schematy ------------------------------- */
.signs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.sign-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--bg);
}

.sign-card img,
.sign-card svg {
  display: block;
  width: 64px;
  height: 64px;
}

.sign-meta { text-align: center; }

.sign-code {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.sign-name { font-size: 13px; font-weight: 600; line-height: 1.35; margin-top: 2px; }
.sign-desc { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 4px; }

.sign-group-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 2px;
  margin-bottom: 8px;
}

.sign-group-label.warn  { color: var(--red);  border: 1px solid var(--red); }
.sign-group-label.deny  { color: var(--red);  border: 1px solid var(--red); }
.sign-group-label.order { color: var(--blue); border: 1px solid var(--blue); }
.sign-group-label.info  { color: var(--text); border: 1px solid var(--border-strong); }

/* Schematy poglądowe (widok z góry) */
.svg-figure {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin: 16px 0;
  text-align: center;
}

.svg-figure svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 8px;
  /* W Light Mode: filter:none. W Dark Mode invert+hue-rotate odwraca
     jasność kolorów (białe drogi → ciemne, czarny tekst → jasny),
     a hue-rotate(180deg) anuluje przesunięcie odcienia tak, że niebieskie/
     czerwone/zielone pojazdy zachowują swoje kolory semantyczne. */
  filter: var(--schematic-filter);
}

.svg-caption { font-size: 12px; color: var(--muted); text-align: center; }

.svg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.svg-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}

/* 7. Checklist egzaminacyjny --------------------------------- */
.checklist {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.checklist li:last-child { border-bottom: none; }

.checklist input[type="checkbox"] {
  margin-top: 4px;
  width: 16px;
  height: 16px;
  accent-color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.checklist label { cursor: pointer; flex: 1; }
.checklist input:checked + label { color: var(--muted); text-decoration: line-through; }

/* 8. Toolbar i tryb skupienia -------------------------------- */
.toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 50;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.btn:hover { background: var(--code-bg); }
.btn:focus { outline: 2px solid var(--text); outline-offset: 2px; }

body.focus-mode .sidebar { display: none; }
body.focus-mode .layout {
  grid-template-columns: 1fr;
  max-width: var(--max-width);
}

body.focus-mode .toolbar .btn[data-action="focus"] {
  background: var(--text);
  color: var(--bg);
}

/* 9. Highlight wyszukiwania (mark + flash sekcji) ------------ */
mark {
  background: var(--highlight);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
  scroll-margin-top: 80px;
}

/* Aktualnie wybrane dopasowanie (Enter cyklicznie skacze po wystąpieniach) */
mark.current {
  background: #ffaa00;
  color: #000;
  outline: 2px solid #ff6600;
  outline-offset: 1px;
}

@keyframes section-flash {
   0% { background-color: transparent; }
  20% { background-color: var(--flash-bg); }
  80% { background-color: var(--flash-bg); }
 100% { background-color: transparent; }
}

section.highlight {
  animation: section-flash 2s ease-in-out;
  border-radius: 6px;
}

/* 10. Szybki test (quiz) ------------------------------------- */
.quick-quiz {
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  padding: 18px 22px;
  margin: 36px 0 16px;
  background: var(--quiz-bg);
}

.quick-quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}

.quick-quiz-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue);
  margin: 0;
}

.quick-quiz-title::before { content: "→ "; opacity: 0.5; }

.quiz-reset-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.quiz-reset-btn:hover { background: var(--code-bg); color: var(--text); }

.quiz-question { padding: 14px 0; border-top: 1px solid var(--border); }
.quiz-question:first-of-type { border-top: none; padding-top: 0; }
.quiz-q { font-size: 14px; margin: 0 0 10px; line-height: 1.5; }

.quiz-buttons { display: flex; gap: 8px; }

.quiz-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  padding: 6px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  min-width: 64px;
  color: var(--text);
}

.quiz-btn:hover { background: var(--code-bg); }
.quiz-btn.selected { background: var(--text); color: var(--bg); border-color: var(--text); }

.quiz-feedback {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.55;
  padding: 10px 12px;
  border-radius: 4px;
  display: none;
}

.quiz-feedback.shown { display: block; }
.quiz-feedback.correct { background: var(--quiz-correct-bg); color: var(--quiz-correct-text); border-left: 3px solid var(--green); }
.quiz-feedback.wrong   { background: var(--quiz-wrong-bg); color: var(--quiz-wrong-text); border-left: 3px solid var(--red); }

/* Footer strony (poza <main>) */
.page-footer {
  max-width: 1140px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.page-footer p { margin: 0; }

/* 11. Mobile + print ----------------------------------------- */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 24px 16px 80px;
  }

  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    padding-right: 0;
  }

  .sidebar ol { margin-bottom: 8px; }
  .sidebar-footer { display: none; }
  .header h1 { font-size: 26px; }
  .two-col { grid-template-columns: 1fr; }
  .signs-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .toolbar { top: 8px; right: 8px; }
  .btn { font-size: 12px; padding: 5px 10px; }
  .btn span { display: none; }
}

@media print {
  .toolbar, .progress-bar, .sidebar, .search-wrap, .quiz-reset-btn { display: none; }
  .layout { grid-template-columns: 1fr; }
  section.highlight { animation: none; }
}
