:root {
  --red: #c91a09;
  --yellow: #f2cd37;
  --blue: #0055bf;
  --green: #4b9f4a;
  --orange: #fe8a18;
  --ink: #1b2a34;
  --panel: #fffaf0;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd3ff;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(#9fd3ff, #fff6e0);
}

/* ---------------------------------------------------------------- bricks */

.btn, .chip, .icon-btn, .tab, .choice, .swatch, .tbtn {
  font-family: var(--font);
  cursor: pointer;
  border: 0;
}

/* A button is a brick: studs on top, a darker bottom edge. */
.btn {
  --c: #f4f4f4;
  position: relative;
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 13px 18px 12px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--c);
  border-radius: 6px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 3px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s;
}

.btn::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: -9px;
  height: 10px;
  background: radial-gradient(circle at 50% 60%, var(--c) 0 55%, transparent 58%) 0 0 / 25% 100% repeat-x;
  filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.12));
}

.btn.primary { --c: var(--yellow); }
.btn.blue { --c: #3d8fd6; color: #fff; }
.btn.big { font-size: 26px; padding: 16px 18px 15px; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); }
.btn small { display: block; font-size: 12px; opacity: 0.7; font-weight: 700; }

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.25);
}

.chip {
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 800;
  background: #fff;
  border-radius: 20px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* ----------------------------------------------------------------- menus */

#menu {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 24px 16px 28px;
  touch-action: pan-y;
  pointer-events: none;
}

#menu > * { pointer-events: auto; }
#menu.side { justify-content: flex-end; align-items: stretch; }
#menu.left { justify-content: flex-start; align-items: center; padding-left: max(16px, 5vw); }

.panel {
  width: min(560px, 100%);
  padding: 18px 20px 22px;
  background: rgba(255, 250, 240, 0.94);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), inset 0 -6px 0 rgba(0, 0, 0, 0.08);
  max-height: 100%;
  overflow-y: auto;
}

.panel.small { width: min(380px, 100%); align-self: center; }
.panel.title { width: min(420px, 100%); text-align: center; background: rgba(255, 250, 240, 0.86); }
.panel.results { width: min(520px, 100%); text-align: center; }
.panel.builder { width: min(400px, 100%); }
.panel h2 { margin: 0; font-size: 24px; }
.panel h4 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.sub { margin: 6px 0 0; opacity: 0.75; font-weight: 700; line-height: 1.4; }
.stats { margin: 14px 0 0; font-weight: 800; }
.status { min-height: 1.4em; margin: 8px 0 0; font-weight: 700; color: var(--red); }

.logo {
  margin: 0 0 4px;
  line-height: 0.95;
  font-size: clamp(34px, 9vw, 60px);
  font-weight: 900;
  letter-spacing: 0.01em;
}

.logo span { display: block; }
.logo span:first-child { color: var(--red); text-shadow: 0 3px 0 #7d1006; }
.logo span:last-child { color: var(--yellow); -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink); }

.settings { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-top: 12px; color: var(--ink); font-weight: 800; opacity: 0.7; }

.text {
  width: 100%;
  padding: 11px 12px;
  font: 700 18px var(--font);
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: #fff;
  user-select: text;
}

.code { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-size: 26px; }

.tabs { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.tab { padding: 8px 12px; font-weight: 800; font-size: 15px; background: #e8e2d4; border-radius: 8px 8px 0 0; }
.tab.on { background: var(--yellow); }
.tab-body { padding: 4px 0; min-height: 120px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choice { padding: 7px 10px; font-size: 14px; font-weight: 700; background: #fff; border-radius: 6px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12); }
.choice.on { background: var(--yellow); }
.choice.locked { opacity: 0.6; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatch { width: 30px; height: 30px; border-radius: 5px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.3); position: relative; }
.swatch.on { outline: 3px solid var(--ink); outline-offset: 2px; }

.round-btn { text-align: left; margin-top: 8px; padding: 10px 14px; font-size: 17px; }
.round-btn.k-race { --c: #ffe59a; }
.round-btn.k-survival { --c: #bfe3ff; }
.round-btn.k-final { --c: #f9c3c3; }

.verdict { margin: 6px 0; font-size: clamp(30px, 8vw, 46px); font-weight: 900; letter-spacing: 0.02em; }
.verdict.good { color: var(--green); text-shadow: 0 3px 0 #1d5a1c; }
.verdict.bad { color: var(--red); text-shadow: 0 3px 0 #6d0e05; }
.names { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin-top: 12px; }
.name { padding: 4px 8px; border-radius: 5px; font-weight: 800; font-size: 13px; }
.name.in { background: #c9efc4; }
.name.out { background: #f3cfcb; text-decoration: line-through; opacity: 0.75; }
.name.me { outline: 2px solid var(--ink); }

.players { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #fff; border-radius: 8px; font-weight: 800; }
.player-row small { margin-left: auto; opacity: 0.6; }

/* ------------------------------------------------------------------- hud */

#hud { position: fixed; inset: 0; pointer-events: none; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 8px rgba(0, 0, 0, 0.25); }
#hud button { pointer-events: auto; }

.hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); text-align: center; }
.hud-title { font-size: 22px; font-weight: 900; letter-spacing: 0.03em; }
.hud-goal { font-size: 14px; font-weight: 700; opacity: 0.95; }
.hud-counter { position: absolute; top: 12px; right: 16px; font-size: 34px; font-weight: 900; text-align: right; line-height: 1; }
.hud-counter small { display: block; font-size: 13px; letter-spacing: 0.04em; }
.hud-clock { position: absolute; top: 66px; right: 16px; font-size: 26px; font-weight: 900; }
.hud-clock.hurry { color: #ffd54a; animation: pulse 0.5s infinite alternate; }
.hud-place { position: absolute; top: 12px; left: 66px; font-size: 40px; font-weight: 900; }
.hud-place.safe { color: #b8ff9e; }
.hud-menu { position: absolute; top: 10px; left: 10px; width: 44px; height: 44px; font-size: 20px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.85); color: var(--ink); cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15); }
.hud-center { position: absolute; top: 34%; width: 100%; text-align: center; font-size: clamp(60px, 18vw, 150px); font-weight: 900; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); }
.hud-center.pop { animation: pop 0.9s ease-out; }
.hud-banner { position: absolute; top: 24%; width: 100%; text-align: center; font-size: clamp(40px, 11vw, 92px); font-weight: 900; opacity: 0; transform: scale(0.6); transition: opacity 0.2s, transform 0.25s cubic-bezier(.3, 1.6, .6, 1); -webkit-text-stroke: 3px var(--ink); }
.hud-banner.on { opacity: 1; transform: scale(1); }
.hud-banner.good { color: #7ee36b; }
.hud-banner.bad { color: #ff6b5a; }
.hud-banner.neutral { color: var(--yellow); }
.hud-toasts { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; }
.toast { padding: 4px 12px; background: rgba(27, 42, 52, 0.6); border-radius: 14px; font-weight: 800; font-size: 15px; animation: fadein 0.2s; }
.hud-spec { position: absolute; bottom: 120px; width: 100%; text-align: center; font-size: 18px; font-weight: 800; }
.hud-spec.on { pointer-events: auto; cursor: pointer; }
.hud-spec span { font-size: 14px; opacity: 0.8; }
.hud-help { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; font-size: 13px; font-weight: 700; opacity: 0.85; white-space: nowrap; }
.hud-help kbd { padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.9); color: var(--ink); text-shadow: none; font: 800 12px var(--font); }

.round-card {
  position: absolute;
  left: 50%;
  bottom: 9%;
  width: min(520px, 92vw);
  padding: 18px 22px;
  color: var(--ink);
  text-shadow: none;
  background: rgba(255, 250, 240, 0.95);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), inset 0 -6px 0 rgba(0, 0, 0, 0.08);
  transform: translate(-50%, 140%);
  transition: transform 0.45s cubic-bezier(.3, 1.4, .6, 1);
  pointer-events: none;
}

.round-card.on { transform: translate(-50%, 0); pointer-events: auto; }
.round-card h1 { margin: 4px 0; font-size: clamp(30px, 8vw, 48px); font-weight: 900; }
.round-card p { margin: 6px 0; font-weight: 700; line-height: 1.35; }
.rc-kind { display: inline-block; padding: 3px 10px; border-radius: 12px; font-weight: 900; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: #fff; text-shadow: none; }
.k-race { background: #e2a800; }
.k-survival { background: #2a7fd4; }
.k-final { background: var(--red); }
.rc-goal { font-size: 18px; }
.rc-tip { opacity: 0.8; }
.rc-skip { font-size: 12px; opacity: 0.55; }

/* ----------------------------------------------------------------- touch */

.touch-layer { display: none; }
body.touch .touch-layer { display: block; }
body.touch .hud-help { display: none; }
.stick { position: absolute; width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); border: 3px solid rgba(255, 255, 255, 0.5); opacity: 0; transition: opacity 0.15s; }
.stick.on { opacity: 1; }
.knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
.touch-btns { position: absolute; right: 14px; bottom: 18px; display: grid; grid-template-columns: auto auto; gap: 12px; align-items: end; pointer-events: auto; }
.tbtn { width: 70px; height: 70px; border-radius: 50%; font: 900 15px var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.82); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18); }
.tbtn.jump { width: 92px; height: 92px; font-size: 18px; background: rgba(242, 205, 55, 0.92); grid-column: 2; grid-row: 1 / span 2; }
.tbtn.dive { grid-column: 1; grid-row: 2; background: rgba(120, 190, 255, 0.9); }
.tbtn.grab { grid-column: 1; grid-row: 1; width: 58px; height: 58px; justify-self: end; }

@keyframes pop { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9); opacity: 0.9; } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 600px) {
  .hud-title { font-size: 17px; }
  .hud-goal { font-size: 12px; max-width: 60vw; }
  .hud-counter { font-size: 26px; }
  .hud-place { font-size: 30px; top: 60px; left: 12px; }
  #menu.side { align-items: flex-end; }
  #menu.left { justify-content: center; align-items: flex-end; padding-left: 16px; }
  .panel.title { background: rgba(255, 250, 240, 0.9); }
  .panel.builder { max-height: 55%; }
}
