:root {
  --ink: #f6f1ff;
  --ink-soft: #b7a9d6;
  --night: #120a24;
  --night-2: #1b1035;
  --panel: rgba(30, 18, 58, 0.86);
  --pink: #ff5d8f;
  --pink-2: #ff8fb0;
  --cyan: #59c9ff;
  --yellow: #ffd166;
  --green: #7cf29c;
  --line: rgba(255, 255, 255, 0.12);
  --radius: 22px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }

#app, .screen { height: 100%; }

.screen[hidden] { display: none; }

/* ---------------------------------------------------------------- menu */

.menu-screen {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 48px);
  background:
    radial-gradient(1200px 600px at 15% 0%, rgba(255, 93, 143, 0.18), transparent 60%),
    radial-gradient(900px 500px at 90% 100%, rgba(89, 201, 255, 0.16), transparent 60%),
    linear-gradient(160deg, #160b2b 0%, #120a24 55%, #0c0618 100%);
}

.menu-glow {
  position: absolute;
  inset: auto -20% -40% -20%;
  height: 60%;
  background: radial-gradient(closest-side, rgba(255, 93, 143, 0.16), transparent);
  pointer-events: none;
}

.menu-grid {
  position: relative;
  width: min(1060px, 100%);
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: clamp(22px, 4vw, 56px);
  align-items: center;
}

.menu-hero { display: grid; justify-items: start; }

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.menu-hero h1 {
  margin: 6px 0 0;
  font-size: clamp(46px, 9vw, 96px);
  line-height: 0.92;
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, #fff 10%, var(--pink-2) 45%, var(--cyan) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 8px 30px rgba(255, 93, 143, 0.25));
}

.subtitle {
  margin: 10px 0 4px;
  font-size: clamp(16px, 2vw, 22px);
  color: var(--ink-soft);
}

.mascot {
  width: clamp(150px, 22vw, 220px);
  margin: 18px 0 8px;
  animation: float 4.5s ease-in-out infinite;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.4));
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-12px) rotate(1.5deg); }
}

.howto {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 14.5px;
  color: var(--ink-soft);
}

.howto li:first-child { color: var(--ink); font-size: 15px; margin-bottom: 2px; }

.howto li::before {
  content: "◆";
  color: var(--pink);
  margin-right: 9px;
  font-size: 10px;
  vertical-align: 2px;
}

.howto li:first-child::before { content: ""; margin: 0; }

.menu-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(20px, 3vw, 30px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: grid;
  gap: 14px;
}

.field { display: grid; gap: 7px; font-size: 13px; color: var(--ink-soft); }

.field input,
.field select,
.join-row input {
  width: 100%;
  padding: 13px 15px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(9, 5, 20, 0.6);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.join-row input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 93, 143, 0.22);
}

.btn {
  border: 0;
  border-radius: 16px;
  padding: 14px 20px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.07); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn.primary {
  background: linear-gradient(120deg, var(--pink), #ff7a5c);
  color: #2a0a1c;
  box-shadow: 0 12px 26px rgba(255, 93, 143, 0.28);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  border: 1px solid var(--line);
}

.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.join-row input { text-transform: uppercase; letter-spacing: 0.22em; font-weight: 700; }

.tip { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-soft); }

.fine-print { margin: 0; font-size: 12px; color: rgba(183, 169, 214, 0.7); display: flex; align-items: center; gap: 7px; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 10px currentColor;
}
.dot.online { background: var(--green); }
.dot.offline { background: var(--pink); }

.form-error { margin: 0; min-height: 18px; font-size: 13px; color: #ffb3c6; }

/* ---------------------------------------------------------------- game */

.game-screen { position: relative; background: #0a0517; }

#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
  pointer-events: none;
  z-index: 3;
}

.hud-left { display: flex; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(18, 10, 36, 0.72);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.chip strong { color: var(--ink); letter-spacing: 0.16em; }

.chip-button { pointer-events: auto; cursor: pointer; color: var(--ink); }
.chip-button:hover { border-color: var(--pink); }
.chip[hidden] { display: none; }

.hud-timer {
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(18, 10, 36, 0.72);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.hud-timer strong { color: var(--ink); font-size: 17px; margin-left: 4px; font-variant-numeric: tabular-nums; }

.scores {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: grid;
  gap: 4px;
  min-width: 150px;
  max-width: 210px;
  background: rgba(18, 10, 36, 0.62);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}

.scores li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 9px;
  color: var(--ink-soft);
}

.scores li.me { background: rgba(255, 255, 255, 0.09); color: var(--ink); }

.scores .swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.scores .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores .pts { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

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

.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(16px, env(safe-area-inset-left)) max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  pointer-events: none;
}

.touch button {
  pointer-events: auto;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(24, 14, 46, 0.6);
  color: var(--ink);
  font-size: 22px;
  backdrop-filter: blur(8px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch button:active { background: rgba(255, 93, 143, 0.45); }

.touch-move, .touch-action { display: flex; gap: 12px; }

.touch .web { background: rgba(89, 201, 255, 0.28); }
.touch .jump { background: rgba(255, 93, 143, 0.28); }

@media (pointer: coarse), (hover: none) {
  .touch { display: flex; }
}

/* ------------------------------------------------------------ overlay */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(8, 4, 18, 0.62);
  backdrop-filter: blur(7px);
  padding: 20px;
}

.overlay[hidden] { display: none; }

.overlay-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card h2 { margin: 0 0 8px; font-size: 30px; }
.overlay-card p { margin: 0; color: var(--ink-soft); }

.overlay-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.overlay-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 15px;
}

.overlay-list .rank { width: 22px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.overlay-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overlay-list .pts { font-weight: 700; }
.overlay-list li.winner { background: linear-gradient(120deg, rgba(255, 93, 143, 0.3), rgba(89, 201, 255, 0.22)); }

/* -------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(24, 14, 46, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 20;
  font-size: 14px;
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 760px) {
  .menu-grid { grid-template-columns: 1fr; gap: 20px; }
  .menu-hero { justify-items: center; text-align: center; }
  .howto { text-align: left; }
  .mascot { width: 132px; margin: 10px 0 4px; }
  .menu-screen { place-items: start center; }
  .menu-panel { width: 100%; }
  .scores { min-width: 118px; max-width: 150px; font-size: 12px; }
  .chip { font-size: 12px; padding: 7px 10px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud { padding-top: 8px; }
  .touch button { width: 56px; height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot { animation: none; }
  .btn { transition: none; }
}
