/* Galgenmännchen — Schultafel: dunkles Schiefergrün, Kreide, ein Hauch
   Kreidestaub. Bewusst einthemig, alles explizit gefärbt. */

:root {
  --tafel: #1b2422;
  --tafel-2: #121917;
  --panel: #242f2c;
  --panel-2: #2c3a36;
  --naht: #384845;
  --kreide: #eef3ef;
  --kreide-dim: #a9b8b2;
  --kreide-blass: #71847e;
  --mint: #7fd1b9;
  --mint-tief: #2f6b5c;
  --mint-dunkel: #102a24;
  --rot: #e08466;
  --rot-tief: #6b3a2f;
  --gut: #6fc08f;

  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-num: ui-monospace, SFMono-Regular, 'SF Mono', 'Roboto Mono', Menlo, Consolas, monospace;

  --r-md: 14px;
  --r-lg: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }

body {
  background: var(--tafel);
  /* Zwei weiche Schlieren wie von einem Schwamm, der nie ganz sauber wischt. */
  background-image:
    radial-gradient(120% 55% at 22% 8%, rgba(255, 255, 255, 0.045) 0%, rgba(255, 255, 255, 0) 60%),
    radial-gradient(90% 45% at 80% 92%, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0) 65%),
    linear-gradient(180deg, var(--tafel) 0%, var(--tafel-2) 100%);
  background-attachment: fixed;
  color: var(--kreide-dim);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ---------- Gerüst ---------- */

#app { min-height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; min-height: 0; }
.scrollbar { overflow-y: auto; max-height: 100dvh; }
.wrap { width: 100%; max-width: 560px; margin-inline: auto; padding: 22px 18px calc(18px + var(--safe-b)); }
.blatt { padding: calc(var(--safe-t) + 16px) 18px calc(18px + var(--safe-b)); width: 100%; max-width: 560px; margin-inline: auto; }

h2 { font-family: var(--font-display); font-weight: 400; font-size: 26px; color: var(--kreide); margin: 0 0 6px; }
h3 {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--mint-tief); font-weight: 700; margin: 24px 0 8px;
}
p, li { font-size: 15px; line-height: 1.6; color: var(--kreide-dim); }
strong { color: var(--kreide); }
em { color: var(--mint); font-style: italic; }

.kopf {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-t) + 12px) 18px 12px;
  border-bottom: 1px solid var(--naht);
}
.kopf .titel { flex: 1; min-width: 0; }
.kopf .ober {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--kreide-blass); font-weight: 700;
}
.kopf h1 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: 24px; letter-spacing: -0.01em; color: var(--kreide);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.werkzeuge { display: flex; gap: 7px; }
.werkzeug {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--naht); color: var(--kreide-dim); font-size: 15px;
}

/* ---------- Knöpfe ---------- */

.btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 16px 18px; border-radius: var(--r-md);
  font-weight: 650; font-size: 16px; letter-spacing: -0.01em;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.3; transform: none; box-shadow: none; filter: saturate(0.5); }
.btn--kreide { background: var(--mint); color: #08211b; box-shadow: 0 8px 26px rgba(127, 209, 185, 0.16); }
.btn--hell { background: var(--kreide); color: #16211e; }
.btn--geist { background: var(--panel); color: var(--kreide); border: 1px solid var(--naht); }
.btn--leise { background: none; color: var(--kreide-blass); font-weight: 500; font-size: 15px; padding: 13px; }
.knopfsaeule { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.reihe { display: flex; gap: 10px; }
.reihe .btn { width: auto; flex: 1; }

/* ---------- Startbildschirm ---------- */

.start { justify-content: center; text-align: center; padding: 30px 20px calc(28px + var(--safe-b)); }
.wortmarke {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(34px, 11vw, 52px); line-height: 1.03; margin: 0;
  color: var(--kreide); letter-spacing: -0.02em;
}
.wortmarke em { font-style: italic; color: var(--mint); }
.unterzeile { color: var(--kreide-blass); margin: 10px 0 26px; }

/* ---------- Die Bühne: Zeichnung, Wort, Tastatur ---------- */

.buehne {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 14px calc(10px + var(--safe-b));
  flex: 1; min-height: 0; overflow-y: auto;
}

.galgenfeld { display: grid; place-items: center; flex: 1; min-height: 0; }
.galgen { width: auto; height: 100%; max-height: 34dvh; max-width: 100%; display: block; }
.strich {
  fill: none; stroke: var(--kreide); stroke-width: 4.5;
  stroke-linecap: round; stroke-linejoin: round;
  /* Kreide franst aus — ein weicher Schatten reicht als Andeutung. */
  filter: drop-shadow(0 0 1.5px rgba(238, 243, 239, 0.5));
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: zeichnen 0.4s ease-out forwards;
}
.strich--vorab { stroke: var(--kreide-blass); animation: none; stroke-dashoffset: 0; opacity: 0.7; }
.strich--gesicht { stroke-width: 3.5; animation-delay: 0.3s; }
.galgen--froh .strich { stroke: var(--gut); }
.galgen--weg .strich { stroke: var(--rot); }
@keyframes zeichnen { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .strich { animation: none; stroke-dashoffset: 0; }
}

.wortfeld {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px 6px;
  min-height: 46px; align-items: flex-end;
}
.zeichen {
  min-width: 24px; height: 38px; display: grid; place-items: center;
  font-family: var(--font-num); font-size: clamp(19px, 6vw, 26px); font-weight: 700;
  color: var(--kreide); border-bottom: 3px solid var(--naht);
  padding: 0 2px;
}
.zeichen--voll { border-bottom-color: var(--mint-tief); }
.zeichen--neu { animation: aufblitzen 0.35s ease-out; }
.zeichen--luecke { border-bottom: 0; min-width: 12px; }
.zeichen--strich { border-bottom: 0; color: var(--kreide-blass); }
.zeichen--verraten { color: var(--rot); }
@keyframes aufblitzen { from { transform: translateY(6px) scale(0.8); opacity: 0; } }

.tippzeile { text-align: center; font-size: 13px; color: var(--kreide-blass); min-height: 20px; }
.tippzeile b { color: var(--mint); font-weight: 600; }

.leiste {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--kreide-blass); font-weight: 700;
}
.leiste .punkte { display: flex; gap: 4px; }
.leiste .punkt { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--naht); }
.leiste .punkt--weg { background: var(--rot); border-color: var(--rot); }

.tastatur {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(38px, 1fr));
  gap: 6px;
}
.taste {
  aspect-ratio: 1 / 1.12; min-height: 40px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--naht); color: var(--kreide);
  font-family: var(--font-num); font-size: 17px; font-weight: 700;
  display: grid; place-items: center;
  transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease;
}
.taste:active { transform: scale(0.92); }
.taste--treffer { background: var(--mint-dunkel); border-color: var(--mint-tief); color: var(--mint); }
.taste--daneben { background: transparent; border-color: var(--rot-tief); color: var(--rot-tief); text-decoration: line-through; }
.taste:disabled { opacity: 1; }
.taste--treffer:disabled, .taste--daneben:disabled { transform: none; }

.wortknopf { margin-top: 10px; }

/* ---------- Wort eintippen ---------- */

.feld {
  background: var(--panel); border: 1px solid var(--naht);
  border-radius: var(--r-md); padding: 14px; color: var(--kreide); font-size: 16px;
  user-select: text; -webkit-user-select: text; width: 100%;
}
.feld::placeholder { color: var(--kreide-blass); }
.feld--wort {
  text-align: center; letter-spacing: 0.16em; text-transform: uppercase;
  font-family: var(--font-num); font-size: 22px;
}
.feld--code {
  width: 100%; text-align: center; letter-spacing: 0.3em;
  font-family: var(--font-num); font-size: 28px; text-transform: uppercase; margin-top: 8px;
}
.feldlabel {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--kreide-blass); font-weight: 700; text-align: left; margin: 18px 0 7px;
}
.warnton { color: var(--rot); }
.geheim {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 13px; color: var(--kreide-blass);
}

/* ---------- Punktetafel ---------- */

.tafel {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 10px; background: var(--panel); border: 1px solid var(--naht);
  border-radius: var(--r-lg); padding: 16px 14px; margin: 16px 0;
}
.tafel .seite { text-align: center; min-width: 0; }
.tafel .wer { font-size: 12px; color: var(--kreide-blass); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tafel .zahl { font-family: var(--font-num); font-size: 34px; font-weight: 800; color: var(--kreide); line-height: 1.1; }
.tafel .fuehrt .zahl { color: var(--mint); }
.tafel .strichlein { width: 1px; height: 40px; background: var(--naht); }

.zeile {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--naht); font-size: 14px;
}
.zeile:last-child { border-bottom: 0; }
.zeile .wort { font-family: var(--font-num); color: var(--kreide); letter-spacing: 0.06em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.zeile .pkt { font-family: var(--font-num); font-weight: 700; }
.pkt--plus { color: var(--gut); }
.pkt--null { color: var(--kreide-blass); }

/* ---------- Overlays und Übergabe ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--tafel-2);
  display: flex; flex-direction: column;
  animation: einblenden 0.18s ease-out;
}
@keyframes einblenden { from { opacity: 0; } }

.uebergabe {
  justify-content: center; align-items: center; text-align: center;
  padding: 26px calc(24px + var(--safe-b));
  background-image: radial-gradient(90% 50% at 50% 40%, #24302c 0%, rgba(36, 48, 44, 0) 70%);
}
.uebergabe .pfeil { font-size: 40px; animation: schubs 1.5s ease-in-out infinite; }
@keyframes schubs { 50% { transform: translateX(10px); } }
.uebergabe .lbl { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--kreide-blass); font-weight: 700; margin-top: 4px; }
.uebergabe .name { font-family: var(--font-display); font-size: clamp(30px, 9vw, 42px); color: var(--kreide); line-height: 1.1; margin: 4px 0 6px; }
.uebergabe .auftrag { color: var(--kreide-dim); margin: 0 0 26px; max-width: 30ch; }
.uebergabe .btn { max-width: 340px; }

.wahlliste { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.wahl {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--naht); border-radius: var(--r-md); padding: 13px 15px;
}
.wahl--an { border-color: var(--mint-tief); background: var(--mint-dunkel); }
.wahl .haupt { flex: 1; min-width: 0; }
.wahl .oben { color: var(--kreide); font-weight: 650; }
.wahl .unten { font-size: 13px; color: var(--kreide-blass); }
.wahl .haken { color: var(--mint); font-size: 18px; }

/* ---------- Kopplung per QR (zwei Handys im selben WLAN) ---------- */

.qrfeld { display: grid; place-items: center; background: var(--kreide); border-radius: 14px; padding: 14px; margin: 16px 0; }
.qrfeld canvas { width: 100%; max-width: 300px; height: auto; image-rendering: pixelated; display: block; }

.scanfenster {
  position: relative; overflow: hidden; border-radius: 14px; background: #000;
  aspect-ratio: 1; margin: 16px 0; border: 1px solid var(--naht);
}
.scanfenster video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanfenster::after {
  content: ""; position: absolute; inset: 16%;
  border: 2px solid var(--mint); border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
}

.raumcode {
  font-family: var(--font-num);
  font-size: clamp(38px, 13vw, 58px); font-weight: 800; letter-spacing: 0.14em;
  text-align: center; padding: 18px 10px; margin: 16px 0;
  border-radius: 14px; user-select: all; -webkit-user-select: all;
  background: var(--panel); color: var(--kreide); border: 2px solid var(--mint-tief);
}

.codeklappe { margin-top: 6px; }
.codeklappe summary { font-size: 13px; color: var(--kreide-blass); cursor: pointer; padding: 8px 0; list-style: none; }
.codeklappe summary::before { content: "▸ "; }
.codeklappe[open] summary::before { content: "▾ "; }
.codeklappe .btn { margin-top: 8px; }
.codefeld {
  width: 100%; min-height: 84px; resize: vertical; margin-top: 6px;
  background: var(--panel); border: 1px solid var(--naht); border-radius: 10px;
  padding: 10px; color: var(--kreide-blass); font-family: var(--font-num); font-size: 11px;
  word-break: break-all; user-select: text; -webkit-user-select: text;
}

/* Technikzeile beim Koppeln: klein, ruhig, darf umbrechen. */
.lage { margin-top: 12px; font-size: 12px; line-height: 1.55; opacity: 0.62; word-break: break-word; }

/* ---------- Quer: Zeichnung neben Wort und Tastatur ---------- */

@media (orientation: landscape) and (max-height: 560px) {
  .buehne { display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr); gap: 14px; align-items: center; }
  .galgenfeld { grid-row: span 4; }
  .galgen { max-height: 82dvh; }
  .taste { min-height: 34px; aspect-ratio: auto; padding: 6px 0; }
}
