:root {
  color-scheme: light dark;
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #e3e8f2;
  --text: #0f1729;
  --muted: #566079;
  --border: #c9d2e4;
  --accent: #2f4bff;
  --accent-soft: rgba(47, 75, 255, 0.14);
  --glow: rgba(47, 75, 255, 0.28);
  --on-accent: #ffffff;
  --ok: #0b7a42;
  --ok-bg: #d6f2e2;
  --warn: #8f5200;
  --warn-bg: #fcebc2;
  --bad: #c4161c;
  --bad-bg: #fde0e0;
  --on-bad: #ffffff;
  --stop: #d4141b;
  --stop-edge: #8e0d12;
  --on-stop: #ffffff;
  --stick-core: #f7f9ff;
  --stick-edge: #d9e0f2;
  --knob: #2f4bff;
  --knob-edge: #1a2fc4;
  --spark-line: #2f4bff;
  --spark-fill: rgba(47, 75, 255, 0.14);
  --spark-grid: rgba(86, 96, 121, 0.5);
  --spark-text: #566079;
  --shadow: 0 6px 18px rgba(15, 23, 41, 0.12);
  --radius: 14px;
  --gutter: 16px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1e;
    --surface: #121a30;
    --surface-2: #1b2646;
    --text: #e8edff;
    --muted: #9aa6c8;
    --border: #27345c;
    --accent: #8aa2ff;
    --accent-soft: rgba(138, 162, 255, 0.16);
    --glow: rgba(138, 162, 255, 0.35);
    --on-accent: #0a0f1e;
    --ok: #4ade80;
    --ok-bg: rgba(74, 222, 128, 0.14);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, 0.16);
    --bad: #ff5c5c;
    --bad-bg: rgba(255, 92, 92, 0.18);
    --on-bad: #1a0507;
    --stop: #e5131c;
    --stop-edge: #8e0d12;
    --on-stop: #ffffff;
    --stick-core: #16213f;
    --stick-edge: #0d1530;
    --knob: #8aa2ff;
    --knob-edge: #5470f0;
    --spark-line: #8aa2ff;
    --spark-fill: rgba(138, 162, 255, 0.16);
    --spark-grid: rgba(154, 166, 200, 0.45);
    --spark-text: #9aa6c8;
    --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

noscript {
  display: block;
  padding: 16px;
  background: var(--bad);
  color: var(--on-bad);
}

h2,
dl,
dd,
dt,
p,
ol,
ul {
  margin: 0;
  padding: 0;
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  overflow: hidden;
}

body[data-link="offline"] .shell {
  box-shadow: inset 0 0 0 4px var(--bad);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  min-height: 56px;
}

.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  min-width: 0;
}

.link-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-latency {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  opacity: 0.9;
}

.link-latency:empty {
  display: none;
}

.link-dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
}

body[data-link="online"] .link-pill {
  background: var(--ok-bg);
  color: var(--ok);
}

body[data-link="connecting"] .link-pill {
  background: var(--warn-bg);
  color: var(--warn);
}

body[data-link="connecting"] .link-dot {
  animation: pulse 1s ease-in-out infinite;
}

body[data-link="offline"] .link-pill {
  background: var(--bad);
  color: var(--on-bad);
  font-size: 1.05rem;
}

body[data-link="offline"] .link-dot {
  animation: pulse 0.8s ease-in-out infinite;
}

.link-pill[data-quality="fair"] .link-latency {
  color: var(--warn);
}

.link-pill[data-quality="poor"] .link-latency {
  color: var(--bad);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

.top-battery {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.top-battery-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

body[data-battery="low"] .top-battery strong {
  color: var(--warn);
}

body[data-battery="critical"] .top-battery strong {
  color: var(--bad);
}

.link-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 0.92rem;
}

body[data-link="offline"] .link-banner {
  background: var(--bad);
  color: var(--on-bad);
}

body[data-link="connecting"] .link-banner {
  background: var(--warn-bg);
  color: var(--warn);
}

.link-banner-action {
  margin-left: auto;
  min-height: var(--tap);
  background: transparent;
  border-color: currentColor;
  color: inherit;
  font-weight: 600;
}

.update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 0.92rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding-bottom: 4px;
}

.tabs button {
  padding: 0 4px;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
}

.tabs button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.views {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
}

.view {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 0 12px;
  -webkit-overflow-scrolling: touch;
}

.view-drive:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.view-log:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.view-title {
  margin: 14px 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.view-title:first-child {
  margin-top: 4px;
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.mode-select {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.mode-select button {
  padding: 0 2px;
  font-size: clamp(0.66rem, 3vw, 0.82rem);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-select button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

@media (max-width: 359px) {
  .mode-select {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.speed-block {
  padding: 8px 12px 4px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.speed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.speed-head label {
  font-weight: 600;
}

.speed-readout {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

input[type="range"] {
  width: 100%;
  height: var(--tap);
  margin: 0;
  accent-color: var(--accent);
  touch-action: pan-y;
}

.stick-area {
  flex: 1 1 0;
  min-height: 140px;
  display: grid;
  place-items: center;
  container-type: size;
}

.stick-frame {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
}

.stick {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--stick-core) 0%, var(--stick-edge) 100%);
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 8px var(--accent-soft), 0 0 36px var(--glow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

.stick[data-active="true"] {
  cursor: grabbing;
  box-shadow: 0 0 0 8px var(--accent-soft), 0 0 52px var(--glow);
}

.stick[data-enabled="false"] {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.75;
  box-shadow: none;
}

.stick-ring {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  border: 2px dashed var(--accent-soft);
}

.stick-cross::before,
.stick-cross::after {
  content: "";
  position: absolute;
  background: var(--accent-soft);
}

.stick-cross::before {
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 2px;
  margin-left: -1px;
}

.stick-cross::after {
  top: 50%;
  left: 8%;
  right: 8%;
  height: 2px;
  margin-top: -1px;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  aspect-ratio: 1;
  margin-left: -14%;
  margin-top: -14%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--knob) 0%, var(--knob-edge) 100%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), 0 0 22px var(--glow);
  transition: transform 0.14s ease-out;
  will-change: transform;
  pointer-events: none;
}

.stick[data-active="true"] .stick-knob {
  transition: none;
}

.stick-overlay {
  display: none;
  position: absolute;
  inset: 0;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 18%;
  border-radius: 50%;
  text-align: center;
  background: repeating-linear-gradient(45deg, rgba(120, 130, 160, 0.25) 0 10px, rgba(120, 130, 160, 0.08) 10px 20px);
}

.stick:not([data-blocked="none"]) + .stick-overlay {
  display: grid;
}

.stick-overlay-text {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  text-shadow: 0 0 8px var(--bg);
}

body[data-link="offline"] .stick-overlay-text {
  color: var(--bad);
}

.stick-resume {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.drive-readout {
  min-height: 1.35em;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.tele-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tele-card {
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: opacity 0.2s;
}

.tele-card-wide {
  grid-column: 1 / -1;
}

.tele-card dt {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tele-value {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.tele-sub {
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tele-card[data-stale="true"] {
  opacity: 0.5;
}

.tele-card[data-level="warning"] .tele-value {
  color: var(--warn);
}

.tele-card[data-level="danger"] {
  border-color: var(--bad);
}

.tele-card[data-level="danger"] .tele-value {
  color: var(--bad);
}

.spark-block {
  margin-bottom: 8px;
  padding: 8px 12px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.spark-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.spark {
  display: block;
  width: 100%;
  height: 68px;
}

.capability-list {
  list-style: none;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.capability-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.capability-row:last-child {
  border-bottom: 0;
}

.capability-state {
  font-weight: 700;
  text-align: right;
}

.capability-row[data-status="present"] .capability-state {
  color: var(--ok);
}

.capability-row[data-status="limited"] .capability-state {
  color: var(--warn);
}

.capability-row[data-status="missing"] .capability-state {
  color: var(--muted);
  font-weight: 500;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field > span {
  font-size: 0.85rem;
  font-weight: 600;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.log-filter select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;
}

.field input[aria-invalid="true"] {
  border-color: var(--bad);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  align-self: end;
}

.field-check input {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.field-error {
  min-height: 0;
  color: var(--bad);
  font-size: 0.8rem;
}

.field-error:empty {
  display: none;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.form-result {
  min-height: 1.4em;
  font-weight: 600;
}

.form-result[data-kind="ok"] {
  color: var(--ok);
}

.form-result[data-kind="error"] {
  color: var(--bad);
}

.form-result[data-kind="warning"],
.form-result[data-kind="pending"] {
  color: var(--warn);
}

.log-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

.log-filter {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1 1 140px;
}

.log-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.74rem;
}

.log-list:empty {
  display: none;
}

.log-row {
  padding: 5px 8px;
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.log-row[data-level="info"] {
  border-left-color: var(--accent);
}

.log-row[data-level="warn"] {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.log-row[data-level="error"] {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}

.log-row[data-level="debug"] {
  color: var(--muted);
}

.dock {
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}

.stop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 88px;
  padding: 0 16px;
  border: 0;
  border-bottom: 6px solid var(--stop-edge);
  border-radius: 20px;
  background: var(--stop);
  color: var(--on-stop);
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.stop:active {
  transform: translateY(3px);
  border-bottom-width: 3px;
  filter: brightness(0.92);
}

body[data-locked="true"] .stop {
  outline: 4px solid var(--bad);
  outline-offset: 3px;
}

.stop-icon {
  position: relative;
  flex: none;
  width: 38px;
  height: 38px;
  background: var(--on-stop);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}

.stop-icon::after {
  content: "";
  position: absolute;
  inset: 30%;
  background: var(--stop);
}

.app-version {
  margin-top: 6px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 10;
}

@media (max-height: 640px) {
  .stop {
    min-height: 72px;
    font-size: 1.6rem;
  }
  .speed-block {
    padding-top: 4px;
  }
  .topbar {
    min-height: 48px;
    padding: 4px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
