:root {
  --bg: #0f172a; --panel: #1c2538; --line: #2b3750; --text: #f1f5f9; --muted: #8b98ae;
  --blue: #2563eb; --red: #ef4444; --green: #22c55e; --yellow: #eab308;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, "Segoe UI", sans-serif; }
h1, h2, h3, p { margin: 0 0 .5rem; }
h2 { font-size: 1rem; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); }
.error { color: #fca5a5; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; }
.btn { display: inline-block; padding: .7rem 1.1rem; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); font-weight: 600; }
.btn.big { font-size: 1.3rem; padding: 1rem 2.4rem; }
.btn.small { padding: .35rem .8rem; font-size: .85rem; }
input:not([type=range]):not([type=checkbox]) { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; min-width: 0; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }

#toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: #334155; padding: .7rem 1.1rem; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }

/* Trang đầu */
.home main { max-width: 420px; margin: 0 auto; padding: 2.5rem 1rem; text-align: center; display: grid; gap: 1rem; justify-items: center; }
.logo { border-radius: 24px; }
.panel { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.2rem; display: grid; gap: .8rem; justify-items: center; }
.code-input { text-align: center; letter-spacing: .35em; text-transform: uppercase; font-size: 1.4rem; width: 100%; background: var(--bg) !important; }

/* Điều khiển */
.remote { padding-bottom: 96px; }
.remote header { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); padding: calc(.6rem + env(safe-area-inset-top)) .8rem .6rem; }
.remote header > *, .remote main { max-width: 640px; margin-left: auto; margin-right: auto; }
.transport { display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.brand img { border-radius: 50%; display: block; }
.round { flex: none; width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; font-size: 1.15rem; padding: 0; }
.round.primary { background: var(--blue); border-color: var(--blue); }
.round.small { width: 40px; height: 40px; font-size: 1rem; }
.round.fav { color: var(--red); }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dot.on { background: var(--green); } .dot.wait { background: var(--yellow); } .dot.off { background: var(--red); }
.volume { display: flex; align-items: center; gap: .6rem; margin-top: .5rem; }
.volume input { flex: 1; accent-color: var(--blue); }
.who { display: flex; align-items: center; justify-content: space-between; gap: .6rem; font-size: .85rem; color: var(--muted); margin-top: .4rem; }
.who input { width: 12rem; padding: .35rem .6rem !important; color: var(--text); }
.remote main { padding: .8rem; }
.search-box { display: flex; gap: .5rem; align-items: center; }
.search-box input { flex: 1; }
.search-box input::-webkit-search-cancel-button { display: none; }
.switch { display: flex; gap: .5rem; align-items: center; margin: .7rem 0; font-size: .9rem; color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0 .6rem; }
.card { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "thumb info" "actions actions"; gap: .5rem .7rem; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: .7rem; margin-bottom: .6rem; align-items: center; }
.card:has(.handle) { grid-template-columns: auto auto 1fr; grid-template-areas: "handle thumb info" "handle actions actions"; }
.card.playing { border-color: var(--blue); }
.card.waiting { border-style: dashed; border-color: var(--yellow); }
#pending:not(:empty) { margin-top: 1rem; }
.host-panel { border: 1px solid var(--line); border-radius: 16px; padding: 0 .8rem; margin-bottom: .8rem; }
.card.dragging { opacity: .75; border-color: #60a5fa; }
.handle { grid-area: handle; align-self: stretch; display: grid; place-items: center; width: 28px; font-size: 1.5rem; color: var(--muted); cursor: grab; touch-action: none; user-select: none; }
.thumb { grid-area: thumb; position: relative; width: 104px; aspect-ratio: 16 / 9; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }
.thumb b { position: absolute; right: 4px; bottom: 4px; background: rgb(0 0 0 / .75); font-size: .72rem; padding: 0 .3rem; border-radius: 5px; }
.info { grid-area: info; min-width: 0; }
.info h3 { font-size: .93rem; margin: 0 0 .2rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.info small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { grid-area: actions; display: flex; justify-content: flex-end; align-items: center; gap: .5rem; min-width: 0; }
.singer { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: .3rem .7rem; }
.round svg { width: 24px; height: 24px; fill: currentColor; }
.qr-btn { position: relative; }
.qr-btn .dot { position: absolute; top: 1px; right: 1px; border: 2px solid var(--bg); }
.ticker { overflow: hidden; white-space: nowrap; margin-top: .55rem; background: var(--panel); border-radius: 8px; padding: .3rem 0; font-size: .85rem; }
.ticker span { display: inline-block; padding-left: 100%; animation: ticker 20s linear infinite; }
@keyframes ticker { to { transform: translateX(-100%); } }
.fab { position: fixed; right: 14px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 25; display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.fab button { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 1.6rem; padding: 0; box-shadow: 0 6px 18px rgb(0 0 0 / .5); }
.fab .fab-toggle { width: 60px; height: 60px; background: var(--blue); border-color: var(--blue); }
.fab-menu { display: flex; flex-direction: column; gap: .5rem; max-height: calc(100dvh - 190px); overflow-y: auto; padding: 4px; }
.fab-menu button { flex: none; }
.fab-menu button:active { background: var(--blue); }
#tab-queue { padding-bottom: 84px; }
.modal { position: fixed; inset: 0; z-index: 45; background: rgb(0 0 0 / .75); display: grid; place-items: center; padding: 1rem; }
.modal-box { background: var(--panel); border-radius: 20px; padding: 1.2rem; width: min(340px, 100%); display: grid; gap: .9rem; justify-items: center; text-align: center; }
.modal-box .qr { width: min(260px, 70vw, 50vh); }
.card.previewable { cursor: pointer; }
.preview-box { width: min(640px, 100%); }
.preview-box h2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; }
.preview-player { width: 100%; aspect-ratio: 16 / 9; max-height: 60dvh; background: #000; border-radius: 12px; overflow: hidden; }
.preview-player iframe { width: 100%; height: 100%; border: 0; display: block; }
.preview-box p { margin: 0; font-size: .85rem; }
.tabs { position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs button { background: none; border: 0; border-top: 3px solid transparent; padding: .7rem 0 .8rem; display: grid; gap: .25rem; justify-items: center; font-size: .75rem; font-weight: 700; color: var(--muted); }
.tabs button.on { color: #60a5fa; border-top-color: #60a5fa; }
.tabs span { font-size: 1.4rem; position: relative; }
.tabs i { position: absolute; top: -4px; right: -14px; background: var(--red); color: #fff; border-radius: 99px; font: 700 .68rem system-ui; padding: .1rem .38rem; }

/* Màn hình hát */
body.show { background: #000; overflow: hidden; height: 100dvh; }
#stage, #stage iframe { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; }
#idle, #start { position: fixed; inset: 0; background: var(--bg); display: grid; place-content: center; justify-items: center; gap: .8rem; text-align: center; padding: 1rem; }
#idle { z-index: 5; }
#start { z-index: 40; }
.qr svg { display: block; width: 100%; height: auto; background: #fff; border-radius: 10px; }
.big-qr { width: min(42vh, 70vw); }
#idle .room-code { font-size: 2.2rem; font-weight: 800; letter-spacing: .3em; }
.corner { position: fixed; top: 12px; right: 12px; z-index: 6; width: clamp(84px, 9vw, 150px); text-align: center; background: rgb(0 0 0 / .6); padding: 6px; border-radius: 12px; font-weight: 700; letter-spacing: .12em; pointer-events: none; }
.corner.off { display: none; }
.badge { position: fixed; left: 12px; top: 12px; z-index: 6; max-width: 60vw; background: rgb(0 0 0 / .7); padding: .6rem .9rem; border-radius: 12px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#notice { top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 90vw; white-space: normal; text-align: center; }
#tools { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 30; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .5rem; width: max-content; max-width: 96vw; background: rgb(15 23 42 / .92); padding: .6rem; border-radius: 16px; opacity: 0; pointer-events: none; transition: opacity .3s; }
body.active #tools, #tools:focus-within, #idle:not([hidden]) ~ #tools { opacity: 1; pointer-events: auto; }
#host-qr { position: fixed; inset: 0; z-index: 35; background: rgb(15 23 42 / .96); display: grid; place-content: center; justify-items: center; gap: .8rem; text-align: center; padding: 1rem; }
#host-qr .qr-host { width: min(45vh, 70vw); }
.qr-host svg { display: block; width: 100%; height: auto; background: #fff; border-radius: 10px; }
#effect-pop { position: fixed; inset: 0; z-index: 25; pointer-events: none; overflow: hidden; }
#effect-pop span { position: absolute; bottom: -10vh; font-size: 14vh; animation: rise 2.2s ease-out forwards; }
@keyframes rise { to { transform: translateY(-80vh); opacity: 0; } }
