:root {
  --bg: #0e1726;
  --panel: #1b2640;
  --panel-2: #243456;
  --fg: #eaf0fa;
  --muted: #92a1b8;
  --accent: #4aa3ff;
  --green: #3ec376;
  --red: #e85b5b;
  --yellow: #ffc857;
  --grey: #6a7796;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  line-height: 1.45;
}
header {
  padding: 1rem 1.4rem;
  background: var(--panel);
  border-bottom: 1px solid #0b1424;
}
header h1 {
  margin: 0 0 .6rem 0;
  font-size: 1.4rem;
  letter-spacing: .03em;
}
nav {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}
.mode-btn {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid transparent;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}
.mode-btn:hover { border-color: var(--accent); }
.mode-btn.active {
  background: var(--accent);
  color: #061122;
  font-weight: 600;
}

main {
  padding: 1.4rem;
  max-width: 880px;
  margin: 0 auto;
}
.pane { animation: fade .2s ease-in; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.filter-bar {
  margin-bottom: 1rem;
  display: flex;
  gap: .8rem;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar select, .filter-bar input {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--panel-2);
  padding: .4rem .6rem;
  border-radius: 6px;
  font: inherit;
}

.filter-count {
  color: var(--muted);
  font-size: .85rem;
  margin-left: .3rem;
}
.empty-filter {
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
  line-height: 1.6;
}

.jump-group {
  display: flex;
  gap: .3rem;
  align-items: center;
}
#jump-nummer {
  width: 70px;
}
#jump-go {
  padding: .4rem .7rem;
  font-size: .9rem;
}

.question-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.question-card .meta {
  color: var(--muted);
  font-size: .85rem;
  margin: 0 0 .4rem 0;
}
.question-card h2 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
}
.question-card .frage-bilder {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 1rem 0;
  align-items: flex-start;
}
.question-card .frage-bilder img {
  max-width: 340px;
  max-height: 300px;
  background: #fff;
  padding: 6px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.question-card .hinweis {
  background: rgba(255, 200, 87, .15);
  border-left: 3px solid var(--yellow);
  padding: .5rem .8rem;
  margin-bottom: 1rem;
  border-radius: 4px;
  font-size: .9rem;
}
.options { list-style: none; padding: 0; margin: 0; }
.options li {
  margin-bottom: .5rem;
}
.options label {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-start;
  padding: .7rem .9rem;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s;
}
.options label .antwort-bild {
  width: 100%;
  max-height: 80px;
  object-fit: contain;
  object-position: left;
  border-radius: 4px;
  background: #fff;
  padding: 2px;
  cursor: zoom-in;
}
.options label:hover { border-color: var(--accent); }
.options input[type=radio] { margin-top: .2rem; flex-shrink: 0; accent-color: var(--accent); }
.options label > span { flex: 1; min-width: 0; }
.options label.selected { border-color: var(--accent); background: rgba(74, 163, 255, .12); }
.options label.correct { border-color: var(--green); background: rgba(62, 195, 118, .15); }
.options label.wrong { border-color: var(--red); background: rgba(232, 91, 91, .15); }
.options label.disabled { cursor: default; opacity: .9; }
.options input:disabled { cursor: default; }

.action-row { display: flex; gap: .6rem; flex-wrap: wrap; }
button {
  background: var(--accent);
  color: #061122;
  border: 0;
  padding: .7rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
button:disabled { background: var(--grey); color: #d4d9e4; cursor: not-allowed; }
button.secondary {
  background: var(--panel-2);
  color: var(--fg);
}
.feedback {
  margin: 1rem 0;
  padding: .8rem 1rem;
  border-radius: 8px;
  font-weight: 500;
}
.feedback.correct { background: rgba(62, 195, 118, .18); color: #c2f5d5; }
.feedback.wrong { background: rgba(232, 91, 91, .2); color: #ffd6d6; }
.feedback.skipped { background: rgba(155, 122, 204, .18); color: #ddd0f0; }
.rating {
  margin-top: .55rem;
  font-size: .9rem;
  font-weight: 500;
  opacity: .92;
}
.rating-label { color: var(--muted); }
.rating-arrow { color: var(--muted); padding: 0 .15rem; }
.rating-prev { font-weight: 600; }
.rating-new { font-weight: 700; }

#stats-chart-wrap {
  display: flex;
  gap: 1.6rem;
  flex-wrap: wrap;
  align-items: center;
  background: var(--panel);
  padding: 1.2rem;
  border-radius: var(--radius);
}
#stats-chart { width: 220px; height: 220px; }
#stats-legend { list-style: none; padding: 0; margin: 0; }
#stats-legend li {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .35rem;
  font-variant-numeric: tabular-nums;
}
.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
}
#stats-pruefungsreif-detail { min-width: 11rem; }
#stats-pruefungsreif-detail h3 {
  margin: 0 0 .45rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
}
#stats-pruefungsreif-detail ul { list-style: none; padding: 0; margin: 0; }
#stats-pruefungsreif-detail li {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .35rem;
  font-variant-numeric: tabular-nums;
}

.exam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .6rem;
}
.exam-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 1rem;
}
.exam-dot {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--panel-2);
  background: var(--panel);
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-weight: 500;
}
.exam-dot:hover { border-color: var(--accent); }
.exam-dot.answered { background: var(--panel-2); color: var(--fg); }
.exam-dot.current { background: var(--accent); color: #061122; font-weight: 700; border-color: var(--accent); }

#exam-timer {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
  margin-left: .8rem;
  padding: .15rem .5rem;
  background: var(--panel-2);
  border-radius: 4px;
  font-size: .95rem;
  letter-spacing: .04em;
}
#exam-timer.warning {
  background: rgba(232, 91, 91, .25);
  color: var(--red);
  font-weight: 700;
}

.result-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.2rem;
}
.result-card.passed { border-left: 4px solid var(--green); }
.result-card.failed { border-left: 4px solid var(--red); }
.result-card ul { padding-left: 1.2rem; }
.result-card li { margin-bottom: .3rem; }
.result-card li.right { color: #b8f0cd; }
.result-card li.wrong { color: #ffc1c1; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .6rem;
  width: 100%;
}
.category-btn {
  background: var(--panel);
  color: var(--fg);
  text-align: left;
  border-radius: var(--radius);
  padding: .8rem 1rem;
  border: 1px solid var(--panel-2);
  cursor: pointer;
}
.category-btn:hover { border-color: var(--accent); }
.category-btn .count { color: var(--muted); font-size: .85rem; }

.wissen-tab {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid transparent;
  padding: .5rem .9rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.wissen-tab:hover { border-color: var(--accent); }
.wissen-tab.active { background: var(--accent); color: #061122; font-weight: 600; }
.wissen-tab-content { margin-top: 1rem; }
.regeln-list {
  padding-left: 0;
  list-style: none;
  counter-reset: regel;
  display: grid;
  gap: .8rem;
}
.regeln-list li {
  counter-increment: regel;
  background: var(--panel);
  padding: 1rem 1.2rem 1rem 3.2rem;
  border-radius: var(--radius);
  position: relative;
}
.regeln-list li::before {
  content: counter(regel);
  position: absolute;
  left: 1rem;
  top: 1rem;
  width: 1.6rem;
  height: 1.6rem;
  background: var(--accent);
  color: #061122;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .9rem;
}
.regeln-list .regel-titel {
  font-weight: 600;
  margin-bottom: .3rem;
}
.regeln-list .regel-text {
  color: var(--fg);
  font-size: .95rem;
}
.kapitel-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.kapitel-list li button {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid transparent;
  padding: .4rem .8rem;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
}
.kapitel-list li button:hover { border-color: var(--accent); }
#wissen-pdf {
  width: 100%;
  height: 75vh;
  border: 0;
  border-radius: var(--radius);
  background: #fff;
}
.muted { color: var(--muted); font-size: .9rem; }

.spickzettel-group { margin-bottom: 2rem; }
.spickzettel-group h3 {
  margin: 0 0 .3rem 0;
  font-size: 1.1rem;
  color: var(--accent);
}
.spickzettel-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: .6rem;
}
.spickzettel-gallery figure {
  margin: 0;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--panel-2);
}
.spickzettel-gallery a {
  display: block;
}
.spickzettel-gallery img {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  transition: transform .2s;
}
.spickzettel-gallery a:hover img { transform: scale(1.02); }
.spickzettel-gallery figcaption {
  padding: .4rem .8rem;
  color: var(--muted);
  font-size: .8rem;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fade .15s ease-in;
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  min-width: min(600px, 80vw);
  min-height: min(400px, 70vh);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .6);
  background: #fff;
  padding: 16px;
}
.lightbox-counter {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .7);
  font-size: .9rem;
  pointer-events: none;
}
.question-card .frage-bilder img {
  cursor: zoom-in;
}

.erklaerung {
  margin-top: .8rem;
  padding: .7rem 1rem;
  background: rgba(74, 163, 255, .08);
  border: 1px dashed rgba(74, 163, 255, .35);
  border-radius: 8px;
  font-size: .92rem;
  line-height: 1.5;
}
.erklaerung-badge {
  display: inline-block;
  background: var(--yellow);
  color: #1b2640;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: .15rem .45rem;
  border-radius: 4px;
  margin-bottom: .4rem;
}
.erklaerung p { margin: 0; }

.begriff-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: .8rem;
}
.begriff-card h3 {
  margin: 0 0 .4rem 0;
  font-size: 1rem;
  color: var(--accent);
}
.begriff-card p { margin: 0 0 .3rem 0; font-size: .95rem; line-height: 1.5; }
.begriff-card p:last-child { margin-bottom: 0; }

.loading { color: var(--muted); }

.kbd-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  font-size: .85rem;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 50%;
  vertical-align: middle;
  cursor: pointer;
}
#kbd-help-btn {
  margin-left: auto;
}
.kbd-help-btn:hover { color: var(--fg); background: var(--accent); }

.kbd-legend {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, .75);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade .15s ease-in;
}
.kbd-legend-box {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 1.4rem 1.8rem;
  max-width: 420px;
  width: 90vw;
}
.kbd-legend-box h3 { margin: 0 0 .8rem 0; font-size: 1.05rem; }
.kbd-legend-box table { width: 100%; border-collapse: collapse; }
.kbd-legend-box td { padding: .3rem 0; }
.kbd-legend-box td:first-child { white-space: nowrap; padding-right: 1.2rem; }
kbd {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--grey);
  border-radius: 4px;
  padding: .1rem .4rem;
  font-family: inherit;
  font-size: .85rem;
  min-width: 1.4em;
  text-align: center;
}

.cat-progress-card {
  background: var(--panel);
  border-radius: .5rem;
  padding: .8rem 1rem;
  margin-bottom: .6rem;
}
.cat-progress-header {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .4rem;
  flex-wrap: wrap;
}
.cat-progress-header strong { font-size: .95rem; }
.cat-pct {
  margin-left: auto;
  font-weight: 700;
  font-size: 1rem;
}
.cat-progress-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel-2);
}
.cat-progress-bar .seg {
  min-width: 0;
  transition: width .3s;
}
#stats-categories { margin-top: 1.5rem; }

.sync-box {
  margin-top: 2rem;
  padding: 1.2rem;
  background: var(--panel);
  border-radius: .5rem;
}
.sync-box h3 { margin: 0 0 .8rem; font-size: 1.05rem; }
.sync-box label { display: block; margin-bottom: .6rem; font-size: .9rem; }
.sync-box input[type="url"],
.sync-box input[type="password"] {
  width: 100%;
  padding: .45rem;
  margin-top: .2rem;
  border: 1px solid var(--border);
  border-radius: .25rem;
  background: var(--bg);
  color: var(--fg);
  font-size: .95rem;
  box-sizing: border-box;
}
.sync-box .action-row { margin-top: .8rem; }

.profile-section {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.profile-section h3 { margin: 0 0 .8rem; font-size: 1.05rem; }
.profile-section label {
  display: block;
  margin-bottom: .6rem;
  font-size: .9rem;
}
.profile-section input[type="password"] {
  width: 100%;
  padding: .45rem;
  margin-top: .2rem;
  border: 1px solid var(--panel-2);
  border-radius: .25rem;
  background: var(--bg);
  color: var(--fg);
  font-size: .95rem;
  box-sizing: border-box;
}
.profile-section button { margin-top: .5rem; }
.session-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .6rem .8rem;
  background: var(--panel-2);
  border-radius: 6px;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.session-row .session-info { flex: 1; min-width: 200px; }
.session-row .session-ip { font-family: monospace; color: var(--accent); }
.session-row .session-current {
  background: var(--green);
  color: #061122;
  font-size: .7rem;
  font-weight: 700;
  padding: .15rem .4rem;
  border-radius: 4px;
}
.session-row button {
  padding: .3rem .6rem;
  font-size: .8rem;
}
.profile-pw-ok {
  color: var(--green);
  text-align: center;
  min-height: 1.2em;
}
.login-error {
  color: var(--red);
  text-align: center;
  min-height: 1.2em;
}

/* --- Mobile --- */
@media (max-width: 600px) {
  header { padding: .7rem .8rem; }
  header h1 { font-size: 1.15rem; margin-bottom: .4rem; }

  nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: .4rem;
  }
  nav::-webkit-scrollbar { display: none; }
  .mode-btn {
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    padding: .5rem .8rem;
    font-size: .9rem;
  }
  .kbd-help-btn {
    width: 2rem;
    height: 2rem;
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
  }

  main { padding: .8rem; }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
  }
  .filter-bar select, .filter-bar input {
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
  }
  .jump-group {
    width: 100%;
  }
  #jump-nummer { flex: 1; min-height: 44px; }
  #jump-go { min-height: 44px; min-width: 44px; }

  .question-card { padding: .8rem; }
  .question-card h2 { font-size: 1rem; }
  .question-card .frage-bilder img {
    max-width: 100%;
  }

  .options label {
    padding: .8rem;
    min-height: 44px;
    font-size: .95rem;
  }

  .action-row {
    flex-direction: column;
  }
  .action-row button {
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
  }

  button { min-height: 44px; }

  #stats-chart-wrap {
    flex-direction: column;
    align-items: center;
    padding: .8rem;
  }
  #stats-chart { width: 180px; height: 180px; }

  .category-grid {
    grid-template-columns: 1fr;
  }
  .category-btn { min-height: 44px; }

  #wissen-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #wissen-tabs::-webkit-scrollbar { display: none; }
  .wissen-tab {
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    font-size: .9rem;
  }

  .regeln-list li { padding: .8rem .8rem .8rem 2.8rem; }
  .regeln-list li::before { left: .7rem; top: .8rem; }

  .spickzettel-gallery {
    grid-template-columns: 1fr;
  }

  #wissen-pdf { height: 60vh; }

  .lightbox img {
    min-width: 0;
    min-height: 0;
    max-width: 96vw;
    max-height: 90vh;
    padding: 8px;
  }

  .kapitel-list li button { min-height: 44px; }
}

/* --- Breitmodus (Querformat / kurzes Fenster) ---
   Question text + images links, Antworten als 2-Reihen-Raster rechts. Das
   Raster fliesst spaltenweise (4 Antworten -> 2x2) und scrollt bei Bedarf
   horizontal statt die Seite in die Hoehe zu treiben. Aktiv via body.layout-wide
   (JS entscheidet aus Pref + matchMedia). */
body.layout-wide main { max-width: none; }

body.layout-wide .question-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  column-gap: 1.4rem;
  align-items: start;
}
body.layout-wide .question-card .q-main { grid-column: 1; }
body.layout-wide .question-card .options { grid-column: 2; }

body.layout-wide .options {
  display: grid;
  grid-template-rows: repeat(2, auto);
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 1fr);
  column-gap: .6rem;
  row-gap: .5rem;
  overflow-x: auto;
  padding-bottom: .3rem;
}
body.layout-wide .options li { margin-bottom: 0; }
body.layout-wide .options label { height: 100%; }

#layout-btn.active { background: var(--accent); color: #061122; }

/* Im Breitmodus auf sehr kurzen Fenstern hat der manuelle Toggle Vorrang -
   die mobile Spalte greift hier nicht, weil min-width 900px gefordert ist. */
