@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

/* Farbwelt „Majolika“: kobaltblaue Hinweis-Kacheln, glasierte weiße Felder, Ocker als Markierung. */
:root {
  color-scheme: light dark;
  --grund: #e4eaee;
  --fuge: #b9c6d2;
  --glasur: #fbfcf9;
  --kobalt: #1f3f7d;
  --kobalt-tief: #142c5c;
  --kobalt-text: #f4f1e6;
  --tinte: #17264d;
  --leise: #56667f;
  --notiz: #5a6b87;
  --ocker: #c98d1c;
  --ocker-hell: #f5e6bd;
  --ocker-zart: #faf1d9;
  --ziegel: #b23a26;
  --ziegel-grund: #f7d9d1;
  --flaeche-knopf: #f6f8f8;
  --schatten: 0 1px 0 rgb(23 38 77 / 0.1), 0 10px 26px -14px rgb(23 38 77 / 0.45);
  --schrift: 'Atkinson Hyperlegible', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --grund: #0e1626;
    --fuge: #070c17;
    --glasur: #29354d;
    --kobalt: #12285c;
    --kobalt-tief: #0a1735;
    --kobalt-text: #e9c875;
    --tinte: #e4ecf8;
    --leise: #95a6c2;
    --notiz: #a7b6cf;
    --ocker: #e2aa3e;
    --ocker-hell: #5b4a22;
    --ocker-zart: #3a3a33;
    --ziegel: #ff8a72;
    --ziegel-grund: #4a2430;
    --flaeche-knopf: #18233a;
    --schatten: 0 1px 0 rgb(0 0 0 / 0.35), 0 12px 28px -14px rgb(0 0 0 / 0.8);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: 'kopf' 'leiste' 'tisch' 'fuss';
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
  font-family: var(--schrift);
  color: var(--tinte);
  background: var(--grund);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }

/* Kopf */
.kopf {
  grid-area: kopf;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: min(100%, 64rem);
  margin: 0 auto;
  padding: 10px 2px 2px;
}
.titel {
  margin: 0;
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1;
  letter-spacing: 0.02em;
}
/* Das Wort steht auf einer kleinen Kachel mit Diagonale, wie die Hinweisfelder. */
.titel::before {
  content: '';
  display: inline-block;
  width: 0.82em;
  height: 0.82em;
  margin-right: 0.32em;
  vertical-align: -0.06em;
  border-radius: 3px;
  background:
    linear-gradient(to top right, transparent calc(50% - 0.6px), var(--ocker) calc(50% - 0.6px) calc(50% + 0.6px), transparent calc(50% + 0.6px)),
    var(--kobalt);
}
.status {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--leise);
  font-size: 0.9rem;
}
.zeit { font-weight: 700; font-size: 1.35rem; color: var(--tinte); }

/* Knöpfe */
.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--kobalt);
  border-radius: 8px;
  background: var(--flaeche-knopf);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}
@media (prefers-color-scheme: dark) { .knopf { border-color: #3b5a96; } }
.knopf svg, .taste svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.knopf:disabled { opacity: 0.4; cursor: default; }
.knopf:focus-visible, .taste:focus-visible, .pille input:focus-visible + span, .teilen:focus-visible, .teilen-feld input:focus-visible, .schalter input:focus-visible { outline: 3px solid var(--ocker); outline-offset: 2px; }
.knopf-voll { background: var(--kobalt); color: #fff; }
.knopf-rund { padding: 0; width: 44px; }
.knopf-hilfe { border-radius: 50%; font-size: 1.25rem; }
.leiste {
  grid-area: leiste;
  display: flex;
  gap: 8px;
  width: min(100%, 64rem);
  margin: 0 auto;
  padding: 6px 0;
}
.knopf-neu { margin-left: auto; }

/* Spielfläche */
.tisch {
  grid-area: tisch;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: 'flaeche' 'bedienung';
  width: min(100%, 64rem);
  margin: 0 auto;
  min-height: 0;
}
.flaeche {
  grid-area: flaeche;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
  padding: 6px 0;
  overflow: hidden;
}
.warten {
  position: absolute;
  inset: auto 0 46%;
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  color: var(--leise);
}
.flaeche[aria-busy] .brett { opacity: 0.25; }

.brett {
  --z: 40px;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--z));
  grid-auto-rows: var(--z);
  gap: 1px;
  padding: 1px;
  background: var(--fuge);
  border-radius: 6px;
  box-shadow: var(--schatten);
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  font-variant-numeric: tabular-nums;
}
.brett:focus-visible { box-shadow: var(--schatten), 0 0 0 3px var(--ocker); }

.kachel {
  position: relative;
  background: var(--kobalt);
  box-shadow: inset 1px 1px 0 rgb(255 255 255 / 0.1), inset -1px -1px 0 rgb(0 0 0 / 0.18);
}
.brett > :first-child { border-top-left-radius: 5px; }
.kachel.leer { background: var(--kobalt-tief); }
.kachel.hinweis {
  background:
    linear-gradient(to top right, transparent calc(50% - 0.7px), rgb(255 255 255 / 0.32) calc(50% - 0.7px) calc(50% + 0.7px), transparent calc(50% + 0.7px)),
    var(--kobalt);
}
.kachel .summe {
  position: absolute;
  color: var(--kobalt-text);
  font-weight: 700;
  font-size: calc(var(--z) * 0.32);
  line-height: 1;
  padding: 0 1px;
  border-radius: 3px;
}
.kachel .summe-h { top: 8%; right: 8%; }
.kachel .summe-v { bottom: 8%; left: 8%; }
.kachel .summe.hl { background: var(--ocker); color: var(--kobalt-tief); }
.kachel .summe.konflikt { background: var(--ziegel); color: #fff; }

.feld {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--glasur);
  color: var(--tinte);
  cursor: pointer;
}
.feld.hl { background: var(--ocker-zart); }
.feld.gewaehlt { background: var(--ocker-hell); }
.feld.gewaehlt::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2.5px var(--ocker);
  pointer-events: none;
}
.feld .wert { font-size: calc(var(--z) * 0.6); font-weight: 700; line-height: 1; }
.feld.konflikt { background: var(--ziegel-grund); }
.feld.konflikt .wert { color: var(--ziegel); }
.notizen {
  position: absolute;
  inset: 6%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  font-size: calc(var(--z) * 0.25);
  line-height: 1;
  color: var(--notiz);
}

/* Gelöst: eine Lichtwelle läuft diagonal über die Glasur, danach ruhen die Ziffern in Kobalt. */
.brett.geloest .feld { cursor: default; animation: welle 0.9s ease-out var(--verz) both; }
.brett.geloest .feld.gewaehlt::after { box-shadow: none; }
@keyframes welle {
  0% { background: var(--glasur); }
  35% { background: var(--ocker-hell); }
  100% { background: var(--glasur); }
}
@media (prefers-reduced-motion: reduce) {
  .brett.geloest .feld { animation: none; }
}

/* Meldung nach dem Lösen: sitzt an der Stelle des Ziffernblocks */
.meldung {
  padding: 12px 14px;
  background: var(--glasur);
  border: 1.5px solid var(--kobalt);
  border-radius: 10px;
  box-shadow: var(--schatten);
  text-align: center;
}
.meldung[hidden] { display: none; }
.meldung h2 { margin: 0; font-size: 1.35rem; }
.meldung p { margin: 4px 0 10px; color: var(--leise); font-variant-numeric: tabular-nums; }
.meldung-aktionen { display: flex; gap: 8px; }
.meldung-aktionen .knopf { flex: 1; padding: 0 8px; }
@media (prefers-color-scheme: dark) { .meldung { border-color: #3b5a96; } }

/* Bedienung: Kombinationen und Ziffernblock */
.bedienung {
  grid-area: bedienung;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0 6px;
  width: min(100%, 26rem);
  margin: 0 auto;
}
.tisch.fertig .kombis, .tisch.fertig .block { display: none; }
.kombis {
  display: grid;
  gap: 2px;
  min-height: calc(2 * 30px + 2px);
  font-size: 0.9rem;
}
.kombis[hidden] { display: none; }
.kombi-zeile {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
.kombi-zeile::-webkit-scrollbar { display: none; }
.kombi-kopf {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 4.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kombi-kopf svg { width: 15px; height: 15px; fill: none; stroke: var(--ocker); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.kombi-kopf small { font-weight: 400; color: var(--leise); font-size: 0.82rem; }
.kombi {
  flex: none;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--glasur);
  border: 1px solid var(--fuge);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.kombi.aus { opacity: 0.38; text-decoration: line-through; }
.kombi-leer { color: var(--leise); font-size: 0.85rem; }

.block {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 1.25fr);
  grid-template-areas:
    'd1 d2 d3 d4 d5 notiz'
    'd6 d7 d8 d9 loeschen loeschen';
  gap: 6px;
}
.block [data-ziffer='1'] { grid-area: d1; }
.block [data-ziffer='2'] { grid-area: d2; }
.block [data-ziffer='3'] { grid-area: d3; }
.block [data-ziffer='4'] { grid-area: d4; }
.block [data-ziffer='5'] { grid-area: d5; }
.block [data-ziffer='6'] { grid-area: d6; }
.block [data-ziffer='7'] { grid-area: d7; }
.block [data-ziffer='8'] { grid-area: d8; }
.block [data-ziffer='9'] { grid-area: d9; }
#notiz { grid-area: notiz; }
#loeschen { grid-area: loeschen; }
.taste {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 48px;
  min-width: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 8px;
  background: var(--glasur);
  box-shadow: 0 1px 0 var(--fuge), inset 0 0 0 1px var(--fuge);
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}
.taste:active { background: var(--ocker-hell); }
@media (orientation: portrait) { .taste { min-height: clamp(48px, 6.6dvh, 60px); } }
.taste.blass { color: var(--leise); opacity: 0.45; }
.taste-wort { font-size: 0.88rem; gap: 4px; }
@media (max-width: 440px) { .taste-wort { font-size: 0.8rem; } .taste-wort svg { width: 18px; height: 18px; } }
#notiz[aria-pressed='true'] { background: var(--kobalt); color: #fff; box-shadow: none; }
.block.notizmodus .taste[data-ziffer] { font-size: 1.05rem; font-weight: 400; color: var(--notiz); }
.block.notizmodus .taste.blass { opacity: 0.45; }

/* Fußzeile */
.fuss {
  grid-area: fuss;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(100%, 64rem);
  margin: 0 auto;
  padding: 2px 2px 8px;
  font-size: 0.85rem;
  color: var(--leise);
}
.teilen {
  margin: -4px 0;
  padding: 4px 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 40px);
  translate: -50% 0;
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--kobalt);
  color: #fff;
  font-size: 0.92rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--schatten);
  pointer-events: none;
}
.toast:empty { display: none; }
.teilen-feld {
  width: min(calc(100% - 32px), 24rem);
  padding: 14px 16px 16px;
  border: 1.5px solid var(--kobalt);
  border-radius: 12px;
  background: var(--glasur);
  color: var(--tinte);
  box-shadow: var(--schatten);
}
.teilen-feld label { display: block; margin-bottom: 6px; font-size: 0.88rem; color: var(--leise); }
.teilen-feld input {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1.5px solid var(--fuge);
  border-radius: 8px;
  background: var(--grund);
}

/* Dialoge */
.wahl {
  width: min(calc(100% - 24px), 27rem);
  max-height: calc(100dvh - 24px);
  padding: 18px 18px 14px;
  border: 1.5px solid var(--kobalt);
  border-radius: 12px;
  background: var(--glasur);
  color: var(--tinte);
  box-shadow: var(--schatten);
}
.wahl::backdrop { background: rgb(14 22 38 / 0.5); }
.anleitung { width: min(calc(100% - 24px), 34rem); padding: 0; }
.anleitung[open] { display: flex; }
.anleitung-form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.anleitung-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--fuge);
}
.anleitung .anleitung-kopf h2 { margin: 0; }
.anleitung-kopf .knopf { border-color: transparent; background: none; }
.anleitung-inhalt { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 18px 12px; line-height: 1.45; }
.anleitung h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.anleitung h4 { margin: 10px 0 2px; font-size: 0.95rem; color: var(--leise); }
.anleitung p { margin: 0 0 6px; }
.anleitung ul { margin: 0; padding-left: 18px; }
.anleitung li { margin-bottom: 4px; }
.anleitung .tasten { margin-top: 4px; }
.anleitung-fuss { display: flex; justify-content: flex-end; padding: 10px 18px 14px; border-top: 1px solid var(--fuge); }
.beispiel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  max-width: 22rem;
  margin: 14px auto 4px;
}
.beispiel-bild svg { display: block; width: 100%; height: auto; }
.beispiel-pfeil { font-size: 1.4rem; color: var(--leise); }
.beispiel figcaption { grid-column: 1 / -1; font-size: 0.85rem; color: var(--leise); text-align: center; }
.mini-fuge { fill: var(--fuge); }
.mini-feld { fill: var(--glasur); }
.mini-kachel { fill: var(--kobalt); }
.mini-leer { fill: var(--kobalt-tief); }
.mini-diagonale { stroke: rgb(255 255 255 / 0.32); stroke-width: 0.25; }
.mini-summe, .mini-wert { font-family: var(--schrift); font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.mini-summe { fill: var(--kobalt-text); font-size: 3.3px; }
.mini-wert { fill: var(--tinte); font-size: 6px; }
.wahl h2 { margin: 0 0 12px; font-size: 1.4rem; }
.wahl-gruppe { border: 0; margin: 0; padding: 0; }
.wahl-gruppe legend { padding: 0; margin-bottom: 8px; font-weight: 700; }
.pillen { display: flex; flex-wrap: wrap; gap: 6px; }
.pille { position: relative; flex: 1 1 0; min-width: 4.2rem; }
.pille input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pille span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1.5px solid var(--kobalt);
  border-radius: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pille input:checked + span { background: var(--kobalt); color: #fff; }
.erklaerung { margin: 10px 0 0; font-size: 0.88rem; color: var(--leise); line-height: 1.45; }
.schalter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-weight: 700;
}
.schalter input { width: 22px; height: 22px; accent-color: var(--kobalt); flex: none; }
.wahl-aktionen { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.tasten {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 16px 0 0;
  font-size: 0.88rem;
}
.tasten dt { font-weight: 700; white-space: nowrap; }
.tasten dd { margin: 0; color: var(--leise); }
kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 4px;
  border: 1px solid var(--fuge);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85em;
  text-align: center;
}

@media (max-width: 440px) {
  .leiste .text { display: none; }
  .titel { font-size: 1.4rem; }
}

/* Breite Schirme: Bedienung rechts neben dem Brett, Ziffern als 3×3-Block */
@media (min-width: 760px) and (min-height: 560px) {
  .tisch {
    grid-template-columns: minmax(0, 1fr) 18rem;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: 'flaeche bedienung';
    column-gap: 24px;
  }
  .bedienung { width: 100%; justify-content: center; gap: 14px; }
  .kombis { min-height: 0; }
  .kombi-zeile { flex-wrap: wrap; overflow: visible; row-gap: 4px; padding: 2px 0; }
  .block {
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
      'd1 d2 d3'
      'd4 d5 d6'
      'd7 d8 d9'
      'notiz notiz loeschen';
  }
  .taste { min-height: 58px; }
  #notiz, #loeschen { min-height: 48px; }
}

/* Querformat auf dem Handy: Kopf und Leiste in einer Zeile, Bedienung rechts */
@media (orientation: landscape) and (max-height: 540px) {
  body {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: 'kopf leiste' 'tisch tisch' 'fuss fuss';
  }
  .kopf { width: auto; margin: 0; padding: 6px 2px 0; }
  .titel { font-size: 1.25rem; }
  .leiste { width: auto; margin: 0 0 0 auto; padding: 4px 0 0; }
  .leiste .text { display: none; }
  .tisch {
    grid-template-columns: minmax(0, 1fr) minmax(0, 22rem);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: 'flaeche bedienung';
    width: 100%;
    column-gap: 14px;
  }
  .bedienung { justify-content: center; width: 100%; }
  .block {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      'd1 d2 d3 notiz'
      'd4 d5 d6 loeschen'
      'd7 d8 d9 .';
  }
  .taste { min-height: 42px; }
  .fuss { padding: 0 2px 4px; }
}
