/* ===========================================================================
   Harry-Potter-Pubquiz — Stylesheet

   Die komplette Gestaltung haengt an den Variablen im :root-Block.
   Farben, Schriften, Rundungen und Abstaende dort aendern, der Rest zieht nach.
   =========================================================================== */

:root {
  /* --- Farben ------------------------------------------------------------ */
  --c-bg:          #12131a;   /* Seitenhintergrund      */
  --c-surface:     #1c1e29;   /* Karten                 */
  --c-surface-2:   #252838;   /* Eingabefelder, Chips   */
  --c-border:      #333749;
  --c-text:        #eceef5;
  --c-text-muted:  #9aa0b5;
  --c-accent:      #d3a625;   /* Gold — Buttons, Aktiv-Zustand */
  --c-accent-text: #1a1400;   /* Text auf Gold          */
  --c-correct:     #4caf7d;
  --c-wrong:       #e05563;
  --c-info:        #6c8ce0;

  /* --- Typografie -------------------------------------------------------- */
  --font:          system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display:  var(--font);
  --fs-base:       1rem;
  --fs-question:   1.25rem;
  --lh:            1.55;

  /* --- Form ------------------------------------------------------------- */
  --radius:        14px;
  --radius-sm:     9px;
  --space:         1rem;
  --maxw:          46rem;
  --shadow:        0 2px 16px rgba(0, 0, 0, .35);
  --focus:         0 0 0 3px color-mix(in srgb, var(--c-accent) 45%, transparent);
}

/* Helles Farbschema — greift automatisch nach Systemeinstellung.
   Wer nur ein Theme will, kann diesen Block ersatzlos loeschen. */
@media (prefers-color-scheme: light) {
  :root {
    --c-bg:         #f4f2ec;
    --c-surface:    #ffffff;
    --c-surface-2:  #efece3;
    --c-border:     #ddd8cb;
    --c-text:       #23242b;
    --c-text-muted: #6b6c78;
    --c-accent:     #8a6d12;
    --c-accent-text:#fffdf5;
    --shadow:       0 2px 14px rgba(0, 0, 0, .10);
  }
}

/* --------------------------------------------------------------------------
   Grundgeruest
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* Muss vor allen display-Regeln stehen: Klassen wie .btn-block (display:block)
   oder .actions.row (display:flex) wuerden das hidden-Attribut sonst aushebeln. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  padding: 0 var(--space) calc(var(--space) * 3);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 .8em; }
p:last-child { margin-bottom: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--c-surface-2);
  border-radius: 4px;
  padding: .1em .35em;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   Kopfzeile
   -------------------------------------------------------------------------- */

.site-header {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(var(--space) * 1.2) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
}

.site-header h1 { margin: 0; letter-spacing: .02em; }

/* --- Titel mit Logo ------------------------------------------------------ */

.site-title {
  display: flex;
  align-items: center;
  gap: .7rem;
  min-width: 0;             /* damit der Text im Flexvater umbrechen darf */
  font-size: 1.35rem;
}
.site-logo {
  height: 2.6rem;
  width: auto;
  flex: none;
}
.site-title-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 .45em;
  min-width: 0;
}
.site-dash { color: var(--c-text-muted); font-weight: 400; }
.site-claim { font-weight: 400; }

/* Schmale Anzeige: Name und Zusatz untereinander, der Gedankenstrich entfällt.
   Der Umbruch ist eine eigene Zeile im Textblock, nicht unter dem Logo. */
@media (max-width: 34rem) {
  .site-title { font-size: 1.15rem; gap: .55rem; }
  .site-logo  { height: 2.2rem; }
  .site-dash  { display: none; }
  .site-claim { flex-basis: 100%; font-size: .72em; color: var(--c-text-muted); }
}

/* --- Footer -------------------------------------------------------------- */

.site-footer {
  max-width: var(--maxw);
  margin: calc(var(--space) * 2) auto 0;
  padding: var(--space) 0 calc(var(--space) * 2);
  border-top: 1px solid var(--c-border);
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.2rem;
  margin-bottom: .8rem;
}
.footer-links a {
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: .85rem;
}
.footer-links a:hover { color: var(--c-text); text-decoration: underline; }
.footer-contact {
  margin: 0 0 .8rem;
  font-size: .85rem;
  line-height: 1.5;
  color: var(--c-text-muted);
}
.footer-contact a { color: var(--c-accent); text-decoration: none; }
.footer-contact a:hover { text-decoration: underline; }

.footer-legal {
  margin: 0;
  font-size: .75rem;
  line-height: 1.5;
  color: var(--c-text-muted);
}

/* --- Impressum und Datenschutz ------------------------------------------- */

/* Der Titel ist auf den Rechtsseiten ein Link zurueck zum Quiz */
.site-title-link {
  display: flex;
  align-items: center;
  gap: inherit;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.site-title-link:hover .site-name { color: var(--c-accent); }

.legal-page h3 {
  margin: calc(var(--space) * 1.6) 0 .4em;
  font-size: 1.05rem;
}
.legal-page h3:first-of-type { margin-top: var(--space); }
.legal-page p, .legal-page li { font-size: .92rem; }
.legal-page ul { padding-left: 1.3em; }
.legal-page li { margin-bottom: .3em; }
.legal-page code {
  font-size: .85em;
  padding: .1em .35em;
  background: var(--c-surface-2);
  border-radius: 4px;
}

.legal-dl { margin: .6em 0; }
.legal-dl dt { margin-top: .8em; }
.legal-dl dd { margin: .2em 0 0 1.3em; font-size: .92rem; }

/* Platzhalter sollen auffallen, damit sie nicht versehentlich online gehen */
.ph {
  background: color-mix(in srgb, var(--c-wrong) 22%, transparent);
  border-bottom: 1px dashed var(--c-wrong);
  padding: 0 .2em;
}
.placeholder-note {
  margin: 0 0 var(--space);
  padding: .8em 1em;
  font-size: .88rem;
  background: color-mix(in srgb, var(--c-wrong) 12%, var(--c-surface-2));
  border-left: 3px solid var(--c-wrong);
  border-radius: var(--radius-sm);
}

.admin-link {
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: .85rem;
  padding: .35em .8em;
  border: 1px solid var(--c-border);
  border-radius: 999px;
}
.admin-link:hover { color: var(--c-text); border-color: var(--c-accent); }

/* Beide Links nebeneinander, ohne Mindestbreite pro Kind */
.header-actions { display: flex; gap: .5rem; align-items: center; flex: 0 0 auto; }

/* --------------------------------------------------------------------------
   Screens und Karten
   -------------------------------------------------------------------------- */

#app { max-width: var(--maxw); margin: 0 auto; }

.screen { display: none; }
.screen.active { display: block; animation: fade .18s ease-out; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  * { transition: none !important; }
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(var(--space) * 1.25);
  margin-bottom: var(--space);
}

/* --------------------------------------------------------------------------
   Formularelemente
   -------------------------------------------------------------------------- */

.field { margin: 0 0 calc(var(--space) * 1.4); border: 0; padding: 0; }
.field > label, legend {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .5em;
  padding: 0;
}

output { color: var(--c-accent); font-variant-numeric: tabular-nums; }

.hint { color: var(--c-text-muted); font-size: .85rem; margin: .5em 0 0; }

input[type="range"] {
  width: 100%;
  accent-color: var(--c-accent);
  height: 1.75rem;   /* grosszuegige Trefferflaeche fuer Touch */
}

/* Segmentierte Auswahl (Radio-Buttons als Reiter) */
.segmented {
  display: flex;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: .55em .4em;
  border-radius: calc(var(--radius-sm) - 3px);
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s;
}
.segmented input:checked + span { background: var(--c-accent); color: var(--c-accent-text); font-weight: 600; }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

/* Chips (Mehrfachauswahl) */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: block;
  padding: .45em .9em;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  background: var(--c-surface-2);
  font-size: .85rem;
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
.chips input:checked + span {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-accent-text);
  font-weight: 600;
}
.chips input:focus-visible + span { box-shadow: var(--focus); }

input[type="text"], input[type="password"], input[type="number"],
textarea, select {
  width: 100%;
  font: inherit;
  color: var(--c-text);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: .65em .8em;
}
textarea { resize: vertical; min-height: 4.5em; }

input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--c-accent);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .75em 1.2em;
  cursor: pointer;
  background: var(--c-surface-2);
  color: var(--c-text);
  min-height: 2.9rem;          /* Touch-Ziel */
  transition: filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--c-accent); color: var(--c-accent-text); }
.btn-ghost   { background: transparent; border-color: var(--c-border); color: var(--c-text-muted); }
.btn-block   { display: block; width: 100%; }
.btn-sm      { padding: .4em .8em; min-height: 0; font-size: .85rem; }

.actions { margin-top: calc(var(--space) * 1.2); }
.actions.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.actions.row .btn { flex: 1; min-width: 9rem; }

/* --------------------------------------------------------------------------
   Lern-Modus
   -------------------------------------------------------------------------- */

.learn-box {
  margin-top: .7rem;
  padding-top: .7rem;
  border-top: 1px solid var(--c-border);
}
.learn-row { display: flex; gap: .5rem; align-items: center; }
.learn-row input[type="text"] { flex: 1; }
#learn-state { color: var(--c-text); }

/* Ausgegraute Stufe im Schwierigkeitsumschalter (»im Schnitt« im Lern-Modus) */
.segmented input:disabled + span { opacity: .4; cursor: not-allowed; }

/* --------------------------------------------------------------------------
   Verfuegbarkeitsanzeige
   -------------------------------------------------------------------------- */

.availability {
  text-align: center;
  font-size: .85rem;
  color: var(--c-text-muted);
  margin: 0 0 var(--space);
  min-height: 1.4em;
}
.availability.warn { color: var(--c-wrong); }

/* --------------------------------------------------------------------------
   Quizlauf
   -------------------------------------------------------------------------- */

.quiz-bar { margin-bottom: var(--space); }

.progress {
  height: 6px;
  background: var(--c-surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--c-accent);
  border-radius: 999px;
  transition: width .25s ease-out;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  font-size: .82rem;
  color: var(--c-text-muted);
  margin-top: .5em;
}
.score { font-variant-numeric: tabular-nums; }

/* --- Zeitlimit ----------------------------------------------------------- */

.timer-bar {
  height: 6px;
  background: var(--c-surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--c-info);
  border-radius: 999px;
  /* Dauer passt zum Aktualisierungsintervall in app.js */
  transition: width .1s linear, background .3s;
}

.timer {
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.timer::before { content: "◷ "; }

/* Letzte 10 bzw. 5 Sekunden */
.timer.warn,     .timer-fill.warn     { color: var(--c-accent); }
.timer.critical, .timer-fill.critical { color: var(--c-wrong); font-weight: 700; }
.timer-fill.warn     { background: var(--c-accent); }
.timer-fill.critical { background: var(--c-wrong); }

.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .9em; }
.badge {
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .3em .7em;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-text-muted);
  border: 1px solid var(--c-border);
}
.badge-diff { color: var(--c-accent); border-color: color-mix(in srgb, var(--c-accent) 40%, var(--c-border)); }

.question-text { font-size: var(--fs-question); margin-bottom: .8em; }

.media { margin: 0 0 var(--space); }
.media img {
  display: block;
  width: 100%;
  max-height: 22rem;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
}

/* --- Antwortbereich ------------------------------------------------------ */

.answer-area { display: flex; flex-direction: column; gap: .6rem; }

/* Ankreuzzeile — im Quiz gibt es keine Auswahlantworten mehr, die Klasse
   traegt jetzt nur noch das „aktiv“-Kaestchen im Admin. */
.option {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .8em .9em;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.option input { accent-color: var(--c-accent); width: 1.15em; height: 1.15em; flex: none; margin: 0; }
.option:hover { border-color: var(--c-accent); }

/* Zuordnung */
.match-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  align-items: center;
}
.match-label {
  padding: .7em .8em;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
}
.match-row.is-correct .match-label { border-color: var(--c-correct); }
.match-row.is-wrong   .match-label { border-color: var(--c-wrong); }

@media (max-width: 30rem) {
  .match-row { grid-template-columns: 1fr; gap: .3rem; }
  .match-row select { margin-bottom: .35rem; }
}

/* --- Rueckmeldung -------------------------------------------------------- */

.feedback {
  margin-top: var(--space);
  padding: .9em 1em;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--c-info);
  background: var(--c-surface-2);
  font-size: .95rem;
}
.feedback.correct { border-left-color: var(--c-correct); }
.feedback.wrong   { border-left-color: var(--c-wrong); }
.feedback strong  { display: block; margin-bottom: .25em; }
.feedback .solution { color: var(--c-text); }
.feedback .explanation { color: var(--c-text-muted); font-size: .9rem; margin-top: .5em; }
/* Die Musterloesung ist die vollstaendigste Antwort — etwas kraeftiger als die
   Nebenzeilen, damit sie beim Ueberfliegen haengen bleibt. */
.feedback .sample { color: var(--c-text); font-weight: 600; margin-top: .5em; }

/* --------------------------------------------------------------------------
   Ergebnis
   -------------------------------------------------------------------------- */

.result-summary { text-align: center; }
.big-score {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--c-accent);
  margin: .2em 0;
  font-variant-numeric: tabular-nums;
}

.review { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.review li {
  counter-increment: r;
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: .6rem;
  align-items: start;
  padding: .8em 0;
  border-top: 1px solid var(--c-border);
}
.review li:first-child { border-top: 0; }
.review li::before {
  content: counter(r) ".";
  color: var(--c-text-muted);
  font-size: .85rem;
  padding-top: .15em;
}
.review .r-question { font-size: .95rem; }
.review .r-solution { font-size: .85rem; color: var(--c-text-muted); margin-top: .2em; }
.review .r-sample { font-size: .85rem; margin-top: .2em; }
.review .r-box { font-size: .8rem; color: var(--c-text-muted); margin-top: .2em; }
.review .r-mark { font-size: 1.1rem; line-height: 1.4; }
.review li.ok    .r-mark { color: var(--c-correct); }
.review li.bad   .r-mark { color: var(--c-wrong); }
.review .r-override { margin-top: .4em; }

/* --------------------------------------------------------------------------
   Admin (nutzt dieselben Bausteine, ergaenzt nur Layout)
   -------------------------------------------------------------------------- */

.admin-grid { display: grid; gap: var(--space); }
@media (min-width: 60rem) {
  :root { --maxw: 72rem; }
  .admin-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}

.stat-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.stat {
  flex: 1 1 6rem;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: .7em .8em;
  text-align: center;
}
.stat b { display: block; font-size: 1.4rem; color: var(--c-accent); }
.stat span { font-size: .75rem; color: var(--c-text-muted); }

/* Filterzeile der Fragenliste: bricht bei Bedarf in eine zweite Reihe um,
   statt die Beschriftungen der Auswahlfelder abzuschneiden. */
.filter-row {
  display: grid;
  /* 8.5rem ergibt vier Spalten auf dem Desktop und zwei auf dem Handy */
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .5rem;
  margin-bottom: .8rem;
}

.q-list { list-style: none; margin: 0; padding: 0; }
.q-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  align-items: center;
  padding: .7em 0;
  border-top: 1px solid var(--c-border);
}
.q-list li:first-child { border-top: 0; }
.q-list .q-text { font-size: .92rem; }
.q-list .q-meta { font-size: .75rem; color: var(--c-text-muted); margin-top: .15em; }
.q-list .q-actions { display: flex; gap: .35rem; }
.q-list li.inactive .q-text { opacity: .55; text-decoration: line-through; }


.option-editor { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .6rem; }
.option-editor .oe-row { display: flex; gap: .4rem; align-items: center; }
.option-editor .oe-row input[type="text"] { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-correct);
  border-radius: var(--radius-sm);
  padding: .7em 1.1em;
  box-shadow: var(--shadow);
  font-size: .9rem;
  max-width: calc(100vw - 2rem);
  z-index: 50;
}
.toast.error { border-left-color: var(--c-wrong); }
