:root {
  --bg: #1d2130;
  --card: rgba(24, 28, 42, 0.92);
  --ink: #f4f1e8;
  --muted: #a9b0c2;
  --accent: #ffd23f;
  --accent-ink: #2b2f3a;
  --red: #ff5d5d;
  --line: rgba(255, 255, 255, 0.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto; z-index: 5; }
.card { width: 100%; max-width: 460px; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); margin: auto; }
h1 { margin: 0 0 6px; font-size: 48px; letter-spacing: -1px; font-weight: 900; color: var(--accent); }
h1 span { color: var(--ink); }
h2 { margin: 0 0 12px; font-size: 26px; }
.how { margin: 0 0 16px; color: var(--muted); }
.field { display: block; margin: 10px 0 6px; font-weight: 600; font-size: 14px; color: var(--muted); }
.field span { color: var(--ink); }
input { font: inherit; color: var(--ink); background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; margin-top: 4px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { font: inherit; font-weight: 700; color: var(--ink); background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 16px; cursor: pointer; }
button:hover { background: rgba(255, 255, 255, 0.16); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover { filter: brightness(1.06); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.buttons button { flex: 1 1 auto; }
.join { display: flex; gap: 8px; margin-top: 10px; }
.join input { width: 96px; flex: none; margin: 0; text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 800; }
.join button { flex: 1; }
.err { color: var(--red); min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }
.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chars button { padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 600; border-radius: 10px; }
.chars button.on { outline: 3px solid var(--accent); background: rgba(255, 210, 63, 0.14); }
.code { color: var(--accent); letter-spacing: 4px; }
.share { display: flex; gap: 8px; }
.share input { margin: 0; font-size: 13px; }
.share button { flex: none; }
.players { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: rgba(255, 255, 255, 0.05); border-radius: 10px; }
.players li .tag { margin-left: auto; font-size: 12px; color: var(--muted); }
.players li.me { outline: 1px solid rgba(255, 210, 63, 0.5); }
.note { color: var(--muted); margin: 12px 0 0; font-size: 14px; min-height: 1.4em; }
.help { color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.help b { color: var(--ink); }
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(255, 255, 255, 0.05); border-radius: 10px; }
.ranking li .pl { font-weight: 900; font-size: 20px; width: 40px; color: var(--accent); }
.ranking li .t { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.ranking li.me { outline: 1px solid rgba(255, 210, 63, 0.6); }

.banner { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 4; pointer-events: none;
  background: rgba(20, 24, 36, 0.85); border-radius: 14px; padding: 12px 20px; font-weight: 800; font-size: 20px; text-align: center; max-width: calc(100% - 32px); }
.announce { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 8;
  pointer-events: none; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 16px;
  border-radius: 12px; padding: 10px 16px; text-align: center; width: max-content; max-width: calc(100% - 32px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); overflow-wrap: anywhere; }
.callouts { position: fixed; left: 50%; top: 116px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: calc(100% - 32px); max-width: 560px; }
.callout { background: rgba(20, 24, 36, 0.86); border-radius: 999px; padding: 6px 16px; font-weight: 800; font-size: 17px;
  text-align: center; animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); transition: opacity 0.5s; }
.callout.me { background: var(--red); color: #fff; font-size: 20px; }
.callout.mine { background: var(--accent); color: var(--accent-ink); }
.callout.fade { opacity: 0; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.touch { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; justify-content: space-between;
  padding: 0 16px calc(18px + env(safe-area-inset-bottom)); pointer-events: none; }
.pad { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.touch button { touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 50%; width: 76px; height: 76px;
  padding: 0; font-size: 26px; background: rgba(20, 24, 36, 0.55); border: 2px solid rgba(255, 255, 255, 0.35); color: #fff; }
.touch button.down { background: rgba(255, 210, 63, 0.55); }
.touch #tb { width: 64px; height: 64px; font-size: 12px; margin-bottom: 40px; }
.touch #ti { width: 86px; height: 86px; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.touch #ti canvas { width: 48px; height: 48px; }
.touch #ti.has { background: rgba(255, 210, 63, 0.35); border-color: var(--accent); }

.foot { position: fixed; bottom: 6px; right: 10px; font-size: 11px; color: rgba(255, 255, 255, 0.45); z-index: 6; pointer-events: none; }
body.racing .foot { display: none; }
@media (max-width: 599px) {
  .callouts { top: 100px; }
}
@media (max-width: 420px) {
  h1 { font-size: 40px; }
  .card { padding: 18px 14px; }
  .callout { font-size: 15px; }
  .callout.me { font-size: 17px; }
}
