:root {
  --bg: #f6f5f2; --panel: #fff; --ink: #1d1d1f; --muted: #66645f; --line: #e4e1da; --chip: #efece6;
  --accent: #c2501f; --accent-ink: #fff; --hit: #fff1c2; --star: #d99a00;
  --stage: #0d0d0c; --sung: #ffd23f; --unsung: #ffffff;
  --thai: "Sukhumvit Set", "Thonburi", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --panel: #1e1e1c; --ink: #ecebe7; --muted: #a3a09a; --line: #33322f; --chip: #2a2a27;
          --accent: #e8833a; --accent-ink: #191817; --hit: #5a4a12; --star: #f2b630; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 17px/1.35 var(--thai); -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- browse ---------- */
#browse { display: flex; flex-direction: column; height: 100%; overflow-x: hidden; }
header { background: var(--panel); border-bottom: 1px solid var(--line); padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px; }
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 22px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 10px; font-size: 15px; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected=true] { background: var(--chip); color: var(--ink); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; }
.searchrow { display: flex; gap: 8px; margin-top: 10px; }
#q { flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); outline: none; -webkit-appearance: none; }
#q:focus { border-color: var(--accent); }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--panel); padding: 0 12px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.count { color: var(--muted); font-size: 13px; margin-top: 6px; min-height: 18px; }
#list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(84px + var(--safe-b)); }
.row { display: grid; grid-template-columns: 34px 86px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.row .fav { border: 0; background: none; font-size: 22px; color: var(--line); padding: 0; }
.row .fav.on { color: var(--star); }
.code { font: 700 15px/1 ui-monospace, Menlo, monospace; color: var(--accent); }
.kind { display: block; margin-top: 4px; font: 700 10px/1 system-ui; color: var(--muted); letter-spacing: .5px; }
.ttl { min-width: 0; }
.ttl .th { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ttl .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acts { display: flex; gap: 6px; }
.btn { border: 2px solid var(--accent); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 15px; background: transparent; color: var(--accent); white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }
.more { display: block; margin: 16px auto; }
mark { background: var(--hit); color: inherit; border-radius: 3px; }

/* ---------- mini player ---------- */
#mini { position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--safe-b)); display: flex; align-items: center; gap: 6px;
        background: #1c1b19; color: #fff; border-radius: 16px; padding: 8px 8px 8px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.35); z-index: 10; }
.mini-info { flex: 1; min-width: 0; border: 0; background: none; text-align: left; color: #fff; padding: 2px 0; }
.mini-title { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { display: block; font-size: 12px; color: #b9b6ae; }
.iconbtn { border: 0; background: rgba(255,255,255,.1); color: inherit; border-radius: 12px; min-width: 46px; height: 46px; font-size: 20px; padding: 0 12px; }

/* ---------- singing screen ---------- */
#stage { position: fixed; inset: 0; background: var(--stage); color: #fff; display: flex; flex-direction: column; z-index: 20;
         padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) var(--safe-b) env(safe-area-inset-left, 0px); }
.stage-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.stage-title { flex: 1; min-width: 0; text-align: center; }
#stTitle { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stSub { font-size: 13px; color: #a9a6a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { min-width: 80px; text-align: right; font-size: 13px; color: var(--sung); }
#lyrics { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4vh; padding: 0 4vw; position: relative; overflow: hidden; }
.line { position: relative; font-family: var(--thai); font-weight: 700; font-size: clamp(26px, 6.2vw, 84px); line-height: 1.55; white-space: nowrap; }
#lineA { text-align: left; } #lineB { text-align: right; }
.line .wrap { display: inline-block; position: relative; max-width: none; }
.line .base, .line .hi { display: block; padding: 0 .1em; }
.line .base { color: var(--unsung); text-shadow: 0 0 3px #000, 0 0 3px #000, 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
.line .hi { position: absolute; top: 0; left: 0; color: var(--sung); text-shadow: 0 0 3px #4a2a00, 2px 2px 0 #4a2a00, -2px -2px 0 #4a2a00, 2px -2px 0 #4a2a00, -2px 2px 0 #4a2a00;
            clip-path: inset(0 100% 0 0); pointer-events: none; }
.line.done .base { opacity: .45; }
.intro { text-align: center; font-size: clamp(20px, 3.4vw, 40px); color: #d8d5cf; min-height: 1.4em; }
.intro .big { display: block; font-size: 1.5em; font-weight: 700; color: #fff; }
.upnext { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 14px; color: #8f8c86; }
.progress { display: flex; align-items: center; gap: 10px; padding: 0 16px; font: 13px/1 ui-monospace, Menlo, monospace; color: #b9b6ae; }
#seek { flex: 1; accent-color: var(--sung); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 18px; padding: 12px 12px 14px; }
.controls .grp { display: flex; align-items: center; gap: 6px; }
.controls .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: #a9a6a0; margin-right: 2px; }
.controls .val { min-width: 54px; text-align: center; font: 700 17px/1 ui-monospace, Menlo, monospace; }
.iconbtn.big { min-width: 64px; height: 52px; font-size: 24px; background: var(--sung); color: #1a1a19; }
.toggle { border: 2px solid #555; background: none; color: #fff; border-radius: 12px; height: 46px; padding: 0 14px; font-size: 15px; }
.toggle[aria-pressed=true] { border-color: var(--sung); color: var(--sung); }

/* equalizer sheet */
.sheet { position: absolute; left: 50%; transform: translateX(-50%); bottom: 0; width: min(560px, 100%); z-index: 30;
         background: #1f1e1b; border-radius: 20px 20px 0 0; padding: 14px 18px calc(16px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.5);
         max-height: 85%; overflow-y: auto; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head b { flex: 1; font-size: 18px; }
.sheet-head .btn { border-color: #555; color: #ddd; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { border: 2px solid #444; background: none; color: #ddd; border-radius: 999px; padding: 7px 13px; font-size: 14px; }
.chip[aria-pressed=true] { border-color: var(--sung); color: var(--sung); font-weight: 700; }
.band { display: grid; grid-template-columns: 92px minmax(0, 1fr) 64px; align-items: center; gap: 10px; padding: 6px 0; }
.bname { font-size: 15px; font-weight: 600; line-height: 1.15; }
.bname small { display: block; font-size: 11px; font-weight: 400; color: #9a978f; }
.band input { width: 100%; accent-color: var(--sung); height: 32px; }
.bval { text-align: right; font: 700 15px/1 ui-monospace, Menlo, monospace; }
.syncrow { display: grid; grid-template-columns: minmax(0, 1fr) auto 76px auto auto; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid #2e2d2a; }
.syncrow .sval { text-align: center; font: 700 17px/1 ui-monospace, Menlo, monospace; }
.syncrow .sval.on { color: var(--sung); }
.syncrow .btn { border-color: #555; color: #ddd; }
.sheet-note b { color: #ddd; }
.sheet-note { margin-top: 8px; font-size: 12px; color: #8f8c86; text-align: center; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(12px); opacity: 0; background: #1c1b19; color: #fff;
         padding: 12px 18px; border-radius: 12px; font-size: 15px; transition: all .2s; pointer-events: none; z-index: 40; max-width: 86vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: #b3261e; }

/* phones */
@media (max-width: 640px) {
  .row { grid-template-columns: 28px minmax(0, 1fr) auto; }
  .row .codecell { display: none; }
  .row .ttl .th { font-size: 16px; }
  .btn.queue { padding: 8px 12px; } .btn.queue .qtext { display: none; }
  .top { gap: 6px; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .tabs button { padding: 6px 10px; font-size: 14px; flex: none; }
  #kindseg { display: none; }
  .controls { gap: 8px 10px; }
  .controls .val { min-width: 40px; }
}
@media (orientation: portrait) and (max-width: 640px) {
  .line { font-size: clamp(22px, 8vw, 40px); }
}
