:root {
  --bg-0: #070b16;
  --bg-1: #0d1424;
  --bg-2: #131c30;
  --line: rgba(148, 180, 226, 0.16);
  --text: #e8eefc;
  --text-dim: #8fa3c4;
  --cyan: #22d3ee;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 16px;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  user-select: none;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(34, 211, 238, 0.13), transparent 60%),
    radial-gradient(900px 500px at 92% 110%, rgba(52, 211, 153, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 22, 0.55);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.12);
  transition: background .3s, box-shadow .3s;
}
.brand .dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18), 0 0 14px rgba(52, 211, 153, .8); }
.brand .dot.warn { background: var(--amber); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.16); }

.brand-title { font-size: clamp(18px, 1.5vw, 26px); font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: clamp(12px, .85vw, 15px); color: var(--text-dim); padding-left: 4px; }

.pills { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  font-size: clamp(12px, .9vw, 15px);
  color: var(--text-dim);
  background: rgba(19, 28, 48, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.pill b { color: var(--text); font-weight: 600; }
.pill .led {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim);
  transition: background .3s, box-shadow .3s;
}
.pill.ok .led { background: var(--green); box-shadow: 0 0 8px var(--green); }
.pill.warn .led { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.pill.bad .led { background: var(--red); box-shadow: 0 0 8px var(--red); }
.pill.speaking { border-color: rgba(251, 191, 36, .5); color: var(--amber); }
.pill-clock { font-variant-numeric: tabular-nums; letter-spacing: .5px; }

/* ---------------- 画面 ---------------- */
.stage {
  position: relative;
  margin: 14px 18px;
  border-radius: 22px;
  overflow: hidden;
  background: #05080f;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 120px rgba(0, 0, 0, .7);
  min-height: 0;
}

#preview {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  background: #05080f;
}
#preview.mirror { transform: scaleX(-1); }
#preview.hidden { opacity: 0; }

.placeholder {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 30px;
  background: radial-gradient(600px 300px at 50% 40%, rgba(34, 211, 238, .06), transparent 70%);
}
.placeholder.show { display: flex; }
.ph-icon { font-size: 54px; color: #2b3b58; }
.ph-title { font-size: 22px; font-weight: 700; color: #7f93b3; }
.ph-desc { font-size: 14px; color: #5b6c8a; max-width: 520px; line-height: 1.7; }
.ph-err { font-size: 12px; color: #46587a; max-width: 560px; margin-top: 10px; word-break: break-all; }
.ph-btn {
  margin-top: 18px; padding: 10px 34px; font-size: 15px; cursor: pointer;
  color: #cfe0ff; background: #1d3054; border: 1px solid #33507e; border-radius: 8px;
}
.ph-btn:hover { background: #26406c; }

.stage-badges {
  position: absolute; left: 16px; bottom: 16px;
  display: flex; gap: 8px;
}
.badge {
  padding: 6px 11px;
  font-size: 12px;
  color: #a9bcd8;
  background: rgba(5, 8, 15, .68);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}

.speaking {
  position: absolute; top: 16px; left: 50%;
  transform: translate(-50%, -14px);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px;
  background: rgba(251, 191, 36, .12);
  border: 1px solid rgba(251, 191, 36, .45);
  border-radius: 999px;
  color: #fde68a;
  font-size: clamp(14px, 1.1vw, 19px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  backdrop-filter: blur(8px);
}
.speaking.show { opacity: 1; transform: translate(-50%, 0); }
.sp-wave { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.sp-wave i {
  width: 3px; background: #fbbf24; border-radius: 2px;
  animation: wv .9s ease-in-out infinite;
}
.sp-wave i:nth-child(1) { height: 8px; animation-delay: 0s; }
.sp-wave i:nth-child(2) { height: 16px; animation-delay: .15s; }
.sp-wave i:nth-child(3) { height: 11px; animation-delay: .3s; }
.sp-wave i:nth-child(4) { height: 6px; animation-delay: .45s; }
@keyframes wv { 0%, 100% { transform: scaleY(.5); } 50% { transform: scaleY(1); } }

.toast {
  position: absolute; top: 20px; right: 20px;
  padding: 12px 18px;
  font-size: 14px;
  background: rgba(13, 20, 36, .95);
  border: 1px solid var(--line);
  border-left: 3px solid var(--cyan);
  border-radius: 10px;
  color: #cfe3ff;
  opacity: 0;
  transform: translateY(-8px);
  transition: all .22s ease;
  pointer-events: none;
  max-width: 380px;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------------- 控制条 ---------------- */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: rgba(7, 11, 22, .6);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex; align-items: center; gap: 9px;
  min-height: 58px;
  padding: 0 20px;
  font-size: clamp(14px, 1vw, 17px);
  font-family: inherit;
  color: var(--text);
  background: linear-gradient(180deg, #1b2743, #141d33);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: transform .12s ease, border-color .2s, background .2s;
}
.btn:hover { border-color: rgba(34, 211, 238, .45); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn .ico { font-size: 19px; line-height: 1; color: var(--cyan); }
.btn[data-on="0"] { color: #6b7c99; }
.btn[data-on="0"] .ico { color: #45566f; }
.btn[data-on="0"]::after {
  content: ""; position: absolute;
}
.btn.active { border-color: rgba(34, 211, 238, .7); box-shadow: 0 0 0 1px rgba(34,211,238,.25) inset; }

.ctl-group { display: flex; flex-direction: column; gap: 5px; }
.ctl-group.grow { flex: 1; min-width: 180px; }
.ctl-group label { font-size: 12px; color: var(--text-dim); padding-left: 2px; }

select, input[type="text"], input[type="password"], input:not([type]) {
  font-family: inherit;
  font-size: clamp(13px, .95vw, 16px);
  color: var(--text);
  background: #101a2c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  min-height: 44px;
}
select:focus, input:focus { border-color: rgba(34, 211, 238, .6); }

input[type="range"] {
  -webkit-appearance: none;
  height: 44px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--cyan), rgba(34,211,238,.18));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%;
  background: #e8eefc;
  border: 3px solid var(--cyan);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}

/* ---------------- 遮罩 ---------------- */
.mask {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 600px at 50% 40%, rgba(34, 211, 238, .12), transparent 65%), rgba(4, 7, 13, .96);
  transition: opacity .35s ease;
}
.mask.hide { opacity: 0; pointer-events: none; visibility: hidden; }
.mask-card { text-align: center; padding: 40px; }
.mask-logo { font-size: 62px; margin-bottom: 8px; }
.mask-card h1 { margin: 0 0 6px; font-size: clamp(26px, 2.6vw, 44px); letter-spacing: 1px; }
.mask-card p { margin: 0 0 28px; color: var(--text-dim); font-size: clamp(14px, 1.1vw, 18px); }

.btn-primary {
  font-family: inherit;
  font-size: clamp(16px, 1.2vw, 21px);
  font-weight: 600;
  color: #04121a;
  padding: 16px 46px;
  border: none; border-radius: 999px;
  background: linear-gradient(135deg, #22d3ee, #34d399);
  cursor: pointer;
  box-shadow: 0 10px 34px rgba(34, 211, 238, .35);
}
.btn-primary:active { transform: scale(.98); }
.mask-tip { margin-top: 18px; font-size: 13px; color: #5f7191; }

/* ---------------- 抽屉 ---------------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 80;
  width: min(460px, 92vw);
  background: rgba(10, 16, 30, .98);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .55);
  transform: translateX(102%);
  transition: transform .3s cubic-bezier(.3, .8, .3, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 19px; }
.drawer .x {
  width: 40px; height: 40px; border-radius: 10px;
  background: transparent; border: 1px solid var(--line);
  color: var(--text-dim); font-size: 16px; cursor: pointer;
}
.drawer-body { padding: 20px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

.hint { margin: 0; font-size: 13px; line-height: 1.75; color: var(--text-dim); }

.kv { display: flex; flex-direction: column; gap: 7px; }
.kv > span { font-size: 12px; color: var(--text-dim); }
.kv code {
  display: block;
  padding: 13px 14px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 15px;
  color: #7ee7f7;
  background: #0b1424;
  border: 1px solid var(--line);
  border-radius: 10px;
  word-break: break-all;
}
.kv { position: relative; }
.kv .mini {
  position: absolute; right: 8px; bottom: 8px;
  font-size: 12px; font-family: inherit;
  padding: 5px 10px; border-radius: 7px;
  background: #17233a; color: var(--text-dim);
  border: 1px solid var(--line); cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; color: var(--text-dim); }

.switches { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.sw { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: #b9c9e2; line-height: 1.5; }
.sw input { width: 20px; height: 20px; accent-color: var(--cyan); }

.drawer-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.btn-ghost {
  flex: 1;
  min-height: 48px;
  font-family: inherit; font-size: 14px;
  color: #c4d4ea;
  background: #131d31;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}
.drawer-actions .btn-primary { flex: 1; font-size: 15px; padding: 14px 20px; }

@media (max-width: 900px) {
  .controls { gap: 8px; padding: 10px 12px 14px; }
  .btn { min-height: 50px; padding: 0 14px; }
  .stage { margin: 10px; }
}
