:root {
  --bg: #070a0f;
  --bg-soft: #0d1118;
  --panel: rgba(13, 17, 24, 0.84);
  --panel-strong: rgba(18, 23, 32, 0.92);
  --surface: #151b25;
  --surface-2: #1b2330;
  --line: rgba(235, 242, 255, 0.08);
  --line-strong: rgba(235, 242, 255, 0.14);
  --text: #edf3fb;
  --text-dim: #aeb8c8;
  --text-faint: #748094;
  --orange: #ff9346;
  --orange-2: #ffd36a;
  --cyan: #5bd8c7;
  --green: #7ee06f;
  --red: #ff5f6d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.44);
  --r-sm: 6px;
  --r-md: 8px;
}

* { box-sizing: border-box; }

html,
body,
#app {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  user-select: none;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

#app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  grid-template-rows: 64px 1fr;
}

#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    radial-gradient(80% 56% at 34% 8%, rgba(91, 216, 199, 0.12), transparent 64%),
    radial-gradient(75% 56% at 78% 20%, rgba(255, 147, 70, 0.10), transparent 62%);
  background-size: 48px 48px, 48px 48px, auto, auto;
  opacity: 0.8;
  z-index: 1;
}

#stage {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  position: relative;
  z-index: 0;
}

#topbar {
  position: relative;
  z-index: 5;
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
  background: linear-gradient(to bottom, rgba(7, 10, 15, 0.92), rgba(7, 10, 15, 0.52));
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

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

.logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 31% 65%, #ffd36a 0 14%, transparent 15%),
    radial-gradient(circle at 68% 32%, #ff5f6d 0 18%, transparent 19%),
    radial-gradient(circle at 70% 72%, #5bd8c7 0 13%, transparent 14%),
    linear-gradient(140deg, #202b3c, #0d121a);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 10px 22px rgba(0, 0, 0, 0.32);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 720;
  line-height: 1.1;
}

.brand p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, auto));
  gap: 10px;
}

.stat {
  min-width: 76px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(18, 23, 32, 0.54);
}

.stat .k,
.stat .v {
  display: block;
  text-align: right;
}

.stat .k {
  font-size: 10px;
  color: var(--text-faint);
}

.stat .v {
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 720;
  color: var(--text);
}

#panel {
  position: relative;
  z-index: 4;
  grid-column: 2;
  grid-row: 2;
  height: 100%;
  width: 348px;
  padding: 14px 14px 82px;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--panel), rgba(8, 11, 16, 0.95));
  backdrop-filter: blur(20px) saturate(135%);
  -webkit-backdrop-filter: blur(20px) saturate(135%);
  border-left: 1px solid var(--line);
  box-shadow: -22px 0 55px rgba(0, 0, 0, 0.24);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}
#panel::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.20); }

.group {
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.group:first-child {
  border-top: 0;
  padding-top: 2px;
}

.group h2 {
  margin: 0 0 10px;
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 740;
}

.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: rgba(7, 10, 15, 0.62);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.seg.sm {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.seg button,
.preset-list button,
.group.actions button,
.overlay button {
  border: 0;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease, filter 120ms ease;
}

.seg button {
  min-height: 32px;
  padding: 7px 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 650;
  border-radius: var(--r-sm);
  white-space: nowrap;
}

.seg button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.seg button.active {
  color: #fff8ec;
  background: linear-gradient(140deg, rgba(255, 147, 70, 0.24), rgba(91, 216, 199, 0.12));
  box-shadow: inset 0 0 0 1px rgba(255, 147, 70, 0.40);
}

.scene-note {
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(21, 27, 37, 0.62);
}

.scene-note strong {
  display: block;
  font-size: 13px;
  font-weight: 740;
  color: var(--text);
}

.scene-note p {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.45;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 9px;
}

.preset-list button {
  min-height: 30px;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(21, 27, 37, 0.78);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 650;
}

.preset-list button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(28, 36, 49, 0.96);
}

.row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--text-dim);
  font-size: 12px;
}

.row > span:first-child {
  color: var(--text);
  font-weight: 580;
}

.row output {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
}

.row.check {
  grid-template-columns: 18px 1fr;
  min-height: 30px;
  cursor: pointer;
}

.row.check input { margin: 0; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, rgba(91, 216, 199, 0.35), rgba(255, 147, 70, 0.35));
  border-radius: 999px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--orange-2), var(--orange));
  border: 2px solid #151b25;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 3px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--orange-2), var(--orange));
  border: 2px solid #151b25;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--orange);
}

.diagnostics {
  display: grid;
  gap: 7px;
}

.meter-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 11.5px;
}

.meter-row strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.meter i {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--cyan), var(--orange-2), var(--red));
  transition: transform 160ms ease;
}

.meter.flow i {
  background: linear-gradient(90deg, #2c7bf2, var(--cyan), var(--green));
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}

.mini-grid div {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(21, 27, 37, 0.58);
}

.mini-grid span,
.mini-grid b {
  display: block;
}

.mini-grid span {
  color: var(--text-faint);
  font-size: 10.5px;
}

.mini-grid b {
  margin-top: 2px;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.group.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.group.actions button {
  min-height: 39px;
  padding: 9px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.group.actions button:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

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

.group.actions button.primary {
  background: linear-gradient(140deg, var(--orange), #d6601f);
  color: #1a1008;
  border-color: transparent;
}

.group.actions button.primary:hover { filter: brightness(1.05); }

.ico {
  width: 10px;
  height: 10px;
  background: currentColor;
  -webkit-mask: var(--m) center / contain no-repeat;
  mask: var(--m) center / contain no-repeat;
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Crect x='2' y='1' width='2' height='8'/%3E%3Crect x='6' y='1' width='2' height='8'/%3E%3C/svg%3E");
}

.ico.play {
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 1 L9 5 L2 9 Z'/%3E%3C/svg%3E");
}

.legend .bar {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1b2440 0%, #1c4b7a 18%, #21a0a9 36%, #70dc69 54%, #ffd36a 72%, #ff9346 86%, #ff5f6d 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10);
}

.legend .bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
}

.legend .hint {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.5;
}

.legend .hint b {
  color: var(--text);
  font-weight: 740;
}

.hint-mouse {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 3;
  color: var(--text-faint);
  background: rgba(7, 10, 15, 0.58);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: var(--r-md);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: none;
}

.kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 2px;
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.dot {
  color: rgba(255, 255, 255, 0.22);
  margin: 0 4px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 15, 0.54);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay.hidden { display: none; }

.overlay .card {
  max-width: 468px;
  margin: 24px;
  padding: 28px;
  background: linear-gradient(160deg, rgba(27, 35, 48, 0.92), rgba(10, 13, 19, 0.96));
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}

.overlay h2 {
  margin: 0 0 12px;
  font-size: 23px;
  line-height: 1.1;
}

.overlay p {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.55;
}

.overlay button {
  margin-top: 8px;
  padding: 10px 16px;
  background: linear-gradient(140deg, var(--orange), #d6601f);
  color: #1a1008;
  font-weight: 740;
  border-radius: var(--r-md);
}

.overlay button:hover { filter: brightness(1.06); }
.overlay button:active { transform: translateY(1px); }

.row.hidden { display: none; }

@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 64px minmax(220px, 1fr) minmax(340px, 46vh);
  }

  #panel {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-bottom: 34px;
  }

  #stage { grid-row: 1 / 3; }
  .stats { grid-template-columns: repeat(2, minmax(70px, auto)); }
  .stat:nth-child(3),
  .stat:nth-child(4) { display: none; }
  .hint-mouse { display: none; }
}

@media (max-width: 560px) {
  #topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .brand {
    min-width: 0;
    gap: 9px;
  }

  .brand p { display: none; }
  .logo {
    width: 30px;
    height: 30px;
  }

  .stats {
    gap: 6px;
  }

  .stat {
    min-width: 58px;
    padding: 5px 7px;
  }

  .stat .k { font-size: 9px; }
  .stat .v { font-size: 13px; }
  .seg.sm { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preset-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row {
    grid-template-columns: 76px minmax(0, 1fr) 48px;
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
