:root {
  --bg: #0f1117;
  --bg-2: #171a23;
  --card: #1e2230;
  --border: #2b3040;
  --text: #f2f3f7;
  --muted: #9aa1b5;
  --accent: #ff4f7a;
  --accent-2: #ffa64f;
  --ok: #4fe39a;
  --warn: #ffd166;
  --bad: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #27203a 0%, var(--bg) 55%), var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
button:hover { background: #262b3b; border-color: #3a4156; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #ff6a8f; }
button.big { font-size: 1.4rem; padding: 1rem 2.2rem; border-radius: 999px; }
button.danger { border-color: #6a2d35; color: #ffb3b3; }
input[type="text"], input[type="password"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  outline: none;
  width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.app { max-width: 920px; margin: 0 auto; padding: 16px; min-height: 100%; display: flex; flex-direction: column; }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 18px; }
header.top h1 { font-size: 1.15rem; margin: 0; letter-spacing: 0.3px; display: flex; align-items: center; gap: 10px; }
header.top h1 .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: inline-grid; place-items: center; font-size: 15px; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(79, 227, 154, 0.15); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.15); }

main { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- player screens ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 55vh;
  gap: 16px;
}
.stage .big-text { font-size: clamp(1.4rem, 4vw, 2.2rem); font-weight: 600; margin: 0; }
.stage .sub { color: var(--muted); font-size: 1.05rem; margin: 0; max-width: 40ch; }
.countdown {
  font-size: clamp(6rem, 30vw, 14rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
  animation: pop 1s ease-out infinite;
}
@keyframes pop {
  0% { transform: scale(1.08); opacity: 0.6; }
  20% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.bars { display: flex; gap: 6px; align-items: flex-end; height: 70px; }
.bars span { width: 10px; background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 4px; animation: bounce 0.9s ease-in-out infinite; }
.bars span:nth-child(2) { animation-delay: 0.1s; }
.bars span:nth-child(3) { animation-delay: 0.2s; }
.bars span:nth-child(4) { animation-delay: 0.3s; }
.bars span:nth-child(5) { animation-delay: 0.4s; }
.bars span:nth-child(6) { animation-delay: 0.5s; }
.bars span:nth-child(7) { animation-delay: 0.6s; }
@keyframes bounce { 0%, 100% { height: 18px; } 50% { height: 70px; } }
.progress { width: min(420px, 80vw); height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.1s linear; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.reveal { display: grid; grid-template-columns: 160px 1fr; gap: 20px; align-items: center; text-align: left; max-width: 560px; width: 100%; }
.reveal img { width: 160px; height: 160px; border-radius: 12px; object-fit: cover; box-shadow: var(--shadow); background: var(--bg-2); }
.reveal h2 { margin: 0 0 4px; font-size: 1.5rem; }
.reveal .artist { font-size: 1.15rem; margin: 0 0 6px; }
.reveal .album { color: var(--muted); margin: 0 0 12px; }
@media (max-width: 520px) {
  .reveal { grid-template-columns: 1fr; text-align: center; justify-items: center; }
}

.controls-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.volume { display: flex; align-items: center; gap: 10px; min-width: 220px; flex: 1; }
footer { color: var(--muted); font-size: 0.78rem; text-align: center; padding: 18px 0 6px; }

/* ---------- host ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }
.results { list-style: none; margin: 12px 0 0; padding: 0; max-height: 520px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.result { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; background: var(--bg-2); border: 1px solid transparent; }
.result:hover { border-color: var(--border); }
.result.selected { border-color: var(--accent); }
.result img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--card); }
.result .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .meta { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .actions { display: flex; gap: 6px; }
.result .actions button { padding: 0.45rem 0.7rem; font-size: 0.9rem; }
.current { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; }
.current img { width: 96px; height: 96px; border-radius: 10px; object-fit: cover; background: var(--bg-2); }
.current h3 { margin: 0 0 2px; font-size: 1.15rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--bg-2); border-radius: 10px; padding: 10px 12px; }
.stat .n { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 0.8rem; }
.phase-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--bg-2); border: 1px solid var(--border); }
.phase-pill[data-phase="countdown"], .phase-pill[data-phase="playing"] { background: rgba(255, 79, 122, 0.15); border-color: var(--accent); color: #ffb8c9; }
.phase-pill[data-phase="ready"] { background: rgba(79, 227, 154, 0.12); border-color: var(--ok); color: var(--ok); }
.host-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.host-controls select { width: auto; }
.pin-form { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.pin-form input { text-align: center; font-size: 1.4rem; letter-spacing: 0.3em; }
.error-text { color: var(--bad); min-height: 1.4em; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2a1f24; border: 1px solid var(--bad); color: #ffd4d4; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.show { opacity: 1; }
