/* ===== 3D Studio — Sampler Studio dark studio console palette ===== */
:root {
  --bg: #0e0e0e;
  --surface: #161616;
  --surface-2: #1b1b1b;
  --surface-3: #222222;
  --border: #2a2a2a;
  --border-hi: #434343;
  --text: #ececec;
  --muted: #939393;
  --muted-2: #cacaca;
  --cyan: #38bdf8;
  --violet: #a78bfa;
  --emerald: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --accent: #999999;
  --accent-2: #bdbdbd;
  --accent-soft: rgba(153, 153, 153, 0.13);
  --radius: 14px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  --ui-border-alpha: 0.7;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
  color: inherit;
}

/* ---------- Fullscreen 3D Viewport ---------- */
#viewport-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(900px 500px at 50% 45%, #17171c 0%, #0e0e0e 75%);
}

#gl-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#gl-canvas:active {
  cursor: grabbing;
}

/* ---------- Top Studio Header ---------- */
.studio-header {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(22, 22, 22, 0.82);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, calc(0.16 * var(--ui-border-alpha)));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

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

.brand-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--accent-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--accent-soft);
  border: 1px solid rgba(153, 153, 153, 0.35);
  padding: 3px 8px;
  border-radius: 999px;
}

.brand h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-hi);
  margin: 0 2px;
}

.pill-btn {
  background: var(--surface-2);
  color: var(--muted-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease, transform 0.12s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  color: var(--text);
  border-color: var(--accent-2);
  background: var(--surface-3);
  transform: translateY(-1px);
}

.pill-btn:active {
  transform: translateY(0);
}

.pill-btn.active {
  background: var(--text);
  color: #111111;
  border-color: transparent;
  font-weight: 800;
}

.pill-btn.danger:hover {
  border-color: var(--rose);
  color: var(--rose);
}

/* ---------- Left-Bottom Outliner / HUD ---------- */
.hud-left {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 240px;
  pointer-events: none;
}

.hud-card {
  pointer-events: auto;
  background: rgba(22, 22, 22, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, calc(0.16 * var(--ui-border-alpha)));
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.hud-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 6px;
}

.outliner-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 150px;
  overflow-y: auto;
}

.outliner-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted-2);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.outliner-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.outliner-item.selected {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.45);
  color: #ffffff;
}

.outliner-type {
  font-size: 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

.camera-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted-2);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.camera-readout strong {
  color: var(--cyan);
}

/* ---------- Right Control Deck (Sampler Studio Layers 1, 2, 3) ---------- */
.control-deck {
  position: fixed;
  top: 74px;
  right: 12px;
  bottom: 12px;
  width: 248px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 2px;
  pointer-events: auto;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.control-deck.collapsed {
  transform: translateX(270px);
  opacity: 0;
  pointer-events: none;
}

.control-deck::-webkit-scrollbar {
  width: 5px;
}
.control-deck::-webkit-scrollbar-thumb {
  background: #2f2f2f;
  border-radius: 999px;
}

.studio-card {
  background: rgba(22, 22, 22, 0.80);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, calc(0.18 * var(--ui-border-alpha)));
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 700;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid rgba(153, 153, 153, 0.35);
  padding: 1px 5px;
  border-radius: 5px;
}

.readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.10);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 2px 7px;
  border-radius: 999px;
  max-width: 115px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
}

/* Layer 1: 155 5-Row Translucent Knobless Sliders */
.stage-155 {
  width: 100%;
  height: 170px;
  position: relative;
}

.stage-155 canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: ew-resize;
}

/* Layer 2 & 3: 04 & 05 25-button -> XY / X Window */
.sq-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

.sq-win {
  position: relative;
  width: 224px;
  height: 224px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, calc(0.22 * var(--ui-border-alpha)));
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  touch-action: none;
}

.sq-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 4px;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.sq-grid.hidden-mode {
  opacity: 0;
  transform: scale(1.06);
  pointer-events: none;
}

.sq-cell {
  position: relative;
  background: var(--surface-2);
  border: 1px solid #313131;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.sq-cell:hover {
  border-color: var(--accent-2);
  background: var(--surface-3);
}

.sq-cell-dot {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 6px rgba(56, 189, 248, 0.75);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sq-cell-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(56, 189, 248, 0.28);
  border-right: 2px solid var(--cyan);
  pointer-events: none;
}

.sq-cell-idx {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 8px;
  color: rgba(255, 255, 255, 0.45);
  z-index: 1;
  pointer-events: none;
}

.sq-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0e0e0e;
  display: none;
  touch-action: none;
}

.sq-overlay.active {
  display: block;
}

/* ---------- Transform Mode HUD (G / R / S) ---------- */
.transform-hud {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 7px 14px;
  background: rgba(22, 22, 22, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .control-deck {
    top: auto;
    bottom: 12px;
    right: 12px;
    max-height: 55vh;
    width: 236px;
  }
  .hud-left {
    display: none;
  }
}
