/* Layout: Ein Spielautomat in der Mitte, darunter die gelesene Silbe auf Schul-Lineatur.
   Farben nach Fibel-Tradition: Selbstlaute rot, Mitlaute blau. */
@font-face { font-family: "Andika"; src: url("fonts/andika-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Andika"; src: url("fonts/andika-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
/* Grundschrift wie in der Schule (Playwrite DE Grund, OFL) – nur in dünn vorhanden, wird per Kontur kräftiger */
@font-face { font-family: "Grundschrift"; src: url("fonts/playwrite-de-grund-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: block; }

:root {
  --paper: #eef3ef;
  --ink: #1d2b30;
  --muted: #5d6f73;
  --cabinet: #1f4e5a;
  --cabinet-deep: #153941;
  --window: #fffdf8;
  --line: #c9d6d6;
  --band: #f3f0dc;
  --vowel: #d2352b;
  --cons: #1f5fbf;
  --button: #f5b731;
  --button-deep: #c98b0e;
  --surface: #ffffff;
  --border: #d4dfdd;
  --ok: #2e8b57;
  --font: "Andika", "Comic Neue", "Segoe UI", system-ui, sans-serif;
  /* Schrift für alles, was das Kind liest (Walzen, Wort, Buchstaben) */
  --read: "Grundschrift", "Andika", system-ui, sans-serif;
  --read-weight: 400;
  --read-stroke: .028em;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12191b; --ink: #e6ecea; --muted: #9aaaa9; --cabinet: #23535f; --cabinet-deep: #183d45;
    --window: #fbf8ef; --line: #c9d6d6; --band: #f1edd5; --vowel: #d2352b; --cons: #1f5fbf;
    --button: #f5b731; --button-deep: #b57c0a; --surface: #1b2427; --border: #2d3b3e; --ok: #4fb47b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12191b; --ink: #e6ecea; --muted: #9aaaa9; --cabinet: #23535f; --cabinet-deep: #183d45;
  --window: #fbf8ef; --line: #c9d6d6; --band: #f1edd5; --vowel: #d2352b; --cons: #1f5fbf;
  --button: #f5b731; --button-deep: #b57c0a; --surface: #1b2427; --border: #2d3b3e; --ok: #4fb47b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
:root.font-andika { --read: var(--font); --read-weight: 700; --read-stroke: 0px; }
.cell, .word .letters, .history span, .chip, .login .mini-reels b {
  font-family: var(--read); font-weight: var(--read-weight);
  -webkit-text-stroke: var(--read-stroke) currentColor; paint-order: stroke fill;
}
.word .letters.empty { font-family: var(--font); -webkit-text-stroke: 0; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
/* Sicherung: die Seite darf nie seitlich scrollen */
html, body { max-width: 100%; overflow-x: clip; }
.top > * { min-width: 0; }
body { -webkit-tap-highlight-color: transparent; }
.machine, .result, .top, .chip, .seg, .pill { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body {
  background: var(--paper); color: var(--ink);
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  font-family: var(--font); font-size: 17px; line-height: 1.5;
  padding-inline: 16px; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cons); outline-offset: 2px; }

/* ---------- Kopfzeile ---------- */
.top {
  max-width: 760px; margin: 0 auto; padding-block: 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.25rem; letter-spacing: .01em; margin-right: auto; }
.brand span { color: var(--vowel); }
.who { color: var(--muted); font-size: .95rem; }
.who b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ghost {
  background: transparent; border: 1.5px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: .95rem; min-height: 44px;
}
.ghost:hover { border-color: var(--muted); }
.icon-btn { display: inline-flex; align-items: center; gap: 8px; }
.icon-btn svg { width: 20px; height: 20px; flex: none; }
.who .short { display: none; }

/* ---------- Automat ---------- */
main { max-width: 760px; margin: 0 auto; padding-block: 8px 40px; display: grid; gap: 22px; }

.machine {
  background: linear-gradient(180deg, var(--cabinet) 0%, var(--cabinet-deep) 100%);
  border-radius: 28px; padding: 22px clamp(14px, 4vw, 30px) 26px;
  box-shadow: 0 14px 0 -4px var(--cabinet-deep), 0 22px 40px -18px rgba(0,0,0,.45);
  display: grid; gap: 20px; justify-items: center;
}
.lights { display: flex; gap: 10px; }
.lights i {
  width: 11px; height: 11px; border-radius: 50%; background: #f8e7a8; opacity: .35;
  transition: opacity .15s;
}
.machine.spinning .lights i { animation: blink .5s infinite alternate; }
.machine.spinning .lights i:nth-child(even) { animation-delay: .25s; }
@keyframes blink { to { opacity: 1; } }

.reels {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 2.5vw, 16px);
  width: 100%; max-width: 560px;
  background: #0d2a30; padding: clamp(8px, 2vw, 14px); border-radius: 18px;
  cursor: pointer; touch-action: none;
}
.reel {
  --h: clamp(110px, 26vw, 170px);
  height: var(--h); overflow: hidden; border-radius: 12px; position: relative;
  background: var(--window);
  box-shadow: inset 0 10px 14px -8px rgba(0,0,0,.35), inset 0 -10px 14px -8px rgba(0,0,0,.35);
}
.reel.off { opacity: .28; }
.strip { will-change: transform; }
.cell {
  height: var(--h); display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--h) * .52); font-weight: 700; line-height: 1; white-space: nowrap;
  /* Grundschul-Lineatur: Mittelband zwischen zwei Linien */
  background:
    linear-gradient(var(--line), var(--line)) 0 22% / 100% 1px no-repeat,
    linear-gradient(var(--band), var(--band)) 0 41% / 100% 26% no-repeat,
    linear-gradient(var(--line), var(--line)) 0 80% / 100% 1px no-repeat;
}
.cell.f2 { font-size: calc(var(--h) * .42); }
.cell.f3 { font-size: calc(var(--h) * .33); }
.cell.f4 { font-size: calc(var(--h) * .27); }
.cell.f5 { font-size: calc(var(--h) * .22); }
.cell.f6 { font-size: calc(var(--h) * .19); }
.cell.blank::after { content: ""; width: 34%; height: 4px; border-radius: 2px; background: var(--line); }
.v { color: var(--vowel); }
.k { color: var(--cons); }
/* Farbmodi */
.c-none .v, .c-none .k, .c-syllable .v, .c-syllable .k { color: inherit; }
.reels.c-none .cell, .reels.c-syllable.one-syl .cell { color: #1d2b30; }
.reels.c-syllable .reel:nth-child(odd) .cell { color: var(--cons); }
.reels.c-syllable .reel:nth-child(even) .cell { color: var(--vowel); }
.reels.c-syllable.one-syl .reel .cell { color: var(--cons); }
.letters.c-none { color: var(--ink); }
.letters.c-syllable .syl:nth-child(odd) { color: var(--cons); }
.letters.c-syllable .syl:nth-child(even) { color: var(--vowel); }
.letters.c-syllable.one-syl .syl { color: var(--cons); }

.start {
  border: 0; border-radius: 999px; min-width: 220px; min-height: 64px; padding: 16px 40px;
  background: var(--button); color: #3a2a00; font-size: 1.6rem; font-weight: 700; letter-spacing: .08em;
  box-shadow: 0 6px 0 var(--button-deep);
  transition: transform .08s, box-shadow .08s;
}
.start:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--button-deep); }
.start:disabled { filter: saturate(.5); cursor: default; }
.hint { color: #cfe2e2; margin: -8px 0 0; font-size: .95rem; text-align: center; }

/* ---------- Ladefehler ---------- */
.load-error {
  background: var(--surface); border: 2px solid var(--vowel); border-radius: 16px;
  padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.load-error p { margin: 0; }

/* ---------- Ergebnis ---------- */
.result {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 20px;
  padding: 18px 20px; display: grid; gap: 14px; justify-items: center;
}
.word {
  border: 0; background: none; padding: 4px 8px; border-radius: 16px; cursor: pointer;
  display: inline-block; min-height: 1.4em; max-width: 100%;
}
.word .letters { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: .08em;
  font-size: clamp(3rem, 13vw, 5.4rem); font-weight: 700; line-height: 1.1; letter-spacing: .03em; }
.word .letters { flex-wrap: nowrap; }
.word .letters.len-l { font-size: clamp(2.2rem, 10.5vw, 4.6rem); }
.word .letters.len-xl { font-size: clamp(1.9rem, 8.6vw, 4rem); }
.word .letters.empty { color: var(--muted); font-weight: 400; font-size: 1.3rem; letter-spacing: 0; }
.syl { position: relative; display: inline-block; padding: 0 .06em .32em; border-radius: .15em; }
.syl:active { background: var(--band); }
.arcs .syl::after {
  content: ""; position: absolute; left: 6%; right: 6%; bottom: .06em; height: .26em;
  border: .055em solid var(--ink); border-top: 0; border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pill {
  border: 1.5px solid var(--border); background: var(--paper); border-radius: 999px;
  padding: 10px 20px; min-height: 48px; display: inline-flex; gap: 8px; align-items: center;
}
.pill svg { width: 20px; height: 20px; }
.pill.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.pill:disabled { opacity: .45; cursor: default; }

.history { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 34px; }
.history span {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 2px 10px;
  font-weight: 700; font-size: 1.15rem; background: var(--surface);
}
.history span.read { border-color: var(--ok); }
.section-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); text-align: center; margin: 0; }

/* ---------- Einstellungen ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 0; width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink);
  overflow: hidden; overflow: clip; /* runde Ecken bleiben, gescrollt wird nur der Inhalt; clip lässt sich nicht verschieben */
}
dialog::backdrop { background: rgba(10, 25, 30, .55); }
.dlg {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; padding: 0 clamp(16px, 4vw, 28px) 26px;
  max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; position: relative;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.dlg::-webkit-scrollbar { width: 8px; }
.dlg::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
/* Kopf mit „Fertig“ bleibt beim Scrollen sichtbar */
.dlg-head { position: sticky; top: 0; z-index: 2; background: var(--surface); padding-block: 18px 6px; }
.dlg-head { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.dlg-head > button { flex: none; }
.dlg-head h2 { margin: 0 auto 0 0; font-size: 1.35rem; flex: 1; min-width: 0; text-wrap: balance; }
.saved { position: absolute; right: 0; bottom: -6px; color: var(--ok); font-size: .8rem; line-height: 1; pointer-events: none; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; }
.sub { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 6px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  min-width: 50px; height: 50px; padding: 0 10px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--paper);
  font-weight: 700; font-size: 1.25rem;
}
.chip[aria-pressed="true"].v { background: var(--vowel); border-color: var(--vowel); color: #fff; }
.chip[aria-pressed="true"].k { background: var(--cons); border-color: var(--cons); color: #fff; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick input { flex: 1 1 200px; min-width: 0; }
textarea { width: 100%; resize: vertical; font-size: 1.05rem; }
select { border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--paper); min-height: 46px; max-width: 100%; }
.selectrow { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.selectrow select { width: 100%; text-overflow: ellipsis; }
.possible { background: var(--paper); border-radius: 12px; padding: 12px 14px; font-size: .95rem; line-height: 1.6; overflow-wrap: anywhere; }
input[type="text"], input[type="password"], textarea {
  border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--paper);
}
.small { font-size: .9rem; color: var(--muted); margin: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label {
  border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; min-height: 46px; cursor: pointer; background: var(--paper);
  display: inline-flex; align-items: center; gap: 4px;
}
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { border-color: var(--cabinet); background: var(--cabinet); color: #fff; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--cons); outline-offset: 2px; }
.toggles { display: grid; gap: 8px; }
.toggles label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.toggles label { min-height: 40px; }
.toggles input { width: 24px; height: 24px; flex: none; accent-color: var(--cabinet); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.warn { color: var(--vowel); font-size: .95rem; margin: 0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding-block: 24px; }
.login {
  width: min(400px, 100%); background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 24px; padding: 28px 24px; display: grid; gap: 14px;
}
.login h1 { margin: 0; font-size: 1.9rem; text-wrap: balance; }
.login h1 span { color: var(--vowel); }
.login .mini-reels { display: flex; gap: 6px; }
.login .mini-reels b {
  width: 46px; height: 54px; display: grid; place-items: center; border-radius: 10px;
  background: var(--cabinet); color: #fff; font-size: 1.6rem;
}
.login .mini-reels b.v { background: var(--vowel); }
.login label { display: grid; gap: 4px; font-size: .95rem; }
.login .start { min-width: 0; width: 100%; font-size: 1.2rem; padding: 12px; }
.err { color: var(--vowel); min-height: 1.5em; margin: 0; font-size: .95rem; }
.switch { background: none; border: 0; color: var(--cons); text-decoration: underline; padding: 0; justify-self: start; }

/* Tablet quer: Automat und Wort nebeneinander */
@media (min-width: 900px) and (orientation: landscape) {
  .top, main { max-width: 1200px; }
  main { grid-template-columns: 1.25fr 1fr; align-items: start; }
  .reel { --h: clamp(130px, 22vh, 200px); }
  .result { min-height: 100%; align-content: center; }
}
/* Handy quer: alles kompakter */
@media (max-height: 520px) and (orientation: landscape) {
  .top { padding-block: 6px; }
  main { grid-template-columns: 1.2fr 1fr; max-width: 100%; gap: 14px; padding-block: 0 12px; }
  .machine { padding: 12px 16px 16px; gap: 12px; }
  .lights { display: none; }
  .reel { --h: clamp(80px, 30vh, 130px); }
  .start { min-height: 52px; padding: 10px 30px; font-size: 1.3rem; }
  .hint { display: none; }
  .word .letters { font-size: clamp(2.4rem, 10vh, 4rem); }
}

/* Handy hochkant: alles Wichtige auf einen Bildschirm */
@media (max-width: 520px) and (orientation: portrait) {
  body { font-size: 16px; }
  .top { flex-wrap: nowrap; gap: 8px; padding-block: 8px; }
  .brand { font-size: 1.1rem; }
  .who { font-size: .9rem; white-space: nowrap; }
  .who .long { display: none; }
  .who .short { display: inline; }
  .icon-btn { width: 44px; height: 44px; padding: 0; justify-content: center; flex: none; }
  .icon-btn .label { display: none; }
  main { gap: 14px; padding-block: 4px 24px; }
  .machine { border-radius: 22px; padding: 14px 12px 16px; gap: 14px; }
  .lights { display: none; }
  .reel { --h: clamp(92px, 27vw, 130px); }
  .start { min-width: 0; width: 100%; max-width: 320px; min-height: 60px; font-size: 1.45rem; padding: 12px 20px; }
  .hint { font-size: .85rem; margin-top: -6px; }
  .hint .hint-letters { display: none; }
  .result { padding: 12px 12px 14px; gap: 10px; border-radius: 18px; }
  .word .letters { font-size: clamp(2.6rem, 13vw, 4rem); }
  .actions { flex-wrap: nowrap; gap: 8px; width: 100%; }
  .actions .pill { flex: 1 1 0; justify-content: center; padding: 10px 8px; }
  .history { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; width: 100%; padding-bottom: 4px; scrollbar-width: none; }
  .history span { flex: none; }
  .dlg { padding: 0 14px 20px; gap: 18px; }
  .dlg-head { padding-block: 12px 4px; }
  .dlg-head h2 { font-size: 1.15rem; }
  .chip { min-width: 46px; height: 48px; }
}
@media (max-width: 360px) and (orientation: portrait) {
  .brand { font-size: 1rem; }
  .who { font-size: .8rem; }
  .icon-btn { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .machine.spinning .lights i { animation: none; opacity: 1; }
}
