:root {
  color-scheme: light dark;
  --bg: #eef1f6;
  --bg-grad-1: #e9f7f4;
  --bg-grad-2: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --ink: #131b23;
  --muted: #687683;
  --faint: #93a0ac;
  --line: #e2e8ee;
  --line-strong: #d3dbe3;
  --accent: #0fb39a;
  --accent-strong: #0a8f7c;
  --accent-ink: #06564a;
  --accent-soft: #e3f7f2;
  --secondary: #3b6ea5;
  --danger: #e0483a;
  --danger-soft: #fdecea;
  --warning: #c87f12;
  --warning-soft: #fdf3df;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 10px 30px -12px rgba(16, 35, 50, 0.18);
  --shadow-lg: 0 24px 48px -20px rgba(16, 35, 50, 0.28);
  --radius: 16px;
  --radius-sm: 11px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-grad-1: #0c1a1c;
    --bg-grad-2: #0d1117;
    --panel: #161c24;
    --panel-2: #1b232d;
    --ink: #e7edf3;
    --muted: #93a2b1;
    --faint: #6a7889;
    --line: #252e39;
    --line-strong: #313c49;
    --accent: #2fd4b6;
    --accent-strong: #21b89c;
    --accent-ink: #9af0df;
    --accent-soft: #11302c;
    --secondary: #6aa6e6;
    --danger: #ff6b5e;
    --danger-soft: #2c1715;
    --warning: #e3a83a;
    --warning-soft: #2a2210;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 28px 60px -24px rgba(0, 0, 0, 0.8);
  }
}

/* Manual dark override (settings → テーマ → ダーク) */
:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-grad-1: #0c1a1c;
  --bg-grad-2: #0d1117;
  --panel: #161c24;
  --panel-2: #1b232d;
  --ink: #e7edf3;
  --muted: #93a2b1;
  --faint: #6a7889;
  --line: #252e39;
  --line-strong: #313c49;
  --accent: #2fd4b6;
  --accent-strong: #21b89c;
  --accent-ink: #9af0df;
  --accent-soft: #11302c;
  --secondary: #6aa6e6;
  --danger: #ff6b5e;
  --danger-soft: #2c1715;
  --warning: #e3a83a;
  --warning-soft: #2a2210;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 28px 60px -24px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--bg-grad-1), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Hiragino Sans", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

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

.app-shell {
  width: min(940px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--secondary));
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: clamp(20px, 3.4vw, 26px); line-height: 1.1; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Status pill ---------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
}

.status-pill-online { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.status-pill-online .status-dot { background: var(--accent); animation: pulse 1.8s infinite; }
.status-pill-busy { color: var(--secondary); border-color: color-mix(in srgb, var(--secondary) 35%, var(--line)); }
.status-pill-busy .status-dot { background: var(--secondary); animation: pulse 1s infinite; }
.status-pill-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); background: var(--danger-soft); }
.status-pill-error .status-dot { background: var(--danger); }
.status-pill-idle { color: var(--muted); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; box-shadow: none; }

.button-primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.button-primary:hover { box-shadow: 0 12px 22px -8px color-mix(in srgb, var(--accent) 75%, transparent); }
.button-secondary { color: #fff; background: var(--secondary); }
.button-secondary:hover { filter: brightness(1.05); }
.button-quiet { color: var(--ink); background: var(--panel-2); border-color: var(--line); }
.button-quiet:hover { border-color: var(--line-strong); }
.button-danger { color: #fff; background: var(--danger); }

.icon-action {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}
.icon-action:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.icon-action.is-active {
  color: var(--accent-strong);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: var(--accent-soft);
}
.icon-action-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
}
.icon-action-danger:hover { background: var(--danger-soft); }

.icon-button {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color .12s ease, border-color .12s ease;
}
.icon-button:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- Hero ---------- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-state { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hero-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--faint);
  flex-shrink: 0;
}
.hero-dot[data-state="online"] { background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); animation: pulse 1.8s infinite; }
.hero-dot[data-state="busy"] { background: var(--secondary); box-shadow: 0 0 0 5px color-mix(in srgb, var(--secondary) 16%, transparent); animation: pulse 1s infinite; }
.hero-dot[data-state="error"] { background: var(--danger); box-shadow: 0 0 0 5px var(--danger-soft); }
.hero-state strong { display: block; font-size: 18px; letter-spacing: -0.01em; }
.hero-hint { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }

.hero-stats { display: flex; gap: 26px; flex-wrap: wrap; }
.stat { display: grid; gap: 2px; }
.stat-label { color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.stat strong { font-size: 16px; font-weight: 800; overflow-wrap: anywhere; }
.stat-active strong { color: var(--accent-strong); }
.stat-warning strong { color: var(--warning); }
.stat-muted strong { color: var(--muted); font-weight: 700; font-size: 13px; }

/* ---------- Panels ---------- */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-tag {
  color: var(--muted); font-size: 12px; font-weight: 800;
  padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line);
}
.panel-status { color: var(--muted); font-size: 13px; font-weight: 800; }
.panel-status-active { color: var(--accent-strong); }
.panel-status-pairing { color: var(--secondary); }
.scan-heading-actions { display: inline-flex; align-items: center; gap: 12px; }
.button-row { display: inline-flex; gap: 8px; }

/* ---------- Settings ---------- */
.settings-body { padding: 16px 18px; display: grid; gap: 14px; }
.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.9fr);
  gap: 18px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.setting-row-label strong { display: block; }
.setting-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; font-weight: 700; }
.range { width: 100%; accent-color: var(--accent); height: 28px; }

.ota-control { display: flex; justify-self: end; gap: 8px; flex-wrap: wrap; }
/* Shown only while an update is running. Pulling the dongle mid-write can
 * leave it unbootable, and on a secure-boot locked unit that is permanent -
 * so this stays on screen for the whole operation, not just in the
 * confirmation dialog the user already dismissed. */
.ota-warning {
  margin: 10px 0 0; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--warn, #d97706) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn, #d97706) 45%, transparent);
  color: var(--warn, #b45309); font-size: 13px; font-weight: 800; line-height: 1.5;
}
.ota-progress-track {
  height: 10px; border-radius: 999px; background: var(--panel-3, var(--line));
  overflow: hidden; border: 1px solid var(--line);
}
.ota-progress-fill {
  height: 100%; width: 0%; background: var(--accent); border-radius: inherit;
  /* Slightly longer than the 200 ms tick that drives the install phase, and
   * linear, so consecutive updates blend into one continuous movement instead
   * of easing to a stop between every step. */
  transition: width 240ms linear;
}
/* Pairing has no measurable progress - the firmware just reports success or
 * failure - so show motion rather than a fake percentage. */
.pairing-indeterminate {
  width: 40%; transition: none;
  animation: pairing-slide 1.3s ease-in-out infinite;
}
@keyframes pairing-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pairing-indeterminate { animation: none; width: 100%; margin-left: 0; opacity: 0.5; }
}

/* Segmented control (theme) */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  gap: 3px;
  justify-self: end;
}
.segmented-option {
  border: none; background: transparent; cursor: pointer;
  height: 32px; padding: 0 14px; border-radius: 8px;
  color: var(--muted); font-weight: 800; font-size: 13px;
  transition: background .12s ease, color .12s ease;
}
.segmented-option:hover { color: var(--ink); }
.segmented-option.is-active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); }


/* ---------- Device list ---------- */
.device-list { display: grid; gap: 12px; padding: 16px; }

.device-card {
  display: grid;
  gap: 12px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.device-card[data-connection-state="connected"] {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent), var(--shadow-sm);
}

.device-top { display: flex; align-items: center; gap: 13px; min-width: 0; }
.device-icon {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  flex-shrink: 0;
}
.device-card[data-connection-state="idle"] .device-icon { color: var(--muted); background: var(--panel-2); }

.device-main { display: grid; gap: 3px; min-width: 0; flex: 1; }
.device-header { display: flex; align-items: center; gap: 9px; min-width: 0; flex-wrap: wrap; }
.device-name { font-size: 16px; font-weight: 800; overflow-wrap: anywhere; }
.device-meta { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.connection-timeline {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  min-height: 18px;
  color: var(--muted);
  font-size: 11.5px;
}
.connection-timeline:empty { display: none; }
.timeline-step {
  display: inline-flex; align-items: center; gap: 5px;
  max-width: 100%;
  opacity: .72;
  white-space: nowrap;
}
.timeline-step:not(:last-child)::after {
  content: "→";
  opacity: .45;
}
.timeline-step:last-child { opacity: .9; }
.timeline-time { opacity: .65; font-variant-numeric: tabular-nums; }

.device-state {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 800; white-space: nowrap;
}
.device-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
/* Colour carries meaning here, so keep it honest: green = in use right now,
   neutral grey = registered but idle. "未接続" used to be red, which reads as
   a fault when it is simply a device that is switched off. Red is reserved
   for things that are actually wrong or destructive. */
.device-state-connected { color: var(--accent-strong); background: var(--accent-soft); }
.device-state-offline { color: var(--muted); background: var(--panel-soft, rgba(127,127,127,.12)); }

.device-battery {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px;
  border-radius: 999px;
  color: var(--warning); background: var(--warning-soft);
  font-size: 12px; font-weight: 800; white-space: nowrap;
  flex-shrink: 0;
}
.device-battery-low { color: var(--danger); background: var(--danger-soft); }
.device-battery.is-hidden { display: none; }

.device-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.device-actions-spacer { flex: 1; }
.device-toggle { min-width: 84px; }

.switch {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted); font-size: 13px; font-weight: 800;
  cursor: pointer;
}
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

.device-settings {
  display: grid; gap: 12px;
  padding-top: 13px;
  border-top: 1px dashed var(--line);
}
.device-settings:empty { display: none; padding: 0; border: none; }
.device-settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.button-map-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

.setting-subhead { margin: 2px 0 -2px; color: var(--muted); font-size: 12px; font-weight: 800; }
.setting-field-wide { grid-column: 1 / -1; }

/* Press-to-detect */
.detect-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detect-msg { color: var(--muted); font-size: 13px; font-weight: 700; }
.detect-msg.is-live { color: var(--accent-strong); }
.setting-field.is-detected select { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.setting-field.is-detected label { color: var(--accent-strong); }
.setting-field.is-detected label::after { content: " ●"; color: var(--accent); }
@keyframes detectflash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 75%, transparent); }
  100% { box-shadow: 0 0 0 12px transparent; }
}
.setting-field.is-detected select { animation: detectflash .9s ease-out; }

.setting-field { display: grid; gap: 6px; }
.setting-field label { color: var(--muted); font-size: 12px; font-weight: 800; }
.setting-field select, .setting-field input {
  width: 100%; height: 38px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0 11px; background: var(--panel); color: var(--ink);
}
.setting-field select:focus, .setting-field input:focus { outline: none; }
.setting-field select:focus-visible, .setting-field input:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
  border-color: var(--accent);
}
.setting-field input[type="range"] { padding: 0; accent-color: var(--accent); }

.device-card-scan .device-top { gap: 13px; }
.device-card-scan .pair-device { flex-shrink: 0; }

/* ---------- Log ---------- */
.log-panel { overflow: visible; }
.log-summary { cursor: pointer; list-style: none; }
.log-summary::-webkit-details-marker { display: none; }
.log-summary h2::before {
  content: "▸"; display: inline-block; margin-right: 8px; color: var(--faint);
  transition: transform .15s ease;
}
details[open] .log-summary h2::before { transform: rotate(90deg); }
.log-output {
  min-height: 140px; max-height: 300px;
  margin: 0; padding: 14px 16px; overflow: auto;
  color: #b8f0e2; background: #0c1418;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.6; white-space: pre-wrap;
}

/* ---------- Empty / foot ---------- */
.empty-state {
  display: grid; place-items: center; gap: 10px;
  min-height: 130px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 700; text-align: center; padding: 16px;
}
.empty-state-text { white-space: pre-line; }
.empty-state-busy { border-color: color-mix(in srgb, var(--accent) 45%, var(--line-strong)); color: var(--accent-strong); }

.spinner {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 60;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  cursor: pointer;
  max-width: 100%;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  animation: toast-in .22s ease-out;
  overflow-wrap: anywhere;
}
.toast-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: var(--danger-soft); color: var(--danger); }
.toast-success { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); color: var(--accent-ink); }
.toast-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Confirm dialog ---------- */
.confirm-dialog {
  width: min(420px, calc(100vw - 40px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.confirm-dialog::backdrop {
  background: rgba(10, 16, 22, 0.45);
  backdrop-filter: blur(2px);
}
.confirm-dialog h3 { margin: 0 0 8px; font-size: 17px; letter-spacing: -0.01em; }
/* pre-line so a \n in a confirmation message actually breaks the line: these
 * messages pair a warning with an instruction, and run together they read as
 * one long sentence nobody finishes. */
.confirm-dialog p { margin: 0 0 18px; color: var(--muted); font-size: 14px; font-weight: 600; line-height: 1.6; white-space: pre-line; }
.confirm-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Passkey dialog: the code has to be readable at a glance while the user
   looks away at the keyboard they are typing on. */
.passkey-dialog .passkey-target { margin: 0 0 10px; font-size: 13px; }
.passkey-code {
  display: block;
  margin: 0 0 18px;
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2, var(--panel));
  color: var(--ink);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.appfoot { text-align: center; color: var(--faint); font-size: 12px; font-weight: 600; padding: 4px 0; }

.is-hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-stats { gap: 18px 24px; }
}
@media (max-width: 560px) {
  .topbar { gap: 12px; }
  .device-top { align-items: flex-start; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .device-actions { gap: 8px; }
  .device-actions-spacer { display: none; flex-basis: 100%; }
  .switch { order: 2; }
  .device-toggle { flex: 1; }
  .setting-row { grid-template-columns: 1fr; }
}

/* A button the descriptor claims exists but that has never actually been
 * pressed. Shown (so the user can see there may be more) but not editable -
 * assigning an action to a button the hardware does not have looks like it
 * worked and then silently never fires. */
.setting-field.is-unavailable { opacity: 0.45; }
.setting-field.is-unavailable label::after { content: " （未検出）"; font-weight: 700; }


/* Caution, not failure: the action did not complete but nothing broke. */
.toast-warning {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--line));
  background: var(--warning-soft);
  color: var(--warning);
}

/* "Find devices that are not showing up" - a deliberately quiet, secondary
   control. Turning it on floods the list with everything nearby, so it should
   never look like the normal way to add a device. */
.scan-wide-toggle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  align-items: center;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.scan-wide-toggle span { font-size: 13px; font-weight: 600; }
.scan-wide-toggle small { grid-column: 2; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

/* Troubleshooting line under the button-detect bar. Present at all times, not
 * only after a failure: by the time detection has already failed the user is
 * looking for a fix, and this is the fix. */
.detect-hint {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* ---------- Indicator LED legend ---------- */
.led-legend {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}
.led-legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
/* The state name takes the slack so the optional note stays right-aligned;
 * rows without a note simply end after the name. */
.led-legend-state { flex: 1 1 auto; }
.led-legend-state { font-weight: 700; }
.led-legend-note { color: var(--muted); font-size: 11.5px; }

/* The dot is the point of the whole list, so give it a real glow rather than a
 * flat fill - a lit LED does not look like a printed circle. */
.led-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
}
.led-swatch-green { background: #21c07a; box-shadow: 0 0 6px 1px rgba(33, 192, 122, 0.65); }
.led-swatch-red { background: #ef4a3c; box-shadow: 0 0 6px 1px rgba(239, 74, 60, 0.65); }
.led-swatch-blue { background: #4a90d9; box-shadow: 0 0 6px 1px rgba(74, 144, 217, 0.65); }

/* The legend dialog's own list is the content, so let it breathe more than the
 * inline version did and keep the note above it quiet. */
.led-legend-dialog .led-legend { gap: 10px; margin-bottom: 18px; }
.led-legend-dialog .led-legend li { font-size: 13px; }

/* ---------- Firmware update badge ---------- */
/* Answers "is there an update?" before anyone reads a version number. */
.ota-badge {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.ota-badge-current { color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.ota-badge-available {
  color: #fff;
  background: var(--accent-strong);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
  animation: pulse 2.4s infinite;
}

/* ---------- Settings grouping ---------- */
/* A quiet divider, not a heading competing with the panel title. Its job is
 * to say "a different kind of thing starts here" and then get out of the way. */
.settings-group {
  margin: 22px 0 2px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--faint);
  text-transform: uppercase;
}
.settings-group:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* A setting that only qualifies the one above it. */
.setting-row-child { margin-left: 18px; border-left: 2px solid var(--line); padding-left: 14px; }

.setting-row-control { display: flex; align-items: center; gap: 12px; min-width: 0; }
.setting-value { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* Inline "tell me more" affordance. Deliberately not a button-looking button:
 * it opens an explanation, it does not change anything. */
.link-button {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-button:hover { color: var(--accent); }

.settings-footnote {
  margin: 22px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/*
 * The swatches blink at the rate the dongle does.
 *
 * A static dot next to the words "ゆっくり点滅" asks the reader to imagine the
 * difference between that and "点滅" - and two rhythms described only in words
 * are genuinely hard to separate. Showing them removes the guesswork, and the
 * timings are the firmware's own: 2 s for the idle heartbeat (LED_TICK_MS
 * 100 ms x 20 ticks) and 600 ms for the battery warning (x 6).
 *
 * steps(1, end) rather than a fade: the LED is switched, not dimmed, so an
 * eased opacity would misrepresent what the hardware does.
 */
@keyframes led-blink {
  0%, 45%   { opacity: 1; }
  55%, 100% { opacity: 0.1; }
}
.led-blink-slow { animation: led-blink 2s steps(1, end) infinite; }
.led-blink-fast { animation: led-blink 0.6s steps(1, end) infinite; }

/* Someone who asked for less motion should not be made to watch a blinking
 * dot; the words beside it already carry the meaning. */
@media (prefers-reduced-motion: reduce) {
  .led-blink-slow, .led-blink-fast { animation: none; }
}

/* ---------- Update progress modal ---------- */
.ota-progress-dialog { min-width: min(420px, calc(100vw - 48px)); }
.ota-progress-dialog .ota-progress-track { margin: 16px 0 10px; }
.ota-progress-meta {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.ota-progress-dialog .ota-warning { margin: 16px 0 0; }
