:root {
  color-scheme: light;
  --bg: #f1f4ef; --surface: #fff; --soft: #f6f8f3; --line: #dbe2d9;
  --text: #132923; --muted: #66766c; --accent: #173f31; --accent-text: #fff;
  --ok: #13654a; --ok-bg: #e0f3e7; --warn: #8a5a12; --warn-bg: #fff0d9;
  --danger: #b3261e; --danger-text: #fff; --error: #a3261e;
  font-family: system-ui, -apple-system, sans-serif; line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1613; --surface: #17211d; --soft: #1d2924; --line: #2b3a33;
    --text: #e6eee9; --muted: #95a59c; --accent: #6cc59c; --accent-text: #0b1a14;
    --ok: #8fe0b9; --ok-bg: #1a3a2c; --warn: #f0c27a; --warn-bg: #3a2c14;
    --danger: #e5584f; --danger-text: #fff; --error: #ff8a80;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
main { max-width: 560px; margin: auto; padding: 16px 16px 32px; display: grid; gap: 12px; }
p { margin: 0; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
h1 { font-size: 26px; letter-spacing: -1px; margin: 0; }
.pill { border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill.live { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.pill.wait { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

button, select, input[type=number] { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 8px 14px; min-height: 44px; }
button { cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { filter: brightness(.96); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { background: var(--danger); color: var(--danger-text); border-color: var(--danger); }
button:disabled { opacity: .4; cursor: not-allowed; }
:focus-visible { outline: 3px solid #5b9c81; outline-offset: 2px; }
[hidden] { display: none !important; }

.dash { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.speed { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.speed strong { font-size: 72px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.speed span { color: var(--muted); font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; text-align: center; }
.stats div { background: var(--soft); border-radius: 10px; padding: 8px 4px; min-width: 0; }
dt { color: var(--muted); font-size: 12px; }
dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.control { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; margin: 0; flex: none; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(18px); }
.hint { color: var(--muted); font-size: 13px; }
.hint:empty, #error:empty { display: none; }
#error { color: var(--error); font-size: 13px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
.speed-card { min-height: 64px; font-size: 20px; font-variant-numeric: tabular-nums; }
.speed-card small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.speed-card.active { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.adjust { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 8px; align-items: center; }
.adjust button { min-height: 64px; font-size: 30px; line-height: 1; white-space: nowrap; }
.adjust button small { font-size: 13px; font-weight: 500; color: inherit; opacity: .7; margin-left: 4px; }
.adjust output { text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.adjust output small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; gap: 8px; }
.actions button { min-height: 56px; font-size: 17px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 0 16px; }
.panel summary { cursor: pointer; font-weight: 600; padding: 14px 0; }
.panel[open] { padding-bottom: 16px; }
.panel[open] > :not(summary) + :not(summary) { margin-top: 14px; }
.field { display: grid; gap: 6px; }
.label, .field > label { font-size: 13px; font-weight: 600; }
.row { display: flex; gap: 8px; }
.row input, .row select { flex: 1; min-width: 0; }
select { width: 100%; }
.preset-list { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-list button { min-height: 36px; padding: 4px 10px; font-weight: 500; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0; font-size: 13px; }
.kv dd { font-family: ui-monospace, monospace; font-weight: 400; font-size: 12px; }
.commands { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.commands button { min-height: 36px; padding: 4px; font-family: ui-monospace, monospace; font-weight: 500; font-size: 13px; }
pre { background: var(--soft); border-radius: 10px; padding: 10px; font-size: 11px; overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-all; }
#log { max-height: 320px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; }

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