:root {
  --sky1: #e9f5ff;
  --sky2: #cfe8ff;
  --blue: #1f6fd1;
  --blue-d: #0d3f8f;
  --ink: #12305f;
  --muted: #5d7397;
  --line: #d6e6f8;
  --card: #ffffff;
  --sun: #ffd84d;
  --danger: #d64545;
  --radius: 12px;
  --font: "Leelawadee UI", "Noto Sans Thai", "Sarabun", "Tahoma", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky1), var(--sky2));
  overflow: hidden;
}
#app { display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; }
[hidden] { display: none !important; }

/* ---------- ปุ่ม ---------- */
.btn {
  font: inherit; font-size: 14px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #9cc4f0; background: #f4f9ff; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: #2a7fe6; }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.icon { padding: 7px 10px; }
.btn.small { font-size: 13px; padding: 5px 10px; }
.btn.mini { font-size: 15px; padding: 2px 9px; border-radius: 8px; }
.btn.round { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 15px; }
.btn.round.big { width: 52px; height: 52px; font-size: 20px; background: var(--blue); color: #fff; border-color: var(--blue); }
.btn:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- แถบบน ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: rgba(255,255,255,.85);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: max-content; }
.brand-icon { width: 38px; height: 38px; }
.brand-text { font-size: 20px; line-height: 1.05; color: var(--blue-d); }
.brand-text b { color: var(--blue); font-size: 24px; }
.brand-text span { display: block; font-size: 11px; letter-spacing: .12em; color: var(--muted); }
.search { flex: 1; max-width: 520px; position: relative; }
.search input { padding-right: 46px !important; }
.voice-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: transparent; color: var(--blue); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.voice-btn:hover { background: #eef6ff; }
.voice-btn.listening { background: #e53935; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,57,53,.5); } 50% { box-shadow: 0 0 0 8px rgba(229,57,53,0); } }
@media (prefers-reduced-motion: reduce) { .voice-btn.listening { animation: none; } }
.search input {
  width: 100%; font: inherit; font-size: 15px; padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); outline: none;
}
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,111,209,.15); }
.top-actions { display: flex; gap: 8px; margin-left: auto; }
.only-narrow { display: none; }

/* ---------- พื้นที่หลัก ---------- */
.main { display: grid; grid-template-columns: 1fr 380px; grid-template-rows: minmax(0, 1fr); min-height: 0; }
.stage { position: relative; min-height: 0; background: #0a2f78; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-info {
  position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 18px; pointer-events: none; color: #fff; text-shadow: 0 1px 3px rgba(0,30,80,.6);
}
.now-title { font-size: 20px; font-weight: 700; }
.now-artist { font-size: 14px; opacity: .9; }
.badges { display: flex; gap: 6px; }
.badge { background: rgba(10,40,100,.55); border: 1px solid rgba(255,255,255,.35); padding: 3px 10px; border-radius: 999px; font-size: 13px; }
.stage-next {
  position: absolute; right: 18px; top: 56px; color: #fff; font-size: 13px;
  background: rgba(10,40,100,.45); padding: 4px 12px; border-radius: 999px; pointer-events: none;
}
.drop-hint {
  position: absolute; inset: 16px; border: 3px dashed rgba(255,255,255,.8); border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; font-size: 28px; font-weight: 700; background: rgba(10,47,120,.55); pointer-events: none;
}
.drop-hint small { font-size: 15px; font-weight: 400; margin-top: 6px; }
.stage:fullscreen .stage-info { padding: 22px 28px; }

/* ---------- แผงรายการ ---------- */
.panel { display: flex; flex-direction: column; min-height: 0; background: rgba(255,255,255,.92); border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; font: inherit; font-size: 14px; padding: 11px 6px; background: none; border: 0; cursor: pointer;
  color: var(--muted); border-bottom: 3px solid transparent;
}
.tab.active { color: var(--blue-d); border-bottom-color: var(--blue); font-weight: 700; }
.tab span { font-size: 12px; background: var(--sky2); padding: 1px 7px; border-radius: 999px; margin-left: 2px; }
.tab-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.list-tools { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-tools input { flex: 1; font: inherit; font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.list li {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #eef4fb; cursor: default;
}
.list li:hover { background: #f3f8ff; }
.list li.playing { background: #fff6cf; }
.list .info { flex: 1; min-width: 0; }
.list .t { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .a { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .tag { font-size: 10.5px; color: var(--blue-d); background: var(--sky2); padding: 1px 6px; border-radius: 6px; }
.list .acts { display: flex; gap: 4px; opacity: .85; }
.list .acts .btn { padding: 3px 8px; font-size: 13px; }
.list .num { width: 22px; text-align: right; color: var(--muted); font-size: 12px; }
.list .empty { justify-content: center; color: var(--muted); padding: 30px 16px; text-align: center; border: 0; }
.list .empty:hover { background: none; }
.notice { font-size: 12px; color: var(--muted); line-height: 1.55; }
.small-notice { margin: 0; padding: 10px 12px; border-top: 1px solid var(--line); background: #f7fbff; }

/* ---------- แถบควบคุม ---------- */
.transport {
  display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center;
  padding: 10px 16px; background: rgba(255,255,255,.95); border-top: 1px solid var(--line);
}
.tp-buttons { display: flex; gap: 8px; align-items: center; }
.tp-seek { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.tp-seek input { flex: 1; }
.tp-controls { display: flex; gap: 16px; align-items: center; }
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl-label { font-size: 13px; color: var(--muted); }
.ctl-val { min-width: 44px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.vol input { width: 100px; }
input[type=range] { accent-color: var(--blue); }

/* ---------- หน้าต่างซ้อน ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,35,90,.55); display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px; backdrop-filter: blur(4px);
}
#startOverlay { background: linear-gradient(180deg, #6dbdf6, #1f6fd1 60%, #0a2f78); }
.card { background: var(--card); border-radius: 18px; padding: 22px; box-shadow: 0 20px 60px rgba(0,20,70,.35); max-width: 520px; width: 100%; }
.start-card { text-align: center; padding: 30px 28px; }
.start-icon { width: 84px; height: 84px; }
.start-card h1 { margin: 8px 0 4px; font-size: 32px; color: var(--blue-d); }
.lead { margin: 0 0 18px; color: var(--muted); }
.big-btn { font-size: 18px; padding: 12px 34px; border-radius: 999px; }
.progress { margin: 16px 0 4px; }
.bar { height: 10px; background: var(--sky2); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #5fb4f2, var(--blue)); transition: width .15s; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card h2 { margin: 0; font-size: 20px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; color: var(--blue-d); }
.settings-card { max-height: 90dvh; overflow-y: auto; }
.radio { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.confirm-card { max-width: 380px; }

/* ---------- เมนู / แจ้งเตือน ---------- */
.menu {
  position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,30,80,.2); padding: 6px; min-width: 200px; max-height: 60vh; overflow-y: auto;
}
.menu button { display: block; width: 100%; text-align: left; font: inherit; font-size: 14px; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: #f0f7ff; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu .label { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 70;
  background: #0d3f8f; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,20,60,.3);
  max-width: 90vw; text-align: center;
}

/* ---------- สิทธิ์ฟรี ---------- */
.plan-badge { font-size: 12.5px; color: var(--blue-d); background: #fff6cf; border: 1px solid #f2dc7a; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.plan-badge.out { background: #ffe3e3; border-color: #f0a0a0; color: #a12a2a; }
.limit-card { text-align: center; max-width: 420px; }
.limit-card h2 { color: var(--blue-d); margin: 8px 0; }
.limit-card .price { font-weight: 700; color: var(--blue); }
.row.center { justify-content: center; }

/* ---------- รีโมตมือถือ ---------- */
#btnRemote { position: relative; }
#btnRemote.on { border-color: #36b37e; color: #12663f; background: #e9fbf2; }
#btnRemote[data-count]:not([data-count=""])::after {
  content: attr(data-count); position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; border-radius: 9px;
  background: #36b37e; color: #fff; font-size: 11px; line-height: 18px; text-align: center; padding: 0 4px;
}
.remote-card { max-width: 720px; max-height: 92dvh; overflow-y: auto; }
.remote-grid { display: grid; grid-template-columns: 240px 1fr; gap: 20px; margin-top: 12px; }
.remote-qr { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 8px; }
.remote-qr svg { display: block; width: 100%; height: auto; }
.remote-code { text-align: center; margin-top: 8px; font-size: 14px; color: var(--muted); }
.remote-code b { font-size: 26px; letter-spacing: .18em; color: var(--blue-d); display: block; }
.remote-steps { margin: 0 0 10px; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.remote-status { font-size: 14px; padding: 6px 10px; border-radius: 8px; background: #f0f5fb; margin: 6px 0; }
.remote-status.ok { background: #e9fbf2; color: #12663f; }
.remote-status.err { background: #ffecec; color: #a12a2a; }
.remote-pin { margin: 8px 0; font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.remote-pin b { font-size: 20px; letter-spacing: .15em; color: var(--blue-d); }
.remote-url { word-break: break-all; }
.remote-devices { list-style: none; padding: 0; margin: 0 0 10px; }
.remote-devices li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #eef4fb; font-size: 14px; }
.remote-devices .admin { font-size: 11px; color: #12663f; background: #e9fbf2; padding: 1px 6px; border-radius: 6px; }
.list .by { color: #9a5b00; background: #fff3d6; padding: 0 6px; border-radius: 6px; font-size: 11.5px; }
@media (max-width: 640px) { .remote-grid { grid-template-columns: 1fr; } .remote-qr-box { max-width: 260px; margin: 0 auto; } }

/* ---------- เสียงและเอฟเฟกต์ ---------- */
.fx-card { max-width: 820px; height: min(90dvh, 820px); display: flex; flex-direction: column; padding-bottom: 12px; }
.fx-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px -22px 0; padding: 0 22px; overflow-x: auto; }
.fx-tab { font: inherit; font-size: 14px; padding: 10px 14px; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.fx-tab.active { color: var(--blue-d); border-bottom-color: var(--blue); font-weight: 700; }
.fx-body { flex: 1; overflow-y: auto; padding: 4px 2px 8px; min-height: 0; }
.fx-sl { display: grid; grid-template-columns: minmax(110px, 190px) 1fr 92px; align-items: center; gap: 10px; font-size: 14px; padding: 3px 0; }
.fx-sl b { font-size: 13px; text-align: right; color: var(--blue-d); font-variant-numeric: tabular-nums; }
.fx-sl input { width: 100%; }
.fx-sw { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.fx-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fx-presets .btn { display: flex; flex-direction: column; align-items: center; padding: 10px; white-space: normal; }
.fx-presets small { font-size: 12px; opacity: .8; }
.fx-row2 { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 14px; }
.fx-row2 select, .fx-pick select, #fx-mic select { font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; margin-left: 6px; max-width: 100%; }
.fx-eq { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; text-align: center; margin: 6px 0 12px; }
.fx-eq label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.fx-eq input { writing-mode: vertical-lr; direction: rtl; height: 120px; width: 28px; }
.fx-eq b { font-size: 12px; color: var(--blue-d); }
.fx-chs { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; }
.fx-ch { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: #fbfdff; }
.fx-ch.muted { opacity: .55; }
.fx-ch .fx-sl { grid-template-columns: 62px 1fr 74px; font-size: 13px; }
.fx-ch-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.fx-ch-head b { width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.fx-ch-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.mini.on { background: #ffd84d; border-color: #e6bd1f; }
.fx-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.fx-pick { display: block; margin: 10px 0; font-size: 14px; }
.fx-meter { flex: 1; min-width: 120px; height: 10px; background: #e3eef9; border-radius: 6px; overflow: hidden; }
.fx-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #36b37e, #ffd84d 70%, #e53935); transition: width .08s; }
@media (max-width: 640px) {
  .fx-sl { grid-template-columns: 1fr 74px; } .fx-sl span { grid-column: 1 / 3; }
  .fx-presets { grid-template-columns: 1fr; } .fx-chs { grid-template-columns: 1fr; }
}

@media (max-width: 1280px) { .top-actions .lbl { display: none; } .plan-badge { font-size: 11.5px; } }

/* ---------- จอแคบ / มือถือ ---------- */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .panel {
    position: fixed; z-index: 40; right: 0; top: 58px; bottom: 0; width: min(420px, 100vw);
    box-shadow: -10px 0 30px rgba(0,30,80,.25); transform: translateX(105%); transition: transform .2s;
  }
  .panel.open { transform: none; }
  .only-narrow { display: inline-block; }
  .brand-text span { display: none; }
  #btnAddFolder { display: none; }
  .transport { grid-template-columns: 1fr; gap: 8px; padding: 8px 10px; }
  .tp-buttons { justify-content: center; }
  .tp-controls { justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .vol input { width: 80px; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .plan-badge { order: 4; }
  .brand-text { font-size: 17px; }
  .brand-text b { font-size: 20px; }
  #btnAddFiles { padding: 7px 10px; }
  .panel { top: 104px; }
  .now-title { font-size: 16px; }
}
