:root {
  --api-blue-top: #1d3f73;
  --api-blue-mid: #142f59;
  --api-blue-bot: #0d2140;
  --api-border: #3a5d91;
  --amber: #ff9d2e;
  --vu-center: #fff0c2;
  --vu-edge: #c4842f;
  --silk: #e4ebf5;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }

body {
  background: radial-gradient(circle at 50% 10%, #1d222b 0%, #090b0e 100%);
  color: var(--silk);
  font-family: 'Share Tech Mono', 'Pretendard', monospace;
  min-height: 100vh;
  padding: 16px 12px 36px;
}

.lunchbox {
  max-width: 1140px;
  margin: 0 auto;
  background: #0b0d11;
  border-radius: 8px;
  border: 2px solid #323946;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.rack-unit {
  position: relative;
  padding: 14px 34px 16px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0px, rgba(255,255,255,0.018) 1px, transparent 1px, transparent 3px),
    linear-gradient(180deg, #252a33 0%, #191d24 55%, #12151a 100%);
  border-bottom: 3px solid #07080a;
}

.rack-unit::before, .rack-unit::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; width: 24px;
  background: linear-gradient(90deg, #171a20, #2c313b 50%, #121418);
  border-right: 1px solid #0a0c0f;
  border-left: 1px solid #39404d;
}
.rack-unit::before { left: 0; }
.rack-unit::after { right: 0; }

.bolt {
  position: absolute; width: 12px; height: 12px; border-radius: 50%; z-index: 4;
  background: radial-gradient(circle at 35% 35%, #9aa4b5, #373d47 68%, #12151a 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.bolt::after {
  content: ""; position: absolute; top: 5px; left: 2px; right: 2px; height: 2px;
  background: #14171c; transform: rotate(-30deg);
}
.bolt.tl { top: 9px; left: 6px; } .bolt.bl { bottom: 9px; left: 6px; }
.bolt.tr { top: 9px; right: 6px; } .bolt.br { bottom: 9px; right: 6px; }

.header-bar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px; padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 14px;
}

.brand-title {
  font-family: 'Oswald', sans-serif; font-size: 20px; letter-spacing: 2px;
  color: #f0f5fc; text-shadow: 0 -1px 0 #000; display: flex; align-items: center; gap: 10px;
}
.api-badge {
  font-size: 11px; letter-spacing: 1.4px; padding: 2px 8px;
  background: linear-gradient(180deg, #214a87, #112a52);
  border: 1px solid #4d7ec7; border-radius: 3px; color: #ffd08a;
}
.brand-sub { font-size: 10.5px; color: #8a95a6; letter-spacing: 1px; margin-top: 2px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }

.hw-btn {
  font-family: 'Oswald', sans-serif; font-size: 12px; letter-spacing: 1px;
  padding: 7px 12px; border-radius: 3px; border: 1px solid #3d4554;
  background: linear-gradient(180deg, #252a34, #171a21); color: #b7c2d4;
  cursor: pointer; box-shadow: 0 2px 0 #08090c, inset 0 1px 0 rgba(255,255,255,0.12);
}
.hw-btn:active { transform: translateY(1.5px); }
.hw-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hw-btn.lit-amber {
  background: radial-gradient(circle at 50% 45%, #ffe5ab 0%, #ed9e34 72%, #b5680d 100%);
  color: #1a1004; border-color: #ffdd94; box-shadow: 0 2px 0 #573004, 0 0 14px rgba(255,165,45,0.55); font-weight: 700;
}
.hw-btn.lit-blue {
  background: radial-gradient(circle at 50% 45%, #b8dbff 0%, #3b82f6 72%, #1d4ed8 100%);
  color: #06132b; border-color: #93c5fd; box-shadow: 0 2px 0 #0f2559, 0 0 14px rgba(59,130,246,0.55); font-weight: 700;
}
.hw-btn.lit-green {
  background: radial-gradient(circle at 50% 45%, #ccffe5 0%, #45d18c 72%, #1c8550 100%);
  color: #051f12; border-color: #86efac; box-shadow: 0 2px 0 #0d4528, 0 0 14px rgba(69,209,140,0.5); font-weight: 700;
}
.hw-btn.lit-red {
  background: radial-gradient(circle at 50% 45%, #ffd0c7 0%, #ef5340 72%, #a61e12 100%);
  color: #210402; border-color: #fca5a5; box-shadow: 0 2px 0 #4f0c07, 0 0 18px rgba(239,68,68,0.7); font-weight: 700;
}

/* TOP BAY */
.top-bay { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; }

.stage-bezel {
  background: #0c0f14; border: 2px solid #343c4a; border-radius: 6px;
  padding: 8px; box-shadow: inset 0 2px 10px #000;
}
.stage-title-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px; font-size: 11px; color: #98a6bd;
}
.battle-stage {
  position: relative; height: 215px; border-radius: 4px; overflow: hidden;
  background:
    radial-gradient(circle at 84% 50%, rgba(255,68,45,0.18) 0%, transparent 46%),
    radial-gradient(circle at 50% 50%, #0d1d16 0%, #050b08 100%);
  border: 1px solid #243b30; box-shadow: inset 0 0 24px #000;
}
.stage-grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(82,255,184,0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(82,255,184,0.08) 1px, transparent 1px);
  background-size: 20% 25%;
}
.stage-centerline {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 1px;
  border-left: 1px dashed rgba(255,190,107,0.28); pointer-events: none;
}
.stage-label {
  position: absolute; font-size: 10px; color: rgba(152,214,184,0.72);
  pointer-events: none; letter-spacing: 0.5px;
}

.char-token {
  position: absolute; transform: translate(-50%, -50%);
  padding: 6px 11px; border-radius: 18px; font-size: 12px; font-weight: 700;
  cursor: grab; touch-action: none; white-space: nowrap; max-width: 150px;
  overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.75);
}
.char-token:active { cursor: grabbing; box-shadow: 0 0 18px rgba(255,190,107,0.85); }
.char-token.is-muted { opacity: 0.35; filter: grayscale(0.8); }
.tok-HERO-0 { background: linear-gradient(180deg, #245299, #132c54); border: 2px solid #75b3ff; color: #fff; }
.tok-HERO-1 { background: linear-gradient(180deg, #136e4d, #0a3d2a); border: 2px solid #52ffb8; color: #fff; }
.tok-HERO-2 { background: linear-gradient(180deg, #6b2999, #3b1359); border: 2px solid #d199ff; color: #fff; }
.tok-HERO-3 { background: linear-gradient(180deg, #17697a, #0b3a45); border: 2px solid #67e8f9; color: #fff; }
.tok-MOB { background: linear-gradient(180deg, #9a4a12, #522305); border: 2px solid #fbbf24; color: #fff; }
.tok-BOSS {
  background: linear-gradient(180deg, #991b1b, #450a0a); border: 2px solid #ff5544;
  color: #fff; box-shadow: 0 0 14px rgba(255,68,51,0.55);
}

.stage-footer-bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-top: 8px; flex-wrap: wrap;
}

/* API 2500 MASTER BUS */
.master-2500 {
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px, transparent 1px, transparent 4px),
    linear-gradient(180deg, #1b3b6b 0%, #12294d 55%, #0c1d38 100%);
  border: 2px solid #3c6094; border-radius: 6px; padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 8px 20px rgba(0,0,0,0.7);
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
}
.m2500-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.14); padding-bottom: 6px;
}
.m2500-title { font-family: 'Oswald', sans-serif; font-size: 15px; letter-spacing: 1.8px; color: #fff; }
.m2500-sub { font-size: 10px; color: #ffd08a; background: #0c1729; padding: 2px 7px; border-radius: 3px; border: 1px solid #3a5d91; }

.vu-dual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vu-housing { background: #0b0d12; padding: 5px; border-radius: 4px; border: 1px solid #48638a; box-shadow: inset 0 2px 8px #000; }
.vu-window {
  height: 82px; border-radius: 2px; position: relative; overflow: hidden;
  background: radial-gradient(circle at 50% 95%, var(--vu-center) 0%, #f0c065 58%, var(--vu-edge) 100%);
  box-shadow: inset 0 3px 10px rgba(0,0,0,0.55);
}
.vu-window.gr-tint { background: radial-gradient(circle at 50% 95%, #ffe6c2 0%, #ebac5b 58%, #b36622 100%); }
.vu-svg { width: 100%; height: 100%; display: block; }
.vu-needle {
  position: absolute; bottom: -4px; left: 50%; width: 2px; height: 68px;
  background: #1a140f; transform-origin: bottom center;
  transform: translateX(-50%) rotate(-40deg); will-change: transform;
}
.vu-needle.gr-needle { background: #a6140c; transform: translateX(-50%) rotate(38deg); }
.vu-pivot {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  width: 18px; height: 18px; border-radius: 50%; background: #1b1e24; border: 2px solid #555e6e;
}
.vu-foot {
  display: flex; justify-content: space-between; align-items: center; margin-top: 4px;
  font-family: 'Oswald', sans-serif; font-size: 11px; letter-spacing: 0.8px; color: #d6e3f5;
}
.vu-num { font-family: 'Share Tech Mono', monospace; color: var(--amber); font-size: 11.5px; }
.vu-num.gr-hot { color: #ff6b5b; }
.bus-readout {
  background: #091324; border: 1px solid #2b4a78; border-radius: 4px;
  padding: 8px 10px; font-size: 11.5px; line-height: 1.5; color: #cfe0f7;
}

/* 500-SERIES 1~8 SLOT BAY */
.lunchbox-bay { padding: 16px 34px 20px; background: linear-gradient(180deg, #11151c 0%, #090b0f 100%); }
.bay-label-row {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px; font-family: 'Oswald', sans-serif; font-size: 12px; letter-spacing: 1.5px; color: #7c8aa1;
}
.slots-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.api-module {
  position: relative;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.018) 0px, rgba(255,255,255,0.018) 1px, transparent 1px, transparent 3px),
    linear-gradient(180deg, var(--api-blue-top) 0%, var(--api-blue-mid) 52%, var(--api-blue-bot) 100%);
  border: 1.5px solid var(--api-border); border-radius: 5px;
  padding: 18px 11px 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), 0 8px 18px rgba(0,0,0,0.75);
  display: flex; flex-direction: column; gap: 8px;
}
.api-module.role-BOSS { border-color: #c94b4b; }
.api-module.role-AMBIENCE { border-color: #3e8c74; }
.api-module.role-BGM { border-color: #b5852e; }

.mod-screw {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d6dee8, #596373 70%, #1d222b 100%);
}
.mod-screw::after {
  content: ""; position: absolute; top: 4px; left: 2px; right: 2px; height: 1.5px;
  background: #1b2029; transform: rotate(35deg);
}
.mod-screw.top { top: 5px; } .mod-screw.bot { bottom: 5px; }

.mod-top-bar { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.mod-ch-num { font-family: 'Oswald', sans-serif; font-size: 10px; letter-spacing: 1.1px; color: #ffd08a; }
.role-select {
  background: #091324; color: #9cd0ff; border: 1px solid #35588a; border-radius: 2px;
  font-family: 'Oswald', sans-serif; font-size: 10px; padding: 1px 4px; outline: none; cursor: pointer;
}
.slot-del-btn {
  background: transparent; border: 1px solid rgba(255,107,91,0.45); color: #ff8e82;
  border-radius: 2px; width: 18px; height: 18px; font-size: 11px; line-height: 1; cursor: pointer;
}
.slot-del-btn:hover { background: #a61e12; color: #fff; }

.mod-name-input {
  width: 100%; background: rgba(7, 14, 26, 0.55); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 3px; padding: 4px 6px; color: #fff;
  font-family: 'Oswald', 'Pretendard', sans-serif; font-size: 13.5px; letter-spacing: 0.8px;
  outline: none; user-select: text;
}
.mod-name-input:focus { border-color: var(--amber); background: #070d17; }

.ms-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.ms-group { display: flex; gap: 5px; }
.ms-btn {
  width: 28px; height: 22px; border-radius: 2px; border: 1px solid #48638a;
  background: #0d1a30; color: #9bb3d6; font-family: 'Oswald', sans-serif;
  font-size: 11px; font-weight: 700; cursor: pointer;
}
.ms-btn.active-mute { background: #d93829; color: #fff; border-color: #ff9c94; box-shadow: 0 0 8px rgba(255,59,47,0.65); }
.ms-btn.active-solo { background: #f0b429; color: #1a1004; border-color: #ffe8a3; box-shadow: 0 0 8px rgba(240,180,41,0.65); }

.comp-led { display: inline-flex; align-items: center; gap: 4px; font-size: 9.5px; color: #9bb3d6; }
.led-dot { width: 8px; height: 8px; border-radius: 50%; background: #381313; border: 1px solid #6e2828; }
.led-dot.active { background: #ff3b2f; box-shadow: 0 0 8px #ff3b2f, 0 0 14px #ff0000; }

.ch-readout {
  background: #08101c; border: 1px solid #2b4770; border-radius: 3px;
  padding: 5px 7px; font-size: 10px; line-height: 1.45; color: #8ee6be;
}

.meter-stack {
  display: flex; flex-direction: column; gap: 4px;
  background: #09111d; border: 1px solid #263f63; border-radius: 3px; padding: 5px 6px;
}
.meter-line { display: grid; grid-template-columns: 24px 1fr; align-items: center; gap: 5px; font-size: 9px; color: #93accf; }
.led-track { height: 7px; background: #05080f; border-radius: 2px; overflow: hidden; border: 1px solid #1d2f4a; position: relative; }
.led-fill-out { height: 100%; width: 0%; background: linear-gradient(90deg, #32e88a 0%, #ffb02e 72%, #ff3b2f 94%); transition: width 0.05s linear; }
.led-fill-gr { position: absolute; top: 0; right: 0; height: 100%; width: 0%; background: linear-gradient(270deg, #ff7b24 0%, #ff2e24 100%); transition: width 0.06s linear; }

.ctrl-block { display: flex; flex-direction: column; gap: 3px; }
.ctrl-head { display: flex; justify-content: space-between; font-size: 10px; color: var(--silk); }
.ctrl-val { color: #ffd08a; }

input[type="range"].api-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: #091324; border-radius: 3px; border: 1px solid #35588a; outline: none; cursor: pointer;
}
input[type="range"].api-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 17px; border-radius: 3px;
  background: linear-gradient(180deg, #f4f7fb 0%, #aeb8c7 48%, #778394 100%);
  border: 1px solid #1b222e; box-shadow: 0 2px 5px rgba(0,0,0,0.85); cursor: pointer;
}

.drop-slot {
  display: block; padding: 5px 7px; border: 1px dashed #4a71ab; border-radius: 3px;
  background: rgba(8,16,30,0.55); text-align: center; font-size: 10px; color: #b4c8e6;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drop-slot:hover { border-color: var(--amber); color: #ffdd99; }

@media (max-width: 980px) { .top-bay { grid-template-columns: 1fr; } .slots-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) {
  .rack-unit, .lunchbox-bay { padding-left: 18px; padding-right: 18px; }
  .rack-unit::before, .rack-unit::after { width: 14px; }
  .bolt { width: 9px; height: 9px; } .bolt.tl, .bolt.bl { left: 2.5px; } .bolt.tr, .bolt.br { right: 2.5px; }
  .slots-grid { grid-template-columns: 1fr; }
}