:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --card: #1c2029;
  --card2: #232834;
  --border: #2c3240;
  --text: #e6e9ef;
  --text-dim: #8b93a3;
  --accent: #4f8cff;
  --accent2: #6ba6ff;
  --green: #31c48d;
  --red: #f0524f;
  --yellow: #eab308;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.head-wrap {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 0;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim); flex-shrink: 0;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.connecting { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.status-dot.disconnected { background: var(--red); }

.device-btn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--text);
  font-size: 16px; font-weight: 600; cursor: pointer; text-align: left;
}
.device-btn #deviceName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-btn .chev { color: var(--text-dim); font-size: 12px; }

.scene-mini {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scene-mini.live { color: var(--red); }

/* ---------- 设备卡片栏 ---------- */
.device-strip {
  display: flex; gap: 10px; overflow-x: auto;
  padding: 10px 12px; padding-bottom: 4px;
  scrollbar-width: none; flex-shrink: 0;
}
.device-strip::-webkit-scrollbar { display: none; }
.device-card {
  flex-shrink: 0; min-width: 108px; max-width: 150px;
  padding: 10px 12px; border-radius: 12px;
  background: var(--card); border: 1.5px solid var(--border);
  cursor: pointer; transition: all 0.15s;
  -webkit-user-select: none; user-select: none;
}
.device-card:active { transform: scale(0.96); }
.device-card.active { border-color: var(--accent); background: var(--card2); }
.device-card.is-live { border-color: var(--red); background: #2a1a1a; }
.dc-top { display: flex; align-items: center; gap: 6px; }
.dc-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dc-live {
  margin-top: 6px; font-size: 11px; color: var(--text-dim);
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--border);
}
.dc-live.live {
  background: #3a1c1c; color: #ff7a7a; font-weight: 600;
  box-shadow: 0 0 8px rgba(240, 82, 79, 0.4);
}
.device-card.add {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 64px; border-style: dashed; color: var(--text-dim);
}
.device-card.add .dc-plus { font-size: 22px; line-height: 1; }
.device-card.add .dc-add-txt { font-size: 11px; }

.vcam-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card2);
  color: var(--text-dim); font-size: 13px; cursor: pointer;
  flex-shrink: 0; transition: all 0.15s;
}
.vcam-toggle .cam-ico { font-size: 16px; }
.vcam-toggle .cam-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); flex-shrink: 0;
  transition: all 0.2s;
}
.vcam-toggle.on {
  background: #22392c; border-color: #3f6b4a; color: #a8f0c0;
}
.vcam-toggle.on .cam-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}
.vcam-toggle.busy {
  opacity: 0.7;
  border-color: var(--yellow);
}

/* ---------- 主界面 ---------- */
.app, .empty {
  padding: 12px 12px calc(88px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px;
}

.empty {
  min-height: 70vh; align-items: center; justify-content: center; text-align: center;
}
.empty-icon { font-size: 56px; color: var(--border); }
.empty-title { font-size: 18px; font-weight: 600; margin-top: 12px; }
.empty-desc { color: var(--text-dim); line-height: 1.6; max-width: 320px; margin: 8px 0 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.card-title .hint { font-weight: 400; font-size: 11px; }

/* ---------- 播放卡 ---------- */
.player-card .file {
  font-size: 13px; color: var(--accent2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 14px;
}
.progress {
  height: 16px; background: var(--bg); border-radius: 9px;
  cursor: pointer; position: relative; touch-action: none;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, #3d7ce0, var(--accent));
  border-radius: 9px; width: 0%; transition: width 0.25s linear; pointer-events: none;
}
.progress.dragging .progress-bar { transition: none; }
.progress-knob {
  position: absolute; top: 50%; left: 0%;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px #3d7ce0;
  transform: translate(-50%, -50%);
  opacity: 0.6; transition: opacity 0.12s; pointer-events: none;
}
.progress:active .progress-knob, .progress.dragging .progress-knob { opacity: 1; }
.time-row {
  display: flex; align-items: baseline; gap: 6px;
  margin-top: 10px; font-size: 13px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.time-row .now { color: var(--text); font-weight: 700; font-size: 15px; }
.time-row .left { margin-left: auto; font-size: 12px; }
.time-row .pct { font-size: 12px; }
.state-line {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px;
}
.monitor-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card2);
  color: var(--text-dim); font-size: 12px; cursor: pointer;
  transition: all 0.15s;
}
.monitor-btn.on {
  background: #22392c; border-color: #3f6b4a; color: #a8f0c0;
}
.state-badge {
  padding: 3px 12px; border-radius: 999px; font-size: 12px;
  background: var(--border); color: var(--text-dim);
}
.state-badge.st-play { background: #143c2c; color: var(--green); }
.state-badge.st-pause { background: #3a3a15; color: var(--yellow); }
.state-badge.st-end { background: #3a2020; color: var(--red); }
.dev-meta {
  font-size: 11px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 场景 ---------- */
.scene-list {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 4px; scrollbar-width: none;
}
.scene-list::-webkit-scrollbar { display: none; }
.scene-chip {
  flex-shrink: 0; padding: 10px 18px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); cursor: pointer; font-size: 14px;
  transition: all 0.15s; white-space: nowrap;
}
.scene-chip:active { transform: scale(0.96); }
.scene-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 源列表 ---------- */
.source-list { display: flex; flex-direction: column; gap: 8px; }
.source-item {
  padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card2);
  display: flex; align-items: center; gap: 10px;
}
.source-item.media { cursor: pointer; }
.source-item.media:active { transform: scale(0.98); }
.source-item.media.selected { border-color: var(--accent); background: #26334a; }
.src-icon { font-size: 18px; flex-shrink: 0; }
.src-info { flex: 1; min-width: 0; }
.src-name { font-weight: 600; font-size: 14px; }
.src-path {
  font-size: 12px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.group-tag { font-size: 11px; color: var(--yellow); font-weight: 400; margin-left: 4px; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--border); color: var(--text-dim); flex-shrink: 0;
}
.tag.media-tag { background: #2b3a55; color: var(--accent2); }
.tag.media-tag.st-play { background: #143c2c; color: var(--green); }
.tag.media-tag.st-pause { background: #3a3a15; color: var(--yellow); }
.tag.media-tag.st-end { background: #3a2020; color: var(--red); }
.tag.dim-tag { color: var(--text-dim); }

/* ---------- 日志 ---------- */
.log-card { padding-bottom: 8px; }
.log-head { cursor: pointer; justify-content: space-between; margin-bottom: 6px; }
.chev-up { color: var(--text-dim); transition: transform 0.2s; }
.log-card.collapsed .log { display: none; }
.log-card.collapsed .chev-up { transform: rotate(-90deg); }
.log {
  height: 130px; overflow-y: auto;
  font-family: "SF Mono", "Consolas", monospace; font-size: 12px; line-height: 1.7;
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
  -webkit-user-select: text; user-select: text;
}
.log .entry { display: flex; gap: 8px; }
.log .t { color: var(--text-dim); flex-shrink: 0; }
.log .l-info { color: var(--accent2); word-break: break-all; }
.log .l-warn { color: var(--yellow); word-break: break-all; }
.log .l-error { color: var(--red); word-break: break-all; }

/* ---------- 底部操作栏 ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; gap: 8px; align-items: stretch;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg2); border-top: 1px solid var(--border);
}
.abtn {
  min-height: 52px; flex: 1;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text);
  font-size: 16px; cursor: pointer; transition: all 0.12s;
  display: flex; align-items: center; justify-content: center;
}
.abtn:active { transform: scale(0.95); }
.abtn.seek { font-weight: 600; }
.abtn.play {
  flex: 1.6; font-size: 24px;
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.abtn.play.pause { background: var(--yellow); border-color: var(--yellow); color: #1a1a00; }
.abtn.stop { color: var(--red); }

/* ---------- 设备抽屉 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg2); border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  max-height: 70vh; display: flex; flex-direction: column;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 16px; font-weight: 700; margin-bottom: 12px;
}
.sheet-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.sheet-list { overflow-y: auto; margin-bottom: 12px; }
.sheet-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card);
  margin-bottom: 8px; cursor: pointer;
}
.sheet-item.active { border-color: var(--accent); }
.sheet-item .info { flex: 1; min-width: 0; }
.sheet-item .nm { font-weight: 600; font-size: 15px; }
.sheet-item .hs { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.sheet-item .st { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.sheet-item .icon-btn {
  background: none; border: none; font-size: 18px;
  cursor: pointer; padding: 8px; flex-shrink: 0; line-height: 1;
}
.sheet-item .icon-btn.edit { color: var(--text-dim); }
.sheet-item .icon-btn.edit:active { color: var(--accent); }
.sheet-item .icon-btn.del { color: var(--red); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: 100%; max-width: 380px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 18px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  font-size: 16px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ---------- 按钮 ---------- */
.btn {
  padding: 12px 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); cursor: pointer; font-size: 15px;
  transition: all 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big-btn { padding: 15px 24px; font-size: 16px; }
.add-btn { width: 100%; text-align: center; }

/* ---------- 桌面适配（宽屏） ---------- */
@media (min-width: 760px) {
  body { display: flex; flex-direction: column; }
  .topbar { max-width: 560px; margin: 0 auto; width: 100%; }
  .app, .empty { max-width: 560px; margin: 0 auto; width: 100%; }
  .actionbar { max-width: 560px; margin: 0 auto; left: 0; right: 0; }
  .sheet { max-width: 560px; margin: 0 auto; }
}
