@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage-grotesque-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage-grotesque-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage-grotesque-latin-800-normal.woff2') format('woff2');
  font-weight: 800;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --seite: #e3ebe8;
  --flaeche: #f3f7f5;
  --tinte: #14302f;
  --tinte-leise: #4c6866;
  --linie: #b7c9c5;
  --brett: #1f5b5e;
  --brett-hell: #2b7276;
  --brett-tief: #123b3d;
  --loch: #0b2a2c;
  --bernstein: #eea434;
  --bernstein-hell: #ffd88a;
  --bernstein-tief: #a8650f;
  --perlmutt: #efe8da;
  --perlmutt-hell: #ffffff;
  --perlmutt-tief: #a99d86;
  --fokus: #e0892a;
  --schatten: 0 1.2em 2.4em -1.2em rgb(10 40 40 / 0.55);
  --schrift: 'Bricolage Grotesque', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --seite: #0e1d1f;
    --flaeche: #16292b;
    --tinte: #dce8e5;
    --tinte-leise: #93aeaa;
    --linie: #2c4648;
    --brett: #22676a;
    --brett-hell: #2f7f83;
    --brett-tief: #134446;
    --loch: #071315;
    --fokus: #f0a54a;
    --schatten: 0 1.2em 2.4em -1em rgb(0 0 0 / 0.7);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--seite);
  color: var(--tinte);
  font-family: var(--schrift);
  font-size: 1rem;
  line-height: 1.45;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  padding: max(0.6rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(0.4rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.kopf {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.2rem 1rem;
  max-width: 46rem;
  width: 100%;
  margin: 0 auto;
}

.titel {
  margin: 0;
  font-weight: 800;
  font-size: clamp(1.45rem, 5.2vw, 2rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: var(--tinte-leise);
  min-height: 1.6rem;
}

.mini {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  flex: none;
}
.mini:empty:not(.p0):not(.p1) { display: none; }

.leiste {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 46rem;
  width: 100%;
  margin: 0.6rem auto 0;
}

.knopf {
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 2.6rem;
  padding: 0.45rem 1rem;
  border-radius: 0.8rem;
  border: 1.5px solid var(--linie);
  background: var(--flaeche);
  color: var(--tinte);
  cursor: pointer;
  touch-action: manipulation;
}
.knopf:hover:not(:disabled) { border-color: var(--brett); }
.knopf:disabled { opacity: 0.45; cursor: default; }
.knopf-voll {
  background: var(--brett);
  border-color: var(--brett);
  color: #f4faf8;
}
.knopf-voll:hover:not(:disabled) { background: var(--brett-hell); border-color: var(--brett-hell); }
.knopf-klein { min-height: 2.5rem; font-size: 0.85rem; padding: 0.3rem 0.8rem; }
.knopf-hilfe {
  display: inline-grid;
  place-items: center;
  width: 2.6rem;
  padding: 0;
  font-size: 1.2rem;
  font-weight: 800;
}
.leiste .knopf-hilfe { margin-left: auto; }

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

/* Spielfläche: das Brett nimmt den verbleibenden Platz und bleibt im Seitenverhältnis. */
.tisch {
  position: relative;
  container-type: size;
  min-height: 15rem;
  display: grid;
  justify-items: center;
  align-content: center;
  padding: 0.5rem 0 0.8rem;
}

.brett {
  --z: min(100cqw / 7.4, 100cqh / 7.3, 5.6rem);
  --rand: calc(var(--z) * 0.2);
  position: relative;
  width: calc(var(--z) * 7.4);
  user-select: none;
  -webkit-user-select: none;
}

.vorschau {
  position: relative;
  height: calc(var(--z) * 0.9);
}

.schacht {
  position: relative;
  height: calc(var(--z) * 6 + var(--rand) * 2);
  border-radius: calc(var(--z) * 0.32);
  background: var(--loch);
  box-shadow: var(--schatten);
}

.steine {
  position: absolute;
  inset: 0;
  /* Fallende Steine bleiben in Vorschauzeile und Schacht, nie über Kopf und Leiste. */
  clip-path: inset(calc(var(--z) * -0.9) 0 0 0);
}

.front {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.stein {
  --groesse: calc(var(--z) * 0.86);
  position: absolute;
  width: var(--groesse);
  height: var(--groesse);
  left: calc(var(--rand) + var(--z) * var(--c, 0) + (var(--z) - var(--groesse)) / 2);
  top: calc(var(--rand) + var(--z) * (5 - var(--r, 0)) + (var(--z) - var(--groesse)) / 2);
  border-radius: 50%;
  transition: opacity 0.3s, filter 0.3s;
}

.p0, .stein.p0 {
  background: radial-gradient(circle at 34% 30%, var(--bernstein-hell), var(--bernstein) 42%, var(--bernstein-tief) 100%);
}
.p1, .stein.p1 {
  background: radial-gradient(circle at 34% 30%, var(--perlmutt-hell), var(--perlmutt) 48%, var(--perlmutt-tief) 100%);
}

/* Prägung: Bernstein trägt einen Punkt, Perlmutt einen Ring – unterscheidbar auch ohne Farbe. */
.stein::after, .mini::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
}
.mini { position: relative; }
.stein.p0::after, .mini.p0::after {
  width: 30%;
  height: 30%;
  background: var(--bernstein-tief);
  box-shadow: inset 0 0.08em 0.12em rgb(0 0 0 / 0.35), 0 0.06em 0 rgb(255 255 255 / 0.4);
  opacity: 0.75;
}
.stein.p1::after, .mini.p1::after {
  width: 52%;
  height: 52%;
  border: max(2px, calc(var(--z, 1rem) * 0.055)) solid var(--perlmutt-tief);
  box-shadow: inset 0 0.06em 0.1em rgb(0 0 0 / 0.25);
  opacity: 0.8;
}
.mini.p1::after { border-width: 2px; }

.geist {
  top: auto;
  bottom: calc(var(--z) * 0.02);
  opacity: 0.55;
}

.steine.ende .stein:not(.sieg) {
  opacity: 0.5;
  filter: saturate(0.5);
}
.stein.sieg {
  box-shadow: inset 0 0 0 calc(var(--z) * 0.07) rgb(255 255 255 / 0.9);
  animation: leuchten 0.9s ease-out 1;
}
@keyframes leuchten {
  0% { filter: brightness(1.6); }
  100% { filter: brightness(1); }
}

.spalten {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 var(--rand);
  touch-action: manipulation;
}

.spalte {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: calc(var(--z) * 0.45);
  touch-action: manipulation;
}
.spalte:focus { outline: none; }
.spalte:focus-visible {
  box-shadow: inset 0 0 0 3px var(--fokus);
}
.spalte[aria-disabled='true'] { cursor: not-allowed; }
.brett.gesperrt .spalte { cursor: progress; }
.brett.vorbei .spalte { cursor: default; }

/* End-Meldung schwebt am unteren Rand der Spielfläche, das Brett bleibt sichtbar. */
.meldung {
  position: absolute;
  left: 50%;
  bottom: 0.8rem;
  transform: translateX(-50%);
  width: min(24rem, 100%);
  background: var(--flaeche);
  border: 1.5px solid var(--linie);
  border-radius: 1rem;
  padding: 1rem 1.2rem 1.1rem;
  box-shadow: var(--schatten);
  text-align: center;
  z-index: 2;
}
.meldung.unten {
  bottom: auto;
  top: var(--oben);
}
.meldung.seitlich {
  left: var(--links);
  bottom: auto;
  top: 40%;
  transform: none;
  width: 15.5rem;
}
.meldung.seitlich h2 { font-size: 1.35rem; }
.meldung h2 {
  margin: 0;
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}
.meldung p { margin: 0.3rem 0 0; }
.meldung .bilanz { color: var(--tinte-leise); font-size: 0.9rem; }
.meldung-aktionen {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.wahl {
  width: min(30rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  border: 1.5px solid var(--linie);
  border-radius: 1.1rem;
  background: var(--flaeche);
  color: var(--tinte);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--schatten);
}
.wahl::backdrop { background: rgb(8 26 27 / 0.55); }
.wahl h2 {
  margin: 0 0 0.6rem;
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
}
.gruppe {
  border: 0;
  margin: 0 0 0.9rem;
  padding: 0;
}
.gruppe legend, .gruppe h3 {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 0.35rem;
  padding: 0;
}
.gruppe[hidden] { display: none; }
.pillen {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.pillen label { position: relative; }
.pillen input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}
.pillen span {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.3rem 0.9rem;
  border-radius: 0.8rem;
  border: 1.5px solid var(--linie);
  cursor: pointer;
}
.pillen input:checked + span {
  background: var(--brett);
  border-color: var(--brett);
  color: #f4faf8;
}
.pillen input:focus-visible + span { outline: 3px solid var(--fokus); outline-offset: 2px; }

.statistik table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.5rem;
}
.statistik th, .statistik td {
  padding: 0.25rem 0.3rem;
  text-align: right;
  border-bottom: 1px solid var(--linie);
}
.statistik th:first-child, .statistik td:first-child { text-align: left; }
.statistik thead th { font-weight: 700; font-size: 0.85rem; color: var(--tinte-leise); }

.tasten {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.8rem;
  font-size: 0.9rem;
  margin: 0 0 1rem;
}
.tasten dt { white-space: nowrap; }
.tasten dd { margin: 0; color: var(--tinte-leise); }
kbd {
  font: inherit;
  font-weight: 700;
  font-size: 0.85em;
  padding: 0 0.35em;
  border: 1px solid var(--linie);
  border-bottom-width: 2px;
  border-radius: 0.3em;
}
.wahl-aktionen {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.fuss {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 46rem;
  width: 100%;
  margin: 0 auto;
  font-size: 0.85rem;
  color: var(--tinte-leise);
}
.teilen {
  min-height: 2.5rem;
  margin: -0.7rem 0 -0.4rem -0.35rem;
  padding: 0 0.35rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.anleitung[open] {
  display: flex;
  width: min(34rem, calc(100vw - 2rem));
  padding: 0;
}
.anleitung form {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100dvh - 2rem);
}
.anleitung-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.8rem 0.6rem 1.2rem;
  border-bottom: 1.5px solid var(--linie);
}
.anleitung .anleitung-kopf h2 { margin: 0; }
.anleitung-inhalt {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.2rem 1.2rem 0.8rem;
}
.anleitung-inhalt:focus { outline: none; }
.anleitung h3 {
  margin: 1rem 0 0.3rem;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.anleitung h4 {
  margin: 0.7rem 0 0.25rem;
  font-size: 0.95rem;
  color: var(--tinte-leise);
}
.anleitung p, .anleitung ul { margin: 0 0 0.4rem; }
.anleitung ul { padding-left: 1.2rem; }
.anleitung li + li { margin-top: 0.25rem; }
.anleitung .mini {
  display: inline-block;
  vertical-align: -0.15em;
}
.anleitung .tasten { margin: 0.3rem 0 0; }
.anleitung-fuss {
  display: flex;
  justify-content: flex-end;
  padding: 0.7rem 1.2rem 0.9rem;
  border-top: 1.5px solid var(--linie);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(0.4rem, env(safe-area-inset-bottom)) + 2.2rem);
  z-index: 20;
  max-width: calc(100vw - 2rem);
  margin: 0;
  padding: 0.6rem 1rem;
  border-radius: 0.8rem;
  background: var(--tinte);
  color: var(--flaeche);
  font-weight: 700;
  box-shadow: var(--schatten);
  text-align: center;
  translate: -50% 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 0s 180ms;
}
.toast.sichtbar {
  opacity: 1;
  visibility: visible;
  transition: opacity 180ms ease;
}

.link-feld {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  bottom: calc(max(0.4rem, env(safe-area-inset-bottom)) + 2.2rem);
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.4rem 0.5rem;
  width: min(26rem, calc(100vw - 2rem));
  padding: 0.75rem 0.85rem;
  border: 1.5px solid var(--linie);
  border-radius: 0.9rem;
  background: var(--flaeche);
  box-shadow: var(--schatten);
}
.link-feld[hidden] { display: none; }
.link-feld label {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: var(--tinte-leise);
}
.link-feld input {
  min-width: 0;
  min-height: 2.5rem;
  padding: 0 0.6rem;
  border: 1.5px solid var(--linie);
  border-radius: 0.6rem;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
}

@media (max-width: 30rem) {
  .leiste {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .leiste .knopf { padding-inline: 0.3rem; font-size: 0.88rem; }
  .kopf {
    min-height: 2.6rem;
    padding-right: 3.1rem;
  }
  .leiste .knopf-hilfe {
    position: absolute;
    top: max(0.6rem, env(safe-area-inset-top));
    right: max(1rem, env(safe-area-inset-right));
    font-size: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stein, .stein.sieg { transition: none; animation: none; }
}

/* Flache Querformate (Handy quer): Kopf und Leiste links, Brett rechts über die volle Höhe. */
@media (orientation: landscape) and (max-height: 32rem) {
  body {
    grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: 'kopf tisch' 'leiste tisch' '. tisch' 'fuss tisch';
    column-gap: 1.2rem;
    height: 100dvh;
  }
  .kopf { grid-area: kopf; flex-direction: column; align-items: flex-start; }
  .titel { font-size: 1.35rem; }
  .leiste {
    grid-area: leiste;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .leiste .knopf { padding-inline: 0.6rem; }
  .leiste .knopf-hilfe { margin-left: 0; padding: 0; align-self: flex-start; }
  .tisch { grid-area: tisch; align-content: center; padding: 0; }
  .fuss { grid-area: fuss; flex-direction: column; align-items: flex-start; gap: 0.1rem; }
}
