/* 霓虹涂地 · neon turf */
:root {
  --bg: #05070f;
  --panel: rgba(13, 18, 36, 0.82);
  --line: rgba(140, 200, 255, 0.16);
  --text: #eef4ff;
  --muted: #8d9bbd;
  --cyan: #29e3ff;
  --pink: #ff4d94;
  --yellow: #ffd84d;
  --violet: #a78bfa;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- screens ---------- */
.screens {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  overflow-y: auto;
  pointer-events: none;
}

.screen {
  width: min(430px, 100%);
  pointer-events: auto;
  animation: screenIn 0.35s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* ---------- landing ---------- */
.landing-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 10px 0 4px;
}

.brand { text-align: center; }

.brand-mark {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 10px;
}
.brand-mark i {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
  animation: blink 1.8s infinite ease-in-out;
}
.brand-mark i:nth-child(2) { background: var(--pink); box-shadow: 0 0 12px var(--pink); animation-delay: 0.2s; }
.brand-mark i:nth-child(3) { background: var(--yellow); box-shadow: 0 0 12px var(--yellow); animation-delay: 0.4s; }
.brand-mark i:nth-child(4) { background: var(--violet); box-shadow: 0 0 12px var(--violet); animation-delay: 0.6s; }
@keyframes blink { 0%, 100% { transform: translateY(0); opacity: 1; } 50% { transform: translateY(-4px); opacity: 0.55; } }

h1 {
  margin: 0;
  font-size: clamp(46px, 13vw, 72px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-shadow: 0 0 34px rgba(41, 227, 255, 0.32);
}
h1 span {
  background: linear-gradient(100deg, var(--cyan) 8%, var(--violet) 52%, var(--pink) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(167, 139, 250, 0.5));
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.01em;
}

.join-card {
  width: 100%;
  margin-top: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.join-card label {
  display: block;
  margin: 0 0 8px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

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

#room-input {
  flex: 1;
  min-width: 0;
  height: 54px;
  padding: 0 15px;
  border: 1px solid rgba(140, 200, 255, 0.2);
  border-radius: 14px;
  outline: none;
  background: rgba(5, 9, 20, 0.82);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: border-color 0.18s, box-shadow 0.18s;
}
#room-input::placeholder { color: #58658a; font-weight: 500; }
#room-input:focus {
  border-color: rgba(41, 227, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(41, 227, 255, 0.12);
}
#room-input.shake { animation: shake 0.36s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.join-hint {
  min-height: 16px;
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 12px;
}
.join-hint.err { color: #ff9bbd; }

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 14px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.14s ease, filter 0.18s ease, opacity 0.18s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  color: #04121c;
  background: linear-gradient(135deg, #34e7ff 0%, #8b8bff 100%);
  box-shadow: 0 8px 28px rgba(41, 227, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.09); }
.btn.wide { width: 100%; height: 54px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

#join-btn { height: 54px; padding: 0 22px; flex: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.18s, transform 0.14s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- rules ---------- */
.rules {
  width: 100%;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.rules li {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  color: #b9c6e4;
  font-size: 13px;
}
.rules b {
  font-family: var(--mono);
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 0.1em;
  opacity: 0.85;
}

.p2p-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: #66749a;
  font-size: 11.5px;
  letter-spacing: 0.02em;
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #36f0a5;
  box-shadow: 0 0 8px #36f0a5;
  flex: none;
}

/* ---------- panels (lobby / results) ---------- */
.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.lobby-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}
.conn .live-dot { background: #ffb84d; box-shadow: 0 0 8px #ffb84d; }
.conn.online .live-dot { background: #36f0a5; box-shadow: 0 0 8px #36f0a5; }
.conn.online { color: #c9f8e2; }

.eyebrow {
  margin: 0 0 7px 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.roomcode-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.roomcode {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: clamp(24px, 8.2vw, 36px);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 0 22px rgba(41, 227, 255, 0.38);
}
.roomcode-row .copy { flex: none; height: 42px; }

.lobby-tip {
  margin: 7px 2px 16px;
  color: var(--muted);
  font-size: 12px;
}

.players { display: grid; gap: 8px; margin-bottom: 12px; }

.p-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.035);
  animation: rowIn 0.24s ease both;
}
@keyframes rowIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.p-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c, var(--cyan));
  box-shadow: 0 0 12px var(--c, var(--cyan));
  flex: none;
}
.p-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.p-name em { margin-left: 6px; color: var(--muted); font-style: normal; font-size: 11px; font-weight: 600; }
.p-tag {
  flex: none;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.p-tag.ready { background: rgba(54, 240, 165, 0.14); color: #7df3c4; }

.status {
  min-height: 18px;
  margin: 2px 2px 14px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

.lobby-actions { display: grid; gap: 9px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.row2 .btn { height: 46px; }

.mini-rule {
  margin: 12px 0 0;
  color: #5e6b8d;
  font-size: 11px;
  text-align: center;
}

/* ---------- results ---------- */
.results h2 {
  margin: 0 0 4px;
  font-size: clamp(30px, 9vw, 42px);
  font-weight: 900;
  letter-spacing: 0.01em;
  background: linear-gradient(100deg, #ffffff, #9fe9ff 55%, #ffb4d2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.result-sub {
  min-height: 18px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12.5px;
}
.rank { display: grid; gap: 8px; margin-bottom: 16px; }
.rank-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}
.rank-row.me { border-color: rgba(41, 227, 255, 0.28); background: rgba(41, 227, 255, 0.07); }
.rank-num { color: var(--muted); font-family: var(--mono); font-size: 12px; font-weight: 700; }
.rank-main { min-width: 0; }
.rank-name {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}
.rank-name em { color: var(--muted); font-style: normal; font-size: 11px; font-weight: 600; }
.rank-bar { height: 6px; overflow: hidden; border-radius: 4px; background: rgba(255, 255, 255, 0.08); }
.rank-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--c, var(--cyan));
  box-shadow: 0 0 10px var(--c, var(--cyan));
  transition: width 0.6s cubic-bezier(0.22, 0.9, 0.3, 1);
}
.rank-pct { text-align: right; font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--text); }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: calc(9px + var(--safe-top)) 12px 0;
  pointer-events: none;
}
.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(640px, 100%);
}
#hud-leave { pointer-events: auto; flex: none; font-size: 12px; min-width: 34px; height: 34px; padding: 0 8px; }
.timer {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#timer-text {
  color: #f4f8ff;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-shadow: 0 0 16px rgba(41, 227, 255, 0.4);
  font-variant-numeric: tabular-nums;
}
.timer-bar {
  flex: 1;
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
}
.timer-bar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #34e7ff, #8b8bff);
  box-shadow: 0 0 9px rgba(41, 227, 255, 0.55);
}
.timer.urgent #timer-text { color: #ff8ab6; text-shadow: 0 0 18px rgba(255, 77, 148, 0.6); animation: urgent 0.8s infinite; }
.timer.urgent .timer-bar i { background: linear-gradient(90deg, #ff4d94, #ff8a5b); }
@keyframes urgent { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.room-mini {
  max-width: 92px;
  overflow: hidden;
  color: rgba(200, 216, 255, 0.5);
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: none;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  width: min(640px, 100%);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  background: rgba(8, 12, 26, 0.55);
  color: #b9c6e4;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 0.2s, color 0.2s;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); box-shadow: 0 0 7px var(--c); }
.chip.me { border-color: rgba(255, 255, 255, 0.3); color: #fff; }
.chip b { color: var(--c); font-weight: 800; }

.spectate {
  padding: 6px 13px;
  border: 1px solid rgba(255, 216, 77, 0.3);
  border-radius: 999px;
  background: rgba(255, 216, 77, 0.1);
  color: #ffe9a3;
  font-size: 11.5px;
  font-weight: 700;
}

/* ---------- foot ---------- */
.foot {
  position: fixed;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 20;
  width: min(640px, calc(100% - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}
.paintbar {
  display: flex;
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
}
.paintbar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
  transition: width 0.35s ease;
}
.paintbar i:first-child { border-radius: 4px 0 0 4px; }
.foot-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  color: rgba(170, 187, 220, 0.42);
  font-size: 10px;
  letter-spacing: 0.04em;
}
#foot-room { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- overlays ---------- */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(41, 227, 255, 0.06), rgba(5, 7, 15, 0.3) 60%);
}
#countdown-num {
  color: #fff;
  font-family: var(--font);
  font-size: clamp(90px, 30vw, 190px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 40px rgba(41, 227, 255, 0.65), 0 0 110px rgba(139, 139, 255, 0.45);
}
#countdown-num.pop { animation: countPop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
#countdown-num.go { font-size: clamp(64px, 20vw, 140px); color: #7dffc4; text-shadow: 0 0 46px rgba(54, 240, 165, 0.8); }
@keyframes countPop { 0% { opacity: 0; transform: scale(1.9); } 55% { opacity: 1; transform: scale(0.94); } 100% { transform: scale(1); } }

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(52px + var(--safe-bottom));
  z-index: 25;
  padding: 9px 16px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(8, 12, 26, 0.72);
  color: #cfdcf7;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: hintFloat 2.4s ease-in-out infinite;
}
@keyframes hintFloat { 0%, 100% { transform: translate(-50%, 0); opacity: 0.9; } 50% { transform: translate(-50%, -5px); opacity: 1; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 40;
  max-width: calc(100% - 36px);
  padding: 10px 16px;
  transform: translate(-50%, 12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 13px;
  background: rgba(14, 20, 40, 0.94);
  color: #eaf1ff;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 360px) {
  .brand { margin-top: -4px; }
  .tagline { font-size: 12.5px; }
  .rules li { padding: 8px 12px; font-size: 12px; }
  #join-btn { padding: 0 16px; }
  #timer-text { font-size: 19px; }
  .chip { padding: 3px 7px; font-size: 10px; }
}

@media (max-height: 640px) {
  .brand-mark { display: none; }
  h1 { font-size: 40px; }
  .tagline { margin-top: 6px; font-size: 12px; }
  .rules { gap: 6px; }
  .rules li { padding: 7px 12px; }
  .p2p-note { display: none; }
  .landing-wrap { gap: 11px; }
}
