/* ---------------------------------------------------------------------------
 * Design tokens — shadcn/ui default theme (neutral base), OKLCH values.
 * Light in :root, dark under .dark. Kept faithful to the shadcn system so the
 * app reads as a real shadcn surface rather than a bespoke look.
 * ------------------------------------------------------------------------- */
:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.985 0 0);
  --success: oklch(0.62 0.17 152);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);

  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --content-max: 1200px;
  --gutter: max(1.5rem, calc((100% - var(--content-max)) / 2));

  color-scheme: light;
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --destructive-foreground: oklch(0.985 0 0);
  --success: oklch(0.7 0.15 152);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 20px -4px rgb(0 0 0 / 0.6);

  color-scheme: dark;
}

/* ---------------------------------------------------------------------------
 * Base
 * ------------------------------------------------------------------------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: 3rem;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.hidden { display: none !important; }

::selection { background: color-mix(in oklch, var(--primary) 25%, transparent); }

:focus-visible { outline: none; }

/* ---------------------------------------------------------------------------
 * App shell: header + footer
 * ------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem var(--gutter);
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklch, var(--background) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-sm);
}
.logo-mark svg { width: 1.15rem; height: 1.15rem; }
.brand-text h1 { font-size: 0.975rem; line-height: 1.2; }
.brand-sub { margin: 0.1rem 0 0; font-size: 0.75rem; color: var(--muted-foreground); }

.actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.sep-v { width: 1px; height: 1.5rem; background: var(--border); margin: 0 0.15rem; }

/* Segmented control (platform toggle) */
.seg {
  display: inline-flex;
  gap: 0.15rem;
  padding: 0.2rem;
  background: var(--muted);
  border-radius: var(--radius-md);
}
.seg-btn {
  height: 1.85rem;
  padding: 0 0.7rem;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: calc(var(--radius-md) - 3px);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.seg-btn:hover { color: var(--foreground); }
.seg-btn.active {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-sm);
}

/* Editor note + keycap styling */
.editor-note {
  margin: 0 0 1.1rem;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted-foreground);
}
.editor-note strong { color: var(--foreground); font-weight: 600; }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 0.35rem;
  background: var(--muted);
  color: var(--foreground);
}

.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 0.55rem var(--gutter);
  font-size: 0.75rem;
  color: var(--muted-foreground);
  background: color-mix(in oklch, var(--background) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.log { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; }

/* ---------------------------------------------------------------------------
 * Buttons (shadcn variants: default / secondary / outline / ghost / destructive)
 * Base .btn = outline. .btn.primary = default. .btn.ghost = ghost.
 * ------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  height: 2.25rem;
  padding: 0 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--accent); color: var(--accent-foreground); }
.btn:focus-visible { box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 45%, transparent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn.primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: transparent;
  box-shadow: var(--shadow-xs);
}
.btn.primary:hover:not(:disabled) {
  background: color-mix(in oklch, var(--primary) 90%, transparent);
  color: var(--primary-foreground);
}

.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: var(--accent); color: var(--accent-foreground); }

.btn.danger:hover:not(:disabled) {
  background: color-mix(in oklch, var(--destructive) 12%, transparent);
  color: var(--destructive);
  border-color: color-mix(in oklch, var(--destructive) 40%, transparent);
}

.btn.icon { width: 2.25rem; padding: 0; }
.btn svg { width: 1rem; height: 1rem; }

#themeBtn .icon-sun { display: none; }
#themeBtn .icon-moon { display: block; }
.dark #themeBtn .icon-sun { display: block; }
.dark #themeBtn .icon-moon { display: none; }

/* Small buttons used inside key cards */
.mini {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 1.75rem;
  padding: 0 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.mini:hover { background: var(--accent); color: var(--accent-foreground); }
.mini:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 40%, transparent); }
.mini.danger { border-color: transparent; }
.mini.danger:hover {
  background: color-mix(in oklch, var(--destructive) 12%, transparent);
  color: var(--destructive);
}
.mini.record { color: var(--foreground); }
.mini.record:hover { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }

/* ---------------------------------------------------------------------------
 * Badges
 * ------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 1.6rem;
  padding: 0 0.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-size: 0.75rem;
  font-weight: 500;
}
.badge .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--muted-foreground);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
.badge .dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--success) 25%, transparent);
}

/* ---------------------------------------------------------------------------
 * Alerts
 * ------------------------------------------------------------------------- */
.alert {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 1rem var(--gutter) 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  font-size: 0.85rem;
}
.alert-warning {
  border-color: color-mix(in oklch, var(--destructive) 45%, var(--border));
  background: color-mix(in oklch, var(--destructive) 8%, var(--card));
}
.alert span { color: var(--muted-foreground); }

/* ---------------------------------------------------------------------------
 * Tabs (mode switcher) — toggle-group style pills
 * ------------------------------------------------------------------------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1.5rem;
  padding: 0 var(--gutter);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.tab:hover { background: var(--accent); color: var(--accent-foreground); }
.tab.active {
  background: var(--card);
  border-color: var(--border);
  color: var(--foreground);
  box-shadow: var(--shadow-sm);
}
.tab .swatch { width: 0.65rem; height: 0.65rem; border-radius: 3px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }

.add-tab { position: relative; border: 1px dashed var(--border); color: var(--muted-foreground); }
.add-tab:hover { color: var(--foreground); background: var(--accent); border-style: dashed; }

.add-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 40;
  min-width: 12rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.add-menu.hidden { display: none; }
.add-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.add-item:hover { background: var(--accent); color: var(--accent-foreground); }
.add-item .swatch { width: 0.7rem; height: 0.7rem; border-radius: 3px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }

/* ---------------------------------------------------------------------------
 * Editor
 * ------------------------------------------------------------------------- */
.editor { padding: 1.5rem var(--gutter) 4rem; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 5rem 1rem;
  text-align: center;
  color: var(--muted-foreground);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted-foreground);
}
.empty-icon svg { width: 1.4rem; height: 1.4rem; }
.empty-title { margin: 0; font-weight: 600; color: var(--foreground); }
.empty-sub { margin: 0; font-size: 0.85rem; }

.section-title { font-size: 0.95rem; }
.section-sub { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--muted-foreground); }

/* Mode meta bar */
.mode-meta {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
.mode-meta label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

/* Inputs (shadcn input) */
.mode-meta input[type="text"],
.key-label,
.step select,
.step input[type="text"] {
  height: 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--input);
  background: var(--background);
  color: var(--foreground);
  padding: 0 0.7rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.mode-meta input[type="text"]:focus,
.key-label:focus,
.step select:focus,
.step input[type="text"]:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 35%, transparent);
}
.mode-meta input[type="text"] { min-width: 12rem; }

/* Native select with a chevron affordance */
.step select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  cursor: pointer;
}

/* Color input */
.mode-meta input[type="color"] {
  width: 2.75rem;
  height: 2.25rem;
  padding: 0.2rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: var(--background);
  cursor: pointer;
}
.mode-meta input[type="color"]::-webkit-color-swatch { border: none; border-radius: calc(var(--radius-md) - 3px); }
.mode-meta input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }

.mode-meta .btn { align-self: flex-end; }

/* Key grid + cards */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.key-card {
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.key-card:hover { border-color: color-mix(in oklch, var(--ring) 35%, var(--border)); }

.key-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.75rem; }
.key-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted-foreground);
  background: var(--muted);
  border-radius: var(--radius-sm);
}
.key-label { flex: 1; font-weight: 600; }

/* Steps */
.steps { display: flex; flex-direction: column; gap: 0.5rem; }
.step {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in oklch, var(--muted) 55%, var(--card));
}
.step-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.step-row > select,
.step-row > input[type="text"] { height: 2rem; font-size: 0.8rem; }
.step input[type="text"] { flex: 1; min-width: 8rem; }

.mods { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.mods label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted-foreground);
  cursor: pointer;
}

/* Checkbox (shadcn checkbox) for modifiers */
.mod-cb {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 1rem;
  height: 1rem;
  flex: none;
  border: 1px solid var(--input);
  border-radius: 4px;
  background: var(--background);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.mod-cb:hover { border-color: var(--ring); }
.mod-cb:checked { background: var(--primary); border-color: var(--primary); }
.mod-cb:checked::after {
  content: "";
  position: absolute;
  left: 0.28rem;
  top: 0.08rem;
  width: 0.3rem;
  height: 0.55rem;
  border: solid var(--primary-foreground);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.mod-cb:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 40%, transparent); }

.step-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.65rem; }

/* Switch (shadcn switch) for Hold / Latch */
.hold-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted-foreground);
  cursor: pointer;
}
.step-actions > .hold-toggle:nth-last-child(2) { margin-left: auto; }
.hold-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 1.75rem;
  height: 1rem;
  flex: none;
  border-radius: 9999px;
  background: var(--input);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.hold-toggle input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 0.12rem;
  left: 0.12rem;
  width: 0.76rem;
  height: 0.76rem;
  border-radius: 9999px;
  background: var(--background);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
.hold-toggle input[type="checkbox"]:checked { background: var(--primary); }
.hold-toggle input[type="checkbox"]:checked::before {
  transform: translateX(0.75rem);
  background: var(--primary-foreground);
}
.hold-toggle input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 40%, transparent);
}

/* ---------------------------------------------------------------------------
 * Live key tester — left slide-out drawer shaped like the MacroPad
 * ------------------------------------------------------------------------- */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 150;
  height: 100vh;
  width: 320px;
  max-width: 88vw;
  padding: 1.3rem 1.15rem;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(-110%);
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.drawer-close:hover { background: var(--muted); color: var(--foreground); }
.drawer-close svg { width: 1rem; height: 1rem; }
.drawer-title { margin: 0; padding-right: 2.25rem; font-size: 0.95rem; font-weight: 600; color: var(--foreground); }
.drawer-hint { margin: 0.2rem 0 1.25rem; font-size: 0.8rem; line-height: 1.45; color: var(--muted-foreground); }

/* Device mockup (always dark, like the physical hardware) */
.device {
  --dev-accent: #00e6c3;
  align-self: center;
  width: 244px;
  max-width: 100%;
  padding: 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, #292930, #16161a);
  border: 1px solid #37373f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 12px 30px rgba(0, 0, 0, 0.35);
}
.device-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 8px; }

/* Simulated 128x64 monochrome OLED: inverted title bar + 3x4 legend grid */
.oled {
  flex: 1;
  min-width: 0;
  aspect-ratio: 128 / 64;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  background: #04110d;
  border: 1px solid #000;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  font-family: ui-monospace, Menlo, monospace;
}
.oled-bar {
  flex: none;
  background: #e9fff8;
  color: #04110d;
  text-align: center;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1.35;
  padding: 1px 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.oled-legend {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 1px;
  padding: 2px;
}
.oled-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  line-height: 1;
  color: #d6f5ec;
  border-radius: 2px;
  overflow: hidden;
  white-space: nowrap;
  transition: background 0.05s ease, color 0.05s ease;
}
.oled-cell.lit { background: var(--dev-accent); color: #04110d; font-weight: 700; }

.device-caption {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.6rem;
  color: #8a8a94;
  text-align: right;
  margin: 0 2px 12px;
}
.device-caption span { color: #cfe9e2; }
.device-knob {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3c3c45, #1f1f25);
  border: 1px solid #47474f;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
  transition: box-shadow 0.1s ease, transform 0.1s ease;
}
.knob-dot { width: 5px; height: 5px; border-radius: 50%; background: #6b6b76; transition: background 0.1s ease, box-shadow 0.1s ease; }
.device-knob.on {
  transform: scale(0.95);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dev-accent) 45%, transparent), 0 3px 6px rgba(0, 0, 0, 0.45);
}
.device-knob.on .knob-dot { background: var(--dev-accent); box-shadow: 0 0 8px var(--dev-accent); }

.device-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.test-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 9px;
  background: linear-gradient(180deg, #34343c, #24242a);
  border: 1px solid #3f3f48;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #c9c9d2;
  transition: transform 0.05s ease, box-shadow 0.09s ease, background 0.09s ease, border-color 0.09s ease;
}
.test-cell.active {
  background: linear-gradient(180deg, color-mix(in srgb, var(--dev-accent) 42%, #24242a), #24242a);
  border-color: var(--dev-accent);
  color: #fff;
  box-shadow: 0 0 0 2px var(--dev-accent), 0 0 16px 2px color-mix(in srgb, var(--dev-accent) 55%, transparent);
  transform: translateY(1px) scale(0.96);
}
.tc-num { font-size: 0.6rem; font-family: ui-monospace, Menlo, monospace; color: #7a7a86; }
.test-cell.active .tc-num { color: rgba(255, 255, 255, 0.8); }
.tc-lab { font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.05; padding: 0 3px; }

/* ---------------------------------------------------------------------------
 * Capture overlay (Record key/mouse)
 * ------------------------------------------------------------------------- */
.capture-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in oklch, var(--background) 55%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
}
.capture-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: center;
  padding: 1.75rem 2.5rem;
  border-radius: var(--radius-xl);
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.capture-box strong { font-size: 1.05rem; }
.capture-box span { color: var(--muted-foreground); font-size: 0.8rem; }

/* ---------------------------------------------------------------------------
 * Firmware alert (row layout with action button) + empty-state action
 * ------------------------------------------------------------------------- */
#fwAlert {
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}
#fwAlert .btn.mini { margin-left: auto; flex: none; }
.empty .btn { margin-top: 0.85rem; }

/* ---------------------------------------------------------------------------
 * Setup / firmware modal
 * ------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: color-mix(in oklch, var(--background) 45%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 34rem;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 1.1rem 1.25rem 1.4rem; }
.setup-sub {
  margin: 1.1rem 0 0.55rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--foreground);
}
.setup-steps {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted-foreground);
}
.setup-steps strong { color: var(--foreground); font-weight: 600; }
.setup-steps a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.dl-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.dl-row .btn { text-decoration: none; }
.setup-divider { height: 1px; background: var(--border); margin: 1.25rem 0 0.25rem; }
.setup-note { margin: 1.1rem 0 0; font-size: 0.8rem; color: var(--muted-foreground); }
