:root {
  --bg: #0a0e13;
  --bg-soft: #0f151d;
  --panel: #141b24;
  --panel-hi: #1b2430;
  --line: #23303f;
  --line-soft: #1a2431;
  --text: #e8eef6;
  --muted: #8b9aad;
  --accent: #3b82f6;
  --accent-soft: #1d4ed8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

/* .control-bar / .placeholder 等类设了 display，会盖掉 hidden 属性，
   这里统一让 hidden 生效 */
[hidden] { display: none !important; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.muted { color: var(--muted); }
.small-text { font-size: 12.5px; }

/* ------------------------------------------------------------- shell */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: linear-gradient(180deg, #0d131b, #0a0e13);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: .2px;
}

.brand svg { color: var(--accent); width: 22px; height: 22px; }

.conn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 999px;
  background: #111823;
  border: 1px solid var(--line-soft);
  white-space: nowrap;
}

.conn .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #475569;
  box-shadow: 0 0 0 3px rgba(71, 85, 105, .18);
}

.conn[data-state="online"] .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.conn[data-state="warn"] .dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.conn[data-state="offline"] .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }
.conn .latency { color: var(--muted); font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #131b26;
  border: 1px solid var(--line-soft);
  color: var(--muted);
}

.icon-btn:active { background: var(--panel-hi); color: var(--text); }

/* -------------------------------------------------------------- panels */

main {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel.active { display: flex; }

#tab-screen.active { overflow: hidden; padding-bottom: 6px; }

/* -------------------------------------------------------------- screen */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mirror {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55), 0 0 0 1px var(--line);
  touch-action: none;
  user-select: none;
}

.mirror img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  -webkit-user-drag: none;
  pointer-events: none;
}

.mirror-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 12, 18, .72);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  padding: 30px 20px;
}

.placeholder svg { width: 46px; height: 46px; color: #2b3a4d; }
.placeholder p { margin: 0; }
.placeholder p.muted { font-size: 12.5px; }

.control-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.seg {
  display: flex;
  flex: 1 1 auto;
  background: #101822;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  min-width: 0;
  overflow: hidden;
}

.seg button {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seg button.active {
  background: var(--panel-hi);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.hint {
  flex: 0 0 auto;
  margin: 0;
  font-size: 11.5px;
  color: #63748a;
  text-align: center;
}

/* ------------------------------------------------------------- buttons */

.btn {
  height: var(--tap);
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform .08s ease, background .12s ease;
}

.btn:active { transform: scale(.97); background: var(--panel-hi); }
.btn.primary { background: linear-gradient(180deg, #3b82f6, #2563eb); border-color: #2563eb; color: #fff; font-weight: 500; }
.btn.primary:active { background: var(--accent-soft); }
.btn.primary.on { background: linear-gradient(180deg, #ef4444, #dc2626); border-color: #dc2626; }
.btn.small { height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn.block { width: 100%; }
.btn.danger-solid { background: linear-gradient(180deg, #ef4444, #dc2626); border-color: #b91c1c; color: #fff; }
.btn:disabled { opacity: .45; }

.btn-row { display: grid; gap: 8px; flex: 0 0 auto; }
.btn-row.three { grid-template-columns: repeat(3, 1fr); }
.btn-row.two { grid-template-columns: repeat(2, 1fr); }

/* ------------------------------------------------------------ touchpad */

.touchpad {
  flex: 1 1 auto;
  min-height: 180px;
  position: relative;
  border-radius: 16px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 40%, rgba(59, 130, 246, .09), transparent 62%),
    linear-gradient(180deg, #0f1620, #0c1219);
  touch-action: none;
  user-select: none;
  display: grid;
  place-items: center;
}

.pad-cross {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  opacity: .8;
}

.pad-cross::before,
.pad-cross::after {
  content: "";
  position: absolute;
  background: var(--line);
}
.pad-cross::before { left: 50%; top: 8px; bottom: 8px; width: 1px; transform: translateX(-50%); }
.pad-cross::after { top: 50%; left: 8px; right: 8px; height: 1px; transform: translateY(-50%); }

.pad-hint {
  margin: 0;
  font-size: 12px;
  color: #5b6b80;
  text-align: center;
  line-height: 1.7;
  pointer-events: none;
}

.slider-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 4px;
  font-size: 13px;
  color: var(--muted);
}

.slider-row output { font-variant-numeric: tabular-nums; color: var(--text); min-width: 42px; text-align: right; }

input[type="range"] {
  flex: 1 1 auto;
  -webkit-appearance: none;
  appearance: none;
  height: 26px;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #26333f;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0e13;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}

input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: #26333f; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid #0a0e13; border-radius: 50%; background: var(--accent); }

/* --------------------------------------------------------------- forms */

.field { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }

textarea, input[type="text"], input[type="url"], select {
  width: 100%;
  background: #0e141d;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  color: var(--text);
  outline: none;
  resize: none;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}

.field-label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin: 12px 0 6px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0;
}

.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title {
  flex: 0 0 auto;
  margin: 6px 0 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .4px;
}

.chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  height: 38px;
  padding: 0 13px;
  border-radius: 10px;
  background: #131c26;
  border: 1px solid var(--line-soft);
  color: var(--text);
  font-size: 13.5px;
  transition: transform .08s ease, background .12s ease;
}

.chip:active { transform: scale(.96); background: #1c2734; border-color: var(--line); }

.chip:disabled,
.power-card:disabled,
.seg button:disabled { opacity: .4; pointer-events: none; }

.touchpad.is-disabled { opacity: .45; pointer-events: none; }

/* --------------------------------------------------------------- power */

.power-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  flex: 0 0 auto;
}

.power-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 13px 13px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  text-align: left;
  transition: transform .08s ease, background .12s ease;
}

.power-card:active { transform: scale(.97); background: var(--panel-hi); }
.power-card svg { color: var(--accent); margin-bottom: 3px; }
.power-card span { font-size: 14.5px; font-weight: 500; }
.power-card small { color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.power-card.danger svg { color: var(--danger); }
.power-card.danger { border-color: #3a2027; }

.card-note {
  flex: 0 0 auto;
  margin-top: 4px;
  padding: 13px;
  border-radius: var(--radius);
  background: #101822;
  border: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.card-note p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* -------------------------------------------------------------- status */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  flex: 0 0 auto;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 11px 13px;
  min-width: 0;
}

.stat.wide { width: 100%; }
.stat label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.stat b { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.2px; }
.stat b.small-b { font-size: 14.5px; font-weight: 500; word-break: break-word; }
.stat small { display: block; margin-top: 2px; }

.bar {
  margin-top: 7px;
  height: 4px;
  border-radius: 3px;
  background: #1d2733;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #22c55e, #84cc16);
  transition: width .35s ease, background .35s ease;
}

.bar i.warn { background: linear-gradient(90deg, #f59e0b, #f97316); }
.bar i.hot { background: linear-gradient(90deg, #ef4444, #dc2626); }

/* ------------------------------------------------------------- tabbar */

.tabbar {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--line-soft);
  background: #0c1118;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 0 7px;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 11px;
  transition: color .15s ease;
}

.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ------------------------------------------------------------ overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 7, 11, .88);
  backdrop-filter: blur(6px);
}

.overlay.show { display: flex; }

.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  max-height: 90vh;
  overflow-y: auto;
}

.card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.card p { margin: 0 0 4px; font-size: 13px; }
.card .actions { margin-top: 18px; }
.card code { background: #0c1219; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.error {
  color: #fca5a5;
  font-size: 12.5px;
  min-height: 18px;
  margin: 10px 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 80;
  max-width: min(88vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1c2734;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: #14532d; background: #10241a; }
.toast.err { border-color: #7f1d1d; background: #2a1214; }

@media (min-width: 760px) and (min-height: 700px) {
  .app { border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); }
  .power-grid { grid-template-columns: repeat(3, 1fr); }
}
