@font-face {
  font-family: 'Grenze';
  src: url('../fonts/grenze-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Grenze';
  src: url('../fonts/grenze-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Grenze Gotisch';
  src: url('../fonts/grenze-gotisch-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --grund: #a9b89c;
  --grund-licht: #c4d0b5;
  --tinte: #1d2a1c;
  --tinte-leise: #4a5c45;
  --flaeche: rgb(255 255 245 / 0.32);
  --flaeche-stark: rgb(255 255 245 / 0.6);
  --rand: rgb(29 42 28 / 0.28);
  --knopf-voll: #2f3f2b;
  --knopf-voll-text: #f3f1e4;
  --holz-a: #ecd29c;
  --holz-b: #c99d5c;
  --maser: #9a6b34;
  --holz-kante: #6e4a22;
  --linie: #4a2c12;
  --ziel: #17766b;
  --nehmen: #b3261e;
  --akzent: #7b4f12;
  --fokus: #173f86;
  --karte: #f4efe0;
  --schatten: 0 2px 4px rgb(20 30 18 / 0.25), 0 12px 32px rgb(20 30 18 / 0.25);
  --w-licht: #fffef8;
  --w-mitte: #efe6cf;
  --w-rand: #bfae86;
  --s-licht: #93613f;
  --s-mitte: #4c2c1b;
  --s-rand: #24130a;
  --s-strich: #24130a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #18211a;
    --grund-licht: #243127;
    --tinte: #e6ecdc;
    --tinte-leise: #a9b8a2;
    --flaeche: rgb(230 236 220 / 0.06);
    --flaeche-stark: rgb(230 236 220 / 0.12);
    --rand: rgb(230 236 220 / 0.22);
    --knopf-voll: #d9c08a;
    --knopf-voll-text: #1b1a10;
    --holz-a: #6a4c2c;
    --holz-b: #45301b;
    --maser: #2c1d0e;
    --holz-kante: #1c1208;
    --linie: #e6cb93;
    --ziel: #5fd3c2;
    --nehmen: #ff6a5c;
    --akzent: #f0c873;
    --fokus: #9cc3ff;
    --karte: #253128;
    --schatten: 0 2px 4px rgb(0 0 0 / 0.5), 0 12px 32px rgb(0 0 0 / 0.5);
    --w-licht: #fbf7ea;
    --w-mitte: #ddd2b6;
    --w-rand: #9d8d68;
    --s-licht: #7d4f33;
    --s-mitte: #3a2114;
    --s-rand: #120904;
    --s-strich: #b08a5e;
  }
}

* { box-sizing: border-box; }

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

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(120% 90% at 50% 35%, var(--grund-licht), var(--grund) 70%) var(--grund);
  color: var(--tinte);
  font-family: 'Grenze', Georgia, serif;
  font-size: 1.0625rem;
  line-height: 1.35;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

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

.oben {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 16px 0;
}

.kopf {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  flex-wrap: wrap;
}

.titel {
  margin: 0;
  font-family: 'Grenze Gotisch', 'Grenze', serif;
  font-weight: 600;
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: 0.01em;
}

.status {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 1.5em;
  font-size: 1.05rem;
}

.status-phase {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--flaeche-stark);
  color: var(--tinte-leise);
  font-size: 0.9rem;
}

.status[data-zustand='muehle'] .status-phase { background: var(--nehmen); color: #fff; }
.status[data-zustand='muehle'] .status-text { font-weight: 600; }
.status[data-zustand='ende'] .status-text { font-weight: 600; }

.leiste {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.knopf {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--rand);
  border-radius: 10px;
  background: var(--flaeche);
  cursor: pointer;
  touch-action: manipulation;
  font-size: 1rem;
}
.knopf:hover:not(:disabled) { background: var(--flaeche-stark); }
.knopf:disabled { opacity: 0.45; cursor: default; }
.knopf:focus-visible, .pillen input:focus-visible + span, .schalter input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--fokus);
  outline-offset: 2px;
}
.knopf-voll { background: var(--knopf-voll); color: var(--knopf-voll-text); border-color: transparent; font-weight: 600; }
.knopf-voll:hover:not(:disabled) { background: var(--knopf-voll); filter: brightness(1.1); }
.knopf-klein { min-height: 34px; padding: 4px 10px; font-size: 0.92rem; }

#einstellungen-knopf { margin-left: auto; }
.knopf-rund { width: 40px; min-width: 40px; padding: 0; border-radius: 50%; font-weight: 600; font-size: 1.15rem; }

/* Spielfläche */

.tisch {
  position: relative;
  container-type: size;
  min-height: 0;
  margin: 8px 16px 4px;
}

.spiel {
  --vorrat-h: 46px;
  --luecke: 8px;
  --b: min(100cqw, 100cqh - 2 * var(--vorrat-h) - 2 * var(--luecke), 760px);
  display: grid;
  grid-template-rows: var(--vorrat-h) var(--b) var(--vorrat-h);
  justify-content: center;
  align-content: center;
  gap: var(--luecke);
  height: 100%;
}

.brett-rahmen { width: var(--b); height: var(--b); }

.brett {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  filter: drop-shadow(0 3px 3px rgb(20 20 10 / 0.25)) drop-shadow(0 14px 22px rgb(20 20 10 / 0.25));
}
.brett.ruhig { cursor: default; }

.vorrat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: var(--b);
  min-width: 0;
  overflow: hidden;
  padding: 4px 12px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--flaeche);
}
.vorrat.am-zug { border-color: var(--akzent); background: var(--flaeche-stark); }

.vorrat-name { display: flex; flex-direction: column; min-width: 4.6em; line-height: 1.1; }
.vorrat-seite { font-weight: 600; }
.vorrat-rolle { font-size: 0.85rem; color: var(--tinte-leise); }
.vorrat-rolle:empty { display: none; }

.vorrat-steine { display: flex; gap: 3px; flex: 1; justify-content: center; }

.vorrat-zahl {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0 0 0 auto;
  line-height: 1.05;
  color: var(--tinte-leise);
  white-space: nowrap;
}
.vorrat-zahl b { font-size: 1.15rem; color: var(--tinte); }
.vorrat-zahl span { font-size: 0.78rem; }

.mini {
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: block;
}
.mini-weiss { --m-a: var(--w-licht); --m-b: var(--w-mitte); --m-r: var(--w-rand); }
.mini-schwarz { --m-a: var(--s-licht); --m-b: var(--s-mitte); --m-r: var(--s-rand); }
.mini-vorrat { background: radial-gradient(circle at 38% 32%, var(--m-a), var(--m-b) 55%, var(--m-r)); box-shadow: 0 1px 1.5px rgb(0 0 0 / 0.35); }
.mini-brett { border: 2px solid var(--m-r); opacity: 0.55; }
.mini-weg { border: 1.5px dashed var(--tinte-leise); opacity: 0.35; transform: scale(0.7); }

@container (min-aspect-ratio: 6 / 5) {
  .spiel {
    --vorrat-w: clamp(92px, 16cqw, 150px);
    --b: min(100cqh, 100cqw - 2 * var(--vorrat-w) - 2 * var(--luecke), 760px);
    grid-template-rows: var(--b);
    grid-template-columns: var(--vorrat-w) var(--b) var(--vorrat-w);
  }
  .vorrat {
    width: auto;
    flex-direction: column;
    align-items: flex-start;
    align-self: center;
    padding: 10px 12px;
  }
  .vorrat-steine { display: grid; grid-template-columns: repeat(3, 15px); gap: 6px; flex: none; }
  .vorrat-zahl { margin: 0; flex-direction: row; align-items: baseline; gap: 5px; white-space: normal; }
}

/* Brett (SVG) */

.holz { fill: url(#g-holz); }
.holz-a { stop-color: var(--holz-a); }
.holz-b { stop-color: var(--holz-b); }
.maser { fill: none; stroke: var(--maser); stroke-width: 1.6; opacity: 0.22; }
.maser-stark { stroke-width: 3.2; opacity: 0.16; }
.holz-kante { fill: none; stroke: var(--holz-kante); stroke-width: 3; opacity: 0.45; }
.linien rect, .linien line { fill: none; stroke: var(--linie); stroke-width: 7; stroke-linecap: square; }
.punkte circle { fill: var(--linie); }

.w-licht { stop-color: var(--w-licht); }
.w-mitte { stop-color: var(--w-mitte); }
.w-rand { stop-color: var(--w-rand); }
.s-licht { stop-color: var(--s-licht); }
.s-mitte { stop-color: var(--s-mitte); }
.s-rand { stop-color: var(--s-rand); }

.stein > * { transition: transform 0.15s ease-out, opacity 0.2s; }
.stein-schatten { fill: rgb(20 10 0 / 0.3); }
.weiss .stein-koerper { stroke: var(--w-rand); stroke-width: 2; }
.schwarz .stein-koerper { stroke: var(--s-strich); stroke-width: 2.5; }
.stein-rille { fill: none; stroke-width: 2.5; }
.weiss .stein-rille { stroke: rgb(120 100 60 / 0.35); }
.schwarz .stein-rille { stroke: rgb(255 220 190 / 0.18); }
.stein-mitte { fill: rgb(255 255 255 / 0.1); }

.gleitet { transition: transform 0.24s cubic-bezier(0.3, 0.7, 0.3, 1); }
.neu > * { animation: setzen 0.22s ease-out; }
.weg { animation: weg 0.45s ease-in forwards; }
.gewaehlt > :not(.stein-schatten):not(.mark-nehmen) { transform: translateY(-6px) scale(1.08); }
.gewaehlt .stein-koerper { stroke: var(--ziel); stroke-width: 6; }
.gezogen > :not(.stein-schatten) { transform: scale(1.14); }
.gezogen .stein-schatten { transform: translate(4px, 10px) scale(1.1); opacity: 0.6; }

.mark-ziel { fill: var(--ziel); opacity: 0.9; }
.mark-nehmen { fill: none; stroke: var(--nehmen); stroke-width: 7; animation: puls 1.1s ease-in-out infinite alternate; }
.mark-zu { fill: none; stroke: var(--akzent); stroke-width: 4; opacity: 0.85; }
.mark-von { fill: none; stroke: var(--akzent); stroke-width: 4; stroke-dasharray: 5 6; opacity: 0.85; }
.mark-weg line { stroke: var(--nehmen); stroke-width: 5; stroke-linecap: round; opacity: 0.8; }

.brett.entfernen[data-zug='1'] .stein.schwarz:not(.nehmbar),
.brett.entfernen[data-zug='2'] .stein.weiss:not(.nehmbar) { opacity: 0.45; }

.treffer { pointer-events: none; }
.punkt { outline: none; }
.punkt-flaeche { fill: transparent; }
.punkt-fokus { fill: none; stroke: none; }
.punkt:focus-visible .punkt-fokus { stroke: var(--fokus); stroke-width: 5; }

@keyframes setzen { from { transform: scale(1.3); opacity: 0.2; } }
@keyframes weg { to { transform: scale(0.5); opacity: 0; } }
@keyframes puls { from { opacity: 1; } to { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, .stein > * { animation: none !important; transition: none !important; }
  .weg { display: none; }
}

/* Meldung */

.meldung {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, 100%);
  padding: 18px 20px 16px;
  border-radius: 14px;
  background: var(--karte);
  box-shadow: var(--schatten);
  text-align: center;
  z-index: 2;
}
.meldung h2 { margin: 0 0 4px; font-family: 'Grenze Gotisch', 'Grenze', serif; font-weight: 600; font-size: 2rem; }
.meldung p { margin: 0 0 14px; color: var(--tinte-leise); }
.meldung-aktionen { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Dialog */

.wahl {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 18px 20px;
  border: none;
  border-radius: 14px;
  background: var(--karte);
  color: var(--tinte);
  box-shadow: var(--schatten);
}
.wahl::backdrop { background: rgb(10 20 10 / 0.45); }
.wahl h2 { margin: 0 0 10px; font-weight: 600; font-size: 1.4rem; }

.gruppe { border: none; margin: 0 0 12px; padding: 0; }
.gruppe:disabled { opacity: 0.45; }
.gruppe legend { padding: 0; margin-bottom: 6px; color: var(--tinte-leise); }

.pillen { display: flex; flex-wrap: wrap; gap: 6px; }
.pillen label { position: relative; }
.pillen input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.pillen span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--rand);
  cursor: pointer;
}
.pillen input:checked + span { background: var(--knopf-voll); color: var(--knopf-voll-text); border-color: transparent; }

.schalter { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin-bottom: 8px; }
.schalter input { width: 22px; height: 22px; accent-color: var(--ziel); }

details { margin: 6px 0; border-top: 1px solid var(--rand); padding-top: 6px; }
summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
details p { margin: 4px 0 8px; max-width: 60ch; }

.statistik { border-collapse: collapse; width: 100%; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.statistik th, .statistik td { padding: 3px 6px; text-align: right; }
.statistik th:first-child { text-align: left; }
.statistik tr:has(> th + th) th { color: var(--tinte-leise); font-weight: 400; padding-top: 8px; }

.tasten { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0; font-size: 0.95rem; }
.tasten dt { white-space: nowrap; }
.tasten dd { margin: 0; color: var(--tinte-leise); }
kbd { font: inherit; padding: 0 5px; border: 1px solid var(--rand); border-radius: 4px; }

.wahl-aktionen { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

/* Anleitung */

.anleitung {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: 14px;
  background: var(--karte);
  color: var(--tinte);
  box-shadow: var(--schatten);
  overflow: hidden;
}
.anleitung[open] { display: flex; flex-direction: column; }
.anleitung::backdrop { background: rgb(10 20 10 / 0.45); }
.anleitung-kopf { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px 8px 20px; border-bottom: 1px solid var(--rand); }
.anleitung-kopf h2 { margin: 0; font-family: 'Grenze Gotisch', 'Grenze', serif; font-weight: 600; font-size: 1.8rem; line-height: 1.1; }
.anleitung-inhalt { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 12px; min-height: 0; }
.anleitung h3 { margin: 14px 0 4px; font-size: 1.2rem; font-weight: 600; }
.anleitung h4 { margin: 10px 0 2px; font-size: 1rem; font-weight: 600; color: var(--tinte-leise); }
.anleitung p { margin: 4px 0; }
.anleitung ul { margin: 4px 0; padding-left: 1.2em; }
.anleitung li { margin: 3px 0; }
.anleitung-fuss { display: flex; justify-content: flex-end; padding: 10px 20px 14px; border-top: 1px solid var(--rand); }
.beispiel { display: flex; gap: 14px; align-items: center; margin: 12px 0 4px; }
.beispiel-brett { flex: none; width: 150px; height: 150px; }
.beispiel figcaption { font-size: 0.95rem; color: var(--tinte-leise); }
.bsp-pfeil { stroke: var(--ziel); stroke-width: 12; stroke-linecap: round; }
.bsp-spitze { fill: var(--ziel); }
@media (max-width: 420px) {
  .beispiel { flex-direction: column; align-items: center; text-align: center; }
  .beispiel-brett { width: 190px; height: 190px; }
}

.verweis { margin: 10px 0 0; color: var(--tinte-leise); font-size: 0.95rem; }
.link { padding: 0; border: none; background: none; color: var(--tinte); text-decoration: underline; cursor: pointer; }
.link:focus-visible, .teilen:focus-visible { outline: 3px solid var(--fokus); outline-offset: 2px; }

/* Teilen */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(36px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--knopf-voll);
  color: var(--knopf-voll-text);
  box-shadow: var(--schatten);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}
.toast.sichtbar { opacity: 1; }
.link-pop {
  width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  background: var(--karte);
  color: var(--tinte);
  box-shadow: var(--schatten);
}
.link-pop label { display: block; margin-bottom: 6px; }
.link-pop input { width: 100%; min-height: 40px; padding: 4px 8px; margin-bottom: 10px; border: 1px solid var(--rand); border-radius: 8px; background: var(--flaeche-stark); }

/* Fußzeile */

.fuss {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 2px 16px 6px;
  font-size: 0.9rem;
  color: var(--tinte-leise);
}
.teilen { padding: 0; border: none; background: none; color: inherit; font-size: inherit; text-decoration: underline; cursor: pointer; }

@media (max-width: 380px) {
  .titel { font-size: 2.1rem; }
  .knopf { padding: 6px 10px; }
  .leiste { gap: 6px; }
  .leiste .knopf { padding: 6px 8px; font-size: 0.95rem; white-space: nowrap; }
  .leiste .knopf-rund { padding: 0; }
  .vorrat { gap: 8px; padding: 4px 10px; }
  .vorrat-name { min-width: 0; }
  .vorrat-steine { gap: 2px; }
  .mini { width: 13px; height: 13px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .oben { display: flex; align-items: center; gap: 12px; padding-top: 4px; max-width: none; }
  .kopf { flex: 1; flex-wrap: nowrap; justify-content: flex-start; align-items: center; }
  .titel { font-size: 1.8rem; }
  .leiste { margin-top: 0; }
  #einstellungen-knopf { margin-left: 0; }
  .tisch { margin: 4px 16px 0; }
  .fuss { padding-bottom: 2px; max-width: none; }
}
