@font-face { font-family: "Caveat"; src: url("fonts/caveat-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-800-normal.woff2") format("woff2"); font-weight: 800; font-display: swap; }

/* Papier: Karoheft, Füller und Rotstift */
:root {
  --paper: #f9fbfd;
  --grid: #d8e5f0;
  --margin: #eba4a8;
  --ink: #1d3fa6;
  --text: #22262e;
  --muted: #586170;
  --line: #8fa3bd;
  --red: #c91d2a;
  --marker: #ffe94a;
  --marker-text: #1a2340;
  --cell: 24px;
  --hand: "Caveat", "Segoe Script", cursive;
  --ui: "Figtree", system-ui, sans-serif;
  --wobble: 240px 18px 220px 16px / 16px 220px 18px 240px;
  color-scheme: light;
}
/* Tafel: Dunkelmodus mit Kreide */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1d2f2a; --grid: #28403a; --margin: #6f4a48; --ink: #f1f6ea; --text: #e9efe4;
    --muted: #aebdb3; --line: #70877d; --red: #ff9c8d; --marker: #f7e37c; --marker-text: #1d2f2a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1d2f2a; --grid: #28403a; --margin: #6f4a48; --ink: #f1f6ea; --text: #e9efe4;
  --muted: #aebdb3; --line: #70877d; --red: #ff9c8d; --marker: #f7e37c; --marker-text: #1d2f2a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font: 400 17px/1.5 var(--ui);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}
#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom)) 28px;
  border-left: 2px solid var(--margin);
}
@media (min-width: 800px) { #app { padding-left: 48px; padding-right: 32px; } }

h1, h2, h3, p { margin: 0; }
h1:focus { outline: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Kopfzeile */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { border: 0; background: none; padding: 4px 0; font: 700 26px/1 var(--hand); color: var(--ink); }
.change {
  margin-left: auto; min-height: 44px; padding: 6px 16px; background: var(--paper);
  border: 2px solid var(--ink); border-radius: var(--wobble); color: var(--ink); font-weight: 600;
}
.change:hover { background: var(--marker); color: var(--marker-text); }

/* Knöpfe */
.btn {
  display: inline-block; min-height: 52px; padding: 10px 26px; background: var(--paper);
  border: 2px solid var(--ink); border-radius: var(--wobble); color: var(--ink);
  font-weight: 600; text-align: center;
}
.btn.main {
  min-height: 64px; padding: 12px 36px; background: var(--marker); color: var(--marker-text);
  border-color: var(--marker-text); font: 700 34px/1.1 var(--hand);
}
.btn:hover { transform: rotate(-.6deg); }
.btn:active { transform: translateY(1px); }
.btn.danger { border-color: var(--red); color: var(--red); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 32px; }
.tiny-link { border: 0; background: none; padding: 8px 2px; color: var(--muted); text-decoration: underline; min-height: 40px; }

/* Startseite */
.hero { position: relative; padding: 28px 0 8px; }
.hero h1 { font: 700 clamp(72px, 21vw, 136px)/.84 var(--hand); color: var(--ink); }
.hero h1 span { display: block; }
.hero h1 span:nth-child(2) { padding-left: .42em; }
.hero h1 span:nth-child(3) { padding-left: .9em; }
.hero .letter { position: absolute; right: 0; top: 18px; }
.lead { margin-top: 20px; color: var(--muted); max-width: 34em; }
.summary { margin: 36px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.summary button {
  display: grid; grid-template-columns: 7.5em 1fr; gap: 12px; width: 100%; padding: 11px 2px;
  text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
}
.summary button:hover { background: color-mix(in srgb, var(--marker) 40%, transparent); }
.summary b { font-weight: 600; color: var(--muted); }
.summary span { overflow-wrap: anywhere; }

/* Der eingekreiste Buchstabe */
.letter {
  position: relative; display: inline-grid; place-items: center; width: 112px; height: 112px;
  font: 700 76px/1 var(--hand); color: var(--ink); flex: none; transform: rotate(-4deg);
}
.letter svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.letter path { fill: none; stroke: var(--red); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .55s ease-out .1s forwards; }
.letter.big { width: 200px; height: 200px; font-size: 140px; }
.letter.small { width: 76px; height: 76px; font-size: 50px; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Weitergeben und Zwischenseiten */
.stage { display: flex; flex-direction: column; align-items: flex-start; padding-top: 12vh; }
.eyebrowless { color: var(--muted); }
.stage h1, .page-title { font: 700 clamp(50px, 12vw, 76px)/1 var(--hand); color: var(--ink); overflow-wrap: anywhere; }
.stage p { margin-top: 14px; max-width: 32em; }
.stage .letter { margin: 18px 0 4px -8px; }
.cat-list { display: flex; flex-wrap: wrap; gap: 2px 20px; margin-top: 24px; font: 700 32px/1.3 var(--hand); color: var(--ink); }

/* Schreiben */
.write-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px;
  margin: 0 -8px; padding: 8px; background: var(--paper); border-bottom: 2px solid var(--ink);
}
.write-who { min-width: 0; flex: 1; }
.write-who strong { display: block; font: 700 30px/1.05 var(--hand); color: var(--ink); overflow-wrap: anywhere; }
.timer { font: 800 34px/1 var(--ui); font-variant-numeric: tabular-nums; color: var(--text); }
.timer.none { display: none; }
.timer.urgent { color: var(--red); }
.write-head .change { margin-left: 0; padding: 4px 12px; }
.rows { margin-top: 18px; }
.row { display: block; padding: 10px 0 4px; }
.row label, .row .lab { display: block; font-weight: 600; font-size: 15px; color: var(--muted); }
.answer {
  width: 100%; min-height: 48px; padding: 2px 2px; background: transparent; border: 0;
  border-bottom: 2px solid var(--line); border-radius: 0; font: 700 34px/1.2 var(--hand); color: var(--ink);
}
.answer::placeholder { color: var(--muted); opacity: .55; font-size: 26px; }
.answer:focus { outline: none; border-bottom-color: var(--ink); background: color-mix(in srgb, var(--marker) 28%, transparent); }
.hint { min-height: 22px; font-size: 14px; color: var(--red); }

/* Prüfen */
.note { margin-top: 10px; color: var(--muted); max-width: 36em; }
.review-title { display: flex; align-items: center; gap: 14px; padding-top: 4px; }
.review-title h1 { font: 700 44px/1 var(--hand); color: var(--ink); }
.cat-block { margin-top: 26px; }
.cat-block h2 { font: 700 32px/1 var(--hand); color: var(--red); }
.player-row { display: grid; grid-template-columns: minmax(0, 6.5em) minmax(0, 1fr) 62px; gap: 2px 10px; align-items: center; padding: 6px 0; }
.player-row .who { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.player-row .answer { min-height: 42px; font-size: 28px; }
.player-row.zero .answer { text-decoration: line-through; text-decoration-color: var(--red); text-decoration-thickness: 2px; }
.pts {
  width: 58px; height: 46px; background: var(--paper); border: 2px solid var(--red); border-radius: 50% 46% 52% 48%;
  color: var(--red); font: 700 28px/1 var(--hand); padding: 0;
}
.pts:hover { background: var(--marker); color: var(--marker-text); }
.pts:disabled { cursor: default; opacity: 1; }
.pts:disabled:hover { background: var(--paper); color: var(--red); }
.answer[readonly] { cursor: default; }
.stopnote { margin: 8px 0 0; font-weight: 800; color: var(--red); }
.stopnote[hidden] { display: none; }
.why { grid-column: 2 / 4; min-height: 0; font-size: 14px; color: var(--muted); }
.why:empty { display: none; }
.why button { border: 0; background: none; padding: 0 0 0 6px; color: inherit; text-decoration: underline; font-size: inherit; }
.round-sum { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 30px; padding-top: 12px; border-top: 2px solid var(--ink); font-weight: 600; }
.round-sum b { font: 700 28px/1 var(--hand); color: var(--red); margin-left: 6px; }

/* Papierwertung */
.paper-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.paper-row .who { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.step { width: 48px; height: 48px; padding: 0; background: var(--paper); border: 2px solid var(--ink); border-radius: 50%; color: var(--ink); font-weight: 800; font-size: 15px; }
.num { width: 76px; height: 48px; text-align: center; background: var(--paper); border: 0; border-bottom: 2px solid var(--line); font: 700 32px/1 var(--hand); color: var(--red); }

/* Wertung */
.winner { padding: 22px 0 6px; color: var(--muted); }
.winner-name { position: relative; display: inline-block; max-width: 100%; margin: 8px 0 0; padding: 22px 44px; font: 700 clamp(52px, 13vw, 88px)/1 var(--hand); color: var(--ink); overflow-wrap: anywhere; }
.winner-name svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.winner-name path { fill: none; stroke: var(--red); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .8s ease-out .15s forwards; }
.table-wrap { margin-top: 22px; overflow-x: auto; background: var(--paper); border: 2px solid var(--ink); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border: 1px solid var(--line); text-align: center; }
th:first-child, td:first-child { text-align: left; font-weight: 600; overflow-wrap: anywhere; min-width: 6.500em; }
thead th { font-weight: 600; }
.round-link { min-width: 40px; min-height: 40px; padding: 0 4px; background: none; border: 0; text-decoration: underline; font: 700 28px/1 var(--hand); color: var(--ink); }
.round-link:hover { background: var(--marker); color: var(--marker-text); }
td.sum, th.sum { font-weight: 800; color: var(--red); }

/* Ändern */
dialog {
  width: min(520px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; padding: 0;
  background: var(--paper); color: var(--text); border: 0; border-left: 2px solid var(--ink);
}
dialog::backdrop { background: rgb(20 30 50 / .45); }
.panel { display: flex; flex-direction: column; height: 100%; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 2px solid var(--ink);
}
.panel-head h2 { font: 700 34px/1 var(--hand); color: var(--ink); }
.panel-body { flex: 1; overflow-y: auto; padding: 0 16px calc(40px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
.sec { padding: 20px 0; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h3 { font-size: 17px; font-weight: 800; margin-bottom: 8px; }
.sec .note { margin: 0 0 10px; font-size: 15px; }
.edit-row { display: flex; align-items: center; gap: 4px; padding: 3px 0; }
.edit-row input {
  flex: 1; min-width: 0; height: 44px; padding: 4px 8px; background: var(--paper);
  border: 0; border-bottom: 2px solid var(--line); border-radius: 0;
}
.edit-row input:focus { outline: none; border-bottom-color: var(--ink); background: color-mix(in srgb, var(--marker) 28%, transparent); }
.icon { width: 40px; height: 44px; flex: none; padding: 0; background: none; border: 0; font-size: 18px; font-weight: 600; color: var(--muted); border-radius: 6px; }
.icon:hover:not(:disabled) { background: var(--grid); color: var(--text); }
.icon:disabled { opacity: .3; cursor: default; }
.icon.x:hover:not(:disabled) { color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { min-height: 40px; padding: 5px 13px; background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--wobble); font-size: 15px; }
.chip[aria-pressed="true"] { background: var(--marker); border-color: var(--marker-text); color: var(--marker-text); font-weight: 600; }
.chip.ltr { width: 44px; height: 44px; padding: 0; font: 700 25px/1 var(--hand); }
.chip.ltr[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.add { margin-top: 8px; min-height: 44px; padding: 6px 16px; background: none; border: 2px dashed var(--ink); border-radius: var(--wobble); color: var(--ink); font-weight: 600; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; }
.field input[type="number"] { width: 92px; height: 44px; padding: 4px 8px; text-align: center; background: var(--paper); border: 0; border-bottom: 2px solid var(--line); font-weight: 600; }
.field select { max-width: 60%; height: 44px; padding: 4px 8px; background: var(--paper); border: 2px solid var(--line); border-radius: 6px; }
.field input[type="checkbox"] { width: 26px; height: 26px; flex: none; accent-color: var(--ink); }
.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.radio { display: flex; gap: 10px; padding: 7px 0; align-items: flex-start; }
.radio input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--ink); }
.radio small { display: block; color: var(--muted); font-size: 14px; }
.pending-note { padding: 8px 0 0; color: var(--red); font-size: 15px; }

/* Online */
.home-form { margin-top: 28px; max-width: 420px; }
.home-form label { display: block; font-weight: 600; color: var(--muted); font-size: 15px; }
.text-input { width: 100%; height: 48px; padding: 4px 8px; background: var(--paper); border: 0; border-bottom: 2px solid var(--line); border-radius: 0; }
.text-input:focus { outline: none; border-bottom-color: var(--ink); background: color-mix(in srgb, var(--marker) 28%, transparent); }
.join-row { display: flex; gap: 10px; align-items: stretch; margin-top: 4px; }
.join-row .text-input { flex: 1; min-width: 0; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.join-row .btn { flex: none; min-height: 48px; padding: 6px 18px; }
.or-join { margin-top: 28px; }
.lobby { display: grid; gap: 24px; padding-top: 8px; }
@media (min-width: 620px) { .lobby { grid-template-columns: minmax(0, 1fr) 208px; } }
.room-code { margin-top: 2px; font: 800 clamp(52px, 15vw, 76px)/1 var(--ui); letter-spacing: .08em; color: var(--ink); }
.qr { width: 208px; max-width: 100%; aspect-ratio: 1; padding: 8px; background: #fff; border: 2px solid var(--ink); }
.qr svg { display: block; width: 100%; height: 100%; }
.share-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.share-link { width: 100%; height: 40px; margin-top: 10px; padding: 4px 6px; font-size: 14px; color: var(--muted); background: var(--paper); border: 0; border-bottom: 1px solid var(--line); }
.player-list { margin: 8px 0 0; padding: 0; list-style: none; }
.player-list li { padding: 7px 0; border-bottom: 1px solid var(--line); font-weight: 600; overflow-wrap: anywhere; }
.player-list small { font-weight: 400; color: var(--muted); }
.section-title { margin-top: 28px; font: 700 34px/1.1 var(--hand); color: var(--ink); }

/* Meldungen */
#toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 20; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
#toast:empty { display: none; }
#toast div { padding: 9px 18px; background: var(--ink); color: var(--paper); border-radius: var(--wobble); font-weight: 600; }

@media (max-width: 480px) {
  .hero .letter { width: 84px; height: 84px; font-size: 56px; top: 12px; }
  .letter.big { width: 160px; height: 160px; font-size: 112px; }
  .timer { font-size: 28px; }
  .qr { width: 148px; }
  .share-link { display: none; }
  .write-head { gap: 10px; }
  .write-head .letter.small { width: 62px; height: 62px; font-size: 42px; }
  .write-who strong { font-size: 25px; }
  .winner-name { padding: 18px 30px; }
  .summary button { grid-template-columns: 6.3em 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition: none !important; }
  .btn:hover { transform: none; }
}

.why .obj { color: var(--ink, inherit); font-weight: 600; }
.why button[aria-pressed="true"] { font-weight: 700; }

/* Lobby: Raus-Button links oben */
.leave {
  min-height: 44px; padding: 6px 16px; background: var(--paper);
  border: 2px solid var(--ink); border-radius: var(--wobble); color: var(--ink); font-weight: 600;
}
.leave:hover { background: var(--marker); color: var(--marker-text); }
.waiting { text-align: center; font-weight: 600; margin: 16px 0; }

/* Kopfzeile tiefer (iPhone-Erreichbarkeit) */
.top { padding-top: calc(env(safe-area-inset-top, 0px) + 22px); }
