:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2321;
  --muted: #5d6b67;
  --line: #dde3e1;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --ok: #15803d;
  --wait: #b45309;
  --err: #b91c1c;
  --banner: #fff4d6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1b2120;
    --text: #e7ecea;
    --muted: #9aa8a4;
    --line: #2d3634;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --ok: #4ade80;
    --wait: #fbbf24;
    --err: #f87171;
    --banner: #3a2f12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

h1 { margin: 0; font-size: 1.15rem; }
h1 span { margin-left: 6px; font-weight: 400; color: var(--muted); }
h2 { margin: 0 0 10px; font-size: 1rem; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.card-head { display: flex; justify-content: space-between; align-items: baseline; }

.banner {
  background: var(--banner);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

.pill {
  flex-shrink: 0;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.pill-on { color: var(--ok); }
.pill-wait { color: var(--wait); }
.pill-off { color: var(--err); }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.row label { display: flex; align-items: center; gap: 6px; }

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

input[type="number"], input[type="password"], select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
input[type="number"] { width: 5.5em; }
input[type="password"] { flex: 1; min-width: 0; }

button {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, form button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { background: var(--err); color: #fff; border-color: var(--err); }

.slider { display: block; margin-bottom: 10px; }
.slider input { display: block; width: 100%; margin-top: 4px; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segmented label:has(input:checked) { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.hint { margin: 0; color: var(--muted); font-size: 0.85rem; }
.hint.ok { color: var(--ok); }

.device-line { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}
.stats div { background: var(--bg); border-radius: 8px; padding: 8px; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; white-space: nowrap; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th:nth-child(3), td:nth-child(3), th:nth-child(8), td:nth-child(8) { text-align: center; }
td { font-variant-numeric: tabular-nums; }
td.empty { text-align: center; color: var(--muted); }

.link { color: var(--accent); font-size: 0.9rem; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.85rem;
}
.log li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.log li.ok { color: var(--ok); }
.log li.err { color: var(--err); }

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.actionbar button { min-height: 52px; font-size: 1.05rem; font-weight: 600; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

.pose { margin: 10px 0 6px; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
  margin: 8px 0 12px;
}
.dpad button { font-size: 1.2rem; padding: 0; }
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .home { grid-area: 2 / 2; font-size: 0.95rem; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }
