:root {
  --bg: #10151f; --card: #182030; --line: #2a3448; --text: #e8edf6; --muted: #93a0b8;
  --accent: #5cc8ff; --accent-ink: #04141f; --danger: #ff6b6b; --ok: #6ee7a8; --warn: #ffc857;
  --radius: 14px; --tap: 46px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --card: #ffffff; --line: #d8dee8; --text: #141a24; --muted: #5d687c;
    --accent: #0a84d6; --accent-ink: #ffffff; --danger: #d63c3c; --ok: #13915a; --warn: #a86b00;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { background: var(--line); padding: 0 .3em; border-radius: 4px; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center;
  justify-content: space-between; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand b { display: block; }
.brand small { color: var(--muted); }
.brand small.live { color: var(--ok); }
.conn { display: flex; gap: 6px; flex-wrap: wrap; }

main { max-width: 1100px; margin: 0 auto; padding: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.intro h1 { margin: 0 0 8px; font-size: 1.4rem; }
.help { padding-left: 1.2em; color: var(--muted); }
.notice {
  border: 1px solid color-mix(in srgb, var(--warn) 55%, var(--line)); border-radius: 10px;
  padding: 10px 12px; color: var(--text); background: color-mix(in srgb, var(--warn) 10%, transparent);
  overflow-wrap: anywhere;
}
.help li { margin: 6px 0; }

/* buttons */
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.btn.ghost { background: transparent; }

/* layout */
.layout { display: grid; gap: 12px; }
@media (min-width: 860px) {
  .layout { grid-template-columns: minmax(300px, 420px) 1fr; align-items: start; }
  .dialcard { position: sticky; top: 76px; }
  body { padding-bottom: 0; }
}

/* dial */
.dialcard { text-align: center; }
#dial { width: min(100%, 72vw, 340px); height: auto; display: block; margin: 0 auto; }
#dial .ring { fill: none; stroke: var(--line); stroke-width: 3; }
#dial .ticks { stroke: var(--muted); stroke-width: 2; stroke-linecap: round; fill: none; }
#dial .ticks.done { stroke: var(--accent); stroke-width: 3; }
#dial .arc { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; opacity: .55; }
#dial .start { fill: var(--muted); }
#dial .hub { fill: var(--text); }
#dial #ptr line { stroke: var(--text); stroke-width: 3; stroke-linecap: round; }
#dial #ptr circle { fill: var(--accent); }
#dial #ptr { transition: transform .12s linear; }
.readout { margin-top: -4px; }
.big { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.status { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.status.run { color: var(--ok); }
.status.pause { color: var(--warn); }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 12px 0 4px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
.runline { color: var(--muted); min-height: 1.4em; font-variant-numeric: tabular-nums; }

/* tabs: bottom bar on phones, inline on desktop */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  min-height: 60px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  font-size: .9rem; cursor: pointer; border-top: 3px solid transparent;
}
.tabs button.on { color: var(--accent); border-top-color: var(--accent); }
@media (min-width: 860px) {
  .tabs { position: static; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
  .tabs button { min-height: 48px; border-top: 0; border-bottom: 3px solid transparent; }
  .tabs button.on { border-bottom-color: var(--accent); }
}

/* forms */
.tab { display: grid; gap: 14px; }
label, .field { display: grid; gap: 6px; font-weight: 600; }
.unit, legend small, label small { color: var(--muted); font-weight: 400; }
input[type=number], select {
  min-height: var(--tap); width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-variant-numeric: tabular-nums;
}
input[type=range] { width: 100%; height: var(--tap); accent-color: var(--accent); }
input:focus-visible, select:focus-visible, .btn:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 12px; padding: 12px; margin: 0; }
fieldset:disabled { opacity: .55; }
legend { font-weight: 700; padding: 0 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }
.hint { color: var(--muted); margin: 0; font-weight: 400; }
.warn { color: var(--warn); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 120px; }
.jog { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.jog .btn { min-height: 56px; font-size: 1.05rem; }

/* toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 10;
  max-width: calc(100% - 32px); font-weight: 600;
}
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 18px; width: min(92vw, 380px); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog p { margin: 0 0 16px; font-weight: 600; }
