/* ===== Shell ===== */
.boot { padding: 2rem; color: var(--text-dim); }
.skip { position: absolute; left: -999px; top: 0; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 1rem; border-radius: 0 0 var(--r-sm) 0; }
.skip:focus { left: 0; }

.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: var(--s5);
  padding: var(--s4) var(--s3); background: var(--bg-rail); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); height: 2.5rem; }
.logo { width: 2rem; height: 2rem; color: var(--text); flex: none; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 1.05rem; letter-spacing: 0.01em; }
.brand-text span { font-size: 0.72rem; color: var(--text-faint); letter-spacing: 0.08em; text-transform: uppercase; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--s3); min-height: 2.6rem; padding: 0 var(--s3);
  border-radius: var(--r-sm); color: var(--text-dim); text-decoration: none; font-weight: 500; font-size: 0.93rem;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item svg { width: 1.3rem; height: 1.3rem; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: calc(var(--s3) * -1); top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.rail-foot { margin-top: auto; padding: 0 var(--s2); color: var(--text-faint); font-size: 0.75rem; }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  min-height: var(--topbar-h); padding: 0.5rem var(--gutter); background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.page-title { font-size: 1.15rem; font-weight: 650; letter-spacing: 0.005em; }
.top-actions { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.status {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 2.1rem; padding: 0 0.8rem; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 0.85rem; font-weight: 500; color: var(--text);
  transition: border-color var(--dur) var(--ease);
}
.status:hover { border-color: var(--text-faint); }
.status .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--text-faint); }
.status[data-state="mock"] .dot { background: var(--warn); }
.status[data-state="connected"] .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status[data-state="error"] .dot { background: var(--danger); }
.status[data-state="connecting"] .dot { animation: pulse 1s ease-in-out infinite; }
.status-ro { display: none; align-items: center; gap: 0.3rem; color: var(--warn); padding-left: var(--s2); border-left: 1px solid var(--line-strong); }
.status.ro .status-ro { display: inline-flex; }
.status-ro svg { width: 0.95em; height: 0.95em; }
@keyframes pulse { 50% { opacity: 0.3; } }
.profile-switch { display: flex; align-items: center; gap: var(--s2); }
.prof-name { font-size: 0.85rem; color: var(--text-dim); max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ro-bar { display: flex; gap: var(--s2); align-items: center; padding: 0.45rem var(--gutter); background: var(--warn-soft); color: var(--warn); font-size: 0.85rem; border-bottom: 1px solid var(--line); }
.ro-bar svg { width: 1rem; height: 1rem; flex: none; }

.main { padding: var(--gutter); outline: none; width: 100%; max-width: 112rem; margin-inline: auto; flex: 1; }
.page { display: grid; gap: var(--gutter); animation: page-in 260ms var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1099px) {
  .brand-text, .nav-item span, .rail-foot { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item[aria-current="page"]::before { left: calc(var(--s3) * -1 + 2px); }
  .brand { justify-content: center; padding: 0; }
}
@media (max-width: 719px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; z-index: 30; inset: auto 0 0 0; top: auto; height: auto; flex-direction: row; justify-content: center;
    padding: 0.25rem 0.5rem calc(0.25rem + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .rail-foot { display: none; }
  .nav-list { display: flex; width: 100%; justify-content: space-around; }
  .nav-item { flex-direction: column; gap: 2px; min-height: 3rem; min-width: 3.4rem; font-size: 0.68rem; padding: 0 0.3rem; }
  .nav-item span { display: block; }
  .nav-item[aria-current="page"]::before { display: none; }
  .main { padding-bottom: 5rem; }
  .topbar { gap: var(--s2); }
  .prof-name { display: none; }
  .page-title { font-size: 1.05rem; }
}

/* ===== Keyboard ===== */
.kb-card { display: grid; gap: var(--s3); }
.kb-toolbar { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.kb-chips { display: flex; gap: var(--s2); flex-wrap: wrap; }
.sel-count { color: var(--text-dim); font-size: 0.8rem; }
.kb { position: relative; border-radius: var(--r-md); outline: none; }
.kb.focused { box-shadow: 0 0 0 2px var(--accent-soft); }
.kb-scroll { display: grid; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }
.kb-svg { width: 100%; max-width: 64rem; margin-inline: auto; min-width: 40rem; height: auto; user-select: none; -webkit-user-select: none; touch-action: pan-x pan-y; }
.kb-hint { color: var(--text-faint); font-size: 0.78rem; }
.kb-tip {
  position: absolute; z-index: 5; pointer-events: none; padding: 0.25rem 0.55rem; border-radius: 6px; font-size: 0.78rem;
  background: var(--surface-3); border: 1px solid var(--line-strong); box-shadow: 0 8px 20px -8px rgb(0 0 0 / 0.6); white-space: nowrap; font-family: var(--mono);
}

.key { cursor: pointer; }
.key .cap { fill: var(--key-bg); stroke: var(--key-edge); stroke-width: 1; transition: fill 120ms var(--ease), stroke 120ms var(--ease); }
.key.hover .cap { fill: var(--surface-3); }
.key .fill { fill: var(--accent); opacity: 0.4; pointer-events: none; }
.key.pressed .fill { opacity: 0.88; }
.key.pressed .cap { stroke: var(--accent); }
.key .tick { stroke: var(--text-faint); stroke-width: 1.25; stroke-dasharray: 3 3; opacity: 0; pointer-events: none; transition: opacity 120ms; }
.key.sel.primary .tick { opacity: 1; stroke: var(--accent-strong); stroke-width: 2; stroke-dasharray: none; }
.key .ring { fill: none; stroke: transparent; stroke-width: 2; pointer-events: none; transition: stroke 120ms var(--ease); }
.key.sel .ring { stroke: var(--accent); }
.key.sel .cap { stroke: var(--accent-line); }
.multi .key.sel.primary .ring { stroke-width: 3; }
.kb-svg.mode-lighting .key.sel .ring { stroke: var(--text); stroke-width: 3; }
.kb-svg.mode-lighting .key .cap { stroke: color-mix(in srgb, var(--bg) 60%, transparent); }
.kb.focused .key.focus .ring { stroke: var(--text); stroke-dasharray: 5 4; }
.kb.focused .key.focus.sel .ring { stroke: var(--accent-strong); }
.key .lbl { fill: var(--key-text); font: 600 15px var(--font); pointer-events: none; }
.key .lbl.sm { font-size: 12.5px; }
.key .lbl.xs { font-size: 9.5px; }
.key .alt { fill: var(--key-text-dim); font: 500 11px var(--font); pointer-events: none; }
.key.transparent .lbl { fill: var(--key-text-dim); font-weight: 400; }
.kb-tab rect { fill: var(--surface-2); stroke: transparent; transition: fill 120ms var(--ease); cursor: pointer; }
.kb-tab text { fill: var(--text-faint); font: 600 9.5px var(--mono); pointer-events: none; }
.kb-tab:hover rect { fill: var(--accent-soft); }
.kb-tab:hover text { fill: var(--accent); }
.kb-marquee { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; pointer-events: none; }

.legend { display: flex; gap: var(--s4); flex-wrap: wrap; font-size: 0.78rem; color: var(--text-dim); }
.lg { display: inline-flex; align-items: center; gap: 0.4rem; }
.sw { width: 0.9rem; height: 0.9rem; border-radius: 3px; display: inline-block; border: 1px solid var(--key-edge); }
.sw-depth { background: linear-gradient(to top, color-mix(in srgb, var(--accent) 45%, transparent) 60%, var(--key-bg) 60%); }
.sw-press { background: var(--accent); border-color: var(--accent); }
.sw-tick { background: none; border: 0; border-top: 1.5px dashed var(--text); border-radius: 0; height: 0; margin-top: 2px; }

/* ===== Page layouts ===== */
.page-grid { display: grid; gap: var(--gutter); align-items: start; }
.page-stack { display: grid; gap: var(--gutter); }
.page-intro { display: grid; gap: var(--s1); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s4); }
.note { display: flex; gap: var(--s2); align-items: flex-start; }
.note svg { width: 1rem; height: 1rem; flex: none; margin-top: 0.15rem; }
@media (min-width: 1700px) {
  .page-grid.live, .page-grid.perf, .page-grid.remap, .page-grid.light { grid-template-columns: minmax(0, 1.55fr) minmax(26rem, 1fr); }
}

/* Live */
.live-panel, .perf-panel, .light-panel { container-type: inline-size; }
.live-body { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1fr); align-items: stretch; }
@container (min-width: 42rem) { .live-body { grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); } }
.live-side { display: grid; gap: var(--s4); align-content: space-between; }
.live-readout { display: grid; gap: var(--s3); justify-items: start; }
.big-num { font-size: 2.4rem; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.stat-l { font-size: 0.74rem; color: var(--text-faint); letter-spacing: 0.04em; }
.graph-wrap { position: relative; min-height: 13.5rem; }
.graph { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.stat { padding: var(--s3); background: var(--surface-2); border-radius: var(--r-sm); border: 1px solid var(--line); }
.stat-v { font-size: 1rem; margin-top: 2px; }
.live-foot { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--line); }

/* Performance */
.perf-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-items: start; }
@container (min-width: 34rem) { .perf-grid { grid-template-columns: minmax(0, 1fr) 15rem; } }
.perf-main { display: grid; gap: var(--s5); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: var(--s5) var(--s6); }
.fields .toggle, .fields .note { grid-column: 1 / -1; }
.presets { display: flex; gap: var(--s2); flex-wrap: wrap; }
.perf-diagram { position: sticky; top: 5rem; }
.travel { width: 100%; max-width: 15rem; height: auto; overflow: visible; }
.travel .track { fill: var(--surface-2); stroke: var(--line-strong); }
.travel .dbar { fill: var(--accent); opacity: 0.5; }
.travel.pressed .dbar { opacity: 0.95; }
.travel .dz { fill: var(--text-faint); opacity: 0.35; }
.travel .aline { stroke: var(--accent); stroke-width: 2; }
.travel .rline { stroke: var(--text-dim); stroke-width: 1.5; stroke-dasharray: 4 3; }
.travel .atext, .travel .ticklbl { fill: var(--text-dim); font: 600 12px var(--mono); }
.travel .atext { fill: var(--accent); }
.travel .ticklbl { fill: var(--text-faint); font-weight: 500; }
@media (max-width: 719px) { .perf-diagram { display: none; } }

/* Remap */
.remap-body { display: grid; gap: var(--s4); }
.remap-top { display: flex; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.cur-binding { display: grid; gap: var(--s2); padding: var(--s3) var(--s4); background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--line); }
.cur-row { display: flex; align-items: center; gap: var(--s3); font-size: 1.1rem; }
.cur-row svg { width: 1.1rem; height: 1.1rem; color: var(--text-faint); }
.search { position: relative; }
.search svg { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); width: 1.1rem; height: 1.1rem; color: var(--text-faint); pointer-events: none; }
.search input { padding-left: 2.4rem; }
.group-chips { display: flex; gap: var(--s2); flex-wrap: wrap; }
.usage-list { max-height: 22rem; overflow: auto; display: grid; gap: var(--s3); padding-right: var(--s1); align-content: start; }
.usage-list .grp { margin-top: var(--s2); }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: var(--s2); }
.usage {
  min-height: 2.4rem; padding: 0 var(--s2); border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2);
  font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.usage:hover { background: var(--surface-3); border-color: var(--text-faint); }
.usage.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.empty.small { padding: var(--s4); }

/* Lighting (the keyboard's own lights, LED_GET / LED_SET) */
.led-fields { display: grid; gap: var(--s5); margin-top: var(--s4); }
.led-side { display: grid; gap: var(--s3); align-content: start; }
.led-slot { display: grid; gap: var(--s3); }
.led-desc { margin-top: var(--s2); min-height: 2.6em; }
.led-foot { display: flex; align-items: center; gap: var(--s3); min-height: 2rem; }
.led-state[data-state="error"] { color: var(--danger); }
.led-preview .kb-svg .kb-tabs { display: none; }
.led-preview .kb-svg.mode-lighting .key.sel .ring { stroke: none; }
.led-notice { max-width: 44rem; }

.light-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5) var(--s6); align-items: start; }
@container (min-width: 52rem) { .light-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); } }
.light-col { display: grid; gap: var(--s5); align-content: start; }
.fx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr)); gap: var(--s2); }
.fx {
  position: relative; min-height: 2.4rem; padding: 0 var(--s2); border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2);
  font-size: 0.85rem; transition: all var(--dur) var(--ease);
}
.fx:hover { background: var(--surface-3); border-color: var(--text-faint); }
.fx[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.fx .approx { position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint); opacity: 0.6; }
.palette { display: flex; gap: var(--s2); flex-wrap: wrap; }
.swatch { width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong); padding: 0; transition: transform var(--dur) var(--ease); }
.swatch:hover { transform: scale(1.1); }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(#ff4d4d, #ffd93d, #7bed4f, #3aa7ff, #d46bff, #ff4d4d); cursor: pointer; display: block; }
.swatch.custom input { position: absolute; inset: -10px; opacity: 0; width: 200%; height: 200%; cursor: pointer; padding: 0; border: 0; }
.paint-row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }

/* Profiles */
.prof-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); gap: var(--gutter); }
.prof { display: grid; gap: var(--s4); align-content: start; transition: border-color var(--dur) var(--ease); }
.prof.active { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line), var(--shadow); }
.prof-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s3); align-items: center; }
.prof-idx { width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--surface-3); color: var(--text-dim); font-weight: 600; }
.prof.active .prof-idx { background: var(--accent); color: var(--accent-ink); }
.prof-sum { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s4); margin: 0; font-size: 0.85rem; }
.prof-sum dt { color: var(--text-faint); }
.prof-sum dd { margin: 0; text-align: right; }
.prof-actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.prof-actions select { width: auto; min-height: 1.875rem; font-size: 0.82rem; padding: 0 var(--s2); }
.errlist { margin: var(--s2) 0 0; padding-left: 1.2rem; }
.errlist code, .banner code { font-family: var(--mono); font-size: 0.85em; }

/* Device */
.dev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: var(--gutter); align-items: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s5); margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; word-break: break-word; }
.caps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.cap { display: flex; align-items: center; gap: var(--s3); font-size: 0.9rem; }
.cap svg { width: 1.1rem; height: 1.1rem; flex: none; }
.cap.ok svg { color: var(--accent); }
.cap.no { color: var(--text-dim); }
.cap.no svg { color: var(--text-faint); }
.cap-note { color: var(--text-faint); font-size: 0.8rem; }
.safety { align-items: center; }

@media (max-width: 719px) {
  .big-num { font-size: 2rem; }
  .graph-wrap { min-height: 12rem; }
  .prof-grid, .dev-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 2200px) {
  .main { max-width: 128rem; }
}

/* grid children must be allowed to shrink so the keyboard scrolls inside its card instead of widening the page */
.page > *, .page-grid > *, .page-stack > *, .card, .kb-card, .kb { min-width: 0; }
@media (max-width: 480px) {
  .status-text { display: none; }
  .status { padding: 0 0.7rem; }
  .top-actions { gap: var(--s2); }
  .seg button { padding: 0 var(--s2); }
  .topbar { flex-wrap: nowrap; }
  .page-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
.btn-row + .field-hint { margin-top: var(--s3); }
@media (min-width: 900px) and (max-height: 960px) { .kb-hint { display: none; } }
