:root {
  --bg: #05080a;
  --ink: #e9f3ee;
  --muted: #8fa39a;
  --goo: #4dff7a;
  --accent: #ff8a1c;
  --card: rgba(10, 16, 18, 0.86);
  --line: rgba(120, 255, 160, 0.22);
  --danger: #ff4a4a;
  --display: 'Orbitron', 'Segoe UI', system-ui, sans-serif;
  --body: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: background 0.15s, transform 0.08s;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  width: 100%;
  border: none;
  color: #062010;
  background: linear-gradient(180deg, #8bff9f, #2fd45a);
  box-shadow: 0 0 24px rgba(77, 255, 122, 0.35);
  font-family: var(--display);
  font-size: 15px;
  text-transform: uppercase;
}
button.primary:hover { background: linear-gradient(180deg, #a6ffb6, #3be468); }

input {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
  user-select: text;
}
input:focus { outline: 2px solid var(--goo); outline-offset: 1px; }

/* Lobby */
#lobby {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.6));
  overflow-y: auto;
}
.card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 24px 20px;
  backdrop-filter: blur(6px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 80px rgba(77, 255, 122, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(30px, 8vw, 40px);
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(255, 138, 28, 0.5);
}
h1 span { display: block; color: var(--goo); text-shadow: 0 0 18px rgba(77, 255, 122, 0.6); }
.tagline { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.3; }
#join-view, #room-view, #host-controls { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
#code { text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--display); text-align: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.room-head { display: flex; align-items: baseline; gap: 10px; color: var(--muted); }
.room-head b { font-family: var(--display); font-size: 34px; letter-spacing: 0.25em; color: var(--ink); }
#invite { font-size: 14px; color: var(--muted); }

#slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#slots li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 4px solid var(--c);
}
#slots li.empty { opacity: 0.5; }
#slots .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); flex: none; }
#slots .who { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#slots .badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); color: var(--muted); }
#slots .badge.you { background: var(--goo); color: #062010; }

/* Host settings */
#settings { display: grid; gap: 8px; }
.setting { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 8px; }
.setting .label { color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  flex: 1 1 auto;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 8px;
  white-space: nowrap;
}
.seg button.on { background: var(--goo); color: #062010; border-color: transparent; }
.seg button:disabled { opacity: 1; cursor: default; }
.seg button:disabled:not(.on) { opacity: 0.45; }
#mode-blurb { margin: -2px 0 0 64px; color: var(--muted); font-size: 13px; line-height: 1.3; }
#mode-blurb:empty { display: none; }

.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; cursor: pointer; }
.check input { accent-color: var(--goo); width: 18px; height: 18px; }
#wait-msg, #last-result { margin: 0; color: var(--muted); text-align: center; }
#last-result:empty { display: none; }
#last-result b { color: var(--ink); }
.error { margin: 0; color: var(--danger); min-height: 0; }
.error:empty { display: none; }
.controls { border-top: 1px solid var(--line); padding-top: 12px; color: var(--muted); font-size: 14px; display: grid; gap: 4px; }
kbd {
  font-family: var(--body);
  font-weight: 700;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--ink);
}

/* In-game HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#clock { position: absolute; top: 14px; left: 18px; }
#timer {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 6vw, 56px);
  color: var(--accent);
  text-shadow: 0 0 14px rgba(255, 138, 28, 0.7), 0 2px 4px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
#timer.low { color: var(--danger); text-shadow: 0 0 16px rgba(255, 60, 60, 0.9); animation: pulse 0.5s infinite alternate; }
#round-label { font-family: var(--display); font-size: 12px; letter-spacing: 0.18em; color: var(--ink); margin-top: 4px; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.8); }
#mode-label { font-family: var(--display); font-size: 10px; letter-spacing: 0.16em; color: var(--accent); margin-top: 3px; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.8); }

#banner {
  position: absolute;
  top: 28%;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0 16px;
}
#banner-main {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(32px, 9vw, 84px);
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 0 24px var(--bc, var(--goo)), 0 4px 0 rgba(0, 0, 0, 0.5);
}
#banner-main.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
#banner-sub { font-family: var(--display); font-size: clamp(13px, 2.4vw, 18px); color: var(--ink); opacity: 0.85; margin-top: 8px; letter-spacing: 0.1em; }

#feed { position: absolute; top: 16px; right: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 60vw; }
#feed div {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 15px;
  animation: slide 0.25s ease-out;
  transition: opacity 0.5s;
}
#feed b { color: var(--c, #fff); }

#spectate {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 14px;
  border-radius: 99px;
  color: var(--muted);
  white-space: nowrap;
}

#panels {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  display: flex;
  justify-content: center;
  gap: clamp(8px, 3vw, 40px);
  padding: 0 12px;
}
.panel { display: flex; align-items: center; gap: 8px; min-width: 0; transition: opacity 0.3s, filter 0.3s; }
.panel.out { opacity: 0.4; filter: grayscale(0.8); }
.gauge {
  --p: 1;
  width: clamp(40px, 7vw, 64px);
  aspect-ratio: 1;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.75) 54%, transparent 56%),
    conic-gradient(var(--c) calc(var(--p) * 360deg), rgba(255, 255, 255, 0.12) 0);
  box-shadow: 0 0 14px color-mix(in srgb, var(--c) 50%, transparent);
}
.gauge.ready { box-shadow: 0 0 22px var(--c); }
.gauge { position: relative; }
.gauge span { font-family: var(--display); font-weight: 700; font-size: clamp(10px, 1.6vw, 14px); color: var(--c); }
.gauge .power {
  position: absolute;
  right: -10px;
  top: -12px;
  width: clamp(22px, 3.4vw, 32px);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  background: #000;
}
.gauge .power img { display: block; width: 100%; aspect-ratio: 1; }
.gauge .power i { display: block; height: 3px; background: #fff; transition: width 0.2s linear; }
.gauge .power.hot { animation: pulse 0.25s infinite alternate; box-shadow: 0 0 14px #ff3b30; }
.info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.info .name { text-shadow: 0 1px 3px #000, 0 0 6px #000; font-weight: 700; font-size: clamp(13px, 1.8vw, 17px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 18vw; }
.pips { display: flex; gap: 4px; }
.pips i { width: clamp(16px, 3vw, 30px); height: 8px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
.pips i.on { background: var(--c); box-shadow: 0 0 8px var(--c); }
.kos { font-size: 12px; color: var(--muted); }

/* Name tags above balls */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 700;
  font-size: 14px;
  color: color-mix(in srgb, var(--c) 55%, #fff);
  text-shadow: 0 0 4px #000, 0 1px 2px #000;
  white-space: nowrap;
}
.tag.me { color: var(--c); font-size: 15px; }
.tag.me::after { content: '▼'; display: block; text-align: center; font-size: 11px; line-height: 1; }
.tag.toast { color: #fff; font-family: var(--display); font-size: 16px; letter-spacing: 0.05em; text-shadow: 0 0 8px #000, 0 0 2px #000; }
.tag.toast::after { content: none; }

#sound {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  display: flex;
  gap: 6px;
}
#sound button {
  min-width: 40px;
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.4);
}
#sound button.off { opacity: 0.4; text-decoration: line-through; }
body.in-game #sound { bottom: auto; top: 14px; right: auto; left: 50%; transform: translateX(-50%); }

/* Touch controls */
#touch { position: fixed; inset: 0; touch-action: none; }
#stick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 55%; }
#stick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
  display: none;
}
#stick-knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); }
#dash-btn {
  position: absolute;
  right: 22px;
  bottom: 110px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  font-family: var(--display);
  background: rgba(77, 255, 122, 0.2);
  border: 2px solid var(--goo);
}

@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { to { opacity: 0.6; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }

@media (max-width: 640px) {
  .info .kos { display: none; }
  #panels { gap: 6px; }
  .panel { gap: 4px; }
  .info .name { max-width: 14vw; font-size: 12px; }
  #feed div { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  #banner-main.pop, #timer.low, #feed div { animation: none; }
}
