:root {
  --bg: #0e0f16;
  --panel: #171925;
  --panel-2: #1e2131;
  --border: #2b2f42;
  --text: #f2f3f8;
  --muted: #9aa0b8;
  --primary: #6c5ce7;
  --primary-2: #8577ff;
  --accent: #ffb84d;
  --danger: #ff6b6b;
  --success: #4ade80;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 16px;
}

body[data-theme="light"] {
  --bg: #f4f5fa;
  --panel: #ffffff;
  --panel-2: #f0f1f8;
  --border: #dfe1ec;
  --text: #1c1e2b;
  --muted: #666d84;
  --primary: #5b4ad6;
  --primary-2: #7060ea;
  --shadow: 0 10px 30px rgba(40, 44, 70, .10);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(1200px 600px at 15% -10%, rgba(108, 92, 231, .18), transparent 60%), var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { max-width: 1700px; margin: 0 auto; padding: 18px 20px 36px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #b06ab3);
  color: #fff; font-size: 20px; font-weight: 800; letter-spacing: -.5px;
  box-shadow: 0 6px 18px rgba(108, 92, 231, .4);
}
.brand-text h1 { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.brand-text h1 span { color: var(--primary-2); }
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.lang-select {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; outline: none;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 13px;
  transition: transform .12s, border-color .12s, background .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff; }
.btn-soft { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; font-size: 17px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-play { min-width: 112px; font-size: 15px; }
.btn-danger { color: var(--danger); border-color: rgba(255, 107, 107, .4); }
.btn.active { border-color: var(--primary); background: rgba(108, 92, 231, .18); }

/* ---------- Panels & layout ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr) minmax(280px, 340px);
  gap: 16px; align-items: start;
}
.panel { padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head .hint { font-size: 11px; }
.badge {
  background: rgba(108, 92, 231, .18); color: var(--primary-2); border-radius: 999px;
  padding: 3px 10px; font-size: 11px; font-weight: 700;
}
.hint { color: var(--muted); font-size: 11px; margin: 6px 0 0; }
.mini-check { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; margin: 10px 0; cursor: pointer; }
.mini-check input { accent-color: var(--primary); }

/* ---------- Search ---------- */
.search-box { display: flex; gap: 8px; }
.search-box input, .input, select.input, textarea.input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; outline: none;
}
.search-box input:focus, .input:focus { border-color: var(--primary); }
.status-box { font-size: 12px; color: var(--muted); min-height: 18px; margin: 6px 0; }
.status-box.error { color: var(--danger); }
.result-list, .queue-list { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; padding-right: 4px; }
.result-list::-webkit-scrollbar, .queue-list::-webkit-scrollbar { width: 6px; }
.result-list::-webkit-scrollbar-thumb, .queue-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.result-card {
  display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 8px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2);
}
.result-card img { width: 92px; height: 56px; object-fit: cover; border-radius: 8px; background: #000; }
.result-card .r-title { font-size: 12px; font-weight: 650; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result-card .r-meta { font-size: 11px; color: var(--muted); margin: 3px 0 6px; }
.result-card .btn { padding: 5px 9px; font-size: 11px; }
.local-actions { border-top: 1px dashed var(--border); margin-top: 12px; padding-top: 12px; }
.drop-active .stage { outline: 3px dashed var(--primary); outline-offset: 4px; }

/* ---------- Stage ---------- */
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden;
  background: #05060b; border: 1px solid var(--border);
}
.player-frame, .player-frame iframe, .player-frame video { width: 100%; height: 100%; border: 0; display: block; object-fit: contain; }
.player-frame { position: absolute; inset: 0; }
.player-frame:empty { display: none; }
.idle-screen {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  background: radial-gradient(circle at 50% 35%, rgba(108, 92, 231, .28), transparent 60%), #080912;
  color: #fff;
}
.idle-logo { font-size: 56px; color: var(--primary-2); line-height: 1; }
.idle-screen h2 { margin: 8px 0 2px; font-size: 22px; }
.idle-screen p { margin: 0; color: #aeb3c9; font-size: 13px; }
.countdown {
  position: absolute; inset: auto 0 18px; margin: auto; width: max-content;
  background: rgba(0, 0, 0, .78); color: #fff; border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px; padding: 8px 18px; font-weight: 700; font-size: 14px;
}
.screen-badge {
  position: absolute; top: 10px; right: 10px; background: rgba(0, 0, 0, .72); color: #fff;
  border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 5px 11px; font-size: 11px;
}
.now-playing { display: flex; justify-content: space-between; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.np-label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .9px; color: var(--muted); font-weight: 700; }
.np-info { min-width: 0; flex: 1; }
.np-info h2 { margin: 3px 0 2px; font-size: 17px; overflow-wrap: anywhere; }
.np-info p { margin: 0; color: var(--muted); font-size: 12px; }
.key-control { text-align: right; }
.key-row { display: flex; align-items: center; gap: 7px; margin-top: 4px; justify-content: flex-end; }
.key-row strong { min-width: 24px; text-align: center; color: var(--accent); }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 11px; color: var(--muted); }
.progress-row input { flex: 1; accent-color: var(--primary); }
.transport { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.volume-label { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.volume-label input { width: 90px; accent-color: var(--primary); }
.screen-status { margin-top: 8px; font-size: 11px; color: var(--success); min-height: 16px; }

/* ---------- Queue & rotation ---------- */
.rotation-box {
  border: 1px solid rgba(108, 92, 231, .45); background: rgba(108, 92, 231, .10);
  border-radius: 12px; padding: 10px; margin-bottom: 10px; font-size: 12px;
}
.rotation-box h3 { margin: 0 0 6px; font-size: 12px; }
.rotation-box .rot-line { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.rotation-box .rot-line.current { color: var(--accent); font-weight: 700; }
.queue-list { max-height: 486px; }
.queue-card {
  display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: 11px; padding: 8px; background: var(--panel-2);
}
.queue-card.current { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.queue-card.dragging { opacity: .45; }
.queue-card .q-drag { cursor: grab; color: var(--muted); font-size: 15px; user-select: none; }
.queue-card .q-title { font-size: 12px; font-weight: 650; line-height: 1.3; }
.queue-card .q-sub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.queue-card .q-tools { display: flex; gap: 3px; }
.queue-card .q-tools button {
  border: 0; background: transparent; color: var(--muted); border-radius: 6px; padding: 4px 6px; font-size: 13px;
}
.queue-card .q-tools button:hover { background: var(--border); color: var(--text); }
.queue-actions { margin-top: 10px; }

/* ---------- Pads ---------- */
.pads-section { margin-top: 16px; }
.pads-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.pad {
  border: 1px solid var(--border); border-radius: 13px; background: var(--panel-2);
  padding: 14px 6px; text-align: center; font-weight: 700; font-size: 12px;
  transition: transform .1s, border-color .1s;
}
.pad .pad-icon { font-size: 22px; display: block; margin-bottom: 6px; }
.pad:hover { border-color: var(--primary); transform: translateY(-2px); }
.pad.playing { border-color: var(--accent); background: rgba(255, 184, 77, .14); }

/* ---------- Modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 12, .72);
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(3px);
}
.modal {
  width: min(720px, 100%); max-height: 86vh; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tabs { display: flex; gap: 5px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.tab.active { background: rgba(108, 92, 231, .2); color: var(--primary-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.list-row {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px; background: var(--panel-2);
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow strong { display: block; font-size: 12px; overflow-wrap: anywhere; }
.list-row small { color: var(--muted); font-size: 11px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 12px; max-width: 340px;
  animation: slidein .2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes slidein { from { opacity: 0; transform: translateX(18px); } }

/* ---------- Second screen ---------- */
body.screen-body { background: #000; padding: 0; overflow: hidden; }
.screen-wrap { position: fixed; inset: 0; display: grid; grid-template-rows: 1fr auto; }
.screen-video { width: 100%; height: 100%; background: #000; object-fit: contain; }
.screen-video iframe { width: 100%; height: 100%; border: 0; }
.screen-waiting {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  background: radial-gradient(circle at 50% 40%, rgba(108, 92, 231, .35), #05060c 70%); color: #fff; padding: 30px;
}
.screen-waiting .sw-label { color: #c9c2ff; font-size: clamp(14px, 2vw, 22px); text-transform: uppercase; letter-spacing: 3px; }
.screen-waiting .sw-name { font-size: clamp(34px, 7vw, 92px); font-weight: 800; margin: 8px 0; line-height: 1.05; }
.screen-waiting .sw-song { font-size: clamp(18px, 3vw, 40px); color: #ffd68a; }
.screen-waiting .sw-upcoming { margin-top: 24px; color: #aeb3c9; font-size: clamp(12px, 1.5vw, 18px); }
.screen-topbar {
  position: absolute; top: 12px; right: 14px; z-index: 3; display: flex; gap: 8px; opacity: .25;
  transition: opacity .2s;
}
.screen-topbar:hover { opacity: 1; }
.screen-topbar button { background: rgba(0, 0, 0, .7); color: #fff; border: 1px solid rgba(255, 255, 255, .25); border-radius: 8px; padding: 7px 11px; font-size: 12px; }
.notice-bar {
  height: 54px; background: #000; border-top: 2px solid rgba(255, 255, 255, .1);
  overflow: hidden; position: relative; display: flex; align-items: center;
}
.notice-track {
  display: inline-block; white-space: nowrap; will-change: transform;
  font-weight: 700; padding-left: 100%;
  animation: marquee linear infinite;
}
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-100%); } }
.screen-msg {
  position: absolute; bottom: 70px; left: 0; right: 0; text-align: center; color: #fff;
  font-size: 14px; opacity: .85; pointer-events: none;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(260px, 320px) 1fr; }
  .queue-panel { grid-column: 1 / -1; }
  .queue-list { max-height: 280px; flex-direction: row; flex-wrap: wrap; }
  .queue-card { width: calc(33.333% - 8px); }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .queue-panel { grid-column: auto; }
  .queue-card { width: 100%; }
  .pads-grid { grid-template-columns: repeat(3, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}
