:root {
  --bg: #15191d; --panel: #20272d; --glass: rgba(24, 30, 35, .86); --line: #36424b;
  --fg: #eef1e8; --muted: #9aa69f; --accent: #f2c14e; --good: #9fd36b; --bad: #ff7043;
  --display: "Bungee", "Arial Black", Impact, sans-serif;
  --body: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--fg); font-family: var(--body); }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { font-family: var(--body); color: inherit; }
h1 { font-family: var(--display); font-weight: 400; margin: 0; font-size: 28px; letter-spacing: .02em; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.card.wide { width: min(560px, 100%); }
.card input, .card select { font: inherit; font-size: 20px; padding: 12px 14px; border-radius: 10px; border: 2px solid var(--line); background: #151b1f; color: var(--fg); outline: none; width: 100%; }
.card input:focus, .card select:focus { border-color: var(--accent); }
#code { font-family: var(--display); letter-spacing: .3em; text-transform: uppercase; text-align: center; font-size: 26px; }
.btn { font: inherit; font-weight: 800; font-size: 18px; padding: 12px 16px; border-radius: 12px; border: 2px solid var(--line); background: #2a333a; cursor: pointer; }
.btn.go { background: var(--accent); border-color: var(--accent); color: #1d1a10; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--bad); margin: 0; min-height: 1.2em; font-weight: 600; }

/* Spiel: Feld oben, Aufgabe unten (quer: Aufgabe rechts) */
#game { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#stage { position: relative; flex: 1 1 58%; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#panel { flex: 0 0 auto; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px 10px; display: flex; flex-direction: column; min-height: 0; user-select: none; -webkit-user-select: none; }
@media (orientation: landscape) and (max-height: 600px) {
  #game { flex-direction: row; }
  #panel { width: min(42vw, 330px); border-top: 0; border-left: 1px solid var(--line); justify-content: center; }
  #pad button { padding: 6px 0 !important; font-size: 18px !important; }
}

#hud { position: absolute; top: 6px; left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.hp { flex: 1; max-width: 160px; }
.bar { height: 9px; background: rgba(15,19,22,.7); border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: var(--good); transition: width .3s, background .3s; }
.chips { display: flex; gap: 5px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.chip { background: var(--glass); border-radius: 8px; padding: 3px 7px; font-size: 13px; white-space: nowrap; }
.chip b { font-weight: 800; }
#bombChip { color: var(--accent); }
#bombChip.grow { animation: pop .5s; }
@keyframes pop { 40% { transform: scale(1.35); background: var(--accent); color: #1d1a10; } }
#feed { position: absolute; top: 34px; left: 8px; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
#feed div { background: var(--glass); border-radius: 7px; padding: 2px 7px; font-size: 12px; animation: fade 4s forwards; }
@keyframes fade { 80% { opacity: 1; } 100% { opacity: 0; } }
#msg { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--glass); padding: 10px 16px; border-radius: 12px; font-weight: 800; font-size: 18px; text-align: center; pointer-events: none; white-space: nowrap; }

#ctrl { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 8px; pointer-events: none; }
.cbtn { pointer-events: auto; width: 58px; height: 58px; border-radius: 16px; border: 2px solid rgba(255,255,255,.18); background: rgba(24,30,35,.62); display: grid; place-items: center; touch-action: none; }
.cbtn svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.cbtn.on { background: rgba(242,193,78,.55); }
.cbtn.jump { margin-left: auto; }

#taskBox, #readyBox, #resBox { display: flex; flex-direction: column; gap: 6px; }
#streak { font-size: 12px; color: var(--accent); min-height: 1em; font-weight: 600; }
#ttext { font-size: 20px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
#tin { font-family: var(--display); font-size: 24px; min-height: 40px; padding: 4px 10px; border-radius: 10px; background: #151b1f; border: 2px solid var(--line); display: flex; align-items: center; }
#tin:empty::before { content: "?"; color: var(--muted); }
#pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
#pad button { font-size: 20px; font-weight: 800; padding: 9px 0; border-radius: 10px; border: 0; background: #2f3940; touch-action: manipulation; }
#pad button:active { background: #45525b; }
#pad .fn { background: #27303a; color: #cfd6cc; }
#pad .ok { grid-column: span 2; background: var(--accent); color: #1d1a10; }
#opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#opts button { font-size: 17px; font-weight: 800; padding: 12px 6px; border-radius: 10px; border: 0; background: #2f3940; }
#readyBox { text-align: center; padding: 10px 0; }
#readyBox .big { font-family: var(--display); font-size: 26px; color: var(--accent); }
#readyInfo { font-size: 16px; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; }
#resBox { text-align: center; padding: 8px 0; font-size: 17px; }
#resBox .big { font-family: var(--display); font-size: 24px; }
#resBox .ok { color: var(--good); } #resBox .bad { color: var(--bad); }

#endList { margin: 0; padding-left: 26px; display: flex; flex-direction: column; gap: 4px; font-size: 17px; }
#endList li.me { font-weight: 800; color: var(--accent); }
#fehler { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
#fehler b { color: var(--fg); }

/* Wurm gestalten */
#lookBox { display: flex; flex-direction: column; gap: 8px; }
#lookCv { width: 100%; height: auto; aspect-ratio: 240 / 150; background: linear-gradient(#9cc6cf, #dce8d4); border-radius: 12px; }
.lrow { display: grid; grid-template-columns: 46px 1fr; gap: 8px; align-items: center; }
.ll { font-size: 13px; color: var(--muted); }
.sw { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.sw button { aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255,255,255,.15); padding: 0; cursor: pointer; }
.sw button[aria-pressed="true"] { border: 3px solid #fff; box-shadow: 0 0 0 2px var(--accent); }
.acc { display: flex; flex-wrap: wrap; gap: 4px; }
.acc button { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 8px; border: 2px solid var(--line); background: #2a333a; cursor: pointer; }
.acc button[aria-pressed="true"] { border-color: var(--accent); background: #3b3a2a; }
#join .card { gap: 10px; }
