:root {
  --bg: #0f1420;
  --panel: #182031;
  --panel-2: #212b40;
  --line: #2d3953;
  --text: #eef2f8;
  --muted: #9aa7bd;
  --accent: #f5c542;
  --accent-ink: #1d1600;
  --a: #4fb3ff;
  --b: #ff6b8b;
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin-top: 1.5rem; }
h3 { font-size: 1rem; }
p { margin: .4rem 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: rgba(15, 20, 32, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; font-weight: 700; }
#topnav { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
#topnav a, #topnav button { color: var(--muted); }

main { max-width: 960px; margin: 0 auto; padding: 1rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.hidden { display: none !important; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; padding: .55rem 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
button.link { min-height: 0; padding: 0; border: 0; background: none; color: var(--muted); font-weight: 400; text-decoration: underline; }
button.selected { outline: 3px solid var(--accent); outline-offset: 1px; }

label { display: block; font-size: .9rem; color: var(--muted); margin: .6rem 0 .2rem; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; /* evita el zoom automático en iOS */
}
input:disabled, select:disabled { opacity: .55; }
textarea { min-height: 140px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--text); }
.form-row { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.error { color: var(--bad); min-height: 1.2em; }

.chip { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); }
.chip.live { background: var(--ok); color: #002515; border-color: var(--ok); }
.chip.seg { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.done { color: var(--muted); }

.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 1rem 0; scrollbar-width: none; }
.tabs a { padding: .6rem .9rem; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

/* Tarjetas de partido */
.match-card { display: block; color: inherit; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.match-card:hover { border-color: var(--muted); }
.match-card .teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center; margin-top: .4rem; }
.match-card .teams > div:last-child { text-align: right; }
.match-card .won { color: var(--accent); font-weight: 700; }
.song-name { font-weight: 600; }
.song-artist { color: var(--muted); font-size: .85rem; }
.vs { color: var(--muted); font-weight: 800; font-size: .85rem; }

/* Página de partido */
.versus { display: grid; gap: .75rem; grid-template-columns: 1fr; align-items: stretch; }
.versus .vs { text-align: center; font-size: 1.2rem; }
@media (min-width: 720px) { .versus { grid-template-columns: 1fr auto 1fr; } .versus .vs { align-self: center; } }
.song-card { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: .9rem; display: flex; flex-direction: column; gap: .6rem; }
.song-card.a { border-top-color: var(--a); }
.song-card.b { border-top-color: var(--b); }
.song-card.winner { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245, 197, 66, .2); }
.song-card h2 { margin: 0; }

.countdown { font-variant-numeric: tabular-nums; font-weight: 700; }

.yt { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #000; cursor: pointer; }
.yt img { width: 100%; height: 100%; object-fit: cover; opacity: .85; display: block; }
.yt .yt-play { position: absolute; inset: auto 0 0 0; padding: .5rem .7rem; background: linear-gradient(transparent, rgba(0,0,0,.85)); font-weight: 600; }
.yt iframe { width: 100%; height: 100%; border: 0; display: block; }

.segment { display: grid; gap: .5rem; padding: .8rem 0; border-top: 1px solid var(--line); }
.segment:first-of-type { border-top: 0; }
.segment .choices { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.segment .choices button { white-space: normal; text-align: center; }
.seg-links { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .85rem; }

.bar { position: relative; display: flex; height: 30px; border-radius: 8px; overflow: hidden; background: var(--panel-2); font-size: .85rem; font-weight: 700; }
.bar span { display: flex; align-items: center; padding: 0 .5rem; white-space: nowrap; min-width: 0; }
.bar .ba { background: var(--a); color: #00182b; }
.bar .bb { background: var(--b); color: #2b0009; justify-content: flex-end; margin-left: auto; }
.bar .threshold { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .6; padding: 0; }
.voters { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.voter { font-size: .8rem; padding: .15rem .5rem; border-radius: 999px; background: var(--panel-2); border-left: 4px solid var(--line); }
.voter.a { border-left-color: var(--a); }
.voter.b { border-left-color: var(--b); }
.voter.no { border-left-color: var(--bad); }
.voter.yes { border-left-color: var(--ok); }

.epic { display: grid; gap: .5rem; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.epic + .epic { margin-top: .75rem; }
.epic.approved { border-color: var(--accent); }
.icon { width: 1.6em; height: 1.6em; vertical-align: -0.45em; display: inline-block; }
.icon.sm { width: 1.3em; height: 1.3em; }
.icon.lg { width: 3.75rem; height: 3.75rem; flex: none; }
.epic-alert { display: flex; gap: .8rem; align-items: flex-start; border-color: #ff6a1a; background: linear-gradient(135deg, #3a1a08, var(--panel)); }
.epic-alert p { margin: .3rem 0; }
a.epic-alert { color: inherit; text-decoration: none; }
.pick-list { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .5rem; }
.pick-list li { display: flex; gap: .5rem; align-items: stretch; }
.pick { flex: 1; justify-content: flex-start; text-align: left; gap: .7rem; font-weight: 400; }
.pick.static { display: flex; align-items: center; padding: .55rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.pick .song-artist { color: inherit; opacity: .75; }
.pick-mark { width: 1.6rem; height: 1.6rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid currentColor; font-weight: 800; }
.btn.listen { flex: none; min-width: 48px; padding: 0 .8rem; }
.stoppage { display: inline-block; padding: .05rem .45rem; border-radius: 999px; background: #3a1a08; color: #ffc93c; font-size: .8rem; font-weight: 700; }
.epic .yt { max-width: 480px; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .45rem .4rem; text-align: center; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.song { text-align: left; }
tr.qualify td:first-child { box-shadow: inset 3px 0 var(--ok); }

/* Llaves */
.bracket { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x mandatory; }
.bracket .round { min-width: 230px; flex: 1; display: flex; flex-direction: column; gap: .75rem; justify-content: space-around; scroll-snap-align: start; }
.bracket .round h3 { text-align: center; color: var(--muted); }

.champion { text-align: center; padding: 1.4rem 1rem; border-radius: var(--radius); background: linear-gradient(135deg, #3a2d00, #182031); border: 1px solid var(--accent); }
.champion .trophy { font-size: 2.5rem; }

.invite-url { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2rem); padding: .7rem 1rem; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 600; z-index: 20; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
#toast.err { background: var(--bad); color: #fff; }
