/*
 * components.css: Styles for the shared UI kit (src/ui/*.js).
 * Every class here is produced by a factory in src/ui/controls.js or src/ui/overlay.js;
 * sections should compose those factories rather than invent new one-off styles.
 */

/* ---- Icons --------------------------------------------------------------------------- */
.icon { width: 1.25em; height: 1.25em; flex: none; display: inline-block; vertical-align: middle; }
.icon-lg { width: 1.6em; height: 1.6em; }

/* ---- Buttons ------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: 0 var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-pill);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: var(--text-md); line-height: 1;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-med) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out), opacity var(--dur-med), color var(--dur-med);
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn .icon { width: 1.1em; height: 1.1em; }

/* Raised SFC-style face button: colored, with a "lip" that compresses on press. */
.btn-primary, .btn-danger, .btn-success, .btn-warning, .btn-info {
  --btn-border: transparent;
  --btn-fg: var(--text-on-accent);
  box-shadow: var(--press-depth);
}
.btn-primary { --btn-bg: var(--fill-accent); --btn-fg: var(--on-accent); }
.btn-danger  { --btn-bg: var(--fill-red); --btn-fg: var(--on-red); }
.btn-success { --btn-bg: var(--fill-green); --btn-fg: var(--on-green); }
.btn-warning { --btn-bg: var(--fill-yellow); --btn-fg: var(--on-yellow); }
.btn-info    { --btn-bg: var(--fill-blue); --btn-fg: var(--on-blue); }
.btn-primary:active:not(:disabled), .btn-danger:active:not(:disabled), .btn-success:active:not(:disabled),
.btn-warning:active:not(:disabled), .btn-info:active:not(:disabled) {
  transform: translateY(3px); box-shadow: 0 0 0 transparent;
}
.btn-tonal { --btn-bg: var(--accent-soft); --btn-fg: var(--accent-ink); --btn-border: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { --btn-bg: var(--surface-2); --btn-fg: var(--text); filter: none; }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-lg { min-height: 52px; padding: 0 var(--space-5); font-size: var(--text-lg); }
.btn-icon { padding: 0; width: 40px; min-width: 40px; }
.btn-icon.btn-sm { width: 32px; min-width: 32px; }
.btn-block { width: 100%; }

/* Async button states (set by asyncButton()) */
.btn[data-state="busy"] { pointer-events: none; }
.btn[data-state="busy"] > .btn-label { opacity: 0.85; }
.btn[data-state="ok"]   { --btn-bg: var(--fill-green); --btn-fg: var(--on-green); --btn-border: transparent; }
.btn[data-state="fail"] { --btn-bg: var(--fill-red); --btn-fg: var(--on-red); --btn-border: transparent; animation: nudge 300ms var(--ease-out); }
@keyframes nudge { 0%,100% { transform: none; } 30% { transform: translateX(-3px); } 60% { transform: translateX(3px); } }

/* Pulsing "unsaved changes" dot on buttons */
.btn .pip {
  width: 8px; height: 8px; border-radius: 50%; background: var(--yellow);
  box-shadow: 0 0 0 0 var(--yellow-soft);
  animation: pip 2.2s ease-in-out infinite;
}
@keyframes pip { 0%,100% { box-shadow: 0 0 0 0 rgb(247 193 64 / 0.0); } 50% { box-shadow: 0 0 0 5px rgb(247 193 64 / 0.25); } }

/* ---- Spinner & SFC loader ------------------------------------------------------------- */
.spinner {
  width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Four SFC face-button dots that gently bob in turn. */
.sfc-loader { display: inline-flex; gap: 8px; align-items: center; }
.sfc-loader span { width: 12px; height: 12px; border-radius: 50%; animation: bob 1.2s var(--ease-out) infinite; }
.sfc-loader span:nth-child(1) { background: var(--sfc-red); }
.sfc-loader span:nth-child(2) { background: var(--sfc-yellow); animation-delay: 0.12s; }
.sfc-loader span:nth-child(3) { background: var(--sfc-green); animation-delay: 0.24s; }
.sfc-loader span:nth-child(4) { background: var(--sfc-blue); animation-delay: 0.36s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); opacity: 1; } 30% { transform: translateY(-6px); opacity: 0.85; } }

/* ---- Cards & sections ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--space-4) var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-3);
  min-width: 0;
}
@media (max-width: 560px) { .card { padding: var(--space-4); } }
.card.flat { box-shadow: none; }
.card.sunken { background: var(--surface-sunken); box-shadow: none; }
.card.compact { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
.card-head { display: flex; align-items: flex-start; gap: var(--space-3); flex-wrap: wrap; }
.card-head > div:not(.card-actions):not(.face) { flex: 1 1 180px; min-width: 0; }
.card-head .card-title { font-size: var(--text-lg); font-family: var(--font-display); font-weight: 700; }
.card-head .card-sub { color: var(--text-muted); font-size: var(--text-sm); margin-top: 1px; line-height: 1.4; }
.card-head .card-actions { margin-left: auto; display: flex; gap: var(--space-2); align-items: center; }
.card-tone { border-top: 3px solid var(--tone, var(--accent)); }

.divider { height: 1px; background: var(--border); border: 0; margin: 0; }

/* ---- Field rows: label + description on the left, control on the right ------------- */
.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  min-height: 40px;
}
.field + .field { padding-top: var(--space-3); border-top: 1px dashed var(--border); }
.field-desc { line-height: 1.4; }
.field-label { font-weight: 600; display: flex; align-items: center; gap: var(--space-2); }
.field-desc { color: var(--text-muted); font-size: var(--text-sm); margin-top: 2px; }
.field-control { justify-self: end; display: flex; align-items: center; gap: var(--space-2); }
.field.stacked { grid-template-columns: 1fr; }
.field.stacked .field-control { justify-self: stretch; }
@media (max-width: 560px) {
  .field { grid-template-columns: 1fr; }
  .field .field-control { justify-self: stretch; }
  .field .field-control > .seg { width: 100%; }
}
/* A plain on/off switch always stays beside its label (no extra row on phones or in narrow cards). */
.field:not(.stacked):has(> .field-control > .switch:only-child) { grid-template-columns: minmax(0, 1fr) auto; }
.field:not(.stacked):has(> .field-control > .switch:only-child) > .field-control { justify-self: end; }

/* ---- Segmented control (Start/Select pill vibe) ------------------------------------- */
.seg {
  display: inline-flex; position: relative; padding: 3px; gap: 2px;
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-pill);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  position: relative; z-index: 1; flex: 1 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: transparent; color: var(--text-muted);
  min-height: 34px; padding: 0 var(--space-4); border-radius: var(--radius-pill);
  font-weight: 600; font-size: var(--text-sm); cursor: pointer; white-space: nowrap;
  transition: color var(--dur-med) var(--ease-out);
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { color: var(--tone-on, var(--on-accent)); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.seg .seg-thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0;
  border-radius: var(--radius-pill); background: var(--tone-fill, var(--fill-accent));
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.2);
  transition: transform var(--dur-med) var(--ease-out), width var(--dur-med) var(--ease-out);
}

/* ---- Switch -------------------------------------------------------------------------- */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 46px; height: 28px; border-radius: var(--radius-pill);
  background: var(--surface-3); border: 1px solid var(--border);
  transition: background-color var(--dur-med) var(--ease-out);
  position: relative;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
  transition: transform var(--dur-med) var(--ease-spring);
}
.switch input:checked + .track { background: var(--tone, var(--green)); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
.switch input:disabled + .track { opacity: 0.45; }

/* ---- Slider with numeric entry ------------------------------------------------------- */
.slider { display: flex; align-items: center; gap: var(--space-3); width: min(360px, 100%); }
.slider input[type="range"] {
  --pct: 50%;
  flex: 1; min-width: 120px; height: 28px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(to right, var(--tone, var(--accent)) var(--pct), var(--surface-3) var(--pct));
}
.slider input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--surface-3); }
.slider input[type="range"]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--tone, var(--accent)); }
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: #fff; border: 3px solid var(--tone, var(--accent)); box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-out);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--tone, var(--accent));
}
.slider input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
.slider input[type="range"]:focus-visible { box-shadow: none; }
.slider input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus-ring); }
.slider input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Text inputs, number inputs, selects -------------------------------------------- */
.input, .select {
  min-height: 40px; padding: 0 var(--space-3);
  background: var(--surface-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  transition: border-color var(--dur-med), box-shadow var(--dur-med);
}
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled { opacity: 0.5; }
.input.num { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.input.mono { font-family: var(--font-mono); }
.select {
  -webkit-appearance: none; appearance: none; padding-right: 36px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.num-wrap { display: inline-flex; align-items: center; gap: var(--space-1); }
.num-wrap .unit { color: var(--text-muted); font-size: var(--text-sm); min-width: 1.2em; }

/* Stepper (− value +) */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface-sunken); }
.stepper button { width: 36px; height: 36px; border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--text-muted); display: grid; place-items: center; }
.stepper button:hover { color: var(--text); background: var(--surface-2); }
.stepper input { width: 64px; border: 0; background: transparent; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.stepper input:focus { box-shadow: none; }

/* ---- Color field ------------------------------------------------------------------- */
.color-field { display: inline-flex; align-items: center; gap: var(--space-2); }
.color-field .swatch {
  position: relative; width: 40px; height: 40px; border-radius: var(--radius-md);
  border: 1px solid var(--border); overflow: hidden; cursor: pointer; box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.15);
}
.color-field .swatch input { position: absolute; inset: -8px; width: 64px; height: 64px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.color-field .input { width: 96px; font-family: var(--font-mono); text-transform: uppercase; }

/* ---- Badges, chips, status dots ----------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.02em;
  background: var(--tone-soft, var(--surface-2)); color: var(--tone-ink, var(--text-muted));
  white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--text-faint)); flex: none; }
.dot.live { box-shadow: 0 0 0 0 var(--tone); animation: live 2s ease-out infinite; }
@keyframes live { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* ---- Callouts ------------------------------------------------------------------------ */
.callout {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--tone-soft, var(--surface-2)); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--tone, var(--border)) 30%, transparent);
  font-size: var(--text-sm);
}
.callout > .icon { color: var(--tone, var(--text-muted)); margin-top: 1px; }
.callout strong { font-weight: 700; }
/* An inline button in the text (e.g. "How to connect") must not make its line taller, or the icon
   (top-aligned for multi-line callouts) sits above the text. */
.callout > div > .btn { vertical-align: middle; margin-block: -6px; }

/* ---- Info tip (the "?" bubble) ----------------------------------------------------- */
.tip {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 0; padding: 0; background: var(--surface-2); color: var(--text-muted); cursor: help;
  font-size: 12px; font-weight: 700;
}
.tip:hover, .tip[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.tip-bubble {
  position: fixed; z-index: 1000; max-width: min(320px, calc(100vw - 24px));
  inset: auto; margin: 0; overflow: visible;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-2);
  border: 1px solid var(--border); font-size: var(--text-sm); line-height: 1.45; font-weight: 400;
  animation: fade-in var(--dur-fast) var(--ease-out);
  pointer-events: none;
}

/* ---- Progress ------------------------------------------------------------------------ */
.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-meta { display: flex; justify-content: space-between; font-size: var(--text-sm); color: var(--text-muted); gap: var(--space-3); }
.progress-meta .pct { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.progress-track { height: 10px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--sfc-blue), var(--accent), var(--sfc-red), var(--sfc-yellow));
  background-size: 300% 100%;
  transition: width var(--dur-med) var(--ease-out);
}
.progress[data-active="true"] .progress-fill { animation: sheen 3s linear infinite; }
.progress[data-indeterminate="true"] .progress-fill { width: 35% !important; animation: indet 1.4s var(--ease-out) infinite, sheen 3s linear infinite; }
@keyframes sheen { to { background-position: 300% 0; } }
@keyframes indet { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }

/* ---- Tabs ---------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  position: relative; border: 0; background: transparent; padding: 10px var(--space-4); min-height: 42px;
  color: var(--text-muted); font-weight: 600; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button[aria-selected="true"]::after {
  content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: -1px; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--tone, var(--accent));
  animation: fade-in var(--dur-med) var(--ease-out);
}
.tab-panel { animation: rise-in var(--dur-med) var(--ease-out) both; }

/* ---- Key/value list ----------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-5); font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

/* ---- Empty states -------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3);
  padding: var(--space-6) var(--space-4); color: var(--text-muted);
}
.empty .empty-art {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
  background: var(--tone-soft, var(--accent-soft)); color: var(--tone, var(--accent));
}
.empty .empty-art .icon { width: 34px; height: 34px; }
.empty h3 { color: var(--text); }

/* ---- Dialogs ------------------------------------------------------------------------- */
dialog.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
  overflow: hidden;
}
dialog.dialog[open] { animation: dialog-in var(--dur-slow) var(--ease-out); display: flex; flex-direction: column; }
dialog.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); animation: fade-in var(--dur-med) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.dialog-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5) var(--space-3); }
.dialog-head h2 { font-size: var(--text-xl); flex: 1; }
.dialog-head .dialog-art { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--tone-soft, var(--accent-soft)); color: var(--tone, var(--accent)); }
.dialog-body { padding: 0 var(--space-5) var(--space-4); overflow: auto; display: flex; flex-direction: column; gap: var(--space-4); }
.dialog-foot { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; padding: var(--space-3) var(--space-5) calc(var(--space-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface-2); }
@media (max-width: 560px) {
  dialog.dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
  .dialog-foot .btn { flex: 1; }
}

/* ---- Toasts --------------------------------------------------------------------------
 * Small and out of the way: bottom-right on wide screens (clear of centered dialog buttons), just
 * under the app bar on phones (clear of bottom sheets, primary buttons and the home indicator).
 * The host is a manual popover so toasts also show above an open modal dialog. */
.toasts {
  position: fixed; z-index: 2000; inset: auto max(var(--space-4), env(safe-area-inset-right)) calc(var(--space-4) + env(safe-area-inset-bottom)) auto;
  margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; color: inherit;
  display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end;
  width: min(360px, calc(100vw - 24px)); pointer-events: none;
}
.toasts:popover-open { display: flex; }
@media (max-width: 760px) {
  .toasts {
    inset: calc(var(--appbar-h) + env(safe-area-inset-top) + var(--space-2)) auto auto 50%;
    transform: translateX(-50%); flex-direction: column-reverse; align-items: center;
  }
}
.toast {
  pointer-events: auto; max-width: 100%;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-2); font-size: var(--text-sm); line-height: 1.35;
  animation: rise-in var(--dur-med) var(--ease-out);
  border-left: 3px solid var(--tone, var(--accent));
}
.toast .icon { color: var(--tone, var(--accent)); width: 1.1em; height: 1.1em; }
.toast .toast-msg { flex: 1; }
.toast .btn { min-height: 32px; }
.toast.leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--dur-med), transform var(--dur-med); }

/* ---- Steps (used by the firmware wizard) -------------------------------------------- */
.steps { display: flex; gap: var(--space-2); align-items: center; }
.steps .step { flex: 1; height: 4px; border-radius: 4px; background: var(--surface-3); transition: background-color var(--dur-slow); }
.steps .step[data-state="done"] { background: var(--green); }
.steps .step[data-state="active"] { background: var(--accent); }

/* ---- Section icon "face button" ---------------------------------------------------- */
.face {
  --size: 40px;
  width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--tone, var(--accent)); color: #fff;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.18), inset 0 2px 0 rgb(255 255 255 / 0.25);
}
.face .icon { width: 55%; height: 55%; }
.face.soft { background: var(--tone-soft); color: var(--tone); box-shadow: none; }

/* ---- Left/right split (sticks, triggers…) --------------------------------------------
 * Markup: <div class="lr-split">
 *           <div class="lr-switch">…Left/Right segmented control…</div>       (narrow only)
 *           <div class="lr-cols">
 *             <section class="lr-col" data-side="left" data-active>…</section>
 *             <section class="lr-col" data-side="right">…</section>
 *           </div>
 *         </div>
 * Wide container (≥ 640px of page width): both columns side by side, switch hidden.
 * Narrow: only the [data-active] column shows; the switch picks it.
 * One column only (single-stick build): add .single to .lr-split (full width, no switch). */
.lr-split { container-type: inline-size; display: flex; flex-direction: column; gap: var(--space-4); }
.lr-cols { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); align-items: start; }
.lr-col { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.lr-col-head { display: flex; align-items: center; gap: var(--space-2); font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.lr-col-head .lr-tag {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: var(--text-sm); font-weight: 800; background: var(--tone-soft, var(--accent-soft)); color: var(--tone, var(--accent));
}
.lr-split.single .lr-switch, .lr-split.single .lr-col-head { display: none; }
@container (max-width: 639px) {
  .lr-split:not(.single) .lr-col:not([data-active]) { display: none; }
  .lr-split .lr-col-head { display: none; }
}
@container (min-width: 640px) {
  .lr-split:not(.single) .lr-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lr-split .lr-switch { display: none; }
  .lr-col[data-highlight] { animation: lr-flash 1.2s var(--ease-out); border-radius: var(--radius-lg); }
}
@keyframes lr-flash { 0% { box-shadow: 0 0 0 3px var(--tone, var(--accent)); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* ---- Slider step buttons (‹ range ›) -------------------------------------------------- */
.icon.flip { transform: scaleX(-1); }
.slider { gap: var(--space-2); width: min(400px, 100%); min-width: 0; }
.slider input[type="range"] { flex: 1 1 0; min-width: 0; }
.field-control { min-width: 0; }
.field-control > .slider { flex: 1 1 auto; }
.slider .num-wrap { margin-left: var(--space-1); }
.slider .slider-step {
  flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--text-muted);
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.slider .slider-step:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.slider .slider-step:active:not(:disabled) { background: var(--surface-3); }
.slider .slider-step:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.slider .slider-step:disabled { opacity: 0.35; cursor: default; }
@media (pointer: coarse) { .slider .slider-step { width: 40px; height: 40px; } }
@media (max-width: 560px) {
  /* Phones: the control column must not grow past the card (min-content of the slider row). */
  .field { grid-template-columns: minmax(0, 1fr); }
  .slider { width: 100%; }
  .slider .input.num { width: calc(5ch + 2 * var(--space-2) + 2px); padding: 0 var(--space-2); }
}

/* ---- Card grid: related cards side by side when the page is wide enough ---------------
 * <div class="card-grid">card card card…</div>. One column on phones and narrow pages; two columns
 * once the page body is ≥ 700px wide (sidebar layouts from ~1000px). Add .span-2 to a card for the
 * full row. Cards in the grid are containers, so their field rows stack when a column is narrow. */
.page-body { container: page / inline-size; }
.card-grid { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); align-items: stretch; }
.card-grid > .card { container: card / inline-size; }
@container page (min-width: 700px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid > .span-2 { grid-column: 1 / -1; }
  .card-grid > .span-rows { grid-row: span 2; }
}
@container card (max-width: 470px) {
  .field { grid-template-columns: minmax(0, 1fr); }
  .field .field-control { justify-self: stretch; }
  .field .field-control > .seg { width: 100%; }
  .field .slider { width: 100%; }
}
.card-head .card-title .tip { vertical-align: middle; margin-left: 2px; position: relative; top: -1px; }

/* Copyable code block (Linux setup command): the text scrolls sideways, the Copy button sits below. */
.code-copy { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin: var(--space-2) 0 var(--space-3); min-width: 0; }
.code-copy pre {
  width: 100%; margin: 0; padding: var(--space-3); border-radius: var(--radius-md);
  background: var(--surface-sunken); border: 1px solid var(--border);
  font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text);
}
.linux-steps { padding-left: 1.3em; margin: var(--space-3) 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
.linux-steps > li { min-width: 0; }
.linux-notes summary { cursor: pointer; font-weight: 600; }
.linux-notes ul { margin: var(--space-2) 0 0; padding-left: 1.2em; display: grid; gap: var(--space-2); color: var(--text-muted); font-size: var(--text-sm); }
.linux-notes code { font-family: var(--font-mono); font-size: 0.92em; overflow-wrap: anywhere; }

/* "How to connect" guide (src/app/connect-guide.js). */
.guide-section + .guide-section { margin-top: var(--space-4); }
.guide-modes { display: grid; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; font-size: var(--text-sm); margin: var(--space-2) 0; }
.guide-modes-row { display: grid; grid-template-columns: minmax(90px, 0.9fr) minmax(90px, 0.8fr) minmax(120px, 1.1fr) minmax(150px, 1.5fr); gap: var(--space-2);
  padding: 8px 12px; align-items: baseline; }
.guide-modes-row + .guide-modes-row { border-top: 1px solid var(--border); }
.guide-modes-row.head { background: var(--surface-sunken); color: var(--text-muted); font-size: var(--text-xs, 0.75rem); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.guide-app { color: var(--green); font-weight: 600; }
.guide-combo { display: inline-flex; align-items: center; gap: 2px; vertical-align: middle; margin: -4px 0; }
.guide-combo .inp-glyph { color: var(--text); }
.guide-plus { font-weight: 700; color: var(--text-muted); padding: 0 1px; }
@media (max-width: 560px) {
  .guide-modes-row { grid-template-columns: 1fr 1fr; row-gap: 2px; }
  .guide-modes-row.head { display: none; }
  .guide-modes-row > :nth-child(3), .guide-modes-row > :nth-child(4) { grid-column: span 2; color: var(--text-muted); }
}
.guide-section h3 { font-size: var(--text-md); margin: 0 0 var(--space-2); }
.guide-section ol { margin: 0; padding-left: 1.3em; display: grid; gap: var(--space-2); }
.guide-notes { margin: var(--space-4) 0 0; padding: var(--space-3) var(--space-3) var(--space-3) 2em; border-radius: var(--radius-md); background: var(--surface-sunken); display: grid; gap: var(--space-1); color: var(--text-muted); font-size: var(--text-sm); }

/* A primary button waiting on the user (e.g. "press Update" in the firmware wizard): a soft pulse. */
.btn-attention { animation: btn-attention 1.6s var(--ease-out) infinite; }
@keyframes btn-attention {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone, var(--accent)) 55%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .btn-attention { animation: none; outline: 2px solid var(--tone, var(--accent)); outline-offset: 2px; } }
