:root {
  --bg: #0b0c10;
  --panel: #14161d;
  --panel2: #1c1f2a;
  --line: #262a37;
  --text: #f3f5f9;
  --muted: #8d95a8;
  --accent: #ffb347;
  --accent-ink: #1a1203;
  --danger: #ff6b6b;
  --radius: 16px;
  --dock-h: 250px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
svg { display: block; }
.ico { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.fill { fill: currentColor; stroke: none; }

.screen { min-height: 100dvh; }

/* ---------- Inicio ---------- */
.home-wrap { max-width: 460px; margin: 0 auto; padding: calc(28px + var(--safe-t)) 20px calc(28px + var(--safe-b)); display: grid; gap: 16px; }
.logo { margin: 8px 0 0; font-size: 40px; letter-spacing: -1px; text-align: center; }
.logo span { color: var(--accent); }
.tagline { margin: -8px 0 8px; text-align: center; color: var(--muted); }
.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 14px; }
input[type=text], input:not([type]), input[type=search] {
  width: 100%; height: 56px; padding: 0 16px; border-radius: 14px;
  background: var(--panel2); border: 1px solid var(--line); outline: none;
}
input:focus { border-color: var(--accent); }
.code-input { text-transform: uppercase; letter-spacing: 2px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.card h2 { margin: 0; font-size: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 20px; border-radius: 14px; font-weight: 600;
  background: var(--panel2); border: 1px solid var(--line);
}
.btn.big { min-height: 60px; font-size: 18px; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:active, .icon-btn:active, .ctl:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  min-height: 64px; border-radius: 14px; background: var(--panel2); border: 2px solid transparent;
  display: grid; place-content: center; gap: 2px; font-weight: 600;
}
.seg button small { font-weight: 400; color: var(--muted); font-size: 12px; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg.three button { min-height: 60px; padding: 0 4px; }
.seg button.on { border-color: var(--accent); }
.seg button:disabled { opacity: .5; }

/* ---------- Sala ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px; background: rgba(11, 12, 16, .92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.icon-btn { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--panel2); }
.room-info { flex: 1; min-width: 0; display: grid; text-align: center; }
.room-info strong { font-size: 20px; letter-spacing: 3px; }
.room-info span { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-banner { position: sticky; top: calc(68px + var(--safe-t)); z-index: 19; text-align: center; padding: 6px; background: #3a2a05; color: var(--accent); font-size: 14px; }

.queue-area { padding: 12px 12px calc(var(--dock-h) + 24px); max-width: 720px; margin: 0 auto; }
.queue-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.queue-head h2 { margin: 0; font-size: 22px; }
.queue-tools { display: flex; align-items: center; gap: 8px; }
.add-btn { min-height: 52px; }
.filter-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.filter-row input { flex: 1; }
.list-title { margin: 18px 4px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.list-title.accent { color: var(--accent); }
.songs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.song {
  display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 6px 8px 6px 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; position: relative;
  user-select: none; -webkit-user-select: none; cursor: pointer;
}
.song:active { background: var(--panel2); }
.song.playing { border-color: var(--accent); }
.song .drag { width: 44px; height: 56px; flex: none; display: grid; place-items: center; color: var(--muted); touch-action: none; cursor: grab; }
.song .thumb { width: 56px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--panel2); flex: none; }
.song .meta { flex: 1; min-width: 0; }
.song .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .a { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.songs.plain .drag, .songs.filtering .drag { display: none; }
.songs.plain .song, .songs.filtering .song { padding-left: 10px; }
.song.dragging { opacity: .25; }
.ghost {
  position: fixed; z-index: 100; pointer-events: none; margin: 0; background: var(--panel2);
  border: 1px solid var(--accent); border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.6); transform: scale(1.02);
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 4px; min-height: 68px;
}
.ghost .drag { width: 44px; height: 56px; display: grid; place-items: center; color: var(--accent); }
.ghost .thumb { width: 56px; height: 42px; border-radius: 8px; object-fit: cover; flex: none; }
.ghost .meta { flex: 1; min-width: 0; }
.ghost .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost .a { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song.drop-before { box-shadow: 0 -4px 0 0 var(--accent); }
.song.drop-after { box-shadow: 0 4px 0 0 var(--accent); }
.songs.drop-empty { outline: 2px solid var(--accent); outline-offset: -2px; }
.drag-active .songs { min-height: 60px; border-radius: 14px; }
.drag-active .songs:not(:has(.song:not(.dragging))) { outline: 2px dashed var(--line); }
.drag-active .list-title { display: block !important; }
.search-wrap { display: grid; grid-template-rows: auto 1fr; gap: 10px; min-height: 0; }
.sheet.full .panel { overflow: hidden; }
.drag-active, .drag-active * { user-select: none !important; -webkit-user-select: none !important; }
.history { margin-top: 24px; }
.history summary { color: var(--muted); padding: 12px 4px; cursor: pointer; }

/* ---------- Reproductor (dock) ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 12px 14px calc(12px + var(--safe-b)); background: rgba(16, 18, 25, .97);
  border-top: 1px solid var(--line); backdrop-filter: blur(12px);
  max-width: 720px; margin: 0 auto; border-radius: 20px 20px 0 0;
}
.np { display: flex; align-items: center; gap: 12px; }
.np-art { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--panel2); flex: none; }
.np-text { min-width: 0; }
.np-title { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seek { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; width: 40px; text-align: center; }
input[type=range] { flex: 1; height: 36px; accent-color: var(--accent); background: none; border: 0; padding: 0; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ctl { width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); flex: none; }
.ctl.main { width: 84px; height: 84px; background: var(--accent); color: var(--accent-ink); }
.ctl.main .ico { width: 38px; height: 38px; }
.ctl.small { width: 56px; height: 56px; background: none; color: var(--muted); }
.ctl.small[aria-pressed=true] { color: var(--accent); background: rgba(255, 179, 71, .14); }
.ctl .ico { width: 30px; height: 30px; }
.ctl-spacer { width: 56px; flex: none; }
.player-line { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 36px; margin-top: 6px; font-size: 14px; color: var(--muted); text-align: center; }
.player-line button { min-height: 40px; padding: 0 14px; border-radius: 12px; background: var(--panel2); color: var(--text); font-weight: 600; }

/* ---------- Hojas (bottom sheets) ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); animation: fade .15s ease-out; }
.sheet .panel {
  position: relative; width: 100%; max-width: 560px; max-height: 90dvh; overflow: auto;
  background: var(--panel); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  display: grid; gap: 10px; align-content: start; animation: up .18s ease-out; border-top: 1px solid var(--line);
}
.sheet.full .panel { height: 92dvh; max-height: 92dvh; grid-template-rows: auto 1fr; }
.sheet h3 { margin: 0; font-size: 18px; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-top: -6px; word-break: break-word; }
.sheet .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 4px; }
.action { width: 100%; min-height: 62px; border-radius: 14px; background: var(--panel2); display: flex; align-items: center; gap: 14px; padding: 0 18px; font-size: 18px; font-weight: 600; text-align: left; }
.action.danger { color: var(--danger); }
.action small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.search-top { display: flex; gap: 8px; align-items: center; }
.search-top input { flex: 1; }
.results { overflow: auto; display: grid; gap: 6px; align-content: start; padding-bottom: 12px; }
.results .song .a { white-space: nowrap; }
.status { text-align: center; color: var(--muted); padding: 28px 8px; }
.status button { margin-top: 12px; }
.qr { width: min(72vw, 280px); aspect-ratio: 1; margin: 0 auto; border-radius: 12px; background: #fff; padding: 0; display: block; }
.big-code { text-align: center; font-size: 34px; font-weight: 800; letter-spacing: 6px; }
.link-line { text-align: center; color: var(--muted); font-size: 13px; word-break: break-all; }
.row { display: grid; gap: 8px; }
.row > label { color: var(--muted); font-size: 14px; }
.members { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--panel2); font-size: 14px; }
.chip.off { opacity: .45; }
.chip.me { border: 1px solid var(--accent); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

.gate { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .82); color: var(--accent); font-size: 26px; font-weight: 800; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 20px); transform: translate(-50%, 20px); z-index: 80;
  max-width: 90vw; padding: 12px 18px; border-radius: 14px; background: #2a2f3f; color: var(--text); font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.in-home .toast { bottom: 24px; }

@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-height: 560px) { .np-art { display: none; } .ctl { width: 56px; height: 56px; } .ctl.main { width: 68px; height: 68px; } }
