@font-face {
  font-family: 'Barlow Condensed';
  src: url('../fonts/barlow-condensed-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Barlow Condensed';
  src: url('../fonts/barlow-condensed-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('../fonts/caveat-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --grund: #dfe5df;
  --text: #1d2a2b;
  --text-leise: #56666a;
  --schale: #2c4a47;
  --schale-tief: #1c3331;
  --papier: #fbfcf8;
  --karo: #e3ebf1;
  --linie: #cfdae2;
  --rand: #d6909d;
  --tinte: #2340a0;
  --bleistift: #7d868d;
  --summe: #eff3ee;
  --zug: #fbefd2;
  --messing: #e2b355;
  --wuerfel: #f7f2e6;
  --wuerfel-kante: #d8cfbb;
  --auge: #1b1d22;
  --knopf: #f4f6f2;
  --knopf-rand: #b9c4bf;
  --schatten: 0 1px 2px rgb(20 40 40 / 0.18), 0 6px 18px -8px rgb(20 40 40 / 0.35);
  --zeile: clamp(44px, 6.2dvh, 56px);
  --w: clamp(44px, 14.5vw, 66px);
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #121918;
    --text: #e2e9e6;
    --text-leise: #9aa9a6;
    --schale: #1f3532;
    --schale-tief: #13211f;
    --papier: #1d2427;
    --karo: #232c30;
    --linie: #323e44;
    --rand: #8a4f5a;
    --tinte: #9db5ff;
    --bleistift: #8a959b;
    --summe: #222b2e;
    --zug: #3a3220;
    --messing: #e8bd62;
    --knopf: #1f2829;
    --knopf-rand: #3c4a49;
    --schatten: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 20px -10px rgb(0 0 0 / 0.7);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "kopf" "leiste" "tisch" "fuss";
  background: var(--grund);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.kopf {
  grid-area: kopf;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 2px;
}

.titel {
  margin: 0;
  font-weight: 700;
  font-size: 1.65rem;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.status {
  margin: 0;
  color: var(--text-leise);
  font-size: 1.05rem;
  white-space: nowrap;
}

.leiste {
  grid-area: leiste;
  display: flex;
  gap: 8px;
  padding: 6px 16px;
}

.knopf {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--knopf-rand);
  border-radius: 10px;
  background: var(--knopf);
  font-size: 1.05rem;
  cursor: pointer;
}
.knopf:disabled { opacity: 0.45; cursor: default; }
.knopf:not(:disabled):hover { border-color: var(--tinte); }
.knopf-rund { width: 42px; padding: 0; display: grid; place-items: center; margin-left: auto; }
.knopf-voll { background: var(--tinte); border-color: var(--tinte); color: var(--papier); font-weight: 700; }
.knopf-klein { min-height: 40px; font-size: 0.95rem; }

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

.tisch {
  grid-area: tisch;
  min-height: 0;
  display: flex;
  justify-content: center;
  padding: 4px 16px 8px;
}

.spiel {
  position: relative;
  width: min(100%, 560px);
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

/* Spielerleiste */

.spieler {
  display: flex;
  gap: 6px;
  flex: none;
}
.spiel:not(.mit-leiste) .spieler { display: none; }

.chip {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--knopf-rand);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  line-height: 1.1;
}
.chip-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-rolle { grid-row: 2; font-size: 0.8rem; color: var(--text-leise); }
.chip-punkte { grid-row: 1 / 3; grid-column: 2; font-family: 'Caveat', cursive; font-weight: 600; font-size: 1.45rem; color: var(--tinte); }
.chip[aria-pressed="true"] { background: var(--papier); border-color: var(--tinte); }
.chip.am-zug { box-shadow: inset 0 -4px 0 var(--messing); }

/* Wertungsblock */

.block {
  --n: 1;
  flex: 1 1 auto;
  min-height: calc(8 * 34px + 8px);
  max-height: calc(8 * var(--zeile) + 8px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  background-color: var(--papier);
  background-image:
    linear-gradient(var(--karo) 1px, transparent 1px),
    linear-gradient(90deg, var(--karo) 1px, transparent 1px);
  background-size: 11px 11px;
  border-top: 8px solid var(--schale);
  border-radius: 6px 6px 8px 8px;
  box-shadow: var(--schatten);
  overflow: hidden;
}
.block.mehrere:not(.einzeln) { max-height: calc(9 * var(--zeile) + 8px); min-height: calc(9 * 34px + 8px); }

.haelfte {
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
  min-width: 0;
}
.haelfte + .haelfte { border-left: 2px solid var(--rand); }

.zeile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(var(--n), minmax(40px, 62px));
  align-items: stretch;
  border-bottom: 1px solid var(--linie);
  position: relative;
  min-height: 0;
}
.zeile:last-child { border-bottom: none; }
.block.einzeln .zeile, .block:not(.mehrere) .zeile { grid-template-columns: minmax(0, 1fr) 58px; }
.block.einzeln .zelle:not(.sichtbar) { display: none; }
.block.einzeln .kopfzeile { display: none; }

.name {
  display: flex;
  align-items: center;
  padding: 0 4px 0 9px;
  font-size: clamp(0.98rem, 3.9vw, 1.12rem);
  line-height: 1.05;
  min-width: 0;
  overflow: hidden;
}

.zelle {
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--linie);
  min-width: 0;
  white-space: nowrap;
}
.zelle.am-zug { background: color-mix(in srgb, var(--zug) 75%, transparent); }
.block:not(.mehrere) .zelle.am-zug { background: none; }

.kopfzeile { border-bottom: 2px solid var(--linie); }
.kopfzeile .name { color: var(--text-leise); font-size: 0.95rem; }
.kopfzelle { font-size: 0.9rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.kopfzelle.am-zug { box-shadow: inset 0 -3px 0 var(--messing); }

.zelle.eingetragen {
  font-family: 'Caveat', cursive;
  font-weight: 600;
  font-size: clamp(1.45rem, 6vw, 1.75rem);
  color: var(--tinte);
  line-height: 1;
}
.zelle.vorschau { color: var(--bleistift); font-size: 1.1rem; }
.zelle.null { opacity: 0.55; }
.zelle.gesperrt { color: var(--bleistift); opacity: 0.5; }
.zelle.waehlbar { cursor: pointer; color: var(--text); font-weight: 700; }
.zelle.waehlbar::after {
  content: '';
  position: absolute;
  inset: 0;
}
.block.mehrere:not(.einzeln) .zelle.waehlbar { position: relative; }
.zeile:has(.waehlbar):hover { background: color-mix(in srgb, var(--tinte) 7%, transparent); }
.zelle.waehlbar:focus-visible { outline-offset: -3px; }
.zelle.ki-wahl { box-shadow: inset 0 0 0 2px var(--tinte); border-radius: 50%; color: var(--tinte); }
.zelle.neu { animation: eintragen 0.6s ease-out; }

@keyframes eintragen {
  from { transform: scale(1.5) rotate(-6deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.zeile.summe { background: var(--summe); }
.zeile.summe .name { font-weight: 700; font-size: 1rem; }
.zeile.summe .zelle { font-family: 'Caveat', cursive; font-weight: 600; font-size: 1.5rem; color: var(--tinte); }
.zeile.summe .zelle.hinweis { font-family: 'Barlow Condensed', sans-serif; font-weight: 500; font-size: 0.92rem; color: var(--text-leise); }
.zeile[data-sum="gesamt"] { border-top: 2px solid var(--text); }
.zeile[data-sum="gesamt"] .name { font-size: 1.15rem; }
.zeile[data-sum="gesamt"] .zelle { font-size: 1.85rem; }

/* Würfelschale */

.schale {
  flex: none;
  position: relative;
  overflow: hidden;
  padding: 12px 10px 6px;
  border-radius: 18px;
  background:
    radial-gradient(120% 140% at 50% 0%, var(--schale) 0%, var(--schale) 45%, var(--schale-tief) 100%);
  box-shadow: inset 0 2px 10px rgb(0 0 0 / 0.35), var(--schatten);
}

.wuerfelreihe {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  height: calc(var(--w) + 10px);
}

.wuerfel {
  width: var(--w);
  height: var(--w);
  padding: 0;
  border: none;
  border-radius: 22%;
  background: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 4px 6px rgb(0 0 0 / 0.35);
  touch-action: manipulation;
}
.wuerfel:disabled { cursor: default; }
.wuerfel-bild, .flaeche { display: block; width: 100%; height: 100%; }
.koerper { fill: var(--wuerfel); stroke: var(--wuerfel-kante); stroke-width: 2; }
.glanz { fill: #fff; opacity: 0.35; }
.augen { fill: var(--auge); }
.wuerfel.leer { opacity: 0.4; box-shadow: none; }
.wuerfel.gehalten {
  transform: translateY(-4px);
  box-shadow: 0 0 0 3px var(--messing), 0 7px 10px rgb(0 0 0 / 0.4);
}
.wuerfel.rollt { animation: rollen 0.52s cubic-bezier(.25, .7, .35, 1); }

@keyframes rollen {
  0% { transform: translate(calc(var(--weg) * 10px), -6px) rotate(0deg) scale(0.92); }
  45% { transform: translate(calc(var(--weg) * -8px), 2px) rotate(calc(var(--dreh) * 200deg)) scale(1.04); }
  100% { transform: translate(0, 0) rotate(calc(var(--dreh) * 360deg)) scale(1); }
}

.tipp {
  margin: 4px 0 0;
  min-height: 1.3em;
  text-align: center;
  font-size: 0.98rem;
  color: #d5e3df;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wuerfeln {
  flex: none;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border: none;
  border-radius: 14px;
  background: var(--tinte);
  color: var(--papier);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--schatten);
  touch-action: manipulation;
}
.wuerfeln:disabled { background: color-mix(in srgb, var(--tinte) 35%, var(--grund)); cursor: default; }
.wuerfeln:not(:disabled):active { transform: translateY(1px); }
.wuerfeln-rest { display: flex; gap: 5px; }
.wuerfeln-rest i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid currentColor; opacity: 0.6; }
.wuerfeln-rest i.voll { background: currentColor; opacity: 1; }

/* Meldung */

.meldung {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92%, 360px);
  padding: 18px 20px;
  background: var(--papier);
  border-top: 8px solid var(--schale);
  border-radius: 8px;
  box-shadow: 0 20px 50px -10px rgb(0 0 0 / 0.5);
  text-align: center;
  z-index: 5;
}
.meldung h2 { margin: 0 0 8px; font-size: 1.9rem; font-weight: 700; }
.rangliste { list-style: none; margin: 0 0 8px; padding: 0; }
.rangliste li { display: grid; grid-template-columns: 2em 1fr auto; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid var(--linie); text-align: left; font-size: 1.1rem; }
.rangliste .pkt { font-family: 'Caveat', cursive; font-weight: 600; font-size: 1.5rem; color: var(--tinte); }
.meldung-text { margin: 4px 0 12px; color: var(--text-leise); font-size: 1.1rem; }
.wahl-aktionen { margin-top: 16px; }
.meldung-aktionen, .wahl-aktionen { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Dialoge */

.wahl {
  width: min(94vw, 420px);
  max-height: 92dvh;
  padding: 18px 20px;
  border: none;
  border-top: 8px solid var(--schale);
  border-radius: 10px;
  background: var(--papier);
  color: var(--text);
  box-shadow: 0 20px 50px -10px rgb(0 0 0 / 0.5);
}
.wahl::backdrop { background: rgb(10 20 20 / 0.5); }
.wahl h2 { margin: 0 0 10px; font-size: 1.5rem; }
.wahl p { font-size: 1.1rem; margin: 0 0 14px; }
.gruppe { border: none; margin: 0 0 12px; padding: 0; }
.gruppe legend { padding: 0; margin-bottom: 6px; font-weight: 700; }
.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; min-width: 40px; justify-content: center; padding: 0 12px; border: 1px solid var(--knopf-rand); border-radius: 20px; cursor: pointer; }
.pillen input:checked + span { background: var(--tinte); border-color: var(--tinte); color: var(--papier); font-weight: 700; }
.pillen input:focus-visible + span { outline: 3px solid var(--messing); outline-offset: 2px; }
.plaetze { display: grid; gap: 6px; }
.platz { display: grid; grid-template-columns: 4.5em 1fr; align-items: center; gap: 8px; }
.platz select { min-height: 40px; border: 1px solid var(--knopf-rand); border-radius: 8px; background: var(--knopf); padding: 0 8px; }
.schalter { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 8px; }
.schalter input { width: 22px; height: 22px; accent-color: var(--tinte); }
.bestenliste h3 { margin: 6px 0; font-size: 1.1rem; }
.bestenliste ol { margin: 0 0 8px; padding-left: 1.8em; columns: 2; }
.bestenliste li { padding: 1px 0; }
.bestenliste .pkt { font-family: 'Caveat', cursive; font-weight: 600; font-size: 1.3rem; color: var(--tinte); margin-right: 8px; }
.bestenliste .tag { color: var(--text-leise); font-size: 0.9rem; }
.leer { color: var(--text-leise); }
.tasten { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0; font-size: 0.95rem; }
.tasten dd { margin: 0; color: var(--text-leise); }
kbd { font-family: inherit; border: 1px solid var(--knopf-rand); border-radius: 4px; padding: 0 5px; }

.knopf-rund + .knopf-rund { margin-left: 0; }
.knopf-frage { font-weight: 700; font-size: 1.3rem; line-height: 1; }

/* Anleitung */

.wahl.anleitung { width: min(94vw, 560px); max-height: calc(100dvh - 24px); padding: 0; flex-direction: column; overflow: hidden; }
.wahl.anleitung[open] { display: flex; }
.anleitung-kopf { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px 10px 20px; border-bottom: 1px solid var(--linie); }
.anleitung-kopf h2 { margin: 0; font-size: 1.6rem; }
.anleitung-kopf .knopf-rund { margin: 0; font-size: 1.6rem; line-height: 1; }
.anleitung-inhalt { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; outline: none; padding: 2px 20px 12px; font-size: 1.08rem; line-height: 1.3; }
.anleitung h3 { margin: 16px 0 4px; font-size: 1.3rem; color: var(--tinte); }
.anleitung h4 { margin: 10px 0 2px; font-size: 1.08rem; }
.anleitung .anleitung-inhalt p { font-size: inherit; margin: 0 0 6px; }
.anleitung ul { margin: 0 0 6px; padding-left: 1.2em; }
.anleitung li { margin-bottom: 5px; }
.wertung { width: 100%; border-collapse: collapse; margin: 0 0 10px; font-size: 1rem; background: var(--papier); }
.wertung th, .wertung td { padding: 4px 6px; border-bottom: 1px solid var(--linie); text-align: left; vertical-align: middle; }
.wertung thead th { font-size: 0.9rem; color: var(--text-leise); border-bottom: 2px solid var(--linie); }
.wertung tbody th { font-weight: 700; }
.wertung td.bsp { white-space: nowrap; padding-inline: 4px; }
.mini { display: inline-block; width: 21px; height: 21px; margin-right: 2px; vertical-align: middle; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.3)); }
.mini .flaeche { width: 100%; height: 100%; }
.anleitung .tasten { margin: 4px 0 6px; }
.anleitung-fuss { display: flex; justify-content: flex-end; padding: 10px 20px 14px; border-top: 1px solid var(--linie); }
.anleitung-fuss .knopf { min-width: 9.5rem; min-height: 46px; }

@media (max-width: 400px) {
  .anleitung-inhalt { padding-inline: 14px; }
  .wertung { font-size: 0.95rem; }
  .wertung th, .wertung td { padding-inline: 3px; }
  .mini { width: 17px; height: 17px; margin-right: 1px; }
}

/* Teilen */

.fuss .teilen { padding: 0; border: 0; background: none; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.toast, .link-feld {
  position: fixed;
  left: 50%;
  bottom: calc(34px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 24px);
  border-top: 6px solid var(--schale);
  border-radius: 8px;
  background: var(--papier);
  color: var(--text);
  box-shadow: 0 12px 30px -8px rgb(0 0 0 / 0.5);
}
.toast { margin: 0; padding: 10px 16px; font-size: 1.05rem; text-align: center; }
.link-feld { display: flex; gap: 8px; padding: 8px; }
.link-feld input { width: min(360px, 62vw); min-height: 42px; padding: 0 8px; border: 1px solid var(--knopf-rand); border-radius: 8px; background: var(--knopf); font-size: 0.95rem; }

.fuss {
  grid-area: fuss;
  display: flex;
  justify-content: space-between;
  padding: 2px 16px 6px;
  font-size: 0.9rem;
  color: var(--text-leise);
}
.partie { color: inherit; }

/* Breiter Schirm: Schale links, Block rechts */

@media (min-width: 900px) and (min-height: 560px) {
  :root { --w: 70px; --zeile: clamp(46px, 6.6dvh, 56px); }
  .spiel {
    width: min(100%, 1060px);
    display: grid;
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto auto minmax(0, 1fr);
    grid-template-areas: ". block" "spieler block" "schale block" "knopf block" ". block";
    column-gap: 28px;
    row-gap: 12px;
  }
  .spieler { grid-area: spieler; flex-wrap: wrap; }
  .block { grid-area: block; align-self: center; height: calc(8 * var(--zeile) + 8px); }
  .block.mehrere:not(.einzeln) { height: calc(9 * var(--zeile) + 8px); }
  .schale { grid-area: schale; padding: 22px 12px 10px; }
  .wuerfeln { grid-area: knopf; }
  .titel { font-size: 2rem; }
  .kopf, .leiste, .fuss { width: min(100%, 1092px); justify-self: center; }
  .name { font-size: 1.15rem; padding-left: 12px; }
}

/* Handy quer */

@media (orientation: landscape) and (max-height: 520px) {
  :root { --w: clamp(40px, 11vh, 54px); --zeile: 40px; }
  body {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "kopf leiste" "tisch tisch" "fuss fuss";
  }
  .kopf { padding: 4px 12px 0; align-items: center; }
  .titel { font-size: 1.3rem; }
  .status { display: none; }
  .leiste { padding: 4px 12px 0; justify-content: flex-end; }
  .knopf { min-height: 40px; }
  .knopf-rund { margin-left: 0; width: 40px; }
  .tisch { padding: 4px 12px 2px; }
  .spiel {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-template-rows: minmax(0, 1fr) auto auto auto minmax(0, 1fr);
    grid-template-areas: ". block" "spieler block" "schale block" "knopf block" ". block";
    column-gap: 14px;
    row-gap: 8px;
  }
  .spieler { grid-area: spieler; }
  .chip { min-height: 40px; }
  .block { grid-area: block; height: 100%; min-height: 0; max-height: calc(8 * var(--zeile) + 8px); align-self: center; }
  .block.mehrere:not(.einzeln) { max-height: calc(9 * var(--zeile) + 8px); min-height: 0; }
  .schale { grid-area: schale; padding: 10px 6px 4px; }
  .wuerfeln { grid-area: knopf; min-height: 48px; font-size: 1.25rem; }
  .name { font-size: 0.98rem; }
  .zelle.eingetragen, .zeile.summe .zelle { font-size: 1.4rem; }
  .zeile[data-sum="gesamt"] .zelle { font-size: 1.55rem; }
  .fuss { padding: 0 12px 2px; font-size: 0.82rem; }
}

@media (prefers-reduced-motion: reduce) {
  .wuerfel, .wuerfel.rollt, .zelle.neu { animation: none; transition: none; }
}
