@font-face {
  font-family: 'Marcellus';
  src: url('../fonts/marcellus-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Alegreya Sans';
  src: url('../fonts/alegreya-sans-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Alegreya Sans';
  src: url('../fonts/alegreya-sans-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --seite: #d3dbd6;
  --seite-tief: #c3cdc7;
  --text: #1c2523;
  --gedaempft: #4c5c57;
  --linie: #8e9e97;
  --knopf: #eef2ee;
  --knopf-text: #1c2523;
  --haupt: #5a3923;
  --haupt-text: #f6efe1;
  --holz: #5a3923;
  --holz-kante: #3d2616;
  --filz: #1d3a39;
  --zunge-a: #c9973f;
  --zunge-b: #ddd2bb;
  --stein-weiss: #f5f0e4;
  --stein-weiss-ring: #c4b089;
  --stein-weiss-text: #3d2616;
  --stein-schwarz: #252221;
  --stein-schwarz-ring: #9a7346;
  --stein-schwarz-text: #f1e2c4;
  --ziel: #ffe08a;
  --fokus: #4fc1e8;
  --zuletzt: rgba(255, 224, 138, 0.28);
  --wuerfel: #f7f2e6;
  --wuerfel-auge: #2a1c12;
  --meldung: #f8f6f0;
  --schatten: 0 10px 30px rgba(20, 30, 28, 0.28);
  --serif: 'Marcellus', 'Palatino Linotype', Palatino, serif;
  --sans: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --seite: #111716;
    --seite-tief: #0b100f;
    --text: #e2e7e2;
    --gedaempft: #9db0a9;
    --linie: #3c4b47;
    --knopf: #1c2523;
    --knopf-text: #e2e7e2;
    --haupt: #b8863a;
    --haupt-text: #1a120b;
    --holz: #3e2718;
    --holz-kante: #24160c;
    --filz: #16302f;
    --zunge-a: #b58534;
    --zunge-b: #b9ae97;
    --meldung: #1d2725;
    --schatten: 0 10px 30px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--seite);
  color: var(--text);
  font: 400 1.0625rem/1.4 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.kopf {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem 0.2rem;
}

.titel {
  margin: 0;
  font: 400 1.6rem/1 var(--serif);
  letter-spacing: 0.06em;
}

.status {
  margin: 0;
  color: var(--gedaempft);
  font-size: 0.95rem;
  text-align: right;
}

.leiste {
  display: flex;
  gap: 0.5rem;
  padding: 0.3rem 1rem 0.4rem;
}

.knopf {
  min-height: 2.6rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--linie);
  border-radius: 0.5rem;
  background: var(--knopf);
  color: var(--knopf-text);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.knopf:hover:not(:disabled) { border-color: var(--text); }
.knopf:disabled { opacity: 0.45; cursor: default; }
.knopf:focus-visible, .brett:focus-visible, .pillen input:focus-visible + span, .schalter input:focus-visible {
  outline: 3px solid var(--fokus);
  outline-offset: 2px;
}
.brett:focus:not(:focus-visible) { outline: none; }
.knopf-haupt {
  background: var(--haupt);
  border-color: var(--haupt);
  color: var(--haupt-text);
  font-weight: 700;
}

.tisch {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0 0.5rem;
  --brett-b: 100%;
}

.brett-rahmen {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brett {
  display: block;
  position: absolute;
  inset: 0;
  margin: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 10px;
  box-shadow: var(--schatten);
}

.spieler, .steuerung {
  width: var(--brett-b);
  max-width: 100%;
}

.spieler {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2rem;
  padding: 0 0.25rem;
  font-size: 1rem;
}
.spieler .name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spieler .pips { color: var(--gedaempft); }
.spieler .wert { font-family: var(--serif); color: var(--text); }
.spieler .punkte {
  min-width: 2.2rem;
  padding: 0.05rem 0.5rem;
  border-radius: 0.4rem;
  background: var(--holz);
  color: #f6efe1;
  text-align: center;
}
.spieler .punkte .wert { color: inherit; font-size: 1.15rem; }
.spieler.am-zug .name::after {
  content: '';
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-left: 0.45rem;
  border-radius: 50%;
  background: var(--zunge-a);
  vertical-align: 0.12em;
}
.marke {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  flex: none;
}
.marke.weiss { background: var(--stein-weiss); box-shadow: inset 0 0 0 3px var(--stein-weiss-ring); }
.marke.schwarz { background: var(--stein-schwarz); box-shadow: inset 0 0 0 3px var(--stein-schwarz-ring); }

.steuerung { display: flex; flex-direction: column; gap: 0.35rem; padding-bottom: 0.3rem; }
.tipp {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  color: var(--gedaempft);
  font-size: 0.98rem;
}
.aktionen {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.aktionen .knopf { flex: 1 1 0; min-height: 2.9rem; padding-inline: 0.4rem; }
.aktionen #haupt { flex-grow: 1.35; }
.aktionen .knopf[hidden] { display: none; }

/* Brett */
.brett .rahmen { fill: var(--holz); stroke: var(--holz-kante); stroke-width: 2; }
.brett .feld { fill: var(--filz); }
.brett .bar { fill: var(--holz); }
.brett .ablage { fill: var(--holz-kante); }
.brett .zunge-a { fill: var(--zunge-a); }
.brett .zunge-b { fill: var(--zunge-b); }
.brett .zunge.zuletzt { filter: brightness(1.12); }
.brett .zunge.ziel { fill: var(--ziel); }
.brett .zunge.quelle { filter: brightness(1.18); }
.brett .ablage-ziel { fill: var(--ziel); opacity: 0.55; }
.brett .landung { fill: none; stroke: var(--ziel); stroke-width: 4; stroke-dasharray: 6 5; }
.brett .stein circle { stroke-width: 2; }
.brett .stein.weiss circle { fill: var(--stein-weiss); stroke: var(--stein-weiss-ring); }
.brett .stein.schwarz circle { fill: var(--stein-schwarz); stroke: var(--stein-schwarz-ring); }
.brett .stein .ring { fill: none !important; stroke-width: 2; opacity: 0.8; }
.brett .stein.gewaehlt circle:first-child { stroke: var(--ziel); stroke-width: 5; }
.brett .stein.gehoben { opacity: 0.35; }
.brett .stein.schwebend { pointer-events: none; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.45)); }
.brett .anzahl { font: 400 20px var(--serif); text-anchor: middle; }
.brett .weiss .anzahl { fill: var(--stein-weiss-text); }
.brett .schwarz .anzahl { fill: var(--stein-schwarz-text); }
.brett .scheibe.weiss { fill: var(--stein-weiss); }
.brett .scheibe.schwarz { fill: #4a403b; stroke: var(--stein-schwarz-ring); stroke-width: 1; }
.brett .wuerfel rect { fill: var(--wuerfel); stroke: #b9a77f; stroke-width: 1.5; }
.brett .wuerfel circle { fill: var(--wuerfel-auge); }
.brett .wuerfel.w-schwarz rect { fill: #2c2624; stroke: var(--stein-schwarz-ring); }
.brett .wuerfel.w-schwarz circle { fill: #f1e2c4; }
.brett .wuerfel.benutzt { opacity: 0.35; }
.brett .wuerfel.aufforderung rect { fill: transparent; stroke: var(--ziel); stroke-width: 2.5; stroke-dasharray: 5 4; }
.brett .fragezeichen { font: 400 24px var(--serif); text-anchor: middle; fill: var(--ziel); }
.brett .doppler rect { fill: #efe6cf; stroke: var(--holz-kante); stroke-width: 2; }
.brett .doppler text { font: 400 18px var(--serif); text-anchor: middle; fill: #3d2616; }
.brett .doppler.angeboten rect { stroke: var(--ziel); stroke-width: 4; }
.brett .fokus { fill: none; stroke: var(--fokus); stroke-width: 4; }
.brett .zone { fill: transparent; cursor: pointer; }

@media (prefers-reduced-motion: no-preference) {
  .brett .wuerfel.aufforderung rect { animation: puls 1.6s ease-in-out infinite; }
}
@keyframes puls { 50% { opacity: 0.45; } }

/* Meldung */
.meldung {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(22rem, calc(100% - 2rem));
  padding: 1rem 1.1rem;
  border: 3px solid var(--holz);
  border-radius: 0.8rem;
  background: var(--meldung);
  box-shadow: var(--schatten);
  text-align: center;
  z-index: 2;
}
.meldung h2 { margin: 0 0 0.35rem; font: 400 1.45rem/1.2 var(--serif); }
.meldung p { margin: 0 0 0.8rem; }
.meldung-aktionen { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.meldung-aktionen .knopf { min-width: 8rem; }

/* Dialog */
.einstellungen {
  width: min(30rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 1rem 1.1rem;
  border: 3px solid var(--holz);
  border-radius: 0.8rem;
  background: var(--meldung);
  color: var(--text);
}
.einstellungen::backdrop { background: rgba(10, 16, 15, 0.55); }
.einstellungen h2 { margin: 0 0 0.6rem; font: 400 1.45rem var(--serif); }
.gruppe { border: 0; margin: 0 0 0.6rem; padding: 0; }
.gruppe legend { padding: 0; margin-bottom: 0.3rem; color: var(--gedaempft); }
.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.2rem 0.85rem;
  border: 1px solid var(--linie);
  border-radius: 999px;
  background: var(--knopf);
  cursor: pointer;
}
.pillen input:checked + span { background: var(--haupt); border-color: var(--haupt); color: var(--haupt-text); font-weight: 700; }
.schalter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2.6rem;
}
.schalter input { width: 1.4rem; height: 1.4rem; accent-color: var(--haupt); }
.hinweis { margin: 0.3rem 0 0.5rem; color: var(--gedaempft); font-size: 0.92rem; }
.tasten { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.8rem; margin: 0.4rem 0 0.8rem; font-size: 0.95rem; }
.tasten dd { margin: 0; color: var(--gedaempft); }
kbd { font: inherit; padding: 0 0.3rem; border: 1px solid var(--linie); border-radius: 0.25rem; }
.dialog-aktionen { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }

.fuss {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 1rem 0.45rem;
  font-size: 0.9rem;
  color: var(--gedaempft);
}
.fuss a { color: inherit; }

.knopf.rund, .leiste .knopf.rund {
  flex: none;
  width: 2.6rem;
  padding: 0;
  border-radius: 50%;
  font: 400 1.25rem/1 var(--serif);
}

/* Anleitung */
.anleitung {
  width: min(34rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 3px solid var(--holz);
  border-radius: 0.8rem;
  background: var(--meldung);
  color: var(--text);
  flex-direction: column;
  overflow: hidden;
}
.anleitung[open] { display: flex; }
.anleitung::backdrop { background: rgba(10, 16, 15, 0.55); }
.anleitung-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem 0.5rem 1.1rem;
  border-bottom: 1px solid var(--linie);
}
.anleitung-kopf h2 { margin: 0; font: 400 1.45rem/1.2 var(--serif); }
.anleitung-kopf .rund { width: 2.5rem; min-height: 2.5rem; font-size: 1.5rem; }
.anleitung-inhalt {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  outline: none;
  padding: 0.2rem 1.1rem 0.6rem;
  font-size: 1rem;
}
.anleitung h3 { margin: 0.9rem 0 0.3rem; font: 400 1.15rem/1.2 var(--serif); color: var(--haupt); }
.anleitung h4 { margin: 0.6rem 0 0.2rem; font-size: 1rem; }
.anleitung p { margin: 0 0 0.4rem; }
.anleitung ul { margin: 0 0 0.4rem; padding-left: 1.2rem; }
.anleitung li { margin-bottom: 0.3rem; }
.anleitung .tasten { margin-top: 0.3rem; }
.anleitung-fuss {
  display: flex;
  justify-content: flex-end;
  padding: 0.6rem 1.1rem 0.7rem;
  border-top: 1px solid var(--linie);
}
.anleitung-fuss .knopf { min-width: 9rem; }
.beispiel { margin: 0.6rem 0 0.2rem; }
.beispiel figcaption { margin-top: 0.35rem; color: var(--gedaempft); font-size: 0.93rem; }
.brett.beispiel-brett {
  position: static;
  display: block;
  width: 100%;
  max-width: 24rem;
  height: auto;
  max-height: 20rem;
  margin: 0 auto;
  box-shadow: none;
  pointer-events: none;
}
.brett .weg { fill: none; stroke: var(--ziel); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.brett .weg-spitze { fill: var(--ziel); }

/* Teilen */
.fuss .teilen {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
  touch-action: manipulation;
}
.fuss .teilen:focus-visible { outline: 3px solid var(--fokus); outline-offset: 2px; }
.toast, .link-feld {
  position: fixed;
  left: 50%;
  bottom: calc(2.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  width: max-content;
  max-width: calc(100vw - 2rem);
  border: 2px solid var(--holz);
  border-radius: 0.6rem;
  background: var(--meldung);
  color: var(--text);
  box-shadow: var(--schatten);
}
.toast { margin: 0; padding: 0.55rem 0.9rem; text-align: center; }
.link-feld { display: flex; gap: 0.4rem; padding: 0.45rem; }
.link-feld input {
  width: min(22rem, 60vw);
  min-height: 2.5rem;
  padding: 0 0.5rem;
  border: 1px solid var(--linie);
  border-radius: 0.4rem;
  background: var(--knopf);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.toast[hidden], .link-feld[hidden] { display: none; }

@media (max-width: 420px) {
  .kopf { padding-inline: 0.75rem; }
  .titel { font-size: 1.35rem; }
  .status { font-size: 0.88rem; }
  .leiste { padding-inline: 0.75rem; }
  .leiste .knopf { flex: 1; }
}

@media (orientation: portrait) and (max-height: 780px) {
  body { grid-template-columns: 1fr auto; grid-template-rows: auto 1fr auto; }
  .kopf { flex-direction: column; align-items: flex-start; gap: 0.1rem; padding: 0.4rem 0.75rem 0.1rem; }
  .titel { font-size: 1.25rem; }
  .kopf { min-width: 0; }
  .status { text-align: left; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .leiste .lang { display: none; }
  .leiste { grid-column: 2; grid-row: 1; align-items: center; padding: 0.35rem 0.75rem 0.1rem 0; }
  .leiste .knopf { flex: none; min-height: 2.5rem; padding-inline: 0.6rem; font-size: 0.95rem; }
  .tisch {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "unten oben" "brett brett" "steuerung steuerung";
    justify-items: center;
    column-gap: 0.75rem;
    row-gap: 0.3rem;
  }
  .brett-rahmen { grid-area: brett; height: 100%; }
  .spieler { width: 100%; min-height: 1.8rem; font-size: 0.95rem; }
  .spieler.oben { grid-area: oben; }
  .spieler.unten { grid-area: unten; }
  .spieler .stufe, .spieler .pips-wort { display: none; }
  .steuerung { grid-area: steuerung; width: 100%; }
  .aktionen .knopf { min-height: 2.6rem; }
  .fuss { grid-column: 1 / -1; padding-block: 0.1rem 0.3rem; }
}

@media (orientation: portrait) and (max-height: 780px) and (max-width: 370px) {
  .titel { font-size: 1.12rem; letter-spacing: 0.03em; }
  .leiste { gap: 0.35rem; padding-right: 0.5rem; }
  .leiste .knopf { padding-inline: 0.45rem; }
  .leiste .knopf.rund { width: 2.5rem; }
}

@media (min-width: 720px) and (min-height: 541px) {
  body { grid-template-columns: 1fr auto; grid-template-rows: auto 1fr auto; }
  .kopf { justify-content: flex-start; gap: 1.25rem; padding-top: 0.75rem; }
  .leiste { grid-column: 2; grid-row: 1; padding-top: 0.6rem; }
  .tisch, .fuss { grid-column: 1 / -1; }
}

@media (orientation: landscape) and (max-height: 540px) {
  body {
    grid-template-columns: 1fr minmax(14rem, 17rem);
    grid-template-rows: auto auto auto auto 1fr auto;
    column-gap: 0.75rem;
  }
  .tisch { display: contents; }
  .brett-rahmen { grid-column: 1; grid-row: 1 / 6; height: 100%; padding: 0.4rem 0 0 0.5rem; }
  .kopf { grid-column: 2; grid-row: 1; flex-direction: column; align-items: flex-start; gap: 0.1rem; padding: 0.4rem 0.75rem 0 0; }
  .kopf .status { text-align: left; }
  .leiste { grid-column: 2; grid-row: 2; padding: 0.3rem 0.75rem 0.3rem 0; }
  .leiste .knopf { flex: 1; min-height: 2.5rem; padding-inline: 0.5rem; }
  .spieler.oben { grid-column: 2; grid-row: 3; width: auto; margin-right: 0.75rem; }
  .spieler.unten { grid-column: 2; grid-row: 4; width: auto; margin-right: 0.75rem; }
  .steuerung { grid-column: 2; grid-row: 5; width: auto; align-self: end; margin-right: 0.75rem; }
  .aktionen #haupt { order: -1; flex-basis: 100%; }
  .fuss { grid-column: 1 / -1; grid-row: 6; padding-block: 0.1rem 0.3rem; }
}
