:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d9dee5;
  --accent: #1f6feb;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --row-alt: #f2f4f7;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --panel: #1a2029;
    --text: #e4e8ee;
    --muted: #98a2b3;
    --border: #2c3542;
    --accent: #58a6ff;
    --warn-bg: #3a2e0c;
    --warn-text: #f5d58a;
    --row-alt: #1f2631;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
}

header, main { max-width: 960px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 16px; }
h1 { margin: 0; font-size: 1.4rem; }
h2 { margin: 0 0 8px; font-size: 1.1rem; }
.sub { margin: 0 0 12px; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; border: 0; padding: 0; }
.field span, .field > label, .field legend, .label { color: var(--muted); font-size: 0.9rem; }
.mode { flex-direction: row; gap: 16px; align-items: center; }
.mode legend { float: left; margin-right: 8px; }

select, button, input { font: inherit; }
input { padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.row > .field { flex: 1 1 220px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }
.error { color: #c62828; font-size: 0.85rem; }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 6px; padding: 6px 10px; margin: 4px 0; }
.actions { align-items: center; }
.error:empty { display: none; }
input[aria-invalid="true"] { border-color: #c62828; }
button.secondary { background: transparent; color: var(--accent); white-space: nowrap; }
select { width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); }

.actions { display: flex; gap: 8px; }
button {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
#stop { background: transparent; color: var(--accent); }

.status div { margin: 2px 0; }
.warnings { margin: 8px 0 0; padding: 0; list-style: none; }
.warnings li { background: var(--warn-bg); color: var(--warn-text); border-radius: 6px; padding: 6px 10px; margin-top: 6px; }
.warnings:empty { display: none; }

.count { color: var(--muted); font-weight: normal; font-size: 0.9rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 4px 8px; white-space: nowrap; }
th { color: var(--muted); font-weight: normal; border-bottom: 1px solid var(--border); }
th.num, td.num { text-align: right; }
td.msg { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tr.slot-start td { border-top: 1px solid var(--border); }

/* ── 頂列與左側選單 ── */
.topbar { display: flex; align-items: center; gap: 12px; }
.topbar h1 { line-height: 1.2; }
.topbar .sub { margin: 0; }
.version { color: var(--muted); font-size: 0.8rem; font-weight: normal; margin-left: 6px; white-space: nowrap; }
button.icon {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  flex: none;
}
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 10; }
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(340px, 88vw);
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 16px;
  z-index: 11;
  box-shadow: 2px 0 12px rgb(0 0 0 / 0.2);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-head h2 { margin: 0; }
.drawer h3 { font-size: 1rem; margin: 12px 0 4px; }
.backdrop[hidden], .drawer[hidden] { display: none; }

/* ── 可收折的設定區 ── */
.collapsible > summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before { content: "▸"; color: var(--muted); }
.collapsible[open] > summary::before { content: "▾"; }
.collapsible > summary h2 { margin: 0; }
.collapsible[open] > summary { margin-bottom: 10px; }
.collapsible[open] #settings-summary { display: none; }
.status .actions { margin-bottom: 8px; }
.detect-result { margin: -4px 0 10px; padding-left: 18px; color: var(--muted); font-size: 0.85rem; }
.detect-result:empty { display: none; }
.check { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; color: var(--text); }
#tap-to-start[hidden] { display: none; }
