:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15171c;
  --muted: #5f6673;
  --line: #e1e4ea;
  --accent: #e8402a;
  --accent-hover: #cf3420;
  --accent-soft: #fde9e5;
  --on-accent: #ffffff;
  --ok: #17803a;
  --err: #c0262d;
  --err-soft: #fdecec;
  --focus: #2563eb;
  --link: #1d4ed8;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  color-scheme: light;
}
/* Dark: the system's choice, unless Settings > Look picks one (data-theme on <html>, web/pages/look.js). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #eceef2;
    --muted: #9aa2af;
    --line: #2a2f38;
    --accent: #ff5a3c;
    --accent-hover: #ff7257;
    --accent-soft: #3a1f1a;
    --ok: #4cc26e;
    --err: #ff6b6b;
    --err-soft: #3a1c1e;
    --focus: #6ea0ff;
    --link: #8ab4ff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --text: #eceef2;
  --muted: #9aa2af;
  --line: #2a2f38;
  --accent: #ff5a3c;
  --accent-hover: #ff7257;
  --accent-soft: #3a1f1a;
  --ok: #4cc26e;
  --err: #ff6b6b;
  --err-soft: #3a1c1e;
  --focus: #6ea0ff;
  --link: #8ab4ff;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 18px; }
p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.icon { display: inline-flex; }
.icon svg { width: 20px; height: 20px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, calc((100vw - 1120px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 16px; }
.brand-text .muted { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 24px 16px 40px; outline: none; }
main:focus, main:focus-visible { outline: none; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: var(--err-soft); }
.btn-ghost { border-color: transparent; background: transparent; padding-left: 8px; }
.btn-lg { min-height: 48px; padding: 10px 20px; font-size: 16px; }
.select, .input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; min-height: 40px; padding: 8px 12px; max-width: 100%;
}
.select { min-width: 180px; }
.num { width: 90px; }
.grow { flex: 1; min-width: 140px; }
textarea { width: 100%; }
.code { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12.5px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Home */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.empty { text-align: center; padding: 40px 24px; max-width: 620px; margin: 24px auto; }
.empty-icons { display: flex; justify-content: center; gap: 14px; color: var(--accent); margin-bottom: 14px; }
.empty-icons svg { width: 40px; height: 40px; }
.steps { text-align: left; display: inline-block; margin: 18px 0 8px; padding-left: 22px; }
.steps li { margin: 8px 0; padding-left: 4px; }
.device-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.device-card { display: flex; align-items: center; gap: 14px; padding: 18px; text-decoration: none; transition: border-color 0.15s; }
.device-card:hover { border-color: var(--accent); }
.device-icon { flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.device-icon svg { width: 28px; height: 28px; }
.device-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.device-text strong { font-size: 16px; overflow-wrap: anywhere; }
.device-go { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 550; font-size: 14px; white-space: nowrap; }

/* Notices */
.notice { display: flex; gap: 14px; align-items: flex-start; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); margin: 0 0 16px; }
.notice h1 { font-size: 20px; margin-bottom: 6px; }
.notice p + p { margin-top: 6px; }
.notice-error { border-color: var(--err); background: var(--err-soft); }
.notice-error > .icon { color: var(--err); }

/* Device page */
.device-head { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 20px; }
.device-title { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 220px; }
.device-title h1 { overflow-wrap: anywhere; }
.head-actions { display: flex; gap: 8px; }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 24px 0; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.section { padding: 6px 20px 10px; scroll-margin-top: 84px; min-width: 0; }
.section > h2, .advanced summary { padding: 14px 0 8px; }
.items { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 10px 24px; padding: 14px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.items > .item:first-child { border-top: 0; }
.item-text { flex: 1 1 260px; min-width: 0; }
.item-text label { font-weight: 600; }
.help { color: var(--muted); font-size: 13.5px; margin-top: 3px; max-width: 60ch; }
.item-control { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.item-stat strong { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-width: 0; }

.status { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; min-height: 20px; }
.status .icon svg { width: 16px; height: 16px; }
.status-saving { color: var(--muted); }
.status-saved { color: var(--ok); }
.status-error { color: var(--err); flex-basis: 100%; justify-content: flex-end; text-align: right; }

/* Switch */
.switch {
  appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; flex: none;
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: 0.5; cursor: default; }

/* Slider */
.slider-wrap { display: flex; align-items: center; gap: 12px; }
.slider { width: min(260px, 60vw); accent-color: var(--accent); height: 28px; }
.slider-value { min-width: 82px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.color { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }

/* Equalizer */
.item-eq { flex-direction: column; align-items: stretch; }
.eq { display: grid; grid-template-columns: repeat(10, minmax(28px, 1fr)); gap: 6px; padding: 8px 0; }
.eq-band { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.eq-band output { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.eq-slider { writing-mode: vertical-lr; direction: rtl; height: 150px; width: 28px; accent-color: var(--accent); }
.item-eq .status { align-self: flex-end; }

/* Advanced */
.advanced summary { cursor: pointer; list-style: none; display: flex; align-items: center; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary h2::after { content: ' ▸'; color: var(--muted); }
.advanced[open] summary h2::after { content: ' ▾'; }
.advanced { padding-bottom: 18px; }
.tech { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0; font-size: 13.5px; }
.tech dt { color: var(--muted); }
.tech dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row.spread { justify-content: space-between; }
.out { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow: auto; margin: 6px 0 0; }
.out:empty { display: none; }
.log { max-height: 320px; }

/* Toast and dialog */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); z-index: 20; }
.toast-error { background: var(--err); color: #fff; }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; max-width: min(460px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog p { margin-bottom: 18px; font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.footer { display: flex; gap: 8px 18px; justify-content: center; flex-wrap: wrap; padding: 18px 16px 28px; font-size: 13px; text-align: center; }

/* Device page: side panel + tabs */
body[data-route='device'] main, body[data-route='rgbsync'] main { max-width: 1360px; }
.device-page { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 24px; align-items: start; }
.device-panel {
  position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px;
  max-height: calc(100vh - 100px); overflow-y: auto; padding: 2px 4px 12px 2px;
}
.device-panel .back { align-self: flex-start; margin-left: -8px; }
.panel-device { display: flex; align-items: center; gap: 12px; }
.panel-name { min-width: 0; }
.panel-name h1 { font-size: 21px; overflow-wrap: anywhere; }
.panel-actions, .panel-row { display: flex; gap: 8px; flex-wrap: wrap; }
.panel-block { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.panel-block h2 { font-size: 15px; }
.device-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.section-nav { display: flex; flex-direction: column; gap: 2px; padding-top: 14px; border-top: 1px solid var(--line); }
.section-nav a { padding: 8px 12px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 550; }
.section-nav a:hover { background: var(--surface); color: var(--text); }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 550; font-variant-numeric: tabular-nums; }
.chip .icon svg { width: 16px; height: 16px; }
.chips-sm { margin-top: 6px; }
.chips-sm .chip { font-size: 12px; padding: 2px 8px; background: var(--surface-2); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tab {
  flex: none; font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0;
  border-bottom: 3px solid transparent; padding: 10px 14px 9px; cursor: pointer; white-space: nowrap; border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); }

.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 16px; align-items: start; min-width: 0; }
.section-wide { grid-column: 1 / -1; }
.section-help { margin: -4px 0 6px; }
.section-note { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 4px 0 8px; }
.desktop-link { display: inline-flex; align-items: center; gap: 6px; color: var(--link); font-weight: 550; }
.desktop-link .icon svg { width: 18px; height: 18px; }

.btn-icon { min-width: 40px; padding: 8px; }
.btn-small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn-round { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; }

/* Profiles and saved setups */
.profile-list, .setup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.profile-list li { display: flex; gap: 6px; }
.profile {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-weight: 550; text-align: left; cursor: pointer;
}
.profile:hover { background: var(--surface-2); }
.profile[aria-pressed='true'] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.profile-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-badge { font-size: 12px; color: var(--accent); font-weight: 650; }
.profile:disabled { opacity: 0.55; cursor: default; }
.setup { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.setup-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.setup-actions { display: flex; gap: 4px; }
.setup .btn-icon { min-width: 34px; min-height: 34px; padding: 6px; }
.rename-form { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.rename-form .input { flex: 1; min-width: 120px; }

/* Stacked items (label above a wide control) */
.item-stack { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
.item-stack .item-text { flex: none; }
.item-stack .item-control { justify-content: flex-start; width: 100%; }
.label { font-weight: 600; }
.input.text { width: min(280px, 100%); }

/* Segmented buttons and effect tiles */
.choices { display: grid; gap: 8px; width: 100%; grid-template-columns: repeat(auto-fit, minmax(min(100%, 92px), 1fr)); }
.choices:has(.choice-desc) { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.choices-effects { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); }
.choice {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.choice:hover { background: var(--surface-2); }
.choice[aria-pressed='true'] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.choice:disabled { opacity: 0.55; cursor: default; }
.choice .icon { color: var(--muted); flex: none; }
.choice[aria-pressed='true'] .icon { color: var(--accent); }
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-label { font-weight: 600; }
.choice-desc { font-size: 13px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.choices-segmented .choice:not(:has(.choice-desc)) { justify-content: center; text-align: center; }
.choices-effects .choice { flex-direction: column; justify-content: center; text-align: center; gap: 6px; min-height: 84px; padding: 10px 6px; }
.choices-effects .choice .icon svg { width: 26px; height: 26px; }
.choices-effects .choice-label { font-size: 14px; }

/* Palette */
.palette { flex-direction: column; align-items: flex-start; gap: 12px; }
.palette-pick { display: flex; gap: 8px; align-items: center; }
.hex { width: 112px; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; text-transform: lowercase; }
.hex[aria-invalid='true'], .input[aria-invalid='true'] { border-color: var(--err); }
.field-error { color: var(--err); font-size: 0.875rem; margin: 4px 0 0; flex-basis: 100%; }
.field-error[hidden] { display: none; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); background: var(--sw, #000); cursor: pointer; padding: 0; }
.swatch[aria-pressed='true'] { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 50%; }
.swatch:disabled { opacity: 0.5; cursor: default; }

/* Dial */
.dial { flex-direction: column; align-items: stretch; gap: 8px; }
.dial-face { display: flex; align-items: center; justify-content: center; gap: 18px; }
.dial-center { display: flex; flex-direction: column; align-items: center; min-width: 110px; }
.dial-art { width: 140px; height: auto; }
.dial-track { fill: none; stroke: var(--line); stroke-width: 8; stroke-linecap: round; }
.dial-zero { stroke: var(--muted); stroke-width: 2; }
.dial-needle rect { fill: var(--surface-2); stroke: var(--text); stroke-width: 2; }
.dial-needle path { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.dial-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dial .slider { width: 100%; }
.dial .status { align-self: flex-end; }

/* Equalizer (extended) */
.eq-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px 20px; flex-wrap: wrap; }
.eq-head .item-text { flex: 1 1 240px; min-width: 0; }
.eq-toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; flex-wrap: wrap; }
.eq-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.eq-presets > .muted { margin-right: 4px; }
.chip-btn { font: inherit; font-size: 14px; font-weight: 550; padding: 6px 12px; min-height: 34px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.chip-btn:hover { background: var(--surface-2); }
.chip-btn[aria-pressed='true'], .chip-static.on { border-color: var(--accent); background: var(--accent-soft); }
.chip-static { cursor: default; color: var(--muted); display: inline-flex; align-items: center; }
.chip-static.on { color: var(--text); }
.eq-wrap { width: 100%; min-width: 0; transition: opacity 0.15s; }
.eq-off .eq-graph { opacity: 0.55; }
.eq-graph { display: block; width: 100%; max-width: 100%; background: var(--surface-2); border-radius: 12px; overflow: visible; }
.eq-grid line { stroke: var(--line); stroke-width: 1; }
.eq-grid line.eq-zero { stroke: var(--muted); stroke-dasharray: 4 4; }
.eq-axis { fill: var(--muted); font-size: 11px; }
.eq-line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.eq-area { fill: var(--accent); opacity: 0.1; }
.eq-pt { cursor: ns-resize; touch-action: none; outline: none; }
.eq-pt[aria-disabled='true'] { cursor: default; }
.eq-hit { fill: transparent; }
.eq-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.eq-pt:hover .eq-dot { fill: var(--accent-soft); }
.eq-pt:focus-visible .eq-dot { stroke: var(--focus); stroke-width: 4; }
.eq-val { fill: var(--text); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; pointer-events: none; }
.eq-nums { display: grid; grid-template-columns: repeat(var(--bands, 10), minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
.eq-col { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.eq-num { width: 100%; min-width: 0; min-height: 34px; padding: 4px 2px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.eq-num::-webkit-inner-spin-button, .eq-num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.eq-freq { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.eq-freq .short { display: none; }
.eq-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Key mapping */
.keymap { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 10px 24px; }
.keymap-row { display: grid; grid-template-columns: minmax(80px, 1fr) minmax(150px, 1.5fr); gap: 4px 10px; align-items: center; }
.keymap-row label { font-weight: 550; }
.keymap-row .select { min-width: 0; width: 100%; }
.keymap-row .status { grid-column: 1 / -1; justify-content: flex-end; }
.keymap-row .status:empty { display: none; }

/* Key layout (keyboard items) */
.item-keyboard { gap: 10px; }
.kb-scroll { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 2px; scrollbar-width: thin; overscroll-behavior-x: contain; }
.kb { position: relative; width: calc(var(--kw) * var(--u) * 1px); height: calc(var(--kh) * var(--u) * 1px); user-select: none; -webkit-user-select: none; margin: 0 auto; }
.kb-key {
  position: absolute; left: calc(var(--x) * var(--u) * 1px + 2px); top: calc(var(--y) * var(--u) * 1px + 2px);
  width: calc(var(--w) * var(--u) * 1px - 4px); height: calc(var(--h) * var(--u) * 1px - 4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--text); cursor: pointer;
  font-size: clamp(9px, calc(var(--u) * 0.27px), 13px); line-height: 1.1; text-align: center; padding: 1px 2px;
}
.kb-key:hover { border-color: var(--muted); }
.kb-key[aria-selected='true'] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.kb-key:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; z-index: 1; }
.kb-label { font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.kb-text { font-size: 0.85em; color: var(--muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kb-text:empty { display: none; }
.kb-key[aria-selected='true'] .kb-text { color: var(--text); }
.kb-colored::after { content: ''; position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px; border-radius: 2px; background: var(--kc); }
.kb-box { position: absolute; left: calc(var(--x) * var(--u) * 1px); top: calc(var(--y) * var(--u) * 1px); width: calc(var(--w) * var(--u) * 1px); height: calc(var(--h) * var(--u) * 1px); border: 1.5px dashed var(--accent); background: rgb(232 64 42 / 0.08); border-radius: 4px; pointer-events: none; }
.kb-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.kb-count { font-weight: 600; font-size: 14px; }
.kb-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

/* Macros */
.macro { display: grid; grid-template-columns: minmax(180px, 240px) minmax(0, 1fr); gap: 16px 20px; align-items: start; }
.macro-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.macro-item { justify-content: space-between; }
.macro-editor { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.macro-empty { justify-content: center; min-height: 120px; }
.macro-head { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.macro-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.macro-field > label { font-weight: 600; font-size: 14px; }
.macro-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.macro-rec { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.macro-pad {
  flex: 1 1 240px; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 14px;
  border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 13.5px; user-select: none; -webkit-user-select: none;
}
.macro-pad .icon { flex: none; }
.macro-pad.recording { border-color: var(--accent); background: var(--accent-soft); color: var(--text); cursor: crosshair; }
.macro-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.macro-list-head h3 { margin: 0; }
.macro-events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow-y: auto; }
.macro-event { display: grid; grid-template-columns: 26px 22px minmax(110px, 1fr) minmax(96px, 120px) 104px auto; gap: 6px; align-items: center; padding: 3px 4px; border-radius: 8px; }
.macro-event:nth-child(odd) { background: var(--surface-2); }
.macro-event .select { min-width: 0; width: 100%; min-height: 36px; padding: 4px 8px; }
.macro-n { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.macro-kind { color: var(--muted); display: inline-flex; }
.macro-kind .icon svg { width: 18px; height: 18px; }
.macro-delay { display: flex; align-items: center; gap: 4px; }
.macro-delay .input { width: 76px; min-height: 36px; padding: 4px 8px; }
.macro-row-actions { display: flex; gap: 2px; }
.macro-row-actions .btn-icon { min-width: 34px; min-height: 34px; padding: 6px; }
.macro-row-actions .btn-icon .icon svg { width: 18px; height: 18px; }
.macro-add, .macro-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.macro-add .select { min-width: 0; flex: 1 1 180px; }
.macro-foot { padding-top: 8px; border-top: 1px solid var(--line); }

/* Picture for a screen (image items) */
.img-ctl { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.img-pick, .img-send { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.img-name { overflow-wrap: anywhere; }
.img-stage { display: flex; justify-content: center; align-items: center; padding: 12px; border-radius: 12px; background: var(--surface-2); min-height: 80px; overflow: hidden; border: 2px dashed transparent; }
.img-stage.drop { border-color: var(--accent); }
.img-canvas { width: calc(var(--w) * var(--zoom, 1) * 1px); height: calc(var(--h) * var(--zoom, 1) * 1px); max-width: 100%; image-rendering: pixelated; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); }
.img-progress { width: min(240px, 100%); accent-color: var(--accent); height: 10px; }

/* Read-only tables (list items) */
.list-scroll { max-width: 100%; overflow-x: auto; }
.list-table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.list-table th, .list-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.list-table th { font-weight: 600; color: var(--muted); font-size: 13px; }
.list-table tbody tr:last-child td { border-bottom: 0; }

/* Home: RGB Sync entry */
.rgb-entry { display: flex; align-items: center; gap: 14px; padding: 18px; margin-top: 14px; text-decoration: none; transition: border-color 0.15s; }
.app-settings { margin-top: 14px; }
.rgb-entry:hover { border-color: var(--accent); }
.rgb-icon { background: linear-gradient(135deg, #ff5a3c, #ffb02e 35%, #2ec4ff 70%, #8a5cff); color: #fff; }

/* Narrow screens */
@media (max-width: 860px) {
  .device-page { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .device-panel { position: static; max-height: none; overflow: visible; padding: 0; min-width: 0; }
  .device-panel .section-nav { flex-direction: row; overflow-x: auto; gap: 6px; padding: 10px 0 2px; scrollbar-width: none; }
  .device-panel .section-nav a { white-space: nowrap; background: var(--surface); border: 1px solid var(--line); padding: 7px 12px; }
  .tabs { position: sticky; top: 64px; z-index: 4; background: var(--bg); margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
}
@media (max-width: 760px) {
  h1 { font-size: 21px; }
  .section { padding: 4px 16px 8px; }
  .item-control { justify-content: flex-start; width: 100%; }
  .slider-wrap { width: 100%; }
  .slider { flex: 1; width: auto; }
  .eq { gap: 2px; }
  .eq-slider { height: 120px; }
  .brand-text .muted { display: none; }
  .eq-num { font-size: 12px; }
  .eq-freq .short { display: inline; }
  .eq-freq .long { display: none; }
  .choices-effects { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
  .macro { grid-template-columns: minmax(0, 1fr); }
  .macro-editor { padding: 10px; }
  .macro-event { grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: 'n code code' 'n dir delay' 'n act act'; row-gap: 4px; padding: 6px 4px; }
  .macro-event .macro-n { grid-area: n; align-self: start; padding-top: 8px; }
  .macro-event .macro-kind { display: none; }
  .macro-event > .select:not(.macro-dir) { grid-area: code; }
  .macro-event .macro-dir { grid-area: dir; }
  .macro-event .macro-delay { grid-area: delay; }
  .macro-event .macro-row-actions { grid-area: act; justify-content: flex-end; }
}

/* Dock "Music lighting" row (renderMusicItem) */
.item-music .music-state.music-on { color: var(--ok); }
.item-music .music-note { flex-basis: 100%; text-align: right; margin-left: auto; }

/* ---------------------------------------------------------------- app pages (web/pages/) */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Top bar: Settings */
.topnav { display: flex; align-items: center; gap: 4px; flex: none; }
.topnav-link { padding: 8px 10px; }
@media (max-width: 480px) { .topnav-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } }

/* Own background picture (Settings > Look) */
#wallpaper { display: none; position: fixed; inset: 0; z-index: -1; background: center / cover no-repeat; pointer-events: none; }
.has-wallpaper #wallpaper { display: block; }
.has-wallpaper body { background: transparent; }
.has-wallpaper .card, .has-wallpaper .notice { background: color-mix(in srgb, var(--surface) 78%, transparent); backdrop-filter: blur(var(--card-blur, 20px)); -webkit-backdrop-filter: blur(var(--card-blur, 20px)); }
.has-wallpaper .footer { background: color-mix(in srgb, var(--bg) 70%, transparent); }

/* Home: tips */
.home-tips { margin-top: 18px; padding: 4px 18px; }
.home-tips summary { display: flex; align-items: center; gap: 8px; padding: 12px 0; cursor: pointer; font-weight: 600; }
.home-tips ul { margin: 0 0 14px; padding-left: 22px; }
.home-tips li { margin: 6px 0; }

/* Settings */
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.settings-status:empty, .settings-status:has(.status:empty) { display: none; }
.item-label { font-weight: 600; }
.seg-group { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.seg { font: inherit; font-weight: 550; color: var(--text); background: transparent; border: 0; border-radius: 9px; min-height: 36px; padding: 6px 14px; cursor: pointer; }
.seg:hover { background: var(--surface); }
.seg[aria-checked='true'] { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); }
.wallpaper-thumb { width: 96px; height: 54px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2) center / cover no-repeat; flex: none; }
.wallpaper-thumb-empty { display: none; }
.pair-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }
.pair { border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
.pair summary { display: flex; align-items: center; gap: 10px; padding: 12px 0; cursor: pointer; font-weight: 600; }
.pair-steps { display: block; margin: 0 0 8px; }
.pair-done { display: flex; gap: 8px; align-items: flex-start; color: var(--ok); margin: 0 0 14px; }
.about { display: flex; flex-direction: column; gap: 10px; padding-bottom: 16px; }
.about-name { display: flex; align-items: center; gap: 12px; }
.about-name strong { font-size: 18px; }
.about-links a { color: var(--link); }

/* Testers */
body[data-route='test-keyboard'] main, body[data-route='test-mouse'] main { max-width: 1360px; }
.tester-tabs { margin-bottom: 16px; }
.tester-tab { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.tester-tab[aria-current='page'] { color: var(--text); border-bottom-color: var(--accent); }
.tester { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.tester-main { padding: 16px; min-width: 0; grid-column: 1 / -1; }
.tester-log { padding: 8px 16px 14px; grid-row: 2 / span 2; grid-column: 2; min-width: 0; }
.tester-stats { grid-row: 2; grid-column: 1; }
.tester-help { grid-row: 3; grid-column: 1; }
.tester-mouse .tester-log { grid-row: auto; }
.tester-log h2 { font-size: 16px; }
.tester-log-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 460px; overflow-y: auto; font-size: 13.5px; }
.tester-log-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); }
.tester-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.tester-down { color: var(--accent); font-weight: 600; }
.tester-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 12px; }
.tester-stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; }
.tester-stat-value { font-size: 24px; font-variant-numeric: tabular-nums; }
.tester-warn { border-color: var(--err); }
.tester-warn .tester-stat-value { color: var(--err); }
.tester-help { padding: 14px 16px; }
.kt-scroll { overflow-x: auto; padding: 4px; container-type: inline-size; }
.kt-board { --g: 4px; --u: clamp(26px, calc((100cqw - 110px) / 22.8), 46px); display: flex; gap: calc(var(--u) * 0.4); width: max-content; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.kt-board:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.kt-block { display: flex; flex-direction: column; gap: var(--g); }
.kt-row, .kt-group { display: flex; gap: var(--g); position: relative; }
.kt-group + .kt-group, .kt-key + .kt-group { margin-left: calc(var(--u) * 0.35); }
/* The function row stands a little apart; the nav block and the number pad line up with the rows. */
.kt-main > .kt-row:first-child, .kt-middle > .kt-row:first-child, .kt-numpad > .kt-spacer:first-child { margin-bottom: calc(var(--u) * 0.25); }
.kt-spacer { height: var(--u); flex: none; }
.kt-gap { width: var(--u); flex: none; }
.kt-key { --w: 1; --h: 1; position: relative; width: calc(var(--u) * var(--w) + var(--g) * (var(--w) - 1)); height: calc(var(--u) * var(--h) + var(--g) * (var(--h) - 1)); flex: none; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 11.5px; line-height: 1.1; user-select: none; }
.kt-key .kt-count { position: absolute; right: 3px; bottom: 1px; font-size: 9.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kt-tall { margin-bottom: calc(-1 * (var(--u) + var(--g))); z-index: 1; }
.kt-key.kt-active, .kt-swatch.kt-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.kt-key.kt-active .kt-count { color: var(--on-accent); }
.kt-key.kt-tested, .kt-swatch.kt-tested { background: var(--accent-soft); border-color: var(--accent); }
.kt-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.kt-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.kt-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); }
.kt-last { font-variant-numeric: tabular-nums; font-weight: 600; min-height: 1.5em; }
.tester-main .help { margin-top: 8px; }
.tester-mouse { grid-template-columns: minmax(0, 1fr) 300px; }
.mt-area { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; padding: 20px; align-items: center; user-select: none; min-width: 0; }
.mt-stats { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.mt-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; max-width: 220px; }
.mt-mouse { width: 150px; height: auto; }
.mt-mouse path, .mt-mouse rect { fill: var(--surface-2); stroke: var(--muted); stroke-width: 2; transition: fill 0.05s; }
.mt-mouse .mt-body { fill: var(--surface); }
.mt-mouse .mt-arrow { fill: var(--line); stroke: none; }
.mt-mouse .mt-lit { fill: var(--accent); stroke: var(--accent); }
@media (max-width: 860px) {
  .tester, .tester-mouse { grid-template-columns: minmax(0, 1fr); }
  .tester-log, .tester-stats, .tester-help { grid-row: auto; grid-column: auto; }
  .mt-area { grid-template-columns: minmax(0, 1fr); }
  .mt-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 120px), 1fr)); }
  .mt-stage { max-width: none; }
}
@media (max-width: 480px) { .kt-board { --g: 3px; } .kt-key { font-size: 10px; } }

/* Profiles per app */
.ap-top { max-width: 900px; padding-top: 16px; padding-bottom: 14px; }
.ap-list { display: flex; flex-direction: column; gap: 16px; max-width: 900px; margin-top: 16px; }
.ap-exe { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; overflow-wrap: anywhere; }
.ap-recent { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ap-recent li { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ap-add { padding-bottom: 16px; }
.ap-game { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 200px; }
.ap-games-bar .input { flex: 1 1 180px; }

/* Magnetic keyboards: advanced keys editor and live key travel (web/controls/advkeys*.js) */
.item-control.adv { flex-direction: column; align-items: stretch; flex-wrap: nowrap; min-width: 0; }
.adv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.adv-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.adv-type { font-weight: 600; }
.adv-sum { overflow-wrap: anywhere; }
.adv-buttons { display: flex; gap: 8px; margin-left: auto; }
.adv-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.adv-editor { display: flex; flex-direction: column; gap: 10px; min-width: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.adv-editor h4 { margin: 0; }
.adv-editor .item-keyboard { min-width: 0; padding: 0; border: 0; }
.adv-field { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; }
.adv-field > label, .adv-field > .label { min-width: 8em; }
.adv-field .slider-wrap { flex: 1 1 200px; min-width: 0; }
.adv-dks { display: flex; flex-direction: column; gap: 10px; }
.adv-dks-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.adv-error { color: var(--err); margin: 0; }
.adv-actions { display: flex; gap: 8px; }
.item-travel .item-keyboard { min-width: 0; padding: 0; border: 0; }

/* Macro recorder (web/pages/recorder.js; reuses the macro editor's layout) */
.rec-lead { max-width: 72ch; }
.rec-side-title { font-size: 15px; margin: 0; }
.rec-what { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.rec-pad-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.macro-rec-insert > .small { font-weight: 600; }
.macro-rec-insert > p { flex-basis: 100%; margin: 0; }
@media (max-width: 760px) {
  .macro-event.rec-event { grid-template-columns: 22px minmax(0, 1fr) auto auto; grid-template-areas: 'n code code code' 'n dir delay act'; }
  .rec-event .macro-n { padding-top: 2px; }
  .rec-event .rec-what { grid-area: code; }
  .rec-event .rec-dir { grid-area: dir; align-self: center; }
}

/* Updates of the Windows app (web/pages/update.js) and the download page (web/pages/download.js) */
.update-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: calc(100% - 32px); max-width: 1088px; margin: 12px auto 0; padding: 10px 16px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent); }
.update-banner[hidden] { display: none; }
.update-banner > .icon { color: var(--accent); }
.update-banner-text { flex: 1 1 220px; font-weight: 600; }
.update-row { align-items: center; gap: 12px; margin-top: 12px; }
.update-status:empty { display: none; }
.update-box { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.update-box[hidden] { display: none; }
.update-head { display: flex; align-items: center; gap: 8px; }
.update-head > .icon { color: var(--accent); }
.update-notes { margin-top: 12px; }
.update-notes h3 { font-size: 15px; margin-bottom: 4px; }
.update-notes-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 16em; overflow-y: auto; font-size: 14px; }
.update-action { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.update-action .help { flex: 1 1 260px; margin: 0; }
.update-progress { width: min(320px, 100%); height: 10px; accent-color: var(--accent); }
.download-card { padding-top: 20px; }
.download-list { margin: 10px 0 16px 20px; }
.download-list li + li { margin-top: 4px; }
.download h2 { font-size: 18px; margin: 8px 0 12px; }
.download-file { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.download .help { margin-top: 8px; }

/* Diagnostics file (Settings > About) */
.diagnostics { margin-top: 16px; }
.diag-row { align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.diag-row .status { overflow-wrap: anywhere; }
