:root {
  color-scheme: dark;
  --bg: #070c10;
  --panel: rgba(21, 32, 40, .72);
  --panel-solid: #121c23;
  --line: rgba(151, 196, 214, .16);
  --text: #eaf4f7;
  --muted: #8ea5b0;
  --cyan: #4fe0d6;
  --blue: #5aa9ff;
  --amber: #ffbf5e;
  --red: #ff6f6b;
  --green: #6ff0a4;
  --on-accent: #04181b;
  --phase: var(--cyan);
  --radius: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(90% 420px at 50% -60px, rgba(79, 224, 214, .16), transparent 70%),
    radial-gradient(70% 320px at 100% 30%, rgba(90, 169, 255, .08), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
h3 { font-size: 15px; font-weight: 600; letter-spacing: .02em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0 16px; }
.sprite { position: absolute; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- 頂列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: linear-gradient(rgba(7, 12, 16, .92), rgba(7, 12, 16, .6));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.topbar h1 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; letter-spacing: .04em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); transition: opacity .2s; opacity: .55; }
.live-dot.busy { opacity: 1; animation: blink .9s ease-in-out infinite; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; cursor: pointer;
  color: var(--text); background: transparent; border: 0; border-radius: 12px;
}
.icon-btn:hover { background: rgba(255, 255, 255, .06); }
.icon-btn.small { width: 40px; height: 40px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 0; display: grid; gap: 14px; }
#device { display: grid; gap: 14px; min-width: 0; }
#device.swap { animation: rise .32s cubic-bezier(.2, .8, .2, 1); }

/* ---------- 設備切換 ---------- */
.device-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; scrollbar-width: none; }
.device-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 7px 16px 7px 13px;
  font: inherit; text-align: left; color: var(--text); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 15px;
  transition: border-color .2s, background .2s;
}
.tab strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.25; white-space: nowrap; }
.tab small { display: block; font-size: 12px; line-height: 1.25; color: var(--muted); white-space: nowrap; min-height: 15px; }
.tab[aria-pressed="true"] { border-color: var(--cyan); background: rgba(79, 224, 214, .1); }
.tab-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.tab[data-phase="running"] .tab-dot { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); animation: blink 1.4s ease-in-out infinite; }
.tab[data-phase="charging"] .tab-dot { background: var(--blue); }
.tab[data-phase="paused"] .tab-dot { background: var(--amber); }
.tab[data-phase="error"] .tab-dot { background: var(--red); }
.tab[data-phase="offline"] { opacity: .6; }

/* ---------- 主儀表 ---------- */
.hero { --phase: var(--cyan); display: grid; justify-items: center; text-align: center; padding: 10px 0 4px; }
.hero[data-phase="running"] { --phase: var(--green); }
.hero[data-phase="charging"] { --phase: var(--blue); }
.hero[data-phase="paused"] { --phase: var(--amber); }
.hero[data-phase="error"] { --phase: var(--red); }
.dial { position: relative; width: min(62vw, 232px); aspect-ratio: 1; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring-track { stroke: rgba(151, 196, 214, .13); }
.ring-value {
  --p: 0;
  stroke: var(--phase); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--p));
  filter: drop-shadow(0 0 7px var(--phase));
  transition: stroke-dashoffset .7s cubic-bezier(.2, .8, .2, 1), stroke .3s;
}
.sweep {
  position: absolute; inset: 8%; border-radius: 50%; opacity: 0; transition: opacity .4s;
  background: conic-gradient(from 0deg, transparent 0 72%, color-mix(in srgb, var(--phase) 42%, transparent) 100%);
  -webkit-mask: radial-gradient(circle, #000 66%, transparent 68%);
  mask: radial-gradient(circle, #000 66%, transparent 68%);
}
.ring-value.empty { opacity: 0; }
.hero[data-phase="running"] .sweep { opacity: 1; animation: spin 2.6s linear infinite; }
.hero[data-phase="charging"] .ring-value { animation: breathe 2.4s ease-in-out infinite; }
.hero[data-phase="error"] .ring-value { animation: blink 1.2s ease-in-out infinite; }
.dial-center { position: relative; display: grid; justify-items: center; }
.dial-value { font-size: clamp(50px, 16vw, 64px); font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.dial-value small { font-size: .36em; font-weight: 400; margin-left: 3px; color: var(--muted); letter-spacing: 0; }
.dial-label { font-size: 13px; color: var(--muted); min-height: 20px; margin-top: 2px; }
.state { font-size: 26px; font-weight: 600; line-height: 1.25; margin-top: 12px; color: var(--phase); transition: color .3s; }
.model { font-size: 13px; color: var(--muted); min-height: 20px; }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; margin-top: 10px; }
.stats:empty { display: none; }
.stats li { display: flex; align-items: baseline; gap: 4px; }
.stats strong { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* ---------- 控制 ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 10px; }
.controls:empty { display: none; }
.control {
  display: flex; align-items: center; justify-content: center; font: inherit; cursor: pointer; touch-action: manipulation;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  transition: transform .12s, background .2s, border-color .2s;
}
.control:active:not(:disabled) { transform: scale(.96); }
.control:hover:not(:disabled) { border-color: rgba(79, 224, 214, .55); }
.control.main {
  flex: 1 1 100%; gap: 10px; min-height: 60px; font-size: 18px; font-weight: 700;
  color: var(--on-accent); border: 0;
  background: linear-gradient(120deg, var(--cyan), #7fe9ff);
  box-shadow: 0 8px 30px rgba(79, 224, 214, .28);
}
.control.side { flex: 0 1 calc(25% - 7.5px); min-width: 72px; flex-direction: column; gap: 4px; min-height: 68px; padding: 8px 4px; font-size: 13px; }
.control[aria-busy="true"] > svg { animation: blink .7s ease-in-out infinite; }
.control:disabled { cursor: default; opacity: .75; }
.control.side.wide { flex: 1 1 100%; flex-direction: row; gap: 8px; min-height: 52px; font-size: 15px; }
.view-only { flex: 1 1 100%; text-align: center; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: grid; gap: 12px; min-width: 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin: -8px -8px -4px 0; }
.map-card { padding-bottom: 12px; }
.map-frame {
  position: relative; aspect-ratio: 1; border-radius: 13px; overflow: hidden; display: grid; place-items: center;
  background: rgba(0, 0, 0, .25); touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab;
}
.map-frame.zoomed { touch-action: none; }
.map-frame.dragging { cursor: grabbing; }
.map-tools {
  position: absolute; right: 8px; bottom: 8px; display: grid; gap: 2px; padding: 3px;
  background: rgba(7, 12, 16, .72); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.map-tools button {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; color: var(--text); cursor: pointer;
  background: transparent; border: 0; border-radius: 9px; touch-action: manipulation;
}
.map-tools button:hover { background: rgba(255, 255, 255, .1); }
.map-frame.loading::after, .skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(151, 196, 214, .1) 50%, transparent 80%);
  animation: shimmer 1.3s linear infinite;
}
#d-map { display: block; width: 100%; height: 100%; object-fit: contain; transform-origin: center; will-change: transform; pointer-events: none; animation: fade .3s; }
#d-map.eased { transition: transform .22s cubic-bezier(.2, .8, .2, 1); }
#map-note { padding: 16px; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 15px; color: var(--text); background: rgba(255, 255, 255, .03); cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; min-height: 44px; padding: 6px 17px;
  transition: background .15s, border-color .15s, color .15s;
}
.chip[aria-pressed="true"] { color: var(--on-accent); background: var(--cyan); border-color: var(--cyan); font-weight: 600; }
.chip:disabled { opacity: .5; }
.room-go { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.room-go .btn { flex: 1 1 130px; }
.room-go .seg { flex: 0 1 auto; }

.settings { display: grid; gap: 14px; }
.setting { display: grid; gap: 7px; min-width: 0; }
.setting-title { font-size: 13px; color: var(--muted); }
.seg {
  display: flex; gap: 2px; padding: 3px; min-width: 0; overflow-x: auto; scrollbar-width: none;
  background: rgba(0, 0, 0, .28); border: 1px solid var(--line); border-radius: 13px;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; min-height: 40px; padding: 4px 13px; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer;
  white-space: nowrap; background: transparent; border: 0; border-radius: 10px; transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { color: var(--text); font-weight: 600; background: rgba(79, 224, 214, .2); box-shadow: inset 0 0 0 1px rgba(79, 224, 214, .55); }

.consumable { display: grid; grid-template-columns: 52px 1fr auto auto; align-items: center; gap: 10px; padding: 3px 0; font-size: 14px; }
.bar { display: block; height: 6px; border-radius: 3px; background: rgba(151, 196, 214, .14); overflow: hidden; }
.bar-fill { --p: 0; display: block; height: 100%; width: calc(var(--p) * 1%); border-radius: 3px; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width .5s; }
.bar-fill.low { background: var(--red); }

#d-advanced { display: grid; gap: 14px; }
#d-advanced:empty { display: none; }
.adv-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 15px; font-weight: 400; }
.adv-block { display: grid; gap: 8px; }
.adv-times { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.adv-times input { color-scheme: dark; }
.adv-value { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.switch { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 50px; height: 30px; margin: 0; cursor: pointer; border-radius: 15px; background: rgba(151, 196, 214, .22); transition: background .18s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #eaf4f7; transition: transform .18s; }
.switch:checked { background: var(--cyan); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; }
input[type=range] { width: 100%; min-height: 32px; padding: 0; border: 0; background: transparent; accent-color: var(--cyan); }
select {
  font: inherit; font-size: 16px; color: var(--text); background: rgba(0, 0, 0, .3); color-scheme: dark;
  border: 1px solid var(--line); border-radius: 12px; min-height: 46px; padding: 8px 12px; width: 100%; min-width: 0;
}
.mini-btn { font: inherit; font-size: 13px; color: var(--cyan); background: transparent; border: 0; padding: 8px 4px; min-height: 36px; cursor: pointer; white-space: nowrap; }

.alert { background: rgba(255, 111, 107, .13); color: #ffb3b0; border: 1px solid rgba(255, 111, 107, .35); border-radius: 13px; padding: 9px 13px; font-size: 14px; }
.form-error, .form-note.bad { color: #ffb3b0; font-size: 14px; }

/* ---------- 一般按鈕與表單 ---------- */
.btn {
  font: inherit; font-weight: 600; color: var(--text); background: rgba(255, 255, 255, .04); cursor: pointer;
  border: 1px solid var(--line); border-radius: 13px; min-height: 46px; padding: 8px 16px; touch-action: manipulation;
  transition: transform .12s, border-color .2s, opacity .2s;
}
.btn:hover:not(:disabled) { border-color: rgba(79, 224, 214, .55); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { color: var(--on-accent); border: 0; background: linear-gradient(120deg, var(--cyan), #7fe9ff); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--cyan); padding-inline: 8px; }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row:empty { display: none; }
label { display: grid; gap: 5px; font-size: 14px; font-weight: 600; }
input:not([type=checkbox]) {
  font: inherit; font-weight: 400; font-size: 16px; color: var(--text); background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line); border-radius: 12px; min-height: 46px; padding: 8px 12px; width: 100%; min-width: 0;
}
input:not([type=checkbox]):focus { border-color: var(--cyan); outline: 0; }
.link-card h2 { font-size: 22px; }
.link-form { display: grid; gap: 10px; }

/* ---------- 對話框 ---------- */
dialog {
  width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 18px;
  color: var(--text); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog h2 { font-size: 20px; }
dialog h3 { margin: 18px 0 8px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.account { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 4px; }
.account strong { overflow-wrap: anywhere; min-width: 0; }
.device-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 400; font-size: 15px; }
.device-row input { width: 20px; height: 20px; flex: none; accent-color: var(--cyan); }

/* ---------- 其他 ---------- */
.skeleton-stack { display: grid; gap: 14px; }
.skeleton { position: relative; overflow: hidden; height: 110px; border-radius: var(--radius); background: var(--panel); }
.skeleton.tall { height: 320px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20; max-width: calc(100vw - 32px); width: max-content; padding: 10px 16px; font-size: 14px;
  color: var(--text); background: rgba(30, 46, 56, .96); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: rise .2s;
}
.toast.bad { color: #ffd4d2; background: rgba(90, 30, 30, .96); border-color: rgba(255, 111, 107, .5); }

.login-page { display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); gap: 14px; padding: 26px 24px; }
.login h1 { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 12px; }
.login h1 img { border-radius: 10px; }
.login-step { display: grid; gap: 14px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: .35; } }
@keyframes breathe { 50% { opacity: .55; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.toast { animation-name: fade; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
