:root,
html[data-finish="graphite"] {
  --bg: #0a0b0d;
  --panel: rgba(17, 19, 24, 0.88);
  --panel-solid: #121419;
  --panel-raised: #191c23;
  --well: #0c0d10;
  --hairline: rgba(236, 234, 228, 0.11);
  --hairline-strong: rgba(236, 234, 228, 0.22);
  --ink: #eceae4;
  --ink-dim: rgba(236, 234, 228, 0.56);
  --ink-faint: rgba(236, 234, 228, 0.34);
  --accent: #ff5500;
  --accent-soft: rgba(255, 85, 0, 0.16);
  --amber: #ffb000;
  --cyan: #2dd4bf;
  --led-off: rgba(236, 234, 228, 0.18);
  --bevel-top: rgba(255, 255, 255, 0.06);
  --shadow-deck: 0 12px 32px rgba(0, 0, 0, 0.55);
}

html[data-finish="drafting"] {
  --bg: #e9e6de;
  --panel: rgba(226, 222, 212, 0.9);
  --panel-solid: #dedad0;
  --panel-raised: #ebe8e0;
  --well: #d3cfc4;
  --hairline: rgba(21, 23, 26, 0.13);
  --hairline-strong: rgba(21, 23, 26, 0.28);
  --ink: #15171a;
  --ink-dim: rgba(21, 23, 26, 0.6);
  --ink-faint: rgba(21, 23, 26, 0.38);
  --accent: #e03e1a;
  --accent-soft: rgba(224, 62, 26, 0.13);
  --amber: #b86e00;
  --cyan: #0d746b;
  --led-off: rgba(21, 23, 26, 0.2);
  --bevel-top: rgba(255, 255, 255, 0.55);
  --shadow-deck: 0 10px 26px rgba(21, 23, 26, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

:root {
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", "Consolas", ui-monospace, monospace;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  z-index: 1;
}

/* Top Instrument Chassis */
.hud-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  min-height: 48px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--hairline);
  box-shadow: inset 0 1px 0 var(--bevel-top);
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-right: 1px solid var(--hairline);
  flex-shrink: 0;
}

.unit-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  background: var(--accent);
  color: #ffffff;
  border-radius: 2px;
  line-height: 1.1;
}

.unit-model {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.unit-serial {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.unit-active-name {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  white-space: nowrap;
}

/* Telemetry Readout Strip */
.telemetry-strip {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0 8px;
}

.tele-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 14px;
  height: 100%;
  border-right: 1px solid var(--hairline);
  min-width: 96px;
}

.tele-cell:last-child {
  border-right: none;
}

.tele-label {
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  text-transform: uppercase;
  line-height: 1.2;
}

.tele-val {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
  line-height: 1.35;
}

.tele-cell.fps-cell .tele-val {
  color: var(--cyan);
}

/* System Tactile Switches (Top Right) */
.sys-switches {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-left: 1px solid var(--hairline);
  flex-shrink: 0;
}

.hw-btn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--panel-raised);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  height: 30px;
  padding: 0 10px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--bevel-top);
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease, transform 0.06s ease;
  white-space: nowrap;
}

.hw-btn:hover {
  border-color: var(--hairline-strong);
  color: var(--ink);
}

.hw-btn:active {
  transform: translateY(1px);
}

.hw-btn.is-on {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.hw-btn.is-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--led-off);
  flex-shrink: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.hw-btn.is-on .led {
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
}

.hw-btn.is-warn .led {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
}

.hw-btn.is-accent .led {
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent);
}

.kbd-hint {
  font-size: 0.58rem;
  opacity: 0.5;
  padding-left: 2px;
}

/* Audio mini-bars */
.eq-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 1.5px;
  height: 10px;
}

.eq-bars i {
  display: block;
  width: 2px;
  height: 3px;
  background: var(--led-off);
  transition: height 0.12s ease, background 0.12s ease;
}

.hw-btn.is-on .eq-bars i {
  background: var(--accent);
}

.hw-btn.is-on .eq-bars i:nth-child(1) {
  height: 5px;
  animation: eqPulse 0.9s ease-in-out infinite alternate;
}

.hw-btn.is-on .eq-bars i:nth-child(2) {
  height: 9px;
  animation: eqPulse 0.65s ease-in-out 0.15s infinite alternate;
}

.hw-btn.is-on .eq-bars i:nth-child(3) {
  height: 6px;
  animation: eqPulse 0.8s ease-in-out 0.3s infinite alternate;
}

@keyframes eqPulse {
  from { transform: scaleY(0.45); transform-origin: bottom; }
  to { transform: scaleY(1); transform-origin: bottom; }
}

/* Bottom Hardware Control Deck */
.hud-bottom {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  box-shadow: var(--shadow-deck), inset 0 1px 0 var(--bevel-top);
}

.deck-upper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--hairline);
  overflow-x: auto;
  scrollbar-width: none;
}

.deck-upper::-webkit-scrollbar,
.deck-controls::-webkit-scrollbar {
  display: none;
}

/* Cartridge Bay Tabs */
.cartridge-bay {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.cart-tab {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--well);
  color: var(--ink-dim);
  height: 30px;
  padding: 0 11px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  transition: all 0.12s ease;
  position: relative;
  white-space: nowrap;
}

.cart-tab:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.cart-tab .cart-code {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--ink-faint);
  font-weight: 700;
}

.cart-tab.is-active {
  background: var(--panel-raised);
  color: var(--ink);
  border-color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
}

.cart-tab.is-active .cart-code {
  color: var(--accent);
}

.status-hint {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dynamic Cartridge Controls Row */
.deck-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.ctrl-module {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-right: 14px;
  border-right: 1px solid var(--hairline);
}

.ctrl-module:last-child {
  border-right: none;
  padding-right: 0;
}

.ctrl-label {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

/* Segmented Switch */
.seg-group {
  display: inline-flex;
  background: var(--well);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  height: 24px;
  padding: 0 9px;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-selected {
  background: var(--panel-raised);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--hairline-strong);
}

/* Tactile Fader / Slider */
.fader-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hw-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 4px;
  background: var(--well);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  outline: none;
  cursor: ew-resize;
}

.hw-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 20px;
  background: var(--ink);
  border: 1px solid var(--bg);
  border-radius: 2px;
  cursor: ew-resize;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.hw-slider::-moz-range-thumb {
  width: 11px;
  height: 20px;
  background: var(--ink);
  border: 1px solid var(--bg);
  border-radius: 2px;
  cursor: ew-resize;
}

.hw-slider:focus::-webkit-slider-thumb,
.hw-slider:hover::-webkit-slider-thumb {
  background: var(--accent);
}

.fader-readout {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 44px;
  text-align: right;
}

/* Responsive Breakpoints */
@media (max-width: 980px) {
  .status-hint {
    display: none;
  }
  .kbd-hint {
    display: none;
  }
  .tele-cell:nth-child(3),
  .tele-cell:nth-child(4) {
    display: none;
  }
}

@media (max-width: 640px) {
  .brand-cluster {
    padding: 0 10px;
    gap: 8px;
  }
  .unit-serial {
    display: none;
  }
  .telemetry-strip {
    display: none;
  }
  .sys-switches {
    padding: 0 8px;
    gap: 4px;
  }
  .hw-btn {
    padding: 0 8px;
    font-size: 0.64rem;
  }
  .hud-bottom {
    left: 6px;
    right: 6px;
    bottom: 6px;
  }
}

@media (max-width: 480px) {
  .brand-cluster {
    padding: 0 8px;
    gap: 6px;
    min-width: 0;
    flex: 1;
  }
  .unit-model {
    min-width: 0;
  }
  .unit-active-name {
    font-size: 0.68rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sys-switches {
    padding: 0 6px;
    gap: 3px;
  }
  .hw-btn {
    padding: 0 6px;
    gap: 4px;
    height: 27px;
    font-size: 0.58rem;
  }
}
