/* ============================================================
   Web DJ — 样式
   深色为主，[data-theme="light"] 切换浅色
   ============================================================ */

:root {
  --deck-a: #EF9F27;
  --deck-b: #378ADD;
  --ok: #97C459;
  --warn: #EF9F27;
  --danger: #E24B4A;

  --radius: 8px;
  --radius-lg: 12px;
  --topbar-h: 48px;
  --lib-h: clamp(168px, 24vh, 264px);
}

[data-theme="dark"] {
  --bg: #0d0d0d;
  --bg2: #161616;
  --panel: #1c1c1c;
  --panel2: #242424;
  --panel3: #2c2c2c;
  --border: rgba(255,255,255,.09);
  --border2: rgba(255,255,255,.18);
  --text: #e6e6e6;
  --text2: #9a9a9a;
  --text3: #666;
  --wave-bg: #101010;
  --wave-grid: rgba(255,255,255,.06);
  /* 波形彩虹层：中心(蓝)→外围(红)，频率越高越暖 */
  --wave-blue: #2E6FD8;
  --wave-cyan: #31A8A0;
  --wave-green: #7EC850;
  --wave-yellow: #E5C440;
  --wave-orange: #E89A3D;
  --wave-red: #DF5B4A;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset;
}

[data-theme="light"] {
  --bg: #eceef1;
  --bg2: #f5f6f8;
  --panel: #ffffff;
  --panel2: #f2f3f5;
  --panel3: #e6e8eb;
  --border: rgba(0,0,0,.10);
  --border2: rgba(0,0,0,.20);
  --text: #1c1c1c;
  --text2: #5f5f5f;
  --text3: #9a9a9a;
  --wave-bg: #fafafa;
  --wave-grid: rgba(0,0,0,.06);
  /* 浅底上同色系整体加深一档，黄/橙这类高亮度色才压得住 */
  --wave-blue: #2565C0;
  --wave-cyan: #2E8A84;
  --wave-green: #6FA832;
  --wave-yellow: #C9A227;
  --wave-orange: #C97F2E;
  --wave-red: #C44A3E;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--lib-h);
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  /* 混音台是「操作面板」不是「文档」：拖推子、拖波形、拖曲目的过程中
     最容易带出一道蓝底白字的选区，观感极差且复制不到有意义的内容 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 输入控件不受禁选影响 —— 搜索框还是要能选词删改的 */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; font-size: inherit; }

/* ---------- 顶栏 ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.brand { display: flex; align-items: baseline; gap: 8px; flex: none; }
.brand-mark {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--deck-a), var(--deck-b));
  align-self: center;
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--text3); }

.topbar-mid { flex: 1; min-width: 0; display: flex; justify-content: center; }
#lib-search {
  width: 100%; max-width: 380px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 6px 14px;
  outline: none;
  transition: border-color .15s;
}
#lib-search:focus { border-color: var(--border2); }

.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.engine-status {
  font-size: 11px;
  color: var(--text3);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.engine-status.live { color: var(--ok); border-color: rgba(151,196,89,.4); }

.tb-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  color: var(--text2);
  transition: all .15s;
  white-space: nowrap;
}
.tb-btn:hover { color: var(--text); border-color: var(--border2); }
.tb-primary {
  background: var(--deck-a);
  border-color: var(--deck-a);
  color: #1a1206;
  font-weight: 500;
}
.tb-primary:hover { filter: brightness(1.1); color: #1a1206; }

/* ---------- 主舞台 ---------- */

#stage {
  display: grid;
  /* 卡座按内容高度自动排（它的内容高度基本是固定的），
     多余的高度全部给波形 —— 波形是 DJ 界面的主角，也最吃高度。
     之前两行都按比例分配，高分辨率下卡座会被拉高，底部留一大片空白。 */
  grid-template-rows: minmax(clamp(108px, 20vh, 178px), 1fr) auto;
  min-height: 0;
  gap: 8px;
  padding: 8px;
}

/* ---------- 波形 ---------- */

#waveforms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-height: 0;
}

.wave-panel {
  display: grid;
  /* head / 效果器行 / 概览条 / 主波形 / foot —— Serato 布局 */
  grid-template-rows: 26px auto 28px minmax(0, 1fr) 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}

.wave-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.deck-chip {
  font-size: 10px;
  font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.chip-a { background: var(--deck-a); color: #1a1206; }
.chip-b { background: var(--deck-b); color: #06121f; }

.wave-title {
  font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.wave-meta { font-size: 11px; color: var(--text3); margin-left: auto; white-space: nowrap; }

/* 整首概览条：Serato 式迷你整首波形，按住拖拽定位 */
.wave-fx {
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
  padding: 4px 10px;
  min-width: 0;
}
.wave-fx .fx-row { gap: 10px; }
.wave-fx .knob-bank { flex: none; }

.wave-overview {
  border-bottom: 1px solid var(--border);
  background: var(--wave-bg);
  cursor: grab;
  position: relative;
  min-width: 0;
}
.wave-overview:active { cursor: grabbing; }
.wave-ov-canvas { display: block; width: 100%; height: 100%; }

.wave-canvas-wrap { position: relative; min-height: 0; background: var(--wave-bg); }
.wave-canvas { display: block; width: 100%; height: 100%; }

/* 曲目拖到波形区时的落点提示 —— 用各 deck 的主题色描边 */
.wave-panel.drop-target { border-color: var(--deck-a); }
.wave-panel[data-deck="B"].drop-target { border-color: var(--deck-b); }
.wave-panel.drop-target .wave-canvas-wrap {
  box-shadow: inset 0 0 0 2px var(--deck-a);
}
.wave-panel[data-deck="B"].drop-target .wave-canvas-wrap {
  box-shadow: inset 0 0 0 2px var(--deck-b);
}

/* 曲库行可拖动加载的暗示 */
.lib-table tbody tr { cursor: grab; }

.wave-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  font-size: 12px;
  pointer-events: none;
  text-align: center;
  padding: 0 20px;
}
.wave-empty.hide { display: none; }

.wave-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
}
.t-time { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Consolas", monospace; }
.wave-zoom { display: flex; gap: 3px; margin: 0 auto; }
.zoom-label { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }



.mini-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text2);
  padding: 1px 7px;
  font-size: 11px;
  line-height: 16px;
  transition: all .12s;
}
.mini-btn:hover { color: var(--text); border-color: var(--border2); }
.mini-btn.wide { width: 100%; padding: 4px 7px; }
.mini-btn.on { background: var(--ok); border-color: var(--ok); color: #101a05; }

/* ---------- Deck 面板 ---------- */

#decks {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.deck-panel, .mixer-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.deck-panel[data-deck="A"] { border-top: 2px solid var(--deck-a); }
.deck-panel[data-deck="B"] { border-top: 2px solid var(--deck-b); }

/* 曲目信息 */
.dk-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dk-platter {
  width: 62px; height: 62px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--panel3) 0 22%, var(--panel2) 22% 100%);
  border: 1px solid var(--border2);
  position: relative;
  flex: none;
  /* 别给 transform 加过渡：角度每帧由 JS 写入，取模回绕时过渡会把
     正常的整圈续转演成大角度倒车 —— 转盘「弹回」就是这么来的 */
  will-change: transform;
}
.dk-platter::after {
  content: '';
  position: absolute;
  left: 50%; top: 4px;
  width: 2px; height: 12px;
  background: var(--accent, var(--text2));
  border-radius: 1px;
  transform: translateX(-50%);
}
.deck-panel[data-deck="A"] .dk-platter { --accent: var(--deck-a); }
.deck-panel[data-deck="B"] .dk-platter { --accent: var(--deck-b); }

.dk-texts { min-width: 0; flex: 1; }
.dk-title {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dk-artist {
  font-size: 11px; color: var(--text3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dk-badges { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-variant-numeric: tabular-nums;
}
.badge.accent { color: var(--text); border-color: var(--border2); }

/* 控制行 */
.dk-row { display: flex; gap: 10px; align-items: flex-start; }

.dk-eq { flex: 1; display: grid; gap: 6px; align-content: start; min-width: 0; }

.knob-bank { display: flex; gap: 8px; justify-content: space-around; }

.knob-cell { display: grid; justify-items: center; gap: 3px; }
.knob-cell .k-label { font-size: 9px; color: var(--text3); letter-spacing: .5px; }

.knob {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--panel2);
  border: 1px solid var(--border2);
  position: relative;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}
.knob::before {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 50%;
  background: var(--panel3);
}
.knob-ind {
  position: absolute;
  left: 50%; top: 3px;
  width: 2px; height: 9px;
  background: var(--accent, var(--text));
  border-radius: 1px;
  transform-origin: 50% 16px;
  transform: translateX(-50%) rotate(var(--rot, 0deg));
  pointer-events: none;
}
.deck-panel[data-deck="A"] .knob { --accent: var(--deck-a); }
.deck-panel[data-deck="B"] .knob { --accent: var(--deck-b); }
.knob:hover { border-color: var(--accent, var(--border2)); }
.knob.dragging { border-color: var(--accent, var(--text)); }

.kill-row { display: flex; gap: 8px; justify-content: space-around; }
.kill-btn {
  width: 38px; height: 17px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 9px;
  color: var(--text3);
  letter-spacing: .5px;
}
.kill-btn.on {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Tempo */
.dk-tempo { display: grid; justify-items: center; gap: 4px; flex: none; }
.fader-v {
  width: 26px; height: 76px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  position: relative;
  cursor: ns-resize;
  touch-action: none;
}
.fader-v .fader-cap {
  position: absolute;
  left: 3px; right: 3px;
  height: 16px;
  background: var(--panel3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}
.fader-v .fader-cap::after {
  content: '';
  position: absolute; left: 4px; right: 4px; top: 50%;
  height: 1px; background: var(--accent, var(--text2));
  transform: translateY(-50%);
}
.deck-panel[data-deck="A"] .fader-v { --accent: var(--deck-a); }
.deck-panel[data-deck="B"] .fader-v { --accent: var(--deck-b); }

.tempo-read { font-size: 10px; color: var(--text2); font-variant-numeric: tabular-nums; }

/* 运输控制 */
.dk-transport { display: flex; gap: 6px; align-items: center; }
.big-btn {
  flex: 1;
  height: 38px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text2);
  transition: all .12s;
}
.big-btn:hover { border-color: var(--border2); color: var(--text); }
.big-btn.play.on {
  background: var(--ok);
  border-color: var(--ok);
  color: #101a05;
  font-weight: 600;
}
.big-btn.cue.on { background: var(--warn); border-color: var(--warn); color: #1a1206; }
.big-btn.sync.on { background: var(--deck-b); border-color: var(--deck-b); color: #06121f; }

/* Cue / Loop 网格 */
.pad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.pad {
  height: 26px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 10px;
  color: var(--text2);
  transition: all .12s;
}
.pad:hover { border-color: var(--border2); color: var(--text); }
.pad.set { background: var(--panel3); color: var(--text); border-color: var(--border2); }
.pad.hit { background: var(--accent-pad, var(--deck-a)); color: #101010; }
/* LOOP 开关键：激活时用循环区的同款绿 */
.pad.on { background: rgba(151,196,89,.85); border-color: rgba(151,196,89,.9); color: #0d1a06; }

.deck-panel[data-deck="A"] .pad { --accent-pad: var(--deck-a); }
.deck-panel[data-deck="B"] .pad { --accent-pad: var(--deck-b); }

.loop-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }

/* FX */
.fx-row { display: flex; gap: 8px; align-items: center; }
.fx-select {
  flex: 1;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 3px 6px;
  outline: none;
  font-size: 11px;
  min-width: 0;
}
.fx-select:focus { border-color: var(--border2); }

/* ---------- 混音台 ---------- */

.mixer-panel { align-content: start; }

.mx-title {
  font-size: 10px; color: var(--text3); letter-spacing: 1px;
  text-align: center; text-transform: uppercase;
}

.vu-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.vu {
  height: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.vu i {
  display: block; height: 100%; width: 0%;
  background: var(--ok);
  transition: width .05s linear, background .2s;
}
.vu.hot i { background: var(--warn); }
.vu.clip i { background: var(--danger); }
.vu-label { font-size: 9px; color: var(--text3); text-align: center; }

.xfader-wrap { display: grid; gap: 4px; }
.fader-h {
  height: 30px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  position: relative;
  cursor: ew-resize;
  touch-action: none;
}
.fader-h .fader-cap {
  position: absolute;
  top: 3px; bottom: 3px;
  width: 22px;
  background: var(--panel3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.fader-h .fader-cap::after {
  content: '';
  position: absolute; top: 4px; bottom: 4px; left: 50%;
  width: 1px; background: var(--text2);
  transform: translateX(-50%);
}
.xfader-legend { display: flex; justify-content: space-between; font-size: 10px; color: var(--text3); }

.mx-master { display: grid; gap: 4px; justify-items: center; }
.mx-master .fader-v { width: 44px; height: 56px; }

.mx-stats { display: grid; gap: 3px; font-size: 10px; color: var(--text3); text-align: center; }

/* ---------- 自动混音面板 ---------- */

.am-head { display: flex; align-items: center; justify-content: center; gap: 6px; }
.am-head .mx-title { flex: none; }

.am-chip {
  font-size: 10px; color: var(--text3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 6px;
  line-height: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.am-chip.armed { color: var(--warn); border-color: var(--warn); }
.am-chip.live { color: #101a05; background: var(--ok); border-color: var(--ok); }

.am-row { display: flex; align-items: center; gap: 3px; }
.am-row .mini-btn { flex: 1 1 auto; text-align: center; }

.am-bars .am-bar { flex: 1 1 0; min-width: 0; padding: 1px 2px; }

.am-input {
  width: 44px; flex: none;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 1px 4px;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.am-input:focus { outline: none; border-color: var(--border2); }
.am-input.hide { display: none; }
.am-unit { flex: 0 0 auto !important; min-width: 34px; }
.am-unit.hide { display: none; }
.am-len { flex: 1 1 auto; font-size: 10px; color: var(--text3); text-align: center; white-space: nowrap; }
.am-len.hide { display: none; }
.am-go { flex: 0 0 auto !important; }
.am-go:disabled { opacity: .4; cursor: default; }

/* ---------- 曲库 ---------- */

#library {
  margin: 0 8px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: grid;
  grid-template-rows: 30px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.lib-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}
.lib-title { font-size: 12px; font-weight: 500; }
.lib-count { font-size: 11px; color: var(--text3); }
.lib-spacer { flex: 1; }

.lib-body { display: grid; grid-template-columns: minmax(0, 1fr) 240px; min-height: 0; }

.lib-table-wrap { overflow: auto; position: relative; min-height: 0; }

.lib-table { width: 100%; border-collapse: collapse; }
.lib-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel);
  text-align: left;
  font-size: 10px;
  font-weight: 500;
  color: var(--text3);
  letter-spacing: .5px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.lib-table th.sortable { cursor: pointer; user-select: none; }
.lib-table th.sortable:hover { color: var(--text); }
.lib-table th.asc::after { content: ' ▲'; font-size: 8px; }
.lib-table th.desc::after { content: ' ▼'; font-size: 8px; }

.lib-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}
.lib-table tr { cursor: pointer; }
.lib-table tbody tr:hover td { background: var(--panel2); }
.lib-table tbody tr.playing td { color: var(--ok); }
.lib-table tbody tr.loaded-a td:first-child { box-shadow: inset 3px 0 0 var(--deck-a); }
.lib-table tbody tr.loaded-b td:first-child { box-shadow: inset 3px 0 0 var(--deck-b); }

.c-idx { width: 34px; color: var(--text3); }
.c-bpm { width: 62px; font-variant-numeric: tabular-nums; }
.c-key { width: 52px; }
.c-time { width: 60px; font-variant-numeric: tabular-nums; }
.c-act { width: 96px; }

.row-act { display: flex; gap: 4px; }
.row-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px;
  padding: 1px 6px;
  color: var(--text2);
}
.row-btn:hover { color: var(--text); border-color: var(--border2); }
.row-btn.to-a:hover { border-color: var(--deck-a); color: var(--deck-a); }
.row-btn.to-b:hover { border-color: var(--deck-b); color: var(--deck-b); }

.lib-empty {
  padding: 24px;
  text-align: center;
  color: var(--text3);
  font-size: 12px;
}
.lib-empty.hide { display: none; }

.lib-queue {
  border-left: 1px solid var(--border);
  display: grid;
  /* 四行：head / list / 空状态 / 底部开关。之前只声明三行，
     .queue-empty 落到隐式行上，矮视口下会把 list 挤成 0 高。 */
  grid-template-rows: 26px minmax(0,1fr) auto auto;
  min-height: 0;
}
.queue-head {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--text2);
}
.queue-head .mini-btn { margin-left: auto; }
.queue-list { list-style: none; overflow: auto; min-height: 0; }
.queue-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.queue-list li:hover { background: var(--panel2); color: var(--text); }
.queue-list li span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.queue-list li b { color: var(--text3); font-weight: 400; font-variant-numeric: tabular-nums; }
.queue-empty { padding: 16px; text-align: center; color: var(--text3); font-size: 11px; }
.queue-empty.hide { display: none; }
.queue-foot { padding: 6px; border-top: 1px solid var(--border); }

/* ---------- 拖放遮罩 ---------- */

.drop-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-overlay.show { display: flex; }
.drop-box {
  border: 2px dashed var(--deck-a);
  border-radius: 16px;
  padding: 28px 48px;
  color: #fff;
  font-size: 15px;
  background: rgba(0,0,0,.4);
}

/* ---------- 模态 ---------- */

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  width: min(560px, 90vw);
  max-height: 80vh;
  display: grid;
  grid-template-rows: 40px minmax(0,1fr);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 500;
}
.modal-close {
  margin-left: auto;
  background: none; border: none;
  font-size: 20px; line-height: 1;
  color: var(--text3);
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { overflow: auto; padding: 12px 14px; }

.key-group { margin-bottom: 14px; }
.key-group h4 {
  font-size: 11px; color: var(--text3); font-weight: 500;
  letter-spacing: .5px; margin-bottom: 6px;
}
.key-line {
  display: grid; grid-template-columns: 110px 1fr;
  gap: 10px; padding: 3px 0;
  font-size: 12px; color: var(--text2);
}
.key-line kbd {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--text);
  justify-self: start;
}

/* ---------- Toast ---------- */

.toast-host {
  position: fixed;
  right: 16px; bottom: calc(var(--lib-h) + 16px);
  z-index: 120;
  display: grid; gap: 6px;
  justify-items: end;
  pointer-events: none;
}
.toast {
  background: var(--panel3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text);
  max-width: 340px;
  animation: toast-in .18s ease-out;
}
.toast.err { border-color: var(--danger); color: #ffb4b3; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 窄屏 ---------- */

@media (max-width: 1180px) {
  #decks { grid-template-columns: minmax(0,1fr) 200px minmax(0,1fr); }
  .knob { width: 34px; height: 34px; }
  .lib-body { grid-template-columns: minmax(0,1fr) 190px; }
}

/* 三栏在 760px 以上都排得下（每栏还有约 260px）。
   再窄就竖排，此时高度必然超出一屏，改成整页滚动 —— 不能让三块面板叠着溢出。 */
@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    grid-template-rows: var(--topbar-h) auto auto;
  }
  #stage { grid-template-rows: clamp(100px, 20vh, 160px) auto; }
  #waveforms { grid-template-columns: 1fr; }
  #decks { grid-template-columns: 1fr; }
  .mixer-panel { grid-template-columns: repeat(3, 1fr); }
  #library { min-height: 200px; }
  .lib-body { grid-template-columns: minmax(0,1fr) 190px; }
}

/* ---------- 矮窗口 ----------
   deck 面板的内容有一层约 365px 的硬下限（转盘 62 + 控制行 95 + 运输 38
   + 两行 pad 52 + FX 行 54 + 内边距与间距）。视口不够高时 grid 行会被压到
   365px 以下，面板就会溢出并盖到下面的曲库上。这里按视口高度分两档收缩。 */

@media (max-height: 800px) {
  :root { --lib-h: clamp(170px, 24vh, 230px); }
  #stage { grid-template-rows: minmax(clamp(100px, 17vh, 150px), 1fr) auto; }

  .deck-panel, .mixer-panel { padding: 8px; gap: 6px; }

  .dk-platter { width: 50px; height: 50px; }
  .knob { width: 32px; height: 32px; }
  .knob::before { inset: 3px; }
  .knob-ind { top: 2px; height: 8px; transform-origin: 50% 13px; }
  .knob-bank { gap: 6px; }
  .dk-eq { gap: 4px; }
  .kill-btn { width: 32px; height: 15px; }

  .fader-v { height: 56px; }
  .mx-master .fader-v { height: 46px; }
  .fader-h { height: 26px; }

  .big-btn { height: 32px; }
  .pad { height: 22px; }
  .fx-select { padding: 2px 6px; }

  /* 曲库右栏在矮视口下要留出队列列表的空间 */
  .queue-head { height: 24px; }
  .queue-empty { padding: 8px; }
  .queue-foot { padding: 4px; }
  .lib-table th { padding: 4px 8px; }
  .lib-table td { padding: 3px 8px; }
}

/* 再矮就放弃「一屏装下」，改成整页滚动 —— 宁可滚动，也不能让控件互相盖住 */
@media (max-height: 660px) {
  :root { --lib-h: 150px; }
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    grid-template-rows: var(--topbar-h) auto auto;
  }
  #stage { grid-template-rows: 104px auto; }
  #decks { min-height: 300px; }
  #library { min-height: 148px; }
}
