:root {
  --bg: #070b14;
  --p1: #ff8a3d;
  --p1-soft: rgba(255, 138, 61, 0.16);
  --p2: #39d7ff;
  --p2-soft: rgba(57, 215, 255, 0.16);
  --gold: #ffd166;
  --ink: #eef4ff;
  --muted: #8fa0bd;
  --card: rgba(12, 21, 38, 0.92);
  --line: rgba(255, 255, 255, 0.09);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, #16223c 0%, #0a1020 42%, #04060c 100%);
  color: var(--ink);
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame {
  position: relative;
  width: min(100vw, calc(100dvh * 1.6), 1200px);
  aspect-ratio: 8 / 5;
  max-height: 100dvh;
  overflow: hidden;
  background: #080e1a;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.65);
  container-type: size;
  touch-action: none;
  user-select: none;
}

@media (min-width: 900px) {
  .frame {
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.07);
  }
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ------------------------------------------------------------------- hud */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: clamp(6px, 1.2cqw, 18px);
  padding: clamp(8px, 1.6cqw, 22px) clamp(8px, 1.8cqw, 24px);
  pointer-events: none;
}

.player-card {
  display: flex;
  align-items: center;
  gap: clamp(6px, 0.8cqw, 12px);
  max-width: min(30cqw, 260px);
  padding: clamp(6px, 0.85cqw, 13px) clamp(8px, 1.1cqw, 16px);
  border-radius: clamp(9px, 1.1cqw, 15px);
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}

.player-card.right {
  justify-self: end;
}

.player-card.you {
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 10px 30px rgba(0, 0, 0, 0.4);
}

.player-card.pulse {
  animation: cardPulse 0.5s ease;
}

@keyframes cardPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.pip {
  width: clamp(8px, 1.05cqw, 15px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--p1);
  box-shadow: 0 0 12px rgba(255, 138, 61, 0.85);
  flex: none;
}

#card-1 .pip {
  background: var(--p2);
  box-shadow: 0 0 12px rgba(57, 215, 255, 0.85);
}

.player-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.player-name {
  font-size: clamp(11px, 1.25cqw, 19px);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 18cqw;
}

.player-sub {
  font-size: clamp(8px, 0.75cqw, 11px);
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 600;
}

.player-sub.you-tag {
  color: var(--gold);
}

.player-score {
  margin-left: auto;
  font-size: clamp(20px, 2.9cqw, 42px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#card-1 .player-score {
  margin-left: 0;
  margin-right: auto;
}

#card-1 {
  flex-direction: row-reverse;
  text-align: right;
}

#card-1 .player-meta {
  align-items: flex-end;
}

.clock-wrap {
  text-align: center;
  padding-top: clamp(2px, 0.4cqw, 6px);
  min-width: 14cqw;
}

.clock {
  font-size: clamp(24px, 3.6cqw, 52px);
  font-weight: 800;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-shadow: 0 0 24px rgba(255, 209, 102, 0.25);
}

.clock.urgent {
  color: #ff6b6b;
  text-shadow: 0 0 26px rgba(255, 80, 80, 0.6);
  animation: urgentPulse 0.9s ease-in-out infinite;
}

@keyframes urgentPulse {
  50% { transform: scale(1.07); }
}

.clock-label {
  font-size: clamp(7px, 0.7cqw, 11px);
  letter-spacing: 0.24em;
  color: var(--muted);
  font-weight: 700;
  margin-top: 3px;
}

.round-label {
  display: inline-block;
  margin-top: clamp(3px, 0.5cqw, 7px);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: clamp(7px, 0.66cqw, 10px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--gold);
  background: rgba(255, 209, 102, 0.1);
  border: 1px solid rgba(255, 209, 102, 0.25);
}

.sound-btn {
  position: absolute;
  right: clamp(8px, 1.4cqw, 18px);
  bottom: clamp(8px, 1.4cqw, 18px);
  z-index: 6;
  padding: 6px 10px;
  font-family: var(--font);
  font-size: clamp(8px, 0.7cqw, 11px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  background: rgba(8, 15, 28, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.sound-btn:hover {
  color: var(--ink);
}

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(4, 8, 16, 0.76);
  backdrop-filter: blur(10px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#menu {
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(255, 138, 61, 0.14), transparent 60%),
    radial-gradient(80% 60% at 50% 120%, rgba(57, 215, 255, 0.1), transparent 60%),
    rgba(4, 8, 16, 0.9);
}

.menu-card,
.panel-card {
  width: min(100%, 430px);
  background: linear-gradient(180deg, rgba(20, 32, 56, 0.98), rgba(9, 16, 30, 0.98));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 30px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand-ring {
  width: 26px;
  height: 12px;
  border: 3px solid var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.5);
  transform: rotate(-12deg);
}

.brand-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.32em;
  color: var(--gold);
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 5.4vw, 38px);
  line-height: 1.04;
  letter-spacing: -0.03em;
  font-weight: 800;
}

h1 em {
  font-style: normal;
  color: var(--gold);
}

.lede {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

input {
  width: 100%;
  padding: 13px 15px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  background: rgba(4, 9, 18, 0.75);
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: rgba(255, 209, 102, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.12);
}

input::placeholder {
  color: #5c6b85;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn:active {
  transform: scale(0.985);
}

.btn.primary {
  color: #1a1204;
  background: linear-gradient(180deg, #ffd97a, #ffb936);
  border-color: rgba(255, 209, 102, 0.6);
  box-shadow: 0 10px 30px rgba(255, 174, 52, 0.28);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #ffe08f, #ffc247);
}

.btn.block {
  width: 100%;
  margin-top: 16px;
}

.btn.tiny {
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 10px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn.readying {
  color: var(--gold);
  background: rgba(255, 209, 102, 0.1);
  border-color: rgba(255, 209, 102, 0.35);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 14px;
  color: #64748f;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.join-row {
  display: flex;
  gap: 10px;
}

.join-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-weight: 700;
  text-align: center;
}

.join-row .btn {
  flex: none;
}

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

.fineprint {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: #63718c;
}

/* ----------------------------------------------------------------- lobby */
.eyebrow {
  margin: 0 0 12px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--gold);
}

.code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-code {
  font-size: clamp(34px, 8vw, 46px);
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1;
  text-shadow: 0 0 30px rgba(255, 209, 102, 0.25);
}

.invite-link {
  margin-top: 14px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  text-overflow: ellipsis;
}

.seats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(5, 11, 22, 0.55);
}

.seat.empty {
  border-style: dashed;
  color: #63718c;
  font-size: 14px;
}

.seat .pip {
  width: 10px;
}

.seat-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
}

.seat-tag.ready {
  color: #7ef0a5;
  border-color: rgba(126, 240, 165, 0.35);
  background: rgba(126, 240, 165, 0.08);
}

.seat-tag.you {
  color: var(--gold);
  border-color: rgba(255, 209, 102, 0.3);
}

.mode-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.mode-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.mode-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(5, 11, 22, 0.55);
}

.mode-option {
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}

.mode-option:hover {
  color: var(--ink);
}

.mode-option.active {
  color: #1a1204;
  background: linear-gradient(180deg, #ffd97a, #ffb936);
  box-shadow: 0 4px 14px rgba(255, 174, 52, 0.28);
}

.mode-option:disabled {
  cursor: default;
  opacity: 0.6;
}

.status {
  min-height: 16px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

.link-btn {
  display: block;
  margin: 16px auto 0;
  padding: 6px;
  background: none;
  border: 0;
  color: #6f7f9c;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: var(--ink);
}

/* ---------------------------------------------------------------- result */
.result-card {
  text-align: center;
}

.result-card h2 {
  margin: 0 0 6px;
  font-size: clamp(26px, 6vw, 34px);
  letter-spacing: -0.02em;
}

.result-score {
  font-size: clamp(40px, 11vw, 58px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(255, 209, 102, 0.28);
  margin: 10px 0 2px;
}

/* -------------------------------------------------------------- countdown */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(70px, 19cqw, 220px);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-shadow: 0 0 60px rgba(255, 209, 102, 0.4);
  background: rgba(4, 8, 16, 0.18);
}

.countdown.pop {
  animation: countPop 0.55s cubic-bezier(0.2, 1.6, 0.35, 1);
}

@keyframes countPop {
  0% { transform: scale(0.4); opacity: 0; }
  55% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(12, 22, 40, 0.96);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  animation: toastIn 0.22s ease;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.toast.score {
  color: #1a1204;
  background: linear-gradient(180deg, #ffe08f, #ffc247);
  border-color: rgba(255, 209, 102, 0.7);
}

#disconnect {
  z-index: 60;
}

@media (max-width: 640px) {
  .player-sub {
    display: none;
  }

  .menu-card,
  .panel-card {
    padding: 24px;
    border-radius: 20px;
  }

  .player-name {
    max-width: 22vw;
  }

  .clock-label {
    display: none;
  }
}

@media (max-height: 520px) {
  .menu-card,
  .panel-card {
    padding: 18px 22px;
  }

  .menu-card h1 {
    font-size: 24px;
  }

  .lede {
    display: none;
  }

  .brand {
    margin-bottom: 10px;
  }

  .divider {
    margin: 12px 0 10px;
  }

  .fineprint {
    display: none;
  }
}
