:root {
  --bg: #14173a;
  --bg2: #232863;
  --card: #f6f3ea;
  --ink: #171a3d;
  --muted: #6b6f8f;
  --accent: #ff4d3d;
  --sun: #ffd23f;
  --line: #d9d4c4;
  --radius: 20px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; }

.screen {
  position: fixed; inset: 0;
  display: none;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  background:
    repeating-linear-gradient(115deg, transparent 0 46px, rgba(255, 255, 255, .035) 46px 92px),
    radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg));
}
.screen.active { display: flex; }

/* ---------- Karten ---------- */
.card {
  position: relative;
  width: min(100%, 440px);
  margin: auto;
  background: var(--card);
  border-radius: var(--radius);
  padding: 34px 24px 22px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, .28), 0 30px 60px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.card.wide { width: min(100%, 720px); }
.flagband {
  position: absolute; left: 0; right: 0; top: 0; height: 14px;
  background: conic-gradient(var(--ink) 25%, #fff 0 50%, var(--ink) 0 75%, #fff 0) 0 0 / 14px 14px;
}

.logo {
  margin: 0 0 4px;
  font-size: clamp(44px, 9vw, 84px);
  line-height: .88;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -.03em;
  text-transform: uppercase;
  transform: skewY(-3deg);
  color: #fff;
}
.logo span { display: block; color: var(--accent); margin-left: .5em; text-shadow: 4px 4px 0 var(--sun); }
.logo.small { font-size: 34px; margin-bottom: 16px; color: var(--ink); }
.logo.small span { text-shadow: 3px 3px 0 var(--sun); }

/* ---------- Hauptmenü ---------- */
.home {
  margin: auto;
  width: min(100%, 1020px);
  display: grid;
  grid-template-columns: 1.1fr minmax(320px, 420px);
  gap: 34px;
  align-items: center;
}
.hero { color: #fff; min-width: 0; }
.tagline { margin: 22px 0 6px; color: #c9cdf2; font-weight: 600; font-size: 17px; }
.stage { position: relative; height: clamp(200px, 38vh, 340px); }
.stage::after {
  content: ""; position: absolute; left: 12%; right: 12%; bottom: 8%; height: 26%;
  background: radial-gradient(closest-side, rgba(255, 210, 63, .28), transparent);
  pointer-events: none;
}
#preview { width: 100%; height: 100%; display: block; }
.arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5);
  background: rgba(20, 23, 58, .5); color: #fff;
  font-size: 28px; line-height: 1; font-weight: 900; cursor: pointer; padding: 0 0 4px;
}
.arrow.l { left: 0; } .arrow.r { right: 0; }
.arrow:active { background: var(--sun); color: var(--ink); }
.charinfo { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.charinfo strong { display: block; font-size: 32px; font-weight: 900; font-style: italic; text-transform: uppercase; line-height: 1; }
.charinfo span { color: var(--sun); font-weight: 800; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: auto 110px; gap: 5px 10px; margin: 0; align-items: center; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #c9cdf2; }
.stats dt { margin: 0; }
.stats dd { margin: 0; height: 9px; border-radius: 9px; background: rgba(255, 255, 255, .16); overflow: hidden; }
.stats dd i { display: block; height: 100%; border-radius: 9px; background: linear-gradient(90deg, var(--sun), var(--accent)); transition: width .25s; }

@media (max-width: 860px) {
  .home { grid-template-columns: 1fr; gap: 18px; }
  .hero { text-align: center; }
  .logo { display: inline-block; }
  .tagline { margin-top: 14px; font-size: 15px; }
  .stage { height: 200px; }
  .charinfo { justify-content: center; text-align: left; }
  .setup { width: 100%; }
}

.field { display: block; margin-bottom: 16px; }
.field > span, h2 { display: block; font-size: 12px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 0 0 7px; }
h2 span { color: var(--accent); }
input {
  width: 100%;
  font: inherit; font-weight: 800; font-size: 18px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
input::placeholder { color: #b5b2a6; }
input:focus-visible, button:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chars button {
  display: grid; justify-items: center; gap: 1px;
  background: #fff; border: 2px solid var(--line); border-radius: 14px;
  padding: 7px 2px 6px; cursor: pointer; color: var(--ink);
  font-size: 11px; font-weight: 800;
}
.chars button b { font-size: 27px; line-height: 1.1; font-weight: 400; }
.chars button[aria-checked="true"] { border-color: var(--ink); background: #fff7d1; box-shadow: 0 3px 0 var(--ink); transform: translateY(-2px); }

.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatches button {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line);
  cursor: pointer; padding: 0;
}
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.12); }

.btn {
  font-weight: 900; font-size: 16px;
  border: 0; border-radius: 12px;
  padding: 12px 16px;
  background: var(--ink); color: #fff;
  cursor: pointer;
  transition: transform .08s;
}
.btn:active { transform: translateY(2px); }
.btn.big {
  width: 100%; font-size: 20px; padding: 15px;
  text-transform: uppercase; font-style: italic; letter-spacing: .02em;
  background: var(--accent);
  box-shadow: 0 5px 0 #b02a1f;
}
.btn.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #b02a1f; }
.btn.big:disabled { background: #b9b6ad; box-shadow: 0 5px 0 #96938b; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--ink); }
.btn.small { font-size: 14px; padding: 9px 12px; white-space: nowrap; }
.btn.tiny { font-size: 18px; padding: 6px 11px; background: rgba(20, 23, 58, .72); }
.btn.link { background: none; color: var(--muted); font-weight: 800; font-size: 14px; padding: 8px; }
.btn.wide-btn { display: block; width: 100%; margin-top: 10px; }
.linkrow { display: flex; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.card > .btn.link { display: block; margin: 8px auto 0; }

.joinrow { display: flex; gap: 8px; margin-top: 16px; }
.joinrow input { text-transform: uppercase; letter-spacing: .3em; text-align: center; }

/* ---------- Lobby ---------- */
.lobbyhead { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.lobbyhead small { font-size: 12px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.code { font-size: 46px; font-weight: 900; font-style: italic; letter-spacing: .12em; line-height: 1; color: var(--accent); text-shadow: 2px 2px 0 var(--sun); }
.invite { display: flex; gap: 8px; }
.invite input { font-size: 14px; min-width: 0; font-weight: 700; padding: 9px 12px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; font-weight: 600; }
.hint.center { text-align: center; }
.card.wide > h2 { margin-top: 20px; }

.tracks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tracks button {
  position: relative; text-align: left; padding: 0; overflow: hidden;
  border: 3px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink);
  cursor: pointer;
}
.tracks button:disabled { cursor: default; }
.tracks canvas { display: block; width: 100%; aspect-ratio: 16 / 10; }
.tracks .meta { padding: 8px 10px 10px; }
.tracks strong { display: block; font-weight: 900; font-style: italic; text-transform: uppercase; font-size: 15px; }
.tracks small { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.tracks em { font-style: normal; font-size: 11px; font-weight: 800; color: var(--accent); letter-spacing: .04em; }
.tracks button[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 5px 0 var(--ink); transform: translateY(-3px); }
.tracks button[aria-checked="true"]::after {
  content: "✓"; position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--sun); color: var(--ink); font-weight: 900;
  display: grid; place-items: center; box-shadow: 0 2px 0 var(--ink);
}
@media (max-width: 620px) {
  .tracks { grid-template-columns: 1fr; }
  .tracks button { display: grid; grid-template-columns: 42% 1fr; align-items: center; }
  .tracks canvas { height: 100%; aspect-ratio: auto; min-height: 84px; }
}

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 20px 0; }
@media (max-width: 620px) { .cols { grid-template-columns: 1fr; gap: 14px; } }
.seg { display: flex; gap: 6px; margin-bottom: 16px; }
.seg button {
  flex: 1; padding: 10px 0; border-radius: 11px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
  font-weight: 900; font-size: 16px; cursor: pointer;
}
.seg button:disabled { cursor: default; opacity: .75; }
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; border-color: var(--ink); opacity: 1; }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.players li { display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 7px 11px; font-weight: 800; }
.players .face { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; flex: none; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18); }
.players em { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.players li.empty { border-style: dashed; color: var(--muted); font-weight: 600; background: transparent; justify-content: center; }

/* ---------- Hilfe ---------- */
.keys { margin: 0 0 16px; padding: 0; list-style: none; display: grid; gap: 8px; font-size: 14px; font-weight: 600; line-height: 1.4; }
kbd { display: inline-block; min-width: 26px; text-align: center; background: #fff; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; padding: 1px 6px; font: inherit; font-weight: 900; font-size: 12px; margin-right: 3px; }

/* ---------- Rennen ---------- */
#screen-game { padding: 0; overflow: hidden; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#speedfx {
  position: absolute; inset: -20%; pointer-events: none; opacity: 0; transition: opacity .2s;
  background: repeating-conic-gradient(from 0deg at 50% 46%, rgba(255, 255, 255, .5) 0 .6deg, transparent .6deg 7deg);
  -webkit-mask-image: radial-gradient(closest-side, transparent 52%, #000 100%);
  mask-image: radial-gradient(closest-side, transparent 52%, #000 100%);
  animation: speedspin .5s steps(4) infinite;
}
#speedfx.on { opacity: .55; }
@keyframes speedspin { to { transform: rotate(7deg); } }
@media (prefers-reduced-motion: reduce) { #speedfx { animation: none; } }
.hud { position: absolute; color: #fff; pointer-events: none; text-shadow: 0 2px 0 rgba(10, 12, 30, .7); }
.hud.tl { left: max(12px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); display: grid; gap: 6px; justify-items: start; }
.hud.tr { right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); display: grid; justify-items: end; gap: 4px; }
.hud.tr .btn { pointer-events: auto; color: #fff; }
.hud.br { right: max(16px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
.pos { font-size: 68px; font-weight: 900; font-style: italic; line-height: .85; color: var(--sun); -webkit-text-stroke: 2px var(--ink); }
.pos small { font-size: 24px; color: #fff; -webkit-text-stroke: 1px var(--ink); }
.pill { background: rgba(20, 23, 58, .72); border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: 14px; }
.mono { font-variant-numeric: tabular-nums; }
.speed { font-size: 40px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; text-align: right; }
.speed small { font-size: 13px; margin-left: 4px; }
#minimap { width: 128px; height: 128px; }

.hud.item {
  left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%);
  width: 76px; height: 76px; border-radius: 20px;
  border: 4px solid rgba(255, 255, 255, .85);
  background: rgba(20, 23, 58, .6);
  font-size: 30px; line-height: 1; padding: 0; white-space: nowrap; color: #fff; font-weight: 900;
  pointer-events: auto; cursor: pointer;
}
.hud.item.ready { border-color: var(--sun); box-shadow: 0 0 0 5px rgba(255, 210, 63, .35); }

#countdown, #banner {
  position: absolute; inset: 0; display: grid; place-items: center;
  pointer-events: none;
  font-weight: 900; font-style: italic;
  color: var(--sun);
}
#countdown { font-size: min(34vw, 240px); -webkit-text-stroke: 5px var(--ink); text-shadow: 8px 8px 0 var(--accent); }
#banner { font-size: min(11vw, 72px); text-transform: uppercase; -webkit-text-stroke: 2px var(--ink); text-shadow: 4px 4px 0 var(--accent); opacity: 0; transition: opacity .25s; padding-bottom: 20vh; }
#banner.show { opacity: 1; }

/* ---------- Touch ---------- */
.touch { position: absolute; inset: 0; pointer-events: none; }
.stick {
  position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom));
  width: min(46vw, 210px); height: 92px; border-radius: 46px;
  background: rgba(20, 23, 58, .45); border: 3px solid rgba(255, 255, 255, .55);
  pointer-events: auto; touch-action: none;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  color: rgba(255, 255, 255, .6); font-size: 20px;
}
.knob {
  position: absolute; left: 50%; top: 50%; width: 70px; height: 70px; margin: -35px 0 0 -35px;
  border-radius: 50%; background: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, .35), inset 0 -6px 0 rgba(0, 0, 0, .12);
  pointer-events: none;
}
.tbtns {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(74px, calc(env(safe-area-inset-bottom) + 60px));
  display: grid; grid-template-columns: auto auto; gap: 10px; align-items: end; justify-items: end;
}
.tbtns button {
  pointer-events: auto; touch-action: none;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, .8);
  background: rgba(20, 23, 58, .55); color: #fff;
  font-weight: 900; text-transform: uppercase;
  width: 66px; height: 66px; font-size: 11px; padding: 0;
}
.tbtns .t-item { grid-column: 2; font-size: 26px; width: 72px; height: 72px; text-transform: none; }
.tbtns .t-item:not(.ready) { font-size: 12px; opacity: .6; text-transform: uppercase; }
.tbtns .t-item.ready { border-color: var(--sun); background: rgba(255, 210, 63, .3); }
.tbtns .t-drift { width: 104px; height: 104px; font-size: 19px; font-style: italic; background: rgba(255, 77, 61, .8); grid-column: 2; grid-row: 2 / span 2; }
.tbtns .t-s { grid-column: 1; }
.tbtns button.on { background: var(--sun); color: var(--ink); }

/* ---------- Overlays ---------- */
.overlay { position: absolute; inset: 0; display: flex; padding: 16px; background: rgba(10, 12, 30, .65); overflow-y: auto; z-index: 5; }
.overlay.top { position: fixed; z-index: 20; }
.results { list-style: none; counter-reset: r; margin: 0 0 18px; padding: 0; display: grid; gap: 6px; }
.results li { counter-increment: r; display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-weight: 800; }
.results li::before { content: counter(r) "."; font-style: italic; font-weight: 900; width: 1.6em; color: var(--accent); }
.results li:first-child { background: #fff7d1; }
.results li.mine { border-color: var(--ink); }
.results i { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.results b { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--sun); color: var(--ink);
  font-weight: 800; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .3); z-index: 30;
  max-width: calc(100vw - 32px); text-align: center;
}

@media (prefers-reduced-motion: reduce) { .btn, .stats dd i, #banner { transition: none; } }
