:root {
  --bg: #14161a;
  --panel: #1c2027;
  --panel-2: #232833;
  --panel-3: #2a3040;
  --border: #2e3440;
  --border-2: #3a4150;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #5b9dff;
  --accent-press: #4a86e0;
  --accent-ink: #0c1017;
  --danger: #e5534b;
  --danger-press: #c9443d;
  --danger-text: #ea6a63; /* lighter danger for TEXT — hits WCAG AA (4.5:1) on the panel shades; --danger is for fills/borders */
  --ok: #3fbf7f;
  --warn-bg: #3a2f1a;
  --warn-border: #6b5320;
  --warn-text: #f0d38a;
  --radius: 10px;
  --radius-sm: 8px;
  /* Spacing scale — 4px ramp with one 6px half-step (the intra-label gap).
     Steps: 2 / 4 / 6 / 8 / 12 / 16 / 24 / 32. Layout one-offs (40/48/56/80)
     and hairline nudges stay literal. */
  --sp-1: 4px;
  --sp-2: 6px;
  --sp-3: 8px;
  --sp-4: 12px;
  --sp-5: 16px;
  --sp-6: 24px;
  --sp-7: 32px;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win. Author `display` rules (.picker-overlay,
   .gate, .device-bar all use flex) otherwise beat the UA `[hidden]{display:none}`,
   which left the keycode picker and the connect gate stuck visible. */
[hidden] { display: none !important; }

/* Respect reduced-motion: drop decorative CSS transitions/animations. Content motion
   (the GIF preview canvas, live light effects) is JS-driven and intentionally unaffected. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 56px;
}

/* Visible focus for keyboard users on the dark ground. */
:focus-visible {
  outline: none;
  /* inset ring is never clipped by an overflow:hidden ancestor (.seg-radio /
     .slide-thumb all clip); the outer --focus ring adds polish where nothing clips it. */
  box-shadow: inset 0 0 0 2px var(--accent), var(--focus);
  border-radius: 6px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  flex-wrap: wrap;
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.2px; }
.subtitle { color: var(--muted); font-size: 13px; }
.conn { display: flex; align-items: center; gap: 8px; }
.status-text { color: var(--muted); font-size: 13px; min-width: 96px; text-align: right; }

.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--muted); display: inline-block;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}
.dot[data-state="connected"] { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,191,127,0.18); }
.dot[data-state="connecting"] { background: var(--warn-text); }
.dot[data-state="error"] { background: var(--danger); box-shadow: 0 0 0 3px rgba(229,83,75,0.18); }
.dot[data-state="disconnected"] { background: var(--muted); }

/* Device chrome (Connect + status + warning) is hidden in the Keymap section. */
#app[data-section="keymap"] [data-device-chrome] { display: none; }

/* Warning line — contextual, only while disconnected/error. */
.warn {
  margin: 16px 0 0;
  padding: 8px 16px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.warn strong { color: #fbe9b8; }

/* Top-level sections nav */
.sections {
  display: flex;
  gap: 6px;
  margin: 24px 0 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.section-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.section-btn:hover { color: var(--text); }
.section-btn[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ---- Device status strip (readout + view shortcuts, NOT the editor nav) ---- */
/* Status strip — a live readout line (label + state on the left, quick-switch chips on the
   right), NOT the editor tab nav below it. The left accent edge + inset panel fill mark it as
   an instrument readout so it can't be mistaken for the underlined .tabs. */
.device-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  flex-wrap: wrap;
  margin: 16px 0 0;
  padding: var(--sp-3) var(--sp-5);
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}
.device-bar-state { display: flex; align-items: baseline; gap: 8px; }
.db-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.ns-state {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant: small-caps;
}
.device-bar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.db-hint { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.db-live {
  font-size: 12px; font-weight: 700; letter-spacing: 0.6px;
  color: var(--ok);
  border: 1px solid rgba(63, 191, 127, 0.4);
  background: rgba(63, 191, 127, 0.1);
  border-radius: 999px; padding: 2px 8px;
}
/* The device bar is a LIVE readout of the keyboard, meaningless until connected. Hidden while
   disconnected so the first-run view shows ONE set of view names (the editor tabs), not two. */
#app:not([data-connected]) .device-bar { display: none; }

/* Switch chips — small stand-alone pills, deliberately NOT the connected segmented
   control they used to be, and NOT the underlined editor tabs (.tab). This is a status
   strip's quick-action row, so the chips read as buttons, not navigation. */
.ns-switch {
  display: inline-flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.ns-chip {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  padding: var(--sp-1) var(--sp-4);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
}
.ns-chip:hover:not(:disabled) { color: var(--text); border-color: var(--border-2); background: var(--border-2); }
.ns-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.ns-chip:disabled { opacity: 0.4; cursor: not-allowed; }
.sync-badge {
  font-size: 12px;
  color: var(--ok);
  border: 1px solid rgba(63,191,127,0.4);
  background: rgba(63,191,127,0.1);
  border-radius: 999px;
  padding: 4px 8px;
}

/* Gate — non-blocking banner: preview works offline, Send needs a device. */
.gate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  flex-wrap: wrap;
  margin-top: 16px;
  background: var(--panel);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 16px 16px;
}
.gate-text { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.gate-text strong { color: var(--text); }
.gate-text span { color: var(--muted); }
.gate-text em { color: var(--text); font-style: normal; font-weight: 600; }

/* LCD body wrapper */
.lcd-body { margin-top: 24px; }

/* Content sub-tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Panels */
.panels { margin-top: 24px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.panel-head { margin-bottom: 8px; }
.panel h2 { margin: 0 0 2px; font-size: 18px; }
.panel-head .muted { margin: 0; font-size: 13px; }
.panel h3 { margin: 24px 0 4px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Layout helpers */
.row { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; margin: 16px 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

input[type="time"], input[type="date"], input[type="text"], input[type="search"], select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
input[type="time"]:hover, input[type="date"]:hover, input[type="text"]:hover, input[type="search"]:hover, select:hover { border-color: var(--border-2); }
input::placeholder { color: var(--muted); opacity: 1; }
input[type="range"] { accent-color: var(--accent); width: 100%; margin: 0; }

/* One-line slider: label-left / value-right header, track below.
   .slider is a column <label>; .slider-head is the space-between header row. */
.slider { gap: 6px; width: 240px; max-width: 100%; }
.slider-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
label.inline input[type="range"] { width: 140px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type="color"] {
  width: 48px; height: 32px; padding: 2px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}
input[type="color"]:hover { border-color: var(--border-2); }
output { color: var(--text); font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-press); }
.btn.danger { color: var(--danger-text); border-color: var(--danger-text); background: transparent; }
.btn.danger:hover:not(:disabled) { background: var(--danger-press); color: #fff; }
.btn.block { display: flex; width: 100%; margin-top: 16px; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Shared disclosure (<details>) pattern — one summary + expand triangle for
   "Customize effects", "Recents", and "Device log". Container styling stays
   per-element (inset vs. top-level card); only the interaction reads the same. */
.disclosure > summary {
  cursor: pointer;
  padding: 8px 0;
  font-size: 14px;
  color: var(--muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.disclosure > summary:hover { color: var(--text); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "\25B8"; display: inline-block; transition: transform 0.15s; }
.disclosure[open] > summary::before { transform: rotate(90deg); }

/* Lighting: a "which one do I use" guide above the three effect areas */
/* Shared "which one?" explainer box — a short guide before a set of non-obvious choices. */
.guide {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 0 0 24px;
}
.guide ul {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.guide li {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
.guide li strong { color: var(--text); }

.tool-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  padding: 16px;
}
.tool-card h3:first-child { margin-top: 0; }
.tool-card .row:first-of-type { margin-top: 12px; }
.tool-card .row:last-child { margin-bottom: 0; }

.lighting-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr);
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
}
.lighting-card { margin-top: 16px; }
.lighting-grid .lighting-card { margin-top: 0; }
.lighting-card-wide { margin-top: 16px; }
.lighting-card .effect-customize,
.lighting-card .palette-editor,
.lighting-card .fx-mode {
  background: var(--panel);
}

@media (max-width: 1100px) {
  .keymap-workbench,
  .lighting-grid {
    grid-template-columns: 1fr;
  }
  .keymap-workbench { gap: 16px; }
  .guide ul { grid-template-columns: 1fr; }
}

/* Empty picture preview: hide the src-less <img> (it would show its alt text like a broken image)
   and show a quiet placeholder in the frame instead, until a file is chosen. */
#imagePreview:not([src]) { display: none; }
.preview-frame:has(#imagePreview:not([src])) { display: grid; place-items: center; width: 288px; height: 192px; }
.preview-frame:has(#imagePreview:not([src]))::after {
  content: "Choose an image to preview"; color: var(--muted); font-size: 12px;
}

/* Lighting effects (software-driven strobe / cycle / breathe) */
.fx-mode {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 16px;
  margin: 8px 0;
}
.fx-mode .row { margin: 8px 0; }
.fx-mode strong { color: var(--text); font-size: 13px; min-width: 56px; }

.music-mode { padding: 16px; }
.music-head, .music-title, .music-actions {
  display: flex;
  align-items: center;
}
.music-head { justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.music-title, .music-actions { gap: 10px; }
.music-style-row {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  align-items: end;
  padding: 14px 0;
}
.music-style-picker select { margin-top: 6px; }
.music-style-note {
  margin: 0 0 1px;
  padding: 8px 12px;
  border-left: 2px solid var(--accent);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.music-output-row {
  display: grid;
  grid-template-columns: 120px minmax(260px, 1fr) 160px;
  gap: 20px;
  align-items: end;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.music-control { min-width: 0; }
.music-range { position: relative; }
.music-range > output { position: absolute; right: 0; top: 0; }
.music-range input { margin-top: 6px; }
.music-output {
  color: var(--muted);
  font-size: 13px;
}
.music-output span { display: flex; justify-content: space-between; gap: 8px; }
.music-output meter { width: 100%; height: 10px; margin-top: 8px; accent-color: var(--accent); }
.music-tune { border-top: 1px solid var(--border); margin-top: 0; }
.music-tune > summary { display: flex; align-items: baseline; gap: 10px; padding: 14px 0 8px; }
.music-tune > summary strong { min-width: 0; }
.music-tune-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  padding: 4px 0 14px;
}
.music-control-note {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.music-setup { margin: 0; padding-top: 12px; border-top: 1px solid var(--border); }
.music-mode .statusline { margin: 8px 0 0; }

@media (max-width: 1100px) {
  .music-style-row, .music-output-row { grid-template-columns: 1fr; }
  .music-tune-grid { grid-template-columns: 1fr; }
}

/* Customize effects — a collapsible list that curates the #lightEffect dropdown. */
.effect-customize {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 16px;
  margin: 6px 0 16px;
}
.ec-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.ec-presets { display: flex; gap: 8px; flex-shrink: 0; }
.effect-toggles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px 24px;
  padding-bottom: 12px;
}
.effect-group { display: flex; flex-direction: column; gap: 6px; }
.effect-group-head {
  color: var(--text);
  font-weight: 600;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.effect-toggle { color: var(--muted); padding-left: 4px; }
.effect-toggle:hover { color: var(--text); }

/* Lighting palettes (multi-color presets, global board animation) */
.palette-editor {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 16px 12px;
  margin: 8px 0;
}
.palette-stops { display: flex; flex-wrap: wrap; gap: 12px; }
.palette-stop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
.palette-stop input[type="color"] { width: 44px; height: 34px; }
.palette-stop-nav { display: flex; gap: 4px; }
.palette-move {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.palette-move:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.palette-move:disabled { opacity: 0.3; cursor: not-allowed; }
.palette-stop-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.palette-stop-remove:hover:not(:disabled) { background: var(--danger-press); color: #fff; }
.palette-stop-remove:disabled { opacity: 0.3; cursor: not-allowed; }
.palette-presets { margin-top: 6px; }
.preset-name-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  max-width: 160px;
}
.preset-name-input:hover { border-color: var(--border-2); }

/* Status lines */
.statusline { min-height: 18px; font-size: 13px; margin: 12px 0 0; color: var(--muted); }
.statusline.ok { color: var(--ok); }
.statusline.err { color: var(--danger-text); }

.experimental {
  display: inline-block;
  font-size: 12px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.experimental:hover { border-color: var(--warn-text); }

/* Danger zone (in Picture / GIF editors) */
.danger-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.danger-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--danger-text);
}

/* Picture / GIF editor grid */
.image-grid { display: grid; grid-template-columns: 1fr auto; gap: 32px; align-items: start; }
.image-controls { min-width: 0; }
.image-controls label { margin-bottom: 12px; }
.dropzone {
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(91,157,255,0.08); }
.dropzone p { margin: 6px 0; }

.image-preview { text-align: center; }
.preview-frame {
  display: inline-block;
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 8px;
  background: #000;
}
#imagePreview {
  display: block;
  width: 288px;
  height: 192px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* GIF live preview (canvas, sized inline by JS per destination) */
#gifPreview {
  display: block;
  width: 288px;
  height: 192px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* Slideshow strip */
.slide-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.slide-strip:empty::before {
  content: "No slides yet — add images above.";
  color: var(--muted);
  font-size: 13px;
}
.slide-thumb {
  position: relative;
  width: 72px;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #000;
}
.slide-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.slide-idx {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 12px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}
.slide-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  line-height: 1;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.slide-remove:hover { background: var(--danger-press); color: #fff; }
.slide-reorder {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.5);
}
.slide-move {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  padding: 4px 0;
  cursor: pointer;
}
.slide-move:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.slide-move:disabled { opacity: 0.3; cursor: not-allowed; }
.slide-transport { margin-top: 4px; }

/* Slideshow layout: controls-left | preview-right, matching Weather/Clock (1fr auto). The left
   column carries the dropzone, thumbnail strip, and every setting/transport control so both columns
   run tall; the preview figure is the sole occupant of the right column. */
.slide-grid { display: grid; grid-template-columns: 1fr auto; gap: 32px; align-items: start; }
.slide-main { display: flex; flex-direction: column; gap: 14px; }
.slide-main > label { margin: 0; }
.slide-main .slide-strip { margin: 0; }
.slide-side { display: flex; flex-direction: column; gap: 14px; }
.dropzone-row {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 12px; padding: 14px 16px; margin-bottom: 14px; text-align: left;
}
.dropzone-row .btn { flex: none; }
@media (max-width: 760px) { .slide-grid { grid-template-columns: 1fr; } }

/* ---- now playing ---- */
.np-auth-card,
.np-current-card,
.wx-controls {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.np-auth { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.np-auth > .db-label,
.np-current-card > .db-label { align-self: flex-start; }
.np-redirect {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  color: var(--muted);
}
.np-current-card {
  min-width: 320px;
  text-align: left;
}
.np-track {
  display: flex;
  gap: 12px;
  align-items: center;
  text-align: left;
  margin: 10px 0 16px;
  min-height: 96px;
}
.np-art {
  width: 96px; height: 96px;
  border: 1px solid var(--border-2);
  border-radius: 6px;
  object-fit: cover;
  background: var(--panel-2);
  flex: none;
}
.np-art[hidden] { display: none; }
.np-meta { min-width: 0; }
.np-title { margin: 0 0 4px; font-weight: 600; overflow-wrap: anywhere; }
.np-transport { margin-top: 12px; gap: 8px; }

/* Weather card preview — the 96x160 frame drawn up ~2.5x, framed like the physical LCD it drives.
   Nearest-neighbor keeps the pixel art and 5x7 font crisp instead of blurring it; the padding reads
   as the screen bezel and the shadow lifts it off the panel. */
.wx-preview,
.slide-preview {
  width: 240px; height: 400px;
  max-width: 100%;
  padding: 10px;
  border-radius: 10px;
  background: #05060a;
  box-shadow: 0 0 0 1px var(--border-2), 0 10px 26px rgba(0, 0, 0, .45);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
/* Empty state uses the same LCD frame as the img, centered placeholder text. */
.slide-empty { box-sizing: border-box; display: grid; place-items: center; text-align: center; }
/* Weather controls belong at the top; centering them made the left side look empty. */
.wx-grid { align-items: start; }
.wx-controls { min-width: 0; }
.wx-field { display: block; margin-bottom: 10px; }
.wx-search { display: flex; gap: 8px; margin-top: 6px; }
.wx-search input[type="text"] { flex: 1; min-width: 0; box-sizing: border-box; }
.wx-search .btn { flex: none; }
.wx-units { margin-top: 14px; }
.wx-figure,
.slide-figure { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 0 0 16px; }
.wx-figure figcaption,
.slide-figure figcaption { letter-spacing: .04em; opacity: .7; }

/* Clock: same two-column controls|preview as Weather. The hero is a live device-style clock face
   (the time that Send pushes), so the light controls center against it — no dead column. */
.clock-grid { align-items: center; }
.clock-controls .clock-format { margin-bottom: 16px; }
.clock-controls .clock-sync { margin-top: 16px; color: var(--text); }
.clock-note { margin: 8px 0 0; max-width: 340px; }
.clock-manual { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 4px; }
.clock-manual .row { margin: 12px 0; }
.clock-manual summary { padding-left: 0; }

.clock-figure { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 0; }
.clock-figure figcaption { letter-spacing: .04em; opacity: .7; }
/* Dark screen framed like the physical LCD it drives — bezel padding + lift shadow, matching .wx-preview. */
.clock-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 320px;
  max-width: 100%;
  min-height: 210px;
  padding: 24px;
  border-radius: 12px;
  background: #05060a;
  box-shadow: 0 0 0 1px var(--border-2), 0 10px 26px rgba(0, 0, 0, .45);
}
.clock-live {
  font-size: 68px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: .04em;
  color: var(--text);
  /* Monospaced + tabular so it reads like the firmware's digital home-screen clock and HH:MM
     doesn't reflow as the digits tick. */
  font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
}
.clock-live-date {
  font-size: 15px;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}

/* Destination toggle → segmented control (main page vs separate view) */
.dest-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 4px;
}
.dest-toggle .dest-label {
  color: var(--muted);
  font-size: 13px;
}
.seg-radio {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--panel-2);
}
.seg-radio label {
  margin: 0;
  padding: 6px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.seg-radio label:last-child { border-right: none; }
.seg-radio input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg-radio label:hover { color: var(--text); }
.seg-radio label:has(input:checked) {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
/* the radio is a 0x0 hidden input, so surface keyboard focus on the visible segment */
.seg-radio label:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }
.dest-note { text-align: center; min-height: 16px; max-width: 300px; margin: 0 auto; }

/* Progress */
.progress {
  margin: 16px 0 0;
  height: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width 0.08s linear; }

/* Device log */
.device-log {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
}
.log-count {
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}
.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0 8px;
}
.log-list {
  margin: 0 0 12px;
  padding: 8px 12px;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
}
.log-list:empty::before { content: "No commands sent yet."; color: var(--muted); }
.log-list li { display: flex; gap: 8px; white-space: nowrap; }
.log-time { color: var(--muted); flex-shrink: 0; }
.log-msg { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.log-list li.err .log-msg { color: var(--danger-text); }
.log-list li.ok .log-msg { color: var(--ok); }

/* Footer */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  flex-wrap: wrap;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.footer-links { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.footer-link {
  display: inline-block;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: color .12s, border-color .12s;
}
.footer-link:hover { color: var(--accent); border-color: var(--accent); }

/* Keymap */
.shortcuts-grid { display: grid; grid-template-columns: 260px 1fr; gap: 24px; margin-top: 16px; align-items: start; }
.keycode-readout { margin-top: 16px; font-size: 13px; color: var(--muted); }
.keycode-readout code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--accent);
  font-size: 13px;
}
.preset-catalog { max-height: 420px; overflow-y: auto; }
.preset-group { margin-bottom: 16px; }
.preset-group h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.preset-chip:hover { border-color: var(--accent); }
.preset-chip code { color: var(--muted); font-size: 12px; }

/* ---- Live keymap editor -------------------------------------------------- */
/* Toolbar splits into two groups: the Layer picker (editing context) on the left,
   the load/save actions (Read / Import / Export) pushed to the right. */
.keymap-toolbar { align-items: center; }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-actions { margin-left: auto; }

.keymap-workbench {
  display: grid;
  grid-template-columns: minmax(720px, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
.keymap-main { min-width: 0; }
.keymap-rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.keymap-rail .row {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 0;
}
.keymap-rail .btn { width: 100%; }
.keymap-rail .statusline,
.keymap-rail .muted[role="status"] {
  min-height: 18px;
}

.layer-select { display: inline-flex; gap: 4px; padding: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.layer-btn {
  min-width: 34px; padding: 4px 8px; font: inherit; font-size: 13px;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
.layer-btn:hover { color: var(--text); }
.layer-btn[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Absolute-positioned key grid. --u (key unit, px) is set inline by JS on the container. */
.key-grid {
  position: relative;
  margin: 16px 0 8px;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
}
.key {
  position: absolute;
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  padding: 2px;
  font: inherit; font-size: 12px; line-height: 1.05;
  text-align: center; white-space: nowrap; word-break: normal;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 6px;
  cursor: pointer; overflow: hidden;
}
.key.key-tight { font-size: 11px; }
.key.key-wrap { font-size: 10px; white-space: normal; overflow-wrap: anywhere; }
.key:hover { border-color: var(--accent); }
.key.selected { border-color: var(--accent); box-shadow: var(--focus); }
.key.k-trns { color: var(--muted); background: var(--panel); }
.key.k-no { color: var(--muted); background: var(--panel); opacity: 0.6; }
.key.pressed { background: var(--ok); color: var(--accent-ink); border-color: var(--ok); }

/* Encoder widget */
.encoder-widget { display: flex; align-items: flex-end; gap: 12px; margin: 8px 0 4px; }
.enc-key { display: flex; flex-direction: column; gap: 4px; }
.enc-cap { font-size: 12px; color: var(--muted); }
.enc-btn { position: static; min-width: 104px; height: 40px; }
.enc-dial { font-size: 30px; color: var(--muted); padding-bottom: 4px; }

/* Keycode picker overlay */
.picker-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 14, 0.6); padding: 24px;
}
.picker-box {
  width: min(560px, 100%); max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.picker-head code { color: var(--accent); }
.picker-search {
  width: 100%; padding: 8px 8px; margin-bottom: 8px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 13px;
}
.picker-body { overflow-y: auto; flex: 1; }
.picker-foot { display: flex; align-items: flex-end; gap: 8px; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.picker-custom { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.picker-custom input {
  padding: 8px 8px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 13px;
}

/* Unsupported message */
.unsupported {
  max-width: 520px;
  margin: 80px auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
}
.unsupported h1 { font-size: 22px; margin: 0 0 12px; }
.unsupported p { color: var(--muted); }

/* ============================ Slot cache + recents ============================ */
/* Studio's client-side memory of what it PUSHED to each LCD area. Every surface here is
   labelled "last pushed from Studio", never "on the device now" — the LCD is write-only. */

/* Live-track meta on the device bar (shown while Now Playing runs). */
.ns-track-meta {
  font-size: 13px;
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ns-state.is-live { color: var(--ok); }

/* Device-bar overview strip: the 4 area thumbnails, wraps to its own row. */
.db-overview {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.db-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.db-thumb {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.db-thumb:hover { color: var(--text); border-color: var(--border-2); }
.db-thumb img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  background: #000;
  border-radius: 4px;
  image-rendering: pixelated;
}
.db-thumb .db-thumb-area { text-transform: capitalize; font-weight: 600; }
.db-thumb.is-live { color: var(--ok); border-color: rgba(63,191,127,0.4); }
.db-thumb.is-live .db-thumb-live { color: var(--ok); }

/* Per-tab "Currently on <area>" cards. */
.slot-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 16px;
}
.slot-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  min-width: 260px;
  flex: 1 1 260px;
}
.slot-card-thumb {
  width: 64px;
  height: 64px;
  flex: none;
  object-fit: contain;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  image-rendering: pixelated;
}
.slot-card.is-live .slot-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ok);
  font-size: 22px;
}
.slot-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.slot-card-area { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.slot-card-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slot-card-when { font-size: 12px; color: var(--muted); }
.slot-card.is-live .slot-card-name { color: var(--ok); }
.slot-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.slot-card-actions .btn { padding: 4px 8px; font-size: 12px; }
.slot-card-status { font-size: 12px; margin: 4px 0 0; min-height: 0; }

/* Recents drawer + gallery (mirrors the device-log <details>). */
.recents-drawer {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
}
.recents-drawer[open] > summary { margin-bottom: 6px; }
.recents-toolbar { margin-bottom: 8px; }
.recents-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.recents-gallery:empty::before {
  content: "Nothing pushed yet — send an image, GIF, or slideshow and it lands here.";
  color: var(--muted);
  font-size: 13px;
}
.recent-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.recent-card.pinned { border-color: var(--accent); }
.recent-thumb {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: #000;
  border-radius: 6px;
  image-rendering: pixelated;
  cursor: pointer;
}
.recent-name {
  font-size: 12px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recent-meta { font-size: 12px; color: var(--muted); }
.recent-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.recent-actions .btn { padding: 4px 8px; font-size: 12px; }
.recent-pin { position: absolute; top: 6px; right: 6px; }
.recent-pin.on { color: var(--accent); }

@media (max-width: 860px) {
  #app { padding: 24px 16px 48px; }
  .image-grid, .shortcuts-grid { grid-template-columns: 1fr; }
  .status-text { min-width: 0; }
  .image-preview { text-align: left; }
  .dest-toggle { justify-content: flex-start; }
  .dest-note { margin: 0; text-align: left; }
}
