:root {
  --bg: #0f1117;
  --bg-2: #161a23;
  --panel: #1b202b;
  --panel-2: #222836;
  --line: #2c3343;
  --text: #e9ecf2;
  --muted: #8d96a8;
  --a: #ff6b5b;
  --a-soft: rgba(255, 107, 91, 0.14);
  --b: #36c5c0;
  --b-soft: rgba(54, 197, 192, 0.14);
  --accent: #f4c04e;
  --twitch: #a970ff;
  --kick: #53fc18;
  --web: #6aa7ff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1c2232 0%, transparent 60%), var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.narrow { max-width: 620px; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.02em; text-decoration: none; color: var(--text); }
.brand .logo { display: inline-grid; grid-template-columns: 1fr 1fr; width: 26px; height: 26px; border-radius: 7px; overflow: hidden; }
.brand .logo i:first-child { background: var(--a); }
.brand .logo i:last-child { background: var(--b); }
.room-title { font-size: 1.05rem; color: var(--muted); }
.room-title strong { color: var(--text); }

h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0 0 6px; line-height: 1.15; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

label.field { display: block; }
label.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
input[type='text'], input[type='number'], input[type='url'], select {
  width: 100%; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: #3d4659; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1503; }
.btn.a { background: var(--a); border-color: var(--a); color: #210604; }
.btn.b { background: var(--b); border-color: var(--b); color: #021715; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 0.85rem; border-radius: 8px; }
.btn.lg { padding: 14px 22px; font-size: 1.05rem; }

.copy-box { display: flex; gap: 8px; }
.copy-box input { font-family: var(--mono); font-size: 0.9rem; }

.err-text { color: var(--err); min-height: 1.2em; font-size: 0.9rem; }

/* toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 420px); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
.toast.error { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

/* song list */
.songs { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.songs li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; }
.songs .t { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.songs .t a { color: var(--text); text-decoration: none; }
.songs .by { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.pill { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.pill.youtube { color: #ff5c5c; } .pill.spotify { color: #1ed760; } .pill.soundcloud { color: #ff7a1a; }
.pill.apple { color: #fa5d7b; } .pill.suno { color: #f2e15b; }
.pill.twitch { color: var(--twitch); } .pill.kick { color: var(--kick); } .pill.web { color: var(--web); }

/* match */
.match-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.round-name { font-weight: 800; font-size: 1.2rem; }
.timer { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; padding: 4px 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); }
.timer.low { color: var(--err); border-color: var(--err); }
.status-chip { font-size: 0.8rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.status-chip.open { color: var(--ok); border-color: var(--ok); }

.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: start; }
.vs-mark { align-self: center; font-weight: 900; color: var(--muted); font-size: 1.2rem; }
@media (max-width: 820px) { .versus { grid-template-columns: 1fr; } .vs-mark { justify-self: center; } }

.side { border-radius: var(--radius); padding: 14px; border: 2px solid var(--line); background: var(--bg-2); min-width: 0; }
.side.a { border-color: rgba(255, 107, 91, 0.55); }
.side.b { border-color: rgba(54, 197, 192, 0.55); }
.side.mine.a { background: var(--a-soft); border-color: var(--a); }
.side.mine.b { background: var(--b-soft); border-color: var(--b); }
.side .num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; font-weight: 900; margin-right: 8px; color: #111; }
.side.a .num { background: var(--a); } .side.b .num { background: var(--b); }
.side .song-title { font-weight: 700; display: flex; align-items: center; margin-bottom: 4px; min-width: 0; }
.side .song-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.embed { width: 100%; border: 0; border-radius: 10px; display: block; background: #000; }
.embed.youtube { aspect-ratio: 16 / 9; height: auto; }
.embed.spotify { height: 152px; background: transparent; }
.embed.soundcloud { height: 166px; }
.embed.apple { height: 175px; background: transparent; }
.embed.suno { height: 240px; }
.side .vote-row { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
.side .vote-row .btn { flex: 1; }

/* tally */
.tally { margin-top: 16px; }
.bar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); }
.bar .fa { background: var(--a); transition: width 0.25s ease; }
.bar .fb { background: var(--b); transition: width 0.25s ease; }
.tally-nums { display: flex; justify-content: space-between; margin-top: 6px; font-weight: 800; font-size: 1.1rem; }
.tally-nums .na { color: var(--a); } .tally-nums .nb { color: var(--b); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.split .col { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem; }
.split .col div { display: flex; justify-content: space-between; }

.hint { margin-top: 12px; font-size: 0.9rem; color: var(--muted); }
.hint code, code { font-family: var(--mono); background: var(--bg-2); padding: 1px 6px; border-radius: 6px; color: var(--text); }

/* host controls */
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-status { display: grid; gap: 8px; }
.chat-status .item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.connected { background: var(--ok); }
.dot.connecting, .dot.reconnecting { background: var(--warn); }
.dot.error { background: var(--err); }
.chat-status .detail { flex-basis: 100%; font-size: 0.82rem; color: var(--muted); word-break: break-word; }
.chat-status .detail.error { color: var(--err); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

/* bracket */
.bracket-wrap { overflow-x: auto; padding-bottom: 6px; }
.bracket { display: flex; gap: 22px; min-width: max-content; }
.bracket .round { display: flex; flex-direction: column; min-width: 190px; }
.bracket .matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.bracket .round h4 { margin: 0 0 4px; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; text-align: center; }
.bm { border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; overflow: hidden; font-size: 0.82rem; }
.bm.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(244, 192, 78, 0.25); }
.bm .slot { padding: 5px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.bm .slot + .slot { border-top: 1px solid var(--line); }
.bm .slot.win { font-weight: 700; color: var(--text); background: rgba(244, 192, 78, 0.1); }
.bm .slot.lose { color: var(--muted); text-decoration: line-through; opacity: 0.7; }
.bm .slot.empty { color: var(--muted); font-style: italic; }

/* champion */
.champion { text-align: center; padding: 30px 18px; }
.champion .crown { font-size: 3rem; line-height: 1; }
.champion .ctitle { font-size: clamp(1.4rem, 4vw, 2.2rem); font-weight: 900; margin: 10px 0 4px; word-break: break-word; }
.champion .embed { max-width: 640px; margin: 18px auto 0; }

.center-msg { text-align: center; padding: 40px 16px; }
.hidden { display: none !important; }
