:root {
  --bg: #05010f;
  --panel: rgba(18, 8, 44, 0.84);
  --border: rgba(155, 92, 255, 0.45);
  --text: #f2ecff;
  --muted: #a99bd0;
  --accent: #9b5cff;
  --good: #3dffa0;
  --bad: #ff4d6d;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
}

[hidden] { display: none !important; }

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

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 0.6em 1.1em;
  transition: transform 0.08s, background 0.15s;
  touch-action: manipulation;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary {
  background: linear-gradient(135deg, #ff3d7f, #9b5cff);
  border: none;
  font-weight: 700;
  font-size: 1.05rem;
}
button.ghost { background: transparent; }
button.wide { width: 100%; padding: 0.85em; margin-top: 8px; }
button.small { display: block; margin: 12px auto 0; font-size: 0.85rem; padding: 0.4em 0.9em; }

kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.8em;
  padding: 0.1em 0.45em;
  border: 1px solid currentColor;
  border-radius: 6px;
  opacity: 0.8;
}

select, input {
  width: 100%;
  padding: 0.6em 0.75em;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 10px;
}
select:disabled, input:disabled { opacity: 0.75; }
select option { background: #160a33; }

/* --- Panels ---------------------------------------------------------------- */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 0 60px rgba(155, 92, 255, 0.25);
  z-index: 10;
}
.panel.bottom {
  top: auto;
  bottom: 16px;
  transform: translateX(-50%);
  max-height: 60dvh;
  text-align: center;
  animation: pop-in 0.18s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translate(-50%, 20px) scale(0.96); }
}

h1 {
  margin: 0 0 4px;
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-align: center;
}
h1 span {
  background: linear-gradient(90deg, #ff3d7f, #ffd23d, #3dd6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
h2 {
  font-size: 0.9rem;
  margin: 20px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
h3 { margin: 0 0 14px; font-size: 1.3rem; }
.tagline, .hint { color: var(--muted); text-align: center; font-size: 0.92rem; line-height: 1.45; }
.hint { font-size: 0.85rem; }
.error { color: var(--bad); min-height: 1.2em; text-align: center; margin: 10px 0 0; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); margin: 18px 0 6px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#join-code {
  text-transform: uppercase;
  letter-spacing: 0.4em;
  font-weight: 800;
  font-size: 1.3rem;
  text-align: center;
}

/* --- Lobby ----------------------------------------------------------------- */
.room-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.room-header small { color: var(--muted); letter-spacing: 0.15em; }
#room-code {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.25em;
  background: linear-gradient(90deg, #ff3d7f, #ffd23d, #3dd6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#lobby-players { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
#lobby-players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--color);
  background: color-mix(in srgb, var(--color) 15%, transparent);
  font-weight: 600;
}
#lobby-players li.offline { opacity: 0.4; }
#lobby-players .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color); box-shadow: 0 0 10px var(--color); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
#custom-row { grid-column: 1 / -1; }

.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

/* --- HUD ------------------------------------------------------------------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: 16px 22px;
  pointer-events: none;
  z-index: 5;
}
body[data-phase='home'] #hud, body[data-phase='lobby'] #hud { display: none; }
#round { font-weight: 700; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
#status { font-size: 1.2rem; font-weight: 700; text-align: center; text-shadow: 0 0 18px var(--accent); }
#points {
  justify-self: end;
  font-size: 2.4rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--good);
  text-shadow: 0 0 20px var(--good);
}

#countdown {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28vmin;
  font-weight: 900;
  pointer-events: none;
  z-index: 6;
  text-shadow: 0 0 40px var(--accent), 0 0 80px var(--accent);
}
#countdown.tick { animation: count 0.9s ease-out; }
@keyframes count {
  from { transform: scale(1.6); opacity: 0; }
  25% { opacity: 1; }
  to { transform: scale(0.8); opacity: 0; }
}

#banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: #ffd23d;
  color: #1a0b33;
  font-weight: 800;
  z-index: 20;
  cursor: pointer;
}

/* --- Answering ------------------------------------------------------------- */
#choice-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  text-align: left;
  padding: 0.75em 0.9em;
  min-width: 0;
}
.choice .num {
  grid-row: span 2;
  align-self: center;
  font-family: ui-monospace, monospace;
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--accent);
}
.choice strong, .choice small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice small { color: var(--muted); }
.choice.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 25%, transparent); opacity: 1; }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 25%, transparent); opacity: 1; }

#type-box { position: relative; text-align: left; }
#guess { font-size: 1.1rem; padding: 0.75em 0.9em; }
#suggestions { list-style: none; margin: 6px 0 0; padding: 0; }
#suggestions li {
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#suggestions li small { color: var(--muted); }
#suggestions li.active, #suggestions li:hover { background: rgba(155, 92, 255, 0.35); }
#guesses { list-style: none; margin: 8px 0 0; padding: 0; color: var(--bad); text-decoration: line-through; font-size: 0.9rem; }

#feedback { font-size: 1.25rem; font-weight: 800; margin: 12px 0 0; min-height: 1.4em; }
#feedback.good { color: var(--good); }
#feedback.bad { color: var(--bad); }

/* --- Reveal ---------------------------------------------------------------- */
#my-result { font-size: 1.3rem; font-weight: 800; margin: 0; }
#reveal-title { font-size: 1.7rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 8px 0 2px; }
#reveal-artist { color: var(--muted); margin: 0 0 10px; font-size: 1.1rem; }
#results { list-style: none; padding: 0; margin: 0; text-align: left; }
#results li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 6px 10px;
  border-left: 4px solid var(--color);
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
#results .time { color: var(--muted); }
#results .pts { font-weight: 800; color: var(--good); min-width: 4.5em; text-align: right; }
#results li.miss .pts { color: var(--bad); }

.bar {
  height: 6px;
  margin-top: 14px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--good), #ffd23d, var(--bad));
  transform-origin: left;
}

/* --- Game over ------------------------------------------------------------- */
#ranking { list-style: none; padding: 0; margin: 20px 0; }
#ranking li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 5px solid var(--color);
  font-size: 1.15rem;
}
#ranking li:first-child { font-size: 1.4rem; background: rgba(255, 255, 255, 0.1); }
#ranking .score { font-weight: 900; font-variant-numeric: tabular-nums; color: var(--color); }

/* Wide screens: keep in-round panels beside the stage so the podiums stay visible. */
@media (min-width: 1100px) {
  .panel.bottom {
    left: auto;
    right: 28px;
    top: 50%;
    bottom: auto;
    width: 440px;
    max-height: calc(100dvh - 120px);
    transform: translateY(-50%);
    animation-name: slide-in;
  }
  #choice-buttons { grid-template-columns: 1fr; }
}
@keyframes slide-in {
  from { opacity: 0; transform: translate(30px, -50%); }
}

@media (max-width: 600px) {
  h1 { font-size: 2rem; }
  .panel { padding: 18px; }
  .grid { grid-template-columns: 1fr; }
  #status { font-size: 0.95rem; }
  #points { font-size: 1.6rem; }
  #hud { padding: 10px 12px; }
  .choice { padding: 0.6em 0.7em; }
}
