:root {
  color-scheme: dark;
  --bg: #111316;
  --panel: #1a1e22;
  --panel-2: #20262b;
  --line: #303941;
  --text: #f5f7fa;
  --muted: #9aa6b2;
  --soft: #cbd5df;
  --cyan: #38bdf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --rose: #fb7185;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #242a30;
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: #53606b;
  background: #2b333a;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.primary-button {
  border-color: rgba(56, 189, 248, 0.62);
  background: linear-gradient(135deg, #0e7490, #2563eb);
  color: white;
  font-weight: 700;
}

.danger-button {
  border-color: rgba(251, 113, 133, 0.65);
  background: #7f1d1d;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  border-right: 1px solid #252d34;
  background: #15191d;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid #3b4650;
  border-radius: 8px;
  background: #20262b;
  color: #a3e635;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel-head h3,
.panel-head p,
.device-hero h3,
.device-hero p {
  margin: 0;
}

.brand h1 {
  font-size: 16px;
}

.brand p,
.panel-head p,
.device-hero p,
.eyebrow {
  color: var(--muted);
}

.brand p {
  margin-top: 4px;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  width: 100%;
  padding: 10px 12px;
  border-color: transparent;
  background: transparent;
  color: var(--soft);
  text-align: left;
}

.nav-item.active {
  border-color: #3b4650;
  background: #222a30;
  color: white;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--cyan);
}

.profile-stack {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.section-label {
  color: #a3e635;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.profile-pill {
  justify-content: flex-start;
  padding: 8px 10px;
  text-align: left;
}

.profile-pill.active {
  border-color: rgba(163, 230, 53, 0.56);
  background: #283225;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 28px;
}

.top-actions,
.button-row,
.recorder-strip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--soft);
  background: #181d21;
  white-space: nowrap;
}

.status span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #64748b;
}

.status.connected span {
  background: var(--green);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.75);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.surface {
  border: 1px solid #2b343c;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.device-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.75fr);
  gap: 16px;
}

.device-hero {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  align-items: center;
  min-height: 300px;
  overflow: hidden;
  padding: 28px;
}

.device-hero h3 {
  margin-top: 10px;
  font-size: 42px;
}

.device-hero p {
  max-width: 560px;
  margin-top: 14px;
  line-height: 1.7;
}

.device-visual {
  position: relative;
  min-height: 220px;
}

.device-glow {
  position: absolute;
  inset: 20px 10px auto auto;
  width: 72%;
  height: 170px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.25), transparent 62%);
  filter: blur(8px);
}

.mini-keyboard {
  position: relative;
  margin: 24px auto 0;
  width: min(100%, 640px);
  aspect-ratio: 640 / 230;
  border: 1px solid #3c4650;
  border-radius: 8px;
  background: #0e1114;
  transform: perspective(900px) rotateX(12deg) rotateZ(-1deg);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.45);
}

.mini-key {
  position: absolute;
  border: 1px solid #37424a;
  border-radius: 4px;
  background: linear-gradient(180deg, #303840, #1d2328);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid #29323a;
}

.panel-head h3 {
  font-size: 17px;
}

.panel-head p {
  margin-top: 6px;
  font-size: 13px;
}

.panel-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px 0;
}

.panel-subhead.compact {
  padding-top: 8px;
}

.panel-subhead h3 {
  margin: 0;
  font-size: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  color: #b6e9ff;
  background: rgba(56, 189, 248, 0.08);
  font-size: 12px;
  white-space: nowrap;
}

.chip.muted {
  border-color: #46505a;
  color: #cbd5df;
  background: #222930;
}

.metric-list {
  display: grid;
  padding: 14px 18px 18px;
}

.metric-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid #29323a;
}

.metric-list div:last-child {
  border-bottom: 0;
}

.metric-list span {
  color: var(--muted);
}

.metric-list strong {
  color: var(--text);
  text-align: right;
  overflow-wrap: anywhere;
}

.button-row,
.button-column {
  padding: 18px;
}

.button-column {
  display: grid;
  gap: 10px;
}

.file-button {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #242a30;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  align-items: start;
}

.keymap-workspace {
  display: grid;
  gap: 16px;
}

.keyboard-surface {
  min-width: 0;
}

.keyboard {
  position: relative;
  margin: 20px;
  width: min(100%, 940px);
  aspect-ratio: 600 / 230;
  border: 1px solid #303941;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(56, 189, 248, 0.08), transparent 28%),
    #101417;
  overflow: hidden;
}

.key {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0 2px;
  border: 1px solid #3b4650;
  border-radius: 4px;
  background: linear-gradient(180deg, #2e363d, #20262b);
  color: #f8fafc;
  font-size: clamp(9px, 1.1vw, 13px);
  overflow: hidden;
  white-space: normal;
  text-align: center;
  line-height: 0.98;
  text-overflow: clip;
}

.key.tiny-label {
  font-size: clamp(7px, 0.82vw, 10px);
}

.key.arrow-label {
  font-size: clamp(13px, 1.55vw, 19px);
  line-height: 1;
}

.key.changed {
  border-color: rgba(245, 158, 11, 0.75);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.34);
}

.key.selected {
  border-color: rgba(56, 189, 248, 0.9);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2), 0 0 22px rgba(56, 189, 248, 0.16);
}

.keymap-brush-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 20px 0;
  color: var(--muted);
}

.keymap-brush-bar strong {
  min-width: 110px;
  padding: 7px 10px;
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 7px;
  background: rgba(56, 189, 248, 0.12);
  color: #f8fafc;
}

.keymap-picker-surface .button-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.keymap-category-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 18px 14px;
}

.keymap-category-tab {
  min-height: 42px;
  border-color: rgba(239, 68, 68, 0.28);
  background: #161c20;
  color: #fb7185;
  font-weight: 700;
}

.keymap-category-tab.active {
  background: #dc4949;
  border-color: #dc4949;
  color: white;
}

.keymap-picker {
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
  padding: 16px;
}

.keymap-palette {
  display: grid;
  gap: 6px;
}

.keymap-palette-row {
  display: flex;
  gap: 4px;
  min-width: 0;
}

.keymap-palette-gap {
  flex: 0.7 0 18px;
}

.keyboard-palette-fixed {
  display: grid;
  grid-template-columns: repeat(24, minmax(56px, 1fr));
  grid-template-rows: repeat(6, 44px);
  gap: 6px;
  width: 100%;
  padding: 4px;
  overflow: auto;
}

.keymap-option,
.keymap-palette .keymap-option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 44px;
  padding: 0 8px;
  border-color: #28313a;
  background: #f7f7f7;
  color: #333;
  font-weight: 700;
  text-align: center;
  line-height: 1.08;
  white-space: normal;
}

.keyboard-palette-fixed .keymap-option {
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0 6px;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  font-size: clamp(10px, 0.72vw, 13px);
}

.keymap-option.tiny-label,
.keyboard-palette-fixed .keymap-option.tiny-label {
  font-size: clamp(9px, 0.64vw, 11px);
  letter-spacing: 0;
}

.keymap-option.arrow-label,
.keyboard-palette-fixed .keymap-option.arrow-label {
  font-size: clamp(18px, 1.35vw, 23px);
  line-height: 1;
}

.keymap-option:hover,
.keymap-option.active {
  border-color: #dc4949;
  background: #dc4949;
  color: white;
}

.keymap-option-section {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.keymap-option-section h4 {
  margin: 0;
  color: #f8fafc;
  font-size: 15px;
}

.keymap-option-section h4::after {
  content: "";
  display: block;
  width: 38px;
  height: 2px;
  margin-top: 5px;
  background: #dc4949;
}

.keymap-option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.macro-method-section {
  margin-top: 4px;
}

.macro-method-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.macro-method-button {
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border-color: rgba(239, 68, 68, 0.28);
  background: #161c20;
  color: #fb7185;
  font-weight: 700;
}

.macro-method-button.active {
  border-color: #dc4949;
  background: #dc4949;
  color: white;
}

.macro-times-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 180px);
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.macro-times-row .text-input {
  width: 100%;
  margin: 0;
}

.inspector {
  position: sticky;
  top: 18px;
}

.field-label {
  display: block;
  margin: 16px 18px 8px;
  color: var(--muted);
  font-size: 13px;
}

.text-input,
select,
textarea {
  width: calc(100% - 36px);
  margin: 0 18px;
  border: 1px solid #37424a;
  border-radius: 7px;
  background: #101417;
  color: var(--text);
  outline: none;
}

.text-input,
select {
  min-height: 38px;
  padding: 8px 10px;
}

textarea.text-input {
  padding: 10px;
  resize: vertical;
}

.assignment-list,
.macro-list,
.timeline,
.log {
  margin: 14px 18px 18px;
  border: 1px solid #29323a;
  border-radius: 8px;
  background: #11161a;
}

.assignment-list {
  display: grid;
  max-height: 342px;
  overflow: auto;
  padding: 6px;
}

.assignment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--soft);
  cursor: pointer;
}

.assignment-item:hover,
.assignment-item.active {
  background: #263039;
  color: white;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid #35404a;
  border-radius: 8px;
  background: #101417;
}

.segmented button {
  min-height: 30px;
  border-color: transparent;
  background: transparent;
  padding: 0 13px;
}

.segmented button.active {
  background: #2d3740;
  border-color: #3f4b55;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 10px;
  padding: 18px;
}

.mode-card {
  display: grid;
  gap: 10px;
  min-height: 96px;
  padding: 12px;
  border: 1px solid #303941;
  border-radius: 8px;
  background: #151a1f;
  cursor: pointer;
}

.mode-card.active {
  border-color: rgba(56, 189, 248, 0.78);
  background: #18242b;
}

.mode-card.local-only {
  border-style: dashed;
}

.mode-tone {
  width: 34px;
  height: 8px;
  border-radius: 999px;
}

.mode-card strong {
  font-size: 15px;
}

.mode-card span {
  color: var(--muted);
  font-size: 12px;
}

.lighting-preview-wrap {
  padding-bottom: 18px;
  border-top: 1px solid #29323a;
}

.lighting-preview-keyboard {
  position: relative;
  margin: 16px auto 0;
  width: min(75%, 720px);
  aspect-ratio: 600 / 230;
  border: 1px solid #303941;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 42%),
    #0b0f12;
  overflow: hidden;
}

.lighting-preview-keyboard.firmware-rainbow {
  background:
    linear-gradient(100deg, rgba(255, 0, 0, 0.12), rgba(255, 240, 0, 0.12), rgba(0, 215, 15, 0.12), rgba(0, 153, 255, 0.12), rgba(94, 1, 210, 0.12), rgba(255, 22, 169, 0.12)),
    #0b0f12;
}

.lighting-preview-keyboard.custom-preview {
  border-color: rgba(248, 250, 252, 0.42);
}

.light-key {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0 2px;
  border: 1px solid color-mix(in srgb, var(--key-color), #ffffff 14%);
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 18%, color-mix(in srgb, var(--key-color), #ffffff 18%), var(--key-color) 62%, #11161a 120%);
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(8px, 0.95vw, 12px);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 18px var(--key-glow), inset 0 0 10px rgba(255, 255, 255, 0.08);
  overflow: hidden;
  white-space: normal;
  text-align: center;
  line-height: 0.98;
  text-overflow: clip;
}

.light-key.tiny-label {
  font-size: clamp(7px, 0.72vw, 10px);
}

.light-key.arrow-label {
  font-size: clamp(12px, 1.3vw, 18px);
  line-height: 1;
}

.light-key.selected {
  border-color: white;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18), 0 0 24px var(--key-glow);
}

.light-key.customized::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: white;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.75);
}

input[type="range"] {
  width: calc(100% - 36px);
  margin: 0 18px;
  accent-color: var(--cyan);
}

.inline-value {
  float: right;
  color: #b6e9ff;
  font-weight: 700;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 0 18px 4px;
}

.stage-button {
  min-width: 0;
  padding: 0 6px;
}

.stage-button.active {
  border-color: rgba(56, 189, 248, 0.8);
  background: #18303a;
  color: #dff6ff;
}

.setting-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 18px;
}

.color-edit-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  padding: 0 18px;
}

.color-edit-row input[type="color"] {
  width: 54px;
  min-height: 38px;
  padding: 2px;
  border: 1px solid #37424a;
  border-radius: 7px;
  background: #101417;
}

.color-edit-row .text-input,
.rgb-grid .text-input {
  width: 100%;
  margin: 0;
}

.rgb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 18px 0;
}

.rgb-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.global-light-tools.hidden,
.global-light-tools[hidden],
.custom-light-tools.hidden,
.custom-light-tools[hidden] {
  display: none;
}

.custom-color-field,
.custom-hue-slider {
  position: relative;
  margin: 12px 18px 0;
  border: 1px solid #37424a;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}

.custom-color-field {
  height: 170px;
  background:
    linear-gradient(180deg, transparent, #000),
    linear-gradient(90deg, #fff, var(--picker-hue-color, #ff0000));
}

.custom-hue-slider {
  height: 24px;
  background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
}

#custom-color-field-pointer,
#custom-hue-pointer {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.custom-action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.pixel-import-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 10px;
  padding: 0 18px;
}

.pixel-import-row input[type="file"] {
  width: 100%;
  min-width: 0;
  padding: 8px;
}

.pixel-control-grid {
  display: grid;
  gap: 10px;
  padding: 12px 18px 0;
}

.pixel-control {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pixel-control span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.pixel-control b {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.pixel-control input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.compact-row {
  padding-top: 10px;
  padding-bottom: 0;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 18px;
}

.swatch {
  height: 36px;
  border: 2px solid transparent;
  border-radius: 7px;
}

.swatch.active {
  border-color: white;
}

.macro-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.macro-workspace {
  display: grid;
  grid-template-columns: 280px minmax(380px, 1fr) 330px;
  gap: 16px;
  align-items: start;
}

.macro-slot-panel,
.macro-editor-panel,
.macro-write-panel {
  min-width: 0;
}

.macro-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #29323a;
  border-radius: 7px;
  background: #171c21;
  color: #f8fafc;
  text-align: left;
}

.macro-row.active {
  border-color: rgba(251, 113, 133, 0.8);
  background: rgba(251, 113, 133, 0.12);
}

.macro-row span {
  color: var(--muted);
  font-size: 12px;
}

.timeline {
  min-height: 220px;
  padding: 12px 18px 18px;
  color: var(--muted);
}

.timeline-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed #34404a;
  border-radius: 8px;
  color: var(--muted);
}

.macro-composer {
  margin: 12px 18px 0;
  padding: 12px;
  border: 1px solid #29323a;
  border-radius: 8px;
  background: rgba(15, 20, 24, 0.72);
}

.macro-composer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.macro-composer-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.macro-composer-grid .text-input {
  width: 100%;
  margin: 0;
}

.macro-composer-actions {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.macro-preview-panel {
  display: grid;
  gap: 8px;
  margin: 12px 18px 0;
}

.macro-preview-keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: 34px;
  gap: 6px;
}

.macro-preview-keys span {
  min-width: 34px;
  padding: 5px 9px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 7px;
  background: rgba(56, 189, 248, 0.12);
  color: #e0f2fe;
  text-align: center;
  font-weight: 700;
}

.macro-preview-keys .muted {
  border-color: #303941;
  background: #141a1f;
  color: var(--muted);
  font-weight: 500;
}

.macro-preview-output {
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid #303941;
  border-radius: 7px;
  background: #101417;
  color: #f8fafc;
  white-space: pre-wrap;
}

.macro-step-list {
  display: grid;
  gap: 8px;
}

.macro-step-row {
  display: grid;
  grid-template-columns: 64px minmax(82px, 0.75fr) minmax(110px, 1fr) minmax(112px, 0.9fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid #29323a;
  border-radius: 8px;
  background: #141a1f;
}

.macro-step-row.dragging {
  opacity: 0.58;
}

.macro-step-row.drop-target {
  border-color: rgba(56, 189, 248, 0.85);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.22);
}

.macro-drag-cell {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 4px;
}

.macro-drag-handle {
  min-width: 0;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  cursor: grab;
  color: #cbd5e1;
}

.macro-drag-handle:active {
  cursor: grabbing;
}

.macro-step-number {
  color: #fb7185;
  font-weight: 800;
  text-align: center;
}

.macro-step-row .text-input {
  width: 100%;
  margin: 0;
}

.macro-delay-cell {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

.macro-delay-input:disabled {
  opacity: 0.55;
}

.macro-step-actions {
  display: grid;
  grid-template-columns: repeat(4, 32px);
  gap: 5px;
}

.macro-icon-button {
  min-width: 0;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  font-weight: 800;
}

.recorder-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 18px 0;
}

.macro-meter {
  display: flex;
  justify-content: flex-start;
  padding: 12px 18px 0;
  color: #fb7185;
  font-weight: 700;
}

.macro-capture {
  width: 1px;
  height: 1px;
  margin: 0 18px;
  opacity: 0;
  overflow: hidden;
  outline: none;
}

#macro-record-status.recording {
  border-color: rgba(251, 113, 133, 0.75);
  background: rgba(251, 113, 133, 0.14);
  color: #fecdd3;
}

.metric-list.compact {
  margin-bottom: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(240px, 1fr));
  gap: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 50px;
  padding: 0 18px;
  border-bottom: 1px solid #29323a;
}

.toggle-row:last-child {
  border-bottom: 0;
}

.toggle-row input,
.toggle-inline input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.rate-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 18px;
}

.rate-button.active {
  border-color: rgba(163, 230, 53, 0.75);
  background: #25311f;
}

.test-area {
  min-height: 90px;
  margin-bottom: 18px;
  padding: 10px;
  resize: none;
}

.hid-form {
  display: grid;
  gap: 14px;
  padding-bottom: 4px;
}

.hid-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.mono,
.log {
  font-family: "Cascadia Mono", "Consolas", monospace;
}

.log {
  min-height: 430px;
  max-height: 600px;
  overflow: auto;
  padding: 12px;
  color: #cbd5df;
  font-size: 12px;
  line-height: 1.55;
}

.log-entry {
  padding: 8px 0;
  border-bottom: 1px solid #222a30;
  overflow-wrap: anywhere;
}

.log-entry:last-child {
  border-bottom: 0;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--soft);
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .brand div:last-child,
  .nav-item span:last-child,
  .profile-stack {
    display: none;
  }

  .sidebar {
    align-items: center;
  }

  .nav-item {
    justify-content: center;
    padding: 10px;
  }

  .tool-layout,
  .macro-workspace,
  .settings-grid,
  .device-grid,
  .device-hero {
    grid-template-columns: 1fr;
  }

  .macro-composer-grid,
  .macro-composer-actions,
  .macro-step-row {
    grid-template-columns: 1fr;
  }

  .macro-step-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .keymap-category-tabs,
  .macro-method-grid,
  .rate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inspector {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    flex-direction: row;
    justify-content: space-between;
    padding: 10px;
    border-right: 0;
    border-bottom: 1px solid #252d34;
    overflow-x: auto;
  }

  .brand {
    min-width: 56px;
  }

  .nav {
    display: flex;
    gap: 6px;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .device-hero h3 {
    font-size: 30px;
  }

  .keyboard {
    margin: 12px;
    width: calc(100% - 24px);
  }

  .lighting-preview-keyboard {
    width: calc(100% - 24px);
  }
}

/* White UI refresh */
:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #d9e2ec;
  --text: #16202a;
  --muted: #697586;
  --soft: #344054;
  --cyan: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --rose: #e11d48;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --ease-ui: cubic-bezier(0.22, 1, 0.36, 1);
}

html,
body {
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.055), transparent 32%),
    linear-gradient(315deg, rgba(20, 184, 166, 0.05), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
.file-button,
.key,
.light-key,
.surface,
.nav-item,
.mode-card,
.macro-row,
.macro-step-row,
.keymap-option,
.stage-button,
.rate-button,
.profile-pill,
.chip,
.status,
.text-input,
select,
textarea {
  transition:
    background-color 220ms var(--ease-ui),
    background 220ms var(--ease-ui),
    border-color 220ms var(--ease-ui),
    box-shadow 220ms var(--ease-ui),
    color 220ms var(--ease-ui),
    opacity 220ms var(--ease-ui),
    transform 220ms var(--ease-ui);
}

button,
.file-button {
  border-color: #d6dee8;
  border-radius: 13px;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

button:hover,
.file-button:hover {
  border-color: #b7c4d5;
  background: #f8fafc;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.primary-button {
  border-color: #2563eb;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: white;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.danger-button {
  border-color: #fda4af;
  background: #fff1f2;
  color: #be123c;
}

.app-shell {
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 12px 0 36px rgba(15, 23, 42, 0.04);
  backdrop-filter: blur(16px);
}

.brand-mark {
  border-color: #dbe7f4;
  border-radius: 16px;
  background: linear-gradient(135deg, #eff6ff, #ecfeff);
  color: #2563eb;
}

.nav-item {
  border-radius: 14px;
  color: #475467;
}

.nav-item:hover {
  background: #f1f5f9;
  box-shadow: none;
}

.nav-item.active {
  border-color: #c7d2fe;
  background: #eef4ff;
  color: #1d4ed8;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.nav-item[data-view="hidlab"] {
  margin-top: 8px;
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.nav-item[data-view="hidlab"].active {
  border-color: #f59e0b;
  background: #fef3c7;
  color: #78350f;
}

.profile-pill.active {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.profile-stack {
  display: none;
}

.internal-only,
[hidden].internal-only {
  display: none !important;
}

.workspace {
  padding: 28px;
}

.topbar {
  padding: 16px 18px;
  border: 1px solid #e3eaf3;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(14px);
}

.surface {
  border-color: #e2e8f0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
}

.panel-head,
.metric-list div,
.lighting-preview-wrap,
.toggle-row {
  border-color: #e5edf5;
}

.chip,
.status {
  border-color: #c7d2fe;
  background: #eef4ff;
  color: #1d4ed8;
}

.chip.muted {
  border-color: #d8e0ea;
  background: #f8fafc;
  color: #64748b;
}

.status.disconnected span {
  background: #94a3b8;
}

.status.connected span {
  background: var(--green);
  box-shadow: 0 0 14px rgba(22, 163, 74, 0.42);
}

.device-glow {
  background: radial-gradient(circle, rgba(37, 99, 235, 0.16), transparent 64%);
}

.mini-keyboard,
.keyboard,
.lighting-preview-keyboard {
  border-color: #d7e0ea;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(248, 250, 252, 0.96)),
    #f8fafc;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 18px 42px rgba(15, 23, 42, 0.08);
}

.mini-key {
  border-color: #d4deea;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #eef2f7);
}

.key {
  border-color: #cfd9e6;
  border-radius: 7px;
  background: linear-gradient(180deg, #ffffff, #edf2f7);
  color: #1f2937;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.key:hover,
.light-key:hover {
  transform: translateY(-1px);
}

.key.changed {
  border-color: #f59e0b;
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.18), 0 8px 20px rgba(245, 158, 11, 0.1);
}

.key.selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14), 0 10px 28px rgba(37, 99, 235, 0.12);
}

.keymap-brush-bar strong,
.text-input,
select,
textarea,
.macro-preview-output {
  border-color: #d7e0ea;
  background: #ffffff;
  color: var(--text);
}

.assignment-list,
.macro-list,
.timeline,
.log,
.macro-composer,
.macro-preview-output,
.segmented {
  border-color: #e1e8f0;
  background: #f8fafc;
}

.assignment-item:hover,
.assignment-item.active {
  background: #eaf2ff;
  color: #1d4ed8;
}

.segmented button.active,
.stage-button.active,
.rate-button.active {
  border-color: #2563eb;
  background: #eef4ff;
  color: #1d4ed8;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.keymap-category-tab,
.macro-method-button {
  border-color: #dbe4ee;
  background: #ffffff;
  color: #475467;
}

.keymap-category-tab.active,
.macro-method-button.active,
.keymap-option.active,
.keymap-option:hover {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

.keymap-option,
.keymap-palette .keymap-option {
  border-color: #d7e0ea;
  background: #ffffff;
  color: #1f2937;
}

.keymap-option-section h4 {
  color: var(--text);
}

.keymap-option-section h4::after {
  background: #2563eb;
}

.mode-card {
  border-color: #e1e8f0;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.mode-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  transform: translateY(-2px);
}

.mode-card.active {
  border-color: #2563eb;
  background: #eef4ff;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.13);
}

.lighting-preview-keyboard.firmware-rainbow {
  background:
    linear-gradient(100deg, rgba(255, 0, 0, 0.08), rgba(255, 240, 0, 0.08), rgba(0, 215, 15, 0.08), rgba(0, 153, 255, 0.08), rgba(94, 1, 210, 0.08), rgba(255, 22, 169, 0.08)),
    #f8fafc;
}

.lighting-preview-keyboard.custom-preview {
  border-color: #b7c4d5;
}

.light-key {
  border-radius: 7px;
  color: rgba(255, 255, 255, 0.94);
  box-shadow: 0 0 16px var(--key-glow), inset 0 0 10px rgba(255, 255, 255, 0.12);
}

.light-key.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2), 0 0 24px var(--key-glow);
}

.light-key.hardware-pressed {
  transform: translateY(2px) scale(0.965);
  border-color: #ffffff;
  filter: brightness(1.28) saturate(1.18);
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.24),
    0 0 30px var(--key-glow),
    inset 0 3px 10px rgba(15, 23, 42, 0.2);
}

.custom-color-field,
.custom-hue-slider,
.swatch,
.macro-row,
.macro-step-row {
  border-color: #d7e0ea;
  background: #ffffff;
}

.custom-color-field {
  background:
    linear-gradient(180deg, transparent, #000),
    linear-gradient(90deg, #fff, var(--picker-hue-color, #ff0000));
}

.custom-hue-slider {
  background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
}

.macro-row {
  color: var(--text);
}

.macro-row strong {
  color: #e11d48;
}

.macro-row span {
  color: #475467;
}

.macro-row.active,
#macro-record-status.recording {
  border-color: #fb7185;
  background: #fff1f2;
  color: #be123c;
}

.macro-step-row.drop-target {
  border-color: #2563eb;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18), 0 10px 24px rgba(37, 99, 235, 0.1);
}

.macro-drag-handle,
.macro-icon-button {
  background: #f8fafc;
  color: #475467;
}

.log {
  color: #344054;
}

.log-entry {
  border-color: #e5edf5;
}

#hidlab .surface {
  border-color: #fde68a;
  background: #fffdf5;
}

#hidlab .panel-head {
  background: linear-gradient(180deg, rgba(254, 243, 199, 0.55), rgba(255, 253, 245, 0));
}

#hidlab .chip,
#hidlab .toggle-inline {
  color: #92400e;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 86px minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .sidebar {
    border-bottom-color: #e2e8f0;
  }
}
