:root {
  --bg-app: #0c0f18;
  --bg-panel: #141927;
  --bg-panel-elev: #1b2234;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-main: #f3f6ff;
  --text-muted: #93a0bd;
  --accent: #66b8ff;
  --accent-strong: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
}

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

html,
body {
  height: 100%;
  background: radial-gradient(circle at 20% 20%, #171f36 0%, var(--bg-app) 62%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.studio-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  height: 100vh;
  width: 100vw;
  gap: 20px;
  padding: 18px 22px;
}

/* Stage / 9:16 Viewport */
.stage-column {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.stage-frame {
  position: relative;
  height: min(calc(100vh - 36px), 960px);
  aspect-ratio: 9 / 16;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: #080b14;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 40px rgba(59, 130, 246, 0.12);
}

#towerCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.rec-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 15, 24, 0.82);
  border: 1px solid rgba(239, 68, 68, 0.55);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  pointer-events: none;
}

.rec-badge.hidden {
  display: none;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
  animation: pulseRec 1.1s ease-in-out infinite;
}

@keyframes pulseRec {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.82); }
}

.phase-badge {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(10, 14, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(235, 243, 255, 0.88);
  white-space: nowrap;
  pointer-events: none;
}

/* Controls Sidebar */
.controls-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding-right: 4px;
}

.controls-column::-webkit-scrollbar {
  width: 6px;
}
.controls-column::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

.brand-header {
  padding: 4px 2px;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: linear-gradient(135deg, #2b4c9b 0%, #7c3aed 100%);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
}

.brand-header h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 700;
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-success {
  background: linear-gradient(135deg, #16a34a 0%, #10b981 100%);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.25);
}

.btn-success:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bg-panel-elev);
  border-color: var(--border-strong);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: #232c43;
}

.status-card {
  background: rgba(8, 11, 20, 0.55);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}

.status-label {
  color: var(--text-muted);
}

.status-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.status-value.accent {
  color: var(--accent);
}

.status-value.muted {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11.5px;
}

.progress-track {
  height: 5px;
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8, #f472b6);
  border-radius: 999px;
  transition: width 0.1s linear;
}

/* Controls */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.control-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.control-readout {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.range-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-pill {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.slider-pill::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .slider-pill {
  background: var(--accent-strong);
}

.switch input:checked + .slider-pill::before {
  transform: translateX(20px);
}

/* Floor Directory */
.directory-panel {
  flex: 1 1 auto;
  min-height: 180px;
}

.seed-pill {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 999px;
}

.floor-directory {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.floor-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  font-size: 12.5px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.floor-item.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(102, 184, 255, 0.45);
}

.floor-num {
  min-width: 34px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
}

.floor-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.floor-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

@media (max-width: 920px) {
  html,
  body {
    overflow: auto;
  }
  .studio-shell {
    grid-template-columns: 1fr;
    height: auto;
  }
  .stage-frame {
    height: 75vh;
  }
}
