:root {
  --bg: #f4f2ef;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a64;
  --line: #e4dfd8;
  --accent: #b42318;
  --accent-ink: #ffffff;
  --ok: #157f3b;
  --warn: #b54708;
  --idle: #8a847d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --surface: #211f1d;
    --text: #f2efea;
    --muted: #a39d95;
    --line: #34312d;
    --accent: #f04438;
    --ok: #47cd89;
    --warn: #fdb022;
    --idle: #8a847d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 16px; height: 16px; border: 3px solid var(--accent); border-radius: 3px; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 19px; margin: 0 0 6px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.muted { color: var(--muted); margin: 0 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--text);
  min-height: 48px; padding: 10px 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { font-size: 30px; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }

button { font: inherit; cursor: pointer; border-radius: 12px; border: 0; min-height: 48px; padding: 0 18px; }
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); font-weight: 600; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.link { background: none; color: var(--muted); min-height: 36px; padding: 0 4px; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row > * { flex: 1; }

.tabs { display: flex; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tab { flex: 1; background: transparent; color: var(--muted); min-height: 40px; border-radius: 9px; }
.tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* device card */
.device { position: relative; overflow: hidden; }
.device.ready { border: 3px solid var(--accent); }
.device-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.device-name { font-weight: 700; font-size: 18px; }
.device-id { color: var(--muted); font-size: 12px; }
.chip { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.chip.ready { background: var(--accent); color: #fff; }
.chip.idle { background: var(--line); color: var(--muted); }
.chip.offline { background: transparent; border: 1px dashed var(--idle); color: var(--idle); }
.status-line { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--idle); }
.dot.on { background: var(--ok); }
.dot.warn { background: var(--warn); }
.session { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--bg); }
.session-project { font-weight: 700; font-size: 17px; }
.session-meta { color: var(--muted); font-size: 14px; }
.count { display: flex; align-items: baseline; gap: 6px; margin-top: 8px; }
.count strong { font-size: 32px; font-variant-numeric: tabular-nums; line-height: 1; }
.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.actions > .primary, .actions > .danger { flex: 1 1 140px; }
.more { display: flex; justify-content: flex-end; margin-top: 4px; }

/* sheets */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}
.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.choice {
  display: block; text-align: left; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1.5px solid var(--line); padding: 12px 14px; min-height: 56px;
}
.choice.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice small { display: block; color: var(--muted); }
details { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 32px; line-height: 32px; }
details .form { margin-top: 10px; }

.capture-list { list-style: none; margin: 0; padding: 0; }
.capture-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.capture-list li span:last-child { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 20; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
}
