:root {
  --grund: #f6f5f1;
  --flaeche: #ffffff;
  --text: #1d1f24;
  --leise: #646a75;
  --linie: #dddad2;
  --leer: #ebe8e1;
  --leer-svg: transparent;
  --akzent: #1d1f24;
  --akzent-text: #ffffff;
  --rot: #c62f34;
  --kante: rgba(20, 22, 26, 0.85);
  --kante-duenn: rgba(20, 22, 26, 0.18);
  --schatten: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --grund: #15171b;
    --flaeche: #1e2126;
    --text: #eceef1;
    --leise: #9aa1ad;
    --linie: #31353c;
    --leer: #2b2f36;
    --akzent: #eceef1;
    --akzent-text: #15171b;
    --rot: #ff6b6f;
    --kante: rgba(10, 11, 13, 0.9);
    --kante-duenn: rgba(10, 11, 13, 0.3);
    --schatten: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--grund);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.breite { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: clamp(28px, 5vw, 40px); margin: 28px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 0; }
.unterzeile { margin: 0 0 16px; color: var(--leise); max-width: 60ch; }
.unterzeile strong { color: var(--text); }
.lesehilfe { color: var(--leise); font-size: 14px; margin: 0 0 16px; max-width: 70ch; }
.lesehilfe.mitte { text-align: center; margin-top: 8px; }
.hinweis { margin: 8px 0 4px; font-size: 15px; }

/* Teile-Leiste im Kopf */
.teile-leiste { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 20px; }
.teil-kachel { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.teil-kachel .teil-svg { height: 38px; width: 46px; }
.teil-buchstabe { font-weight: 700; }
.teil-flaeche { stroke: var(--kante); stroke-width: 0.04; stroke-linejoin: round; }

/* Reiter */
.reiter { display: flex; gap: 4px; border-bottom: 1px solid var(--linie); }
.reiter button {
  font: inherit; font-weight: 600; background: none; border: 0; color: var(--leise);
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.reiter button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.bereich { padding: 20px 0 32px; }

/* Filter */
.filter-zeile { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.filter-titel { font-weight: 600; font-size: 15px; }
.filter { display: flex; flex-wrap: wrap; gap: 6px; }
.filter button, .knopf {
  font: inherit; font-size: 14px; color: var(--text); background: var(--flaeche);
  border: 1px solid var(--linie); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.filter button[aria-pressed="true"] { background: var(--akzent); color: var(--akzent-text); border-color: var(--akzent); }
.filter .zahl { opacity: 0.65; margin-left: 4px; font-variant-numeric: tabular-nums; }
.knopf:hover, .filter button:hover { border-color: var(--leise); }
.knopf.haupt { background: var(--akzent); color: var(--akzent-text); border-color: var(--akzent); font-weight: 600; }
.knopf.rund { width: 36px; height: 36px; padding: 0; font-size: 22px; line-height: 1; border-radius: 50%; }

/* Karten */
.karten { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.karte {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 12px;
  box-shadow: var(--schatten); padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
.karte:hover { border-color: var(--leise); }
.karte:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.karte .nr { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; gap: 6px; }
.karte .nr small { font-weight: 400; color: var(--leise); }
.karte .iso { width: 72%; align-self: center; }
.karte .schichten { width: 100%; }
.kante-dick { fill: none; stroke: var(--kante); stroke-width: 0.06; stroke-linejoin: round; stroke-linecap: round; }
.kante-duenn { fill: none; stroke: var(--kante-duenn); stroke-width: 0.03; }
.zelle { stroke: var(--kante-duenn); stroke-width: 0.6; }
.raster-rand { fill: none; stroke: var(--kante); stroke-width: 1; }

/* Baukasten */
.baukasten { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.palette button {
  font: inherit; font-size: 14px; color: var(--text); background: var(--flaeche);
  border: 1px solid var(--linie); border-radius: 10px; padding: 4px 10px 4px 4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.palette button .teil-svg { width: 34px; height: 30px; }
.palette button[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.palette button.aus { opacity: 0.35; }
.palette button.drin { background: var(--grund); }
.palette .haken { color: var(--text); }
.palette .zahl { font-variant-numeric: tabular-nums; color: var(--leise); font-size: 13px; }
.palette .zahl.voll { color: var(--text); font-weight: 700; }
.palette .zahl.zuviel { color: var(--rot); font-weight: 700; }
.radierer-symbol { width: 30px; height: 30px; display: grid; place-items: center; font-size: 18px; }

.raster-reihe { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.schicht-titel { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.schicht-fuss { font-size: 12px; color: var(--leise); text-align: center; margin-top: 2px; }
.raster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.feld {
  aspect-ratio: 1; border: 1px solid var(--linie); border-radius: 6px; background: var(--flaeche);
  cursor: pointer; position: relative; display: flex; flex-wrap: wrap;
  align-content: center; justify-content: center; gap: 2px; padding: 3px;
}
.feld.gesetzt { background: var(--f); border-color: var(--kante); }
.feld.moeglich { border-color: var(--leise); }
.feld.moeglich::after {
  content: ""; width: 30%; aspect-ratio: 1; border-radius: 50%;
  background: var(--f); box-shadow: 0 0 0 1px var(--kante);
}
.feld.moeglich:has(.punkt)::after { display: none; }
.feld.moeglich:hover { border-color: var(--text); background: var(--grund); }
.feld.aus { background: var(--grund); border-style: dashed; cursor: default; }
.feld.vorschau {
  background: repeating-linear-gradient(45deg, var(--f) 0 6px, color-mix(in srgb, var(--f) 45%, var(--flaeche)) 6px 12px);
  border-color: var(--kante);
}
.feld.gewaehlt { outline: 3px solid var(--text); outline-offset: -2px; }
.feld .punkt { width: 9px; height: 9px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.35); }
#lagen-bereich { margin-top: 16px; scroll-margin: 16px; }
.lagen-hinweis { margin: 0 0 10px; font-size: 15px; }
.lagen-hinweis .fehler { color: var(--rot); }
.lagen { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.lage-karte {
  font: inherit; font-size: 13px; color: inherit; cursor: pointer; text-align: center;
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 10px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px; font-variant-numeric: tabular-nums;
}
.lage-karte:hover { border-color: var(--text); }
.knopf-reihe { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 16px; }
.schalter { font-size: 14px; display: flex; gap: 6px; align-items: center; cursor: pointer; }

.ergebnis {
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 12px;
  padding: 16px; box-shadow: var(--schatten); margin-bottom: 12px;
}
.ergebnis .gross { font-size: 44px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ergebnis .gross.null { color: var(--rot); }
.ergebnis p { margin: 4px 0 0; }
.ergebnis .leise { color: var(--leise); font-size: 14px; }
.ergebnis .fehler { color: var(--rot); font-size: 14px; }

.ansicht { width: 100%; aspect-ratio: 1; position: relative; touch-action: none; }
.ansicht canvas { width: 100%; height: 100%; display: block; }
.ansicht.klein { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 12px; }
.treffer-titel { margin: 28px 0 12px; font-size: 18px; }
.mehr-zeile { text-align: center; margin-top: 16px; }

/* Detail */
dialog {
  width: min(980px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0;
  border: 1px solid var(--linie); border-radius: 16px; background: var(--flaeche); color: var(--text);
}
dialog::backdrop { background: rgba(10, 12, 16, 0.55); }
.detail-kopf { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--linie); }
.detail-kopf h2 { flex: 1; font-size: 18px; }
.detail-kopf h2 small { white-space: nowrap; font-weight: 400; color: var(--leise); font-size: 14px; margin-left: 6px; }
.detail-inhalt { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; padding: 16px; }
.detail-seite { display: flex; flex-direction: column; gap: 16px; }
.detail-seite .palette { margin: 0; }
.klein-titel { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--leise); }
.regler { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
.regler input { width: 100%; }
#detail-schichten .schichten { width: 100%; max-width: 360px; }
.merkmale { margin: 0; padding-left: 18px; font-size: 14px; color: var(--leise); }
.merkmale strong { color: var(--text); }

.fuss { color: var(--leise); font-size: 13px; padding-bottom: 32px; }

@media (max-width: 760px) {
  .detail-inhalt { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .baukasten { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .baukasten-rechts { display: contents; }
  .ergebnis { order: -1; margin: 0; }
  .umsetzen { margin: 0; }
  .ansicht.klein { max-width: 300px; margin: 0 auto; }
  .teile-leiste { gap: 4px 14px; }
  .teil-kachel { font-size: 13px; gap: 4px; }
  .teil-kachel .teil-svg { height: 28px; width: 34px; }
  .raster-reihe { gap: 8px; }
  .lesehilfe { font-size: 13px; }
  .ergebnis .gross { font-size: 36px; }
  .karten { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
  .feld .punkt { width: 7px; height: 7px; }
}

/* Impressum, Datenschutz */
.recht { max-width: 720px; padding-top: 24px; padding-bottom: 48px; }
.recht h1 { margin-top: 12px; }
.recht h2 { font-size: 17px; margin: 24px 0 6px; }
.recht address { font-style: normal; }
.recht p, .recht address { margin: 0 0 8px; }
.recht .leise { color: var(--leise); font-size: 14px; margin-top: 24px; }
a { color: inherit; text-underline-offset: 2px; }
.fuss a { color: var(--leise); }

/* Modus „Passt nicht?“ */
body[data-modus="passt"] .nur-streng, body:not([data-modus="passt"]) .nur-frei { display: none; }
.sackgasse { color: var(--rot); }
.lage-karte .leise { color: var(--leise); font-size: 12px; margin-top: -4px; }
.umsetzen {
  background: var(--flaeche); border: 1px solid var(--rot); border-radius: 12px;
  padding: 14px; margin-bottom: 12px;
}
.umsetzen .lagen { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }

/* Rätsel */
.raetsel-steuer { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; margin-bottom: 8px; }
.raetsel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; margin-top: 8px; }
.raetsel-text {
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 12px;
  padding: 16px; box-shadow: var(--schatten);
}
.r-schritt { margin: 0 0 6px; font-weight: 600; }
.r-teile { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; }
.r-teil { display: flex; align-items: center; gap: 4px; font-weight: 700; }
.r-teil .teil-svg { width: 40px; height: 34px; }
.r-schichten { width: 100%; max-width: 380px; display: block; }
.r-legende { font-size: 13px; color: var(--leise); margin: 4px 0 16px; }
.r-zahl { font-size: 18px; margin: 4px 0 0; }
.r-zahl strong { font-size: 32px; font-variant-numeric: tabular-nums; }
.rekord {
  margin-top: 32px; padding: 16px; border-radius: 12px; border: 1px dashed var(--linie);
}
.rekord h2 { font-size: 17px; margin-bottom: 6px; }
.rekord p { margin: 0 0 12px; max-width: 70ch; }
.reiter { overflow-x: auto; scrollbar-width: none; }
.reiter button { white-space: nowrap; }
@media (max-width: 760px) {
  .raetsel { grid-template-columns: 1fr; }
  .raetsel .ansicht.klein { order: 1; }
  .reiter { flex-wrap: wrap; gap: 6px; border-bottom: 0; overflow: visible; }
  .reiter button {
    padding: 6px 12px; font-size: 15px; margin: 0; border: 1px solid var(--linie);
    border-radius: 8px; background: var(--flaeche);
  }
  .reiter button[aria-selected="true"] { background: var(--akzent); color: var(--akzent-text); border-color: var(--akzent); }
}
