@font-face {
  font-family: 'Fredoka';
  src: url('../fonts/fredoka-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Fredoka';
  src: url('../fonts/fredoka-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --grund: #e3e8ee;
  --papier: #f4f6f9;
  --tinte: #1d2943;
  --leise: #56627a;
  --linie: #c3ccd8;
  --wannenrand: #23304e;
  --akzent: #2f55a4;
  --akzent-text: #ffffff;
  --rand-1: #ffffff;
  --rand-2: #141b30;

  --f0: #c73e3a; --s0: rgba(255, 255, 255, 0.72);
  --f1: #ebbd31; --s1: rgba(40, 30, 0, 0.55);
  --f2: #2f55a4; --s2: rgba(255, 255, 255, 0.72);
  --f3: #3d8c52; --s3: rgba(255, 255, 255, 0.7);
  --f4: #8c4ba6; --s4: rgba(255, 255, 255, 0.72);
  --f5: #36b3bc; --s5: rgba(0, 35, 40, 0.55);
  --f6: #e27c2c; --s6: rgba(50, 20, 0, 0.55);

  --schrift: 'Fredoka', ui-rounded, system-ui, sans-serif;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #121a2c;
    --papier: #1c2640;
    --tinte: #e5e9f2;
    --leise: #9aa6bf;
    --linie: #34405f;
    --wannenrand: #3a4a72;
    --akzent: #7e9de0;
    --akzent-text: #0f1626;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--grund);
  color: var(--tinte);
  font: 500 16px/1.4 var(--schrift);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "kopf" "leiste" "buehne" "fuss";
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

/* Kopf */

.kopf {
  grid-area: kopf;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "titel status" "art status";
  align-items: center;
  column-gap: 12px;
  padding: 10px 16px 4px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.titel {
  grid-area: titel;
  margin: 0;
  font-weight: 600;
  font-size: 1.65rem;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.art { grid-area: art; margin: 0; color: var(--leise); font-size: 0.92rem; }

.status { grid-area: status; margin: 0; }

.solo-zaehler { display: inline-flex; align-items: baseline; gap: 2px; font-variant-numeric: tabular-nums; }
.solo-zaehler .zahl { font-size: 1.9rem; font-weight: 600; line-height: 1; }
.solo-zaehler .zahl-limit { color: var(--leise); }
.solo-zaehler .trenner { font-size: 1.4rem; color: var(--leise); padding: 0 2px; }
.solo-zaehler .wort { color: var(--leise); font-size: 0.9rem; margin-left: 6px; }
.solo-zaehler.knapp .zahl:first-child { color: var(--f0); }

body.duell .kopf { grid-template-columns: auto 1fr; grid-template-areas: "titel art" "status status"; }
body.duell .art { text-align: right; align-self: end; }
body.duell .status { margin-top: 6px; }
.duell-stand { display: flex; gap: 8px; }
.duell-stand .spieler { flex: 1 1 0; min-width: 0; }
.spieler .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.spieler {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.spieler::before {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--eigen);
  box-shadow: 0 0 0 2px var(--rahmen);
}
.spieler-1 { --rahmen: var(--rand-1); }
.spieler-2 { --rahmen: var(--rand-2); }
.spieler .punkte { font-weight: 600; font-size: 1.15rem; }
.spieler.dran { border-color: var(--tinte); background: var(--papier); }

/* Leiste */

.leiste {
  grid-area: leiste;
  display: flex;
  gap: 8px;
  padding: 6px 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.knopf {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--linie);
  background: var(--papier);
  cursor: pointer;
  touch-action: manipulation;
  font-weight: 500;
}
.leiste .knopf { flex: 1 1 auto; padding: 0 8px; }
.knopf-zurueck { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.knopf-zurueck svg { display: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.leiste .knopf-hilfe { flex: none; width: 44px; padding: 0; border-radius: 50%; font-weight: 600; font-size: 1.1rem; }
.knopf:hover:not(:disabled) { border-color: var(--tinte); }
.knopf:disabled { opacity: 0.45; cursor: default; }
.knopf-voll { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-text); }
.knopf-voll:hover:not(:disabled) { border-color: var(--tinte); }

:focus-visible { outline: 3px solid var(--akzent); outline-offset: 2px; }

/* Bühne und Spielfeld */

.buehne {
  grid-area: buehne;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 0;
  overflow: hidden;
}

.spiel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.spiel.quer { flex-direction: row; }

.wanne {
  position: relative;
  border-radius: 6px;
  box-shadow: 0 0 0 5px var(--wannenrand), 0 10px 26px -12px rgba(10, 20, 45, 0.55);
  touch-action: none;
}

.gitter {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: var(--groesse);
  height: var(--groesse);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: pointer;
}

.z {
  position: relative;
  background: var(--fc);
  transition: background-color 190ms ease-out;
}
.f0 { --fc: var(--f0); --sc: var(--s0); }
.f1 { --fc: var(--f1); --sc: var(--s1); }
.f2 { --fc: var(--f2); --sc: var(--s2); }
.f3 { --fc: var(--f3); --sc: var(--s3); }
.f4 { --fc: var(--f4); --sc: var(--s4); }
.f5 { --fc: var(--f5); --sc: var(--s5); }
.f6 { --fc: var(--f6); --sc: var(--s6); }

.symbole .z::after {
  content: '';
  position: absolute;
  inset: 26%;
  background: var(--sc);
  -webkit-mask: var(--maske) center / contain no-repeat;
  mask: var(--maske) center / contain no-repeat;
}

.z.o1::before, .z.o2::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 0 solid var(--rand-1);
  z-index: 1;
  pointer-events: none;
}
.z.o2::before { border-color: var(--rand-2); }
.z.rt::before { border-top-width: var(--lw, 2px); }
.z.rr::before { border-right-width: var(--lw, 2px); }
.z.rb::before { border-bottom-width: var(--lw, 2px); }
.z.rl::before { border-left-width: var(--lw, 2px); }

.vorbereitung {
  position: absolute;
  inset: auto 0 50% 0;
  margin: 0 auto;
  width: max-content;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--papier);
  transform: translateY(50%);
  z-index: 2;
}

.meldung {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92%, 360px);
  padding: 18px 20px 16px;
  border-radius: 16px;
  background: var(--papier);
  color: var(--tinte);
  box-shadow: 0 18px 40px -16px rgba(5, 10, 25, 0.7);
  z-index: 3;
  text-align: center;
}
.meldung h2 { margin: 0 0 4px; font-size: 1.45rem; font-weight: 600; }
.meldung p { margin: 0 0 14px; color: var(--leise); }
.meldung-aktionen { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* Farbtöpfe */

.toepfe { display: flex; gap: 8px; justify-content: center; }
.quer .toepfe { display: grid; grid-template-columns: repeat(var(--spalten, 1), var(--topf)); }

.topf {
  position: relative;
  width: var(--topf, 48px);
  height: var(--topf, 48px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease-out, opacity 150ms;
}
.topf-farbe {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--fc);
  display: grid;
  place-items: center;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16), 0 3px 8px -4px rgba(0, 0, 0, 0.5);
}
.topf svg { width: 46%; height: 46%; fill: var(--sc); visibility: hidden; }
.symbole .topf svg { visibility: visible; }
.topf-taste {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--papier);
  color: var(--leise);
  font-size: 0.72rem;
  line-height: 18px;
  display: none;
}
@media (hover: hover) and (pointer: fine) { .topf-taste { display: block; } }
.topf:not(:disabled):hover { transform: translateY(-2px); }
.topf:not(:disabled):active { transform: scale(0.94); }
.topf:disabled { cursor: default; opacity: 0.3; }
.topf.eigen { opacity: 1; }
.topf.eigen::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2.5px dashed var(--tinte);
}
.topf.gesperrt:disabled { opacity: 0.22; }

.hinweis { margin: 0; color: var(--leise); font-size: 0.85rem; text-align: center; }
@media (max-height: 700px), (hover: none) { .hinweis { display: none; } }

/* Fußzeile */

.fuss {
  grid-area: fuss;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px 10px;
  font-size: 0.85rem;
  color: var(--leise);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.teilen-ort { position: relative; }
.teilen {
  min-height: 28px;
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}
.teilen-pop {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: center;
  width: min(380px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--papier);
  color: var(--tinte);
  box-shadow: 0 16px 40px -14px rgba(5, 10, 25, 0.7);
}
.teilen-pop label { grid-column: 1 / -1; font-weight: 600; }
.teilen-pop input {
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  border: 1.5px solid var(--linie);
  border-radius: 8px;
  background: var(--grund);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(46px + env(safe-area-inset-bottom));
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--wannenrand);
  color: #fff;
  font-size: 0.9rem;
  text-align: center;
  box-shadow: 0 16px 40px -14px rgba(5, 10, 25, 0.7);
  transform: translateX(-50%);
  pointer-events: none;
}

/* Menü */

.menue {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--papier);
  color: var(--tinte);
  box-shadow: 0 24px 60px -20px rgba(5, 10, 25, 0.75);
}
.menue::backdrop { background: rgba(12, 18, 34, 0.5); }
.menue form { padding: 18px 20px 20px; }
.menue h2 { margin: 0 0 10px; font-size: 1.4rem; font-weight: 600; }
.menue h3 { margin: 22px 0 6px; font-size: 1.1rem; font-weight: 600; }

.gruppe { border: 0; margin: 0 0 12px; padding: 0; }
.gruppe legend { padding: 0; margin-bottom: 6px; color: var(--leise); font-size: 0.9rem; }
.gruppe[hidden] { display: none; }

.pillen { display: flex; flex-wrap: wrap; gap: 6px; }
.pillen label { flex: 1 1 0; min-width: max-content; cursor: pointer; }
.pillen input { position: absolute; opacity: 0; pointer-events: none; }
.pillen span {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--linie);
  text-align: center;
  line-height: 1.2;
}
.pillen small, .schalter small { display: block; color: var(--leise); font-size: 0.75rem; }
.pillen input:checked + span { border-color: var(--akzent); background: color-mix(in srgb, var(--akzent) 14%, transparent); }
.pillen input:focus-visible + span { outline: 3px solid var(--akzent); outline-offset: 2px; }

.schalter { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; cursor: pointer; }
.schalter input { width: 22px; height: 22px; accent-color: var(--akzent); flex: none; }

.menue-aktionen { display: flex; gap: 8px; flex-wrap: wrap; }
.menue-aktionen .knopf { flex: 1 1 auto; }

.statistik table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.statistik th, .statistik td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--linie); }
.statistik th[scope="row"], .statistik thead th:first-child { text-align: left; }
.statistik thead th { color: var(--leise); font-weight: 500; }
.statistik p, .statistik ul { margin: 8px 0 0; }
.statistik ul { padding-left: 1.2em; }
.regeln { margin: 0 0 8px; color: var(--leise); }
.tasten { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; }
.tasten dd { margin: 0; color: var(--leise); }
/* Anleitung */

.anleitung { overflow: hidden; }
.anleitung-rahmen { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.menue .anleitung-rahmen { padding: 0; }
.anleitung-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 10px 20px;
  border-bottom: 1.5px solid var(--linie);
}
.menue .anleitung-kopf h2 { margin: 0; }
.anleitung-zu { flex: none; width: 44px; padding: 0; border-radius: 50%; font-size: 1.4rem; line-height: 1; }
.anleitung-text { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 2px 20px 14px; }
.anleitung-text:focus { outline: none; }
.menue .anleitung-text h3 { margin: 16px 0 4px; }
.anleitung-text h4 { margin: 8px 0 2px; color: var(--leise); font-size: 0.9rem; font-weight: 500; }
.anleitung-text p, .anleitung-text ul { margin: 0; }
.anleitung-text ul { padding-left: 1.2em; }
.anleitung-text li + li { margin-top: 4px; }
.anleitung-text .tasten { margin: 0; font-size: 0.95rem; }
.beispiel { margin: 0; }
.beispiel-bild { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 6px 0; }
.beispiel-bild svg { width: 108px; height: auto; }
.beispiel-bild .beispiel-schritt { width: 30px; }
.bsp-wanne { fill: var(--wannenrand); }
.bsp-rand { fill: none; stroke: var(--rand-1); stroke-width: 2.5; stroke-linecap: square; }
.bsp-topf { stroke: var(--papier); stroke-width: 2; }
.bsp-pfeil { fill: none; stroke: var(--leise); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.beispiel figcaption { color: var(--leise); font-size: 0.9rem; }
.anleitung-fuss { display: flex; justify-content: flex-end; padding: 10px 20px 14px; border-top: 1.5px solid var(--linie); }
.anleitung-fuss .knopf { min-width: 140px; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--linie);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: inherit;
  font-size: 0.85em;
  text-align: center;
}

/* Querformat mit wenig Höhe: Kopf und Leiste in einer Zeile */

@media (orientation: landscape) and (max-height: 520px) {
  body {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "kopf leiste" "buehne buehne" "fuss fuss";
  }
  .kopf { padding: 6px 8px 0 16px; grid-template-areas: "titel status" "art status"; }
  .titel { font-size: 1.25rem; }
  .art { font-size: 0.78rem; }
  .solo-zaehler .zahl { font-size: 1.4rem; }
  .solo-zaehler .wort { display: none; }
  .leiste { padding: 6px 16px 0 8px; margin: 0; max-width: none; }
  .buehne { padding: 8px 16px 4px; }
  .fuss { padding: 0 16px 4px; max-width: none; }
}

@media (max-width: 440px) {
  .leiste { gap: 6px; }
  .leiste .knopf-zurueck { flex: none; width: 44px; padding: 0; }
  .knopf-zurueck svg { display: block; }
  .knopf-zurueck .text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .z, .topf { transition: none; }
}
