:root {
  --bg: #161a3a;
  --bg2: #1e2350;
  --card: #252b5e;
  --card2: #323a7a;
  --line: #3b4388;
  --text: #f4f5ff;
  --muted: #a8acd8;
  --accent: #ffc83d;
  --accent-ink: #2a1e00;
  --green: #2ecc71;
  --red: #ff5468;
  --orange: #ff9f43;
  --radius: 18px;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100dvh; transition: background-color .4s; }
body.danger { background: #3a1032; }
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.muted { color: var(--muted); }
.small-text { font-size: 14px; text-align: center; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.gap { gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 16px;
  background: var(--card2);
  transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.big { width: 100%; padding: 16px; font-size: 18px; }
.btn.huge { width: 100%; padding: 22px 16px; font-size: 26px; border-radius: 22px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.accent { background: #6c7cff; color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.success { background: var(--green); color: #052a13; }
.btn.danger { background: var(--red); color: #3a0008; }
.btn small { display: block; font-size: 14px; font-weight: 600; opacity: .8; margin-top: 2px; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 20px;
}
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 6px; font-size: 15px; }
.pill {
  padding: 5px 10px; border-radius: 999px;
  background: var(--bg2); color: var(--muted);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.done { background: var(--accent); color: var(--accent-ink); }
.pill.over { background: var(--red); color: #3a0008; }

/* ---------- Vorbereitung ---------- */
.hero { text-align: center; padding: 8px 0 0; }
.logo { font-size: 44px; }
h1 { margin: 4px 0; font-size: 28px; letter-spacing: -.02em; }
.hero p { margin: 4px 0 0; }
h2 { font-size: 18px; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.setting:last-child { border-bottom: 0; }
.setting small { display: block; font-size: 13px; }
.toggle { cursor: pointer; }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.stepper { display: flex; align-items: center; gap: 6px; flex: none; }
.stepper button {
  width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: var(--card2); font-size: 22px; font-weight: 700;
}
.stepper output { min-width: 40px; text-align: center; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }

.card .row.gap { margin-bottom: 8px; }
.check-line { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 15px; color: var(--muted); }
.check-line input { width: 20px; height: 20px; }

.cat {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 18px 0 6px;
}
.q-item {
  position: relative;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; margin: 6px 0;
  border-radius: 14px; background: var(--bg2);
  border: 2px solid transparent; cursor: pointer;
}
.q-item input { position: absolute; opacity: 0; pointer-events: none; }
.q-item.sel { border-color: var(--accent); background: #2c2f62; }
.q-item.dim { opacity: .45; }
.badge {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px;
}
.q-item.sel .badge { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.q-body { flex: 1; min-width: 0; }
.q-q { font-weight: 600; line-height: 1.3; }
.q-a { color: var(--muted); font-size: 14px; margin-top: 3px; }
.del { flex: none; border: 0; background: transparent; font-size: 18px; padding: 2px 4px; opacity: .75; }
.empty { color: var(--muted); text-align: center; padding: 16px 0 4px; }

form { display: grid; gap: 10px; }
input[type=text] {
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2);
  font-size: 16px; /* verhindert Zoom auf iOS */
}
input[type=text]::placeholder { color: #7f84b8; }

.bottom-bar {
  position: sticky; bottom: 0;
  padding: 16px 0 calc(4px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 35%);
}

/* ---------- Spiel ---------- */
#game { display: flex; flex-direction: column; gap: 14px; min-height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.timer-wrap { position: relative; text-align: center; padding: 6px 0 2px; }
.timer {
  font-size: min(32vw, 168px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  transition: color .3s;
}
.timer.warn { color: var(--orange); }
.timer.danger { color: var(--red); animation: pulse 1s infinite; }
.timer.paused { animation: blink 1.4s infinite; }
.timer.done { color: var(--red); }
#timerLabel { margin-top: 6px; font-size: 16px; min-height: 1.3em; }
.bar { height: 10px; border-radius: 99px; background: var(--card); overflow: hidden; margin-top: 14px; }
#barFill { height: 100%; width: 100%; background: var(--accent); border-radius: 99px; transition: width .25s linear, background-color .3s; }
.timer-wrap.warn #barFill { background: var(--orange); }
.timer-wrap.danger #barFill { background: var(--red); }

.flash {
  position: absolute; left: 50%; top: 38%;
  font-size: 64px; font-weight: 900; color: var(--green);
  text-shadow: 0 4px 24px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, -50%);
}
.flash.minus { color: var(--red); }
.flash.go { animation: flash 1.4s ease-out; }

.controls { display: grid; gap: 10px; }

.qcard {
  background: var(--card);
  border: 2px solid #6c7cff;
  border-radius: 22px;
  padding: 18px;
  display: grid; gap: 12px;
  animation: pop .25s ease-out;
}
.qmeta {
  display: flex; justify-content: space-between; gap: 8px;
  color: var(--muted); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
}
.qtext { font-size: 24px; font-weight: 700; margin: 0; line-height: 1.25; }
.qanswer::before {
  content: 'Antwort';
  display: block; margin-bottom: 2px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
}
.qanswer {
  margin: 0; padding: 12px 14px; border-radius: 12px;
  background: var(--bg2); color: var(--accent);
  font-size: 19px; font-weight: 700;
}
.answer-btns { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }
.answer-btns .btn { padding: 18px 8px; font-size: 21px; }
.answer-btns .btn small { display: inline; font-size: 15px; margin: 0; }

/* Menü */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(5, 6, 20, .65);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-inner {
  width: 100%; max-width: 560px;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 12px;
  animation: slideup .2s ease-out;
}
.sheet-inner h3 { margin: 0 0 4px; }
.adjust { display: grid; gap: 8px; }
.adjust .row .btn { flex: 1; padding: 12px 4px; }

/* Ende */
.over {
  position: fixed; inset: 0; z-index: 30;
  background: var(--bg); overflow: auto;
  padding: calc(28px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.over-inner { max-width: 560px; margin: 0 auto; text-align: center; }
.over-emoji { font-size: 76px; animation: wobble .6s 3; }
.over-title { font-size: 34px; margin: 8px 0 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 4px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.results { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; display: grid; gap: 6px; }
.results li { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border-radius: 12px; padding: 10px 12px; }
.results .ico { flex: none; font-size: 18px; }
.results .a { color: var(--muted); font-size: 14px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #fff; color: #14163a;
  padding: 10px 18px; border-radius: 999px;
  font-weight: 700; font-size: 15px;
  max-width: calc(100vw - 32px); text-align: center;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes blink { 50% { opacity: .3; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
@keyframes wobble { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes flash {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  70%  { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -110%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
