/* Rechenheft bei Tag, Tafel bei Nacht */
:root {
  --paper: #fbfaf4;
  --grid: #dbe6f3;
  --ink: #1b2a57;
  --ink-soft: #5a678c;
  --surface: #ffffff;
  --line: #c9d3e6;
  --accent: #e4502a;      /* Rotstift */
  --accent-ink: #ffffff;
  --good: #1f9461;
  --marker: #ffe066;      /* Textmarker */
  --shadow: 0 2px 0 var(--ink);
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17332b;
    --grid: #1f4037;
    --ink: #f3f1e4;
    --ink-soft: #a9c0b6;
    --surface: #1e3f35;
    --line: #386053;
    --accent: #ff8a5c;
    --accent-ink: #1a1a1a;
    --good: #7be0a9;
    --marker: #f5d657;
    --shadow: 0 2px 0 #0d211b;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--round);
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.screen { display: flex; flex-direction: column; gap: 14px; }

h1 { font-size: 30px; line-height: 1.15; margin: 0; text-wrap: balance; }
h2 {
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-soft); margin: 10px 0 -6px;
}
p { margin: 0; }

.eyebrow {
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-soft); text-align: center;
}
.lead { text-align: center; color: var(--ink-soft); margin-bottom: 8px; }
.hint { text-align: center; color: var(--ink-soft); font-size: 15px; }
.count { color: var(--accent); }

/* ---------- Logo ---------- */
.logo { text-align: center; margin: 28px 0 4px; line-height: 1; }
.logo-mark {
  display: inline-block;
  font-size: 76px; font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(transparent 58%, var(--marker) 58%, var(--marker) 90%, transparent 90%);
  padding: 0 10px;
}
.logo-mark i { font-style: normal; color: var(--accent); margin: 0 2px; }
.logo-word {
  display: block; margin-top: 6px;
  font-size: 22px; font-weight: 800; letter-spacing: .32em; text-indent: .32em;
  text-transform: uppercase;
}

/* ---------- Formulare ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 15px; }

input[type="text"] {
  font: inherit; font-weight: 700; color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink); border-radius: 12px;
  padding: 12px 14px; width: 100%; min-width: 0;
}
input[type="text"]::placeholder { color: var(--ink-soft); opacity: .6; font-weight: 500; }
input[type="text"]:focus-visible, button:focus-visible {
  outline: 3px solid var(--marker); outline-offset: 2px;
}

.btn {
  font: inherit; font-weight: 800; color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink); border-radius: 12px;
  padding: 13px 18px; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-size: 19px; padding: 15px 18px; }
.btn.small { padding: 10px 14px; font-size: 15px; white-space: nowrap; }
.btn.link {
  border: 0; box-shadow: none; background: none; color: var(--ink-soft);
  font-weight: 600; font-size: 15px; text-decoration: underline; padding: 6px;
}

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--ink-soft); font-size: 14px; margin: 6px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 2px dashed var(--line); }

.join { display: flex; gap: 10px; }
.join input {
  text-transform: uppercase; text-align: center;
  letter-spacing: .3em; text-indent: .3em; font-size: 20px;
}
.join .btn { flex: none; }

/* ---------- Lobby ---------- */
.code {
  text-align: center; font-size: 64px; font-weight: 900; letter-spacing: .14em; text-indent: .14em;
  line-height: 1; font-variant-numeric: tabular-nums;
}
.share { display: flex; gap: 10px; }
.share input { font-size: 14px; font-weight: 500; padding: 10px 12px; }

.segmented { display: flex; gap: 8px; }
.segmented button {
  flex: 1; min-width: 0;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line); border-radius: 12px;
  padding: 10px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.segmented b { font-size: 15px; }
.segmented small { font-size: 12px; color: var(--ink-soft); }
.segmented button[aria-pressed="true"] {
  border-color: var(--ink); background: var(--marker); color: #1b2a57; box-shadow: var(--shadow);
}
.segmented button[aria-pressed="true"] small { color: #1b2a57; }
.segmented button:disabled { cursor: default; }
.segmented button:disabled:not([aria-pressed="true"]) { opacity: .45; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.players li {
  background: var(--surface); border: 2px solid var(--ink); border-radius: 999px;
  padding: 6px 14px; font-weight: 700;
}
.players li.me { background: var(--marker); color: #1b2a57; }
.players .tag { font-weight: 500; font-size: 13px; opacity: .75; margin-left: 4px; }

#btn-start { margin-top: 10px; }

/* ---------- Spiel ---------- */
.timer { display: flex; align-items: center; gap: 12px; }
.timer-track {
  flex: 1; height: 14px; border: 2px solid var(--ink); border-radius: 999px;
  background: var(--surface); overflow: hidden;
}
.timer-bar { height: 100%; background: var(--good); transform-origin: left; }
.timer.low .timer-bar { background: var(--accent); }
.timer-num { min-width: 2.2ch; text-align: right; font-weight: 900; font-size: 22px; font-variant-numeric: tabular-nums; }

.scores {
  list-style: none; margin: 0; padding: 2px 0 4px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
}
.scores::-webkit-scrollbar { display: none; }
.scores li {
  flex: none; display: flex; align-items: baseline; gap: 8px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: 15px; white-space: nowrap;
}
.scores li.me { border-color: var(--ink); background: var(--marker); color: #1b2a57; }
.scores li.off { opacity: .45; }
.scores b { font-size: 17px; font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface); border: 2px solid var(--ink); border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink);
  padding: 22px 12px 16px; text-align: center;
  transition: background-color .25s;
}
@media (prefers-color-scheme: dark) { .card { box-shadow: 0 4px 0 #0d211b; } }
.card.good { background: color-mix(in srgb, var(--good) 30%, var(--surface)); transition: none; }
.card.bad { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); transition: none; }

.question {
  font-size: clamp(44px, 15vw, 68px); font-weight: 900; line-height: 1.1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.question.solved { font-size: clamp(30px, 10.5vw, 52px); line-height: 1.45; }
.question .op { color: var(--accent); margin: 0 .12em; }
.answer {
  height: 58px; margin: 12px auto 0; max-width: 200px;
  border-bottom: 4px solid var(--ink);
  font-size: 44px; font-weight: 900; line-height: 54px;
  font-variant-numeric: tabular-nums;
}
.answer.struck { text-decoration: line-through; text-decoration-color: var(--accent); color: var(--ink-soft); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  font: inherit; font-size: 26px; font-weight: 800; color: var(--ink);
  background: var(--surface); border: 2px solid var(--ink); border-radius: 14px;
  height: 58px; cursor: pointer; box-shadow: var(--shadow);
  touch-action: manipulation; user-select: none;
}
.keypad button:active { transform: translateY(2px); box-shadow: none; }
.keypad .key-ok { background: var(--good); color: var(--paper); }
.keypad .key-del { color: var(--accent); }
.keypad.locked button { opacity: .5; }

.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) { .desktop-only { display: block; } }

/* ---------- Ergebnis ---------- */
#s-end h1 { text-align: center; margin-bottom: 6px; }
.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ranking li {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 14px;
}
.ranking li.first { border-color: var(--ink); box-shadow: var(--shadow); }
.ranking li.me { background: var(--marker); color: #1b2a57; border-color: var(--ink); }
.ranking .place { font-size: 22px; font-weight: 900; text-align: center; }
.ranking .who { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .who small { display: block; font-weight: 500; font-size: 13px; opacity: .75; }
.ranking .pts { font-size: 28px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- Hinweise ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-weight: 700;
  max-width: calc(100vw - 32px); text-align: center; z-index: 5;
}
.offline {
  position: fixed; inset: 0; z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  font-size: 20px; font-weight: 800;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Herausforderung ---------- */
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.choice { display: flex; flex-direction: column; gap: 4px; }
.choice .hint { font-size: 14px; }
.info { text-align: center; font-weight: 800; }
.eyebrow span { color: var(--ink); font-weight: 900; letter-spacing: .14em; }
.ranking .pts.small { font-size: 14px; font-weight: 600; opacity: .8; }

/* ---------- Spielleiter-Code ---------- */
.dialog {
  width: min(380px, calc(100vw - 32px));
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 18px; padding: 22px 18px;
  box-shadow: 0 4px 0 var(--ink);
}
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog input { text-align: center; font-size: 20px; letter-spacing: .1em; }
.toast { z-index: 20; }
.error { text-align: center; color: var(--accent); font-weight: 800; }
