:root {
  --bg: #07060f;
  --panel: #14112b;
  --panel-2: #1c1840;
  --line: rgba(255, 255, 255, .09);
  --text: #f2f0ff;
  --muted: #9a94c4;
  --pink: #ff3d9a;
  --cyan: #2de2ff;
  --yellow: #ffd23f;
  --green: #3dffa8;
  --red: #ff4d5e;
  --radius: 14px;
  --font: 'Noto Sans KR', system-ui, -apple-system, 'Malgun Gothic', sans-serif;
  --display: 'Black Han Sans', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, #2a0f4a 0%, transparent 60%),
              radial-gradient(1000px 500px at 110% 10%, #0b2a4a 0%, transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 상단바 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
}
.logo {
  font-family: var(--display); font-size: 28px; letter-spacing: 1px;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(45, 226, 255, .7), 0 0 30px rgba(45, 226, 255, .35);
  display: flex; align-items: baseline; gap: 2px;
}
.logo span { color: var(--pink); text-shadow: 0 0 10px rgba(255, 61, 154, .8), 0 0 30px rgba(255, 61, 154, .4); }
.logo small { font-family: var(--font); font-size: 13px; font-weight: 700; color: var(--muted); text-shadow: none; margin-left: 10px; letter-spacing: 0; }
.top-status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  font-size: 13px; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.pill.on { color: var(--green); border-color: rgba(61, 255, 168, .4); }
.pill.rec { color: #fff; background: var(--red); border-color: transparent; animation: blink 1s infinite; }
.btn-ghost:hover { color: var(--text); }
@keyframes blink { 50% { opacity: .45; } }

/* ---------- 레이아웃 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "stage remote" "book remote";
  gap: 16px;
  padding: 0 20px 24px;
  align-items: start;
}
.stage { grid-area: stage; }
.remote { grid-area: remote; display: flex; flex-direction: column; gap: 12px; }
.songbook { grid-area: book; }

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--pink); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 8px; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

/* ---------- 무대 ---------- */
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: #05040c;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5), inset 0 0 120px rgba(0, 0, 0, .6);
  container-type: inline-size;
  user-select: none;
}
#bgCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.stage-hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 2.2cqw 2.8cqw; z-index: 3;
  font-size: clamp(11px, 1.6cqw, 16px); font-weight: 700;
}
.hud-left { color: var(--yellow); text-shadow: 0 2px 4px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { display: flex; gap: 8px; }
.hud-chip { background: rgba(0, 0, 0, .45); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; color: var(--cyan); }

.idle-screen {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 6cqw;
}
.idle-logo {
  font-family: var(--display); font-size: clamp(36px, 11cqw, 130px); line-height: 1;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 20px var(--pink), 0 0 50px var(--pink), 0 0 90px rgba(255, 61, 154, .6);
  animation: flicker 4s infinite;
}
@keyframes flicker {
  0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: .55; }
}
.idle-sub { font-size: clamp(13px, 2.2cqw, 22px); color: var(--text); margin: 2cqw 0 1cqw; text-shadow: 0 2px 6px #000; }
.idle-queue { font-size: clamp(12px, 1.8cqw, 18px); color: var(--yellow); min-height: 1.4em; }
.idle-tip { font-size: clamp(11px, 1.6cqw, 15px); color: var(--muted); position: absolute; bottom: 4cqw; margin: 0; transition: opacity .4s; }

.title-card {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(ellipse at center, rgba(10, 6, 30, .55), rgba(5, 3, 15, .85));
  animation: fadeIn .6s ease both;
  transition: opacity .8s;
}
.title-card.out { opacity: 0; }
.tc-no { font-family: var(--display); color: var(--yellow); font-size: clamp(14px, 3cqw, 32px); letter-spacing: 2px; }
.tc-title {
  font-family: var(--display); font-size: clamp(28px, 8cqw, 96px); line-height: 1.1; margin: 1cqw 4cqw;
  color: #fff; text-shadow: 0 0 20px var(--cyan), 0 4px 0 #0a3a6a;
  animation: pop .7s cubic-bezier(.2, 1.6, .4, 1) both .1s;
}
.tc-artist { font-size: clamp(14px, 2.6cqw, 28px); color: var(--pink); font-weight: 700; }
.tc-meta { font-size: clamp(11px, 1.6cqw, 16px); color: var(--muted); margin-top: 2cqw; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.roll {
  position: absolute; left: 0; right: 0; top: 11%; height: 36%;
  width: 100%; z-index: 2;
}

.judge {
  position: absolute; left: 20%; top: 12%; z-index: 5; transform: translateX(-50%);
  font-family: var(--display); font-size: clamp(16px, 4cqw, 44px); pointer-events: none;
  opacity: 0;
}
.judge.show { animation: judge .8s ease-out both; }
.judge.perfect { color: var(--yellow); text-shadow: 0 0 14px rgba(255, 210, 63, .9), 0 3px 0 #7a5300; }
.judge.great { color: var(--cyan); text-shadow: 0 0 14px rgba(45, 226, 255, .9), 0 3px 0 #064a63; }
.judge.good { color: var(--green); text-shadow: 0 0 14px rgba(61, 255, 168, .8), 0 3px 0 #0b5a3a; }
@keyframes judge {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(.7); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -8px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -24px) scale(1); }
}

.lyrics {
  position: absolute; left: 0; right: 0; bottom: 9%; z-index: 3;
  padding: 0 6cqw;
  font-weight: 900;
  font-size: clamp(18px, 5.2cqw, 62px);
  line-height: 1.5;
}
.lyric-line { min-height: 1.5em; white-space: normal; }
.lyric-line.top { text-align: left; }
.lyric-line.bottom { text-align: right; }
.lyric-line.enter { animation: lineIn .35s ease-out both; }
@keyframes lineIn { from { opacity: 0; transform: translateY(10px); } }
.word { white-space: nowrap; display: inline-block; }
.syl { position: relative; display: inline-block; color: #fff; }
.syl, .syl .fill {
  text-shadow: 0 0 2px #000, 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 0 3px 8px rgba(0, 0, 0, .7);
}
.syl .fill {
  position: absolute; left: 0; top: 0; width: 0; overflow: hidden; white-space: nowrap;
  color: var(--cyan);
}
.lyric-line.bottom .syl .fill { color: var(--pink); }
.lyric-line.top .syl .fill { color: var(--cyan); }
.space { display: inline-block; width: .32em; }

.countdown { height: .5em; display: flex; gap: .25em; margin-bottom: .2em; padding-left: .1em; }
.countdown i {
  width: .38em; height: .38em; border-radius: 50%; display: block;
  background: var(--yellow); box-shadow: 0 0 10px var(--yellow);
}

.progress {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; align-items: center; gap: 10px; padding: 0 2.8cqw 1.6cqw;
  font-size: clamp(10px, 1.4cqw, 14px); color: var(--muted); font-variant-numeric: tabular-nums;
}
.progress-track { flex: 1; height: 4px; background: rgba(255, 255, 255, .12); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--pink)); }

.paused-badge {
  position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45); font-family: var(--display); font-size: clamp(22px, 6cqw, 64px); color: #fff;
  text-shadow: 0 0 20px var(--cyan);
}

.score-screen {
  position: absolute; inset: 0; z-index: 7;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1cqw;
  background: radial-gradient(ellipse at center, rgba(30, 10, 60, .75), rgba(5, 3, 15, .92));
  backdrop-filter: blur(4px);
  text-align: center; padding: 3cqw;
}
.score-label { font-family: var(--display); color: var(--cyan); font-size: clamp(16px, 3.4cqw, 38px); letter-spacing: 6px; text-shadow: 0 0 14px var(--cyan); }
.score-num {
  font-family: var(--display); font-size: clamp(64px, 20cqw, 240px); line-height: .95;
  color: var(--yellow);
  text-shadow: 0 0 20px rgba(255, 210, 63, .9), 0 0 60px rgba(255, 61, 154, .6), 0 8px 0 #8a4b00;
  font-variant-numeric: tabular-nums;
}
.score-num.reveal { animation: pop .6s cubic-bezier(.2, 1.8, .4, 1) both; }
.score-comment { font-size: clamp(14px, 3cqw, 32px); font-weight: 900; text-shadow: 0 2px 8px #000; min-height: 1.3em; }
.score-stats { font-size: clamp(11px, 1.6cqw, 16px); color: var(--muted); }
.score-rec { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; margin-top: 1cqw; }
.score-rec audio { height: 36px; max-width: 70cqw; }
.score-actions { display: flex; gap: 10px; margin-top: 1.4cqw; }
.score-auto { font-size: clamp(11px, 1.4cqw, 14px); color: var(--yellow); min-height: 1.2em; }

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--line); background: #241f4f; color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-weight: 700; font-size: 14px;
  transition: transform .06s, background .15s, box-shadow .15s;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: #2e2862; }
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(180deg, #ff5aab, #e02483); border-color: transparent; box-shadow: 0 4px 16px rgba(255, 61, 154, .35); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.reserve { background: linear-gradient(180deg, #3be8ff, #12a7cf); color: #04202b; border-color: transparent; }
.btn.danger { background: #3a1830; color: #ff8fa0; }
.btn.small { padding: 6px 12px; font-size: 15px; }
.btn.on { box-shadow: 0 0 0 2px var(--green) inset; color: var(--green); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

/* ---------- 번호 입력 ---------- */
.num-display {
  background: #050410; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px; text-align: right;
}
.num-digits {
  font-family: var(--display); font-size: 40px; letter-spacing: 6px; color: #ff6a3d;
  text-shadow: 0 0 12px rgba(255, 106, 61, .8); font-variant-numeric: tabular-nums; line-height: 1.1;
}
.num-digits.empty { color: #3a2a26; text-shadow: none; }
.num-preview { font-size: 12px; color: var(--muted); min-height: 1.4em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num-preview.found { color: var(--yellow); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.numpad button {
  border: 1px solid var(--line); background: #1e1a44; border-radius: 10px;
  font-size: 20px; font-weight: 700; padding: 10px 0;
  transition: background .12s, transform .06s;
}
.numpad button:hover { background: #2a2560; }
.numpad button:active { transform: scale(.94); }
.numpad button.muted { font-size: 14px; color: var(--muted); }

/* ---------- 컨트롤 ---------- */
.ctl-row { display: grid; grid-template-columns: 52px 44px 1fr 44px; align-items: center; gap: 6px; margin-bottom: 8px; }
.ctl-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.ctl-val {
  border: 1px solid var(--line); background: #050410; border-radius: 8px; padding: 6px 0;
  font-family: var(--display); font-size: 18px; color: var(--cyan); text-align: center;
}
.toggles { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.toggle input { accent-color: var(--pink); width: 16px; height: 16px; }
.slider { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.slider input { accent-color: var(--cyan); width: 100%; }

.mic-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.mic-btn { flex: 0 0 auto; }
.meter { flex: 1; height: 10px; background: #050410; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--yellow), var(--red)); transition: width .05s; }

.queue { margin: 0; padding-left: 22px; font-size: 13px; max-height: 180px; overflow: auto; }
.queue li { padding: 5px 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.queue li .q-no { color: var(--yellow); font-weight: 700; margin-right: 6px; }
.queue li button { background: none; border: none; color: var(--muted); font-size: 14px; }
.queue li button:hover { color: var(--red); }
.queue:empty::before { content: '예약된 곡이 없어요'; color: var(--muted); margin-left: -22px; }

/* ---------- 노래책 ---------- */
.sb-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sb-head h2 { margin: 0; font-size: 18px; }
.sb-head input {
  flex: 1; min-width: 160px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: #050410; color: var(--text); font-size: 14px; font-family: inherit;
}
.tabs { display: flex; gap: 6px; margin: 12px 0 8px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
}
.tab.active { background: var(--cyan); color: #04202b; border-color: transparent; }
.sb-table-wrap { max-height: 360px; overflow: auto; }
.sb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sb-table th { text-align: left; color: var(--muted); font-weight: 700; font-size: 12px; padding: 8px; position: sticky; top: 0; background: var(--panel-2); }
.sb-table td { padding: 10px 8px; border-top: 1px solid var(--line); }
.sb-table tr:hover td { background: rgba(255, 255, 255, .03); }
.sb-table .no { font-family: var(--display); color: var(--yellow); font-size: 16px; width: 64px; }
.sb-table .title { font-weight: 700; }
.sb-table .genre { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px; font-weight: 400; }
.sb-table .col-artist, .sb-table td.artist { color: var(--muted); }
.sb-table .acts { text-align: right; white-space: nowrap; }
.sb-table .acts button {
  border: 1px solid var(--line); background: #241f4f; border-radius: 8px; padding: 5px 10px; margin-left: 4px; font-size: 13px; font-weight: 700;
}
.sb-table .acts button.play { background: var(--pink); border-color: transparent; }
.sb-table .acts button:hover { filter: brightness(1.15); }
.sb-empty { text-align: center; color: var(--muted); padding: 24px !important; }

/* ---------- 토스트 ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; pointer-events: none; }
.toast {
  background: rgba(20, 17, 43, .95); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  animation: toastIn .25s ease-out both;
}
.toast.out { animation: toastOut .3s ease-in both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ---------- 대화상자 ---------- */
dialog {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 6px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-top: 12px; }
dialog input:not([type=file]), dialog textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: #050410; color: var(--text); font: inherit; font-size: 14px;
}
dialog input[type=file] { display: block; margin-top: 6px; color: var(--text); font-size: 13px; }
dialog textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
dialog code { background: #050410; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.keys { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.keys td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
.keys td:first-child { white-space: nowrap; width: 40%; }
kbd { background: #050410; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font-size: 12px; font-family: inherit; }

/* ---------- 반응형 ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "stage" "remote" "book"; padding: 0 16px 24px; }
  .remote { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .logo { font-size: 22px; }
  .logo small { display: none; }
  .stage { aspect-ratio: 4 / 3; }
  .sb-table .col-artist, .sb-table td.artist { display: none; }
}
