/* ============================================================
   CF·5 QUANTUM CORE — 3nm Die Explorer
   ============================================================ */

:root {
  --bg-0: #04060c;
  --bg-1: #0a0f1c;
  --ink: #e8eef9;
  --ink-dim: #8b96ad;
  --accent: #6ef3ff;
  --accent-2: #ffb454;
  --glass: rgba(10, 16, 30, 0.62);
  --glass-border: rgba(110, 200, 255, 0.14);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Inter', system-ui, sans-serif;
  --disp: 'Space Grotesk', var(--sans);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #0b1428 0%, var(--bg-0) 55%),
    var(--bg-0);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#app, #app canvas { position: absolute; inset: 0; }
#app canvas { display: block; }

/* vignette + scanline film */
body::after {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(130% 110% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

.ui { z-index: 10; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.hidden { opacity: 0 !important; pointer-events: none !important; transform: translateY(8px); }

/* mode-scoped UI (also hides CSS2D labels of the inactive 3D scene,
   which CSS2DRenderer keeps rendering even under hidden groups) */
body[data-mode='stack'] .soc-only,
body[data-mode='stack'] .block-label { display: none !important; }
body[data-mode='soc'] .stack-only,
body[data-mode='soc'] .layer-label { display: none !important; }

/* ============================================================
   MODE SWITCH
   ============================================================ */
#mode-switch {
  position: fixed; top: 26px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 4px;
  padding: 5px;
  border-radius: 12px;
}
.mbtn {
  padding: 9px 18px;
  font-family: var(--disp); font-size: 11px; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.mbtn:hover { color: var(--ink); }
.mbtn.active {
  color: var(--accent);
  background: rgba(110, 243, 255, 0.1);
  border-color: rgba(110, 243, 255, 0.35);
  text-shadow: 0 0 14px rgba(110, 243, 255, 0.6);
}

/* ============================================================
   LOADER
   ============================================================ */
#loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-0);
  transition: opacity 0.8s ease, visibility 0.8s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-inner { text-align: center; }
.loader-die {
  width: 64px; height: 64px; margin: 0 auto 28px;
  display: flex; flex-direction: column; gap: 6px;
}
.loader-die span {
  flex: 1; border-radius: 3px;
  background: linear-gradient(90deg, rgba(110, 243, 255, 0.15), rgba(110, 243, 255, 0.7), rgba(110, 243, 255, 0.15));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.loader-die span:nth-child(2) { animation-delay: 0.12s; }
.loader-die span:nth-child(3) { animation-delay: 0.24s; }
.loader-die span:nth-child(4) { animation-delay: 0.36s; }
.loader-die span:nth-child(5) { animation-delay: 0.48s; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.loader-title {
  font-family: var(--disp);
  font-weight: 700; font-size: 22px; letter-spacing: 0.35em;
  color: var(--ink);
}
.loader-sub {
  margin-top: 10px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--ink-dim);
  animation: pulse-txt 1.6s ease-in-out infinite;
}
@keyframes pulse-txt { 50% { opacity: 0.35; } }

/* ============================================================
   BRAND HEADER
   ============================================================ */
#brand {
  position: fixed; top: 26px; left: 30px;
  display: flex; align-items: center; gap: 16px;
  user-select: none;
}
.brand-mark {
  font-family: var(--disp); font-weight: 700; font-size: 20px;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border: 1px solid rgba(110, 243, 255, 0.35);
  border-radius: 10px;
  color: var(--accent);
  background: rgba(110, 243, 255, 0.06);
  box-shadow: 0 0 24px rgba(110, 243, 255, 0.15), inset 0 0 18px rgba(110, 243, 255, 0.06);
}
.brand-text h1 {
  font-family: var(--disp); font-size: 19px; font-weight: 600;
  letter-spacing: 0.28em;
}
.brand-text p {
  margin-top: 4px;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-dim);
}

/* ============================================================
   STACK PANEL
   ============================================================ */
#stack-panel {
  position: fixed; top: 26px; right: 26px;
  width: 258px;
  max-height: calc(100vh - 200px);
  padding: 16px 12px 12px;
  display: flex; flex-direction: column;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.panel-title {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 8px 12px;
  font-family: var(--disp); font-weight: 600; font-size: 13px;
  letter-spacing: 0.24em; text-transform: uppercase;
}
.panel-title em {
  font-family: var(--mono); font-style: normal; font-size: 9.5px;
  letter-spacing: 0.1em; color: var(--ink-dim);
}
#layer-list {
  list-style: none;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin; scrollbar-color: rgba(110,200,255,0.2) transparent;
}
#layer-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.18s;
}
#layer-list li:hover { background: rgba(110, 200, 255, 0.07); transform: translateX(-2px); }
#layer-list li.active {
  background: rgba(110, 243, 255, 0.1);
  border-color: rgba(110, 243, 255, 0.35);
}
#layer-list li.dimmed { opacity: 0.35; }
.li-swatch {
  width: 10px; height: 26px; border-radius: 3px; flex: none;
  box-shadow: 0 0 10px currentColor;
}
.li-body { min-width: 0; }
.li-name {
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.li-meta {
  margin-top: 2px;
  font-family: var(--mono); font-size: 9.5px;
  letter-spacing: 0.12em; color: var(--ink-dim);
}

/* ============================================================
   INFO CARD
   ============================================================ */
#info-card {
  position: fixed; left: 30px; top: 50%;
  transform: translateY(-50%);
  width: 330px;
  padding: 20px 22px 18px;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
#info-card.hidden { transform: translateY(-50%) translateX(-14px); }
.info-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.tag {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.22em;
  padding: 4px 9px;
  border-radius: 5px;
  color: var(--accent);
  border: 1px solid rgba(110, 243, 255, 0.35);
  background: rgba(110, 243, 255, 0.07);
}
.icon-btn {
  width: 26px; height: 26px;
  border: 1px solid var(--glass-border); border-radius: 7px;
  background: transparent; color: var(--ink-dim);
  font-size: 11px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--ink); border-color: rgba(110, 243, 255, 0.45); }
#info-card h2 {
  font-family: var(--disp); font-size: 19px; font-weight: 600;
  letter-spacing: 0.02em; line-height: 1.25;
}
#info-card p {
  margin-top: 10px;
  font-size: 12.5px; line-height: 1.65; color: #b6c1d6;
}
#info-specs { margin-top: 14px; border-top: 1px solid rgba(120, 160, 220, 0.12); }
.spec-row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(120, 160, 220, 0.08);
  font-family: var(--mono); font-size: 10.8px;
}
.spec-row b { color: var(--ink-dim); font-weight: 500; letter-spacing: 0.04em; }
.spec-row span { color: var(--accent); text-align: right; }
.info-actions { margin-top: 16px; display: flex; gap: 8px; }
.btn {
  flex: 1;
  padding: 9px 12px;
  font-family: var(--disp); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent);
  background: rgba(110, 243, 255, 0.08);
  border: 1px solid rgba(110, 243, 255, 0.35);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.18s, box-shadow 0.18s;
}
.btn:hover { background: rgba(110, 243, 255, 0.16); box-shadow: 0 0 20px rgba(110, 243, 255, 0.18); }
.btn.warn { color: var(--accent-2); border-color: rgba(255, 180, 84, 0.4); background: rgba(255, 180, 84, 0.08); }

/* ============================================================
   CONTROLS BAR
   ============================================================ */
#controls {
  position: fixed; bottom: 26px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 22px;
  padding: 14px 22px;
  transition: opacity 0.4s ease;
}
#controls.intro-lock { pointer-events: none; opacity: 0.4; }
.ctl-group { display: flex; align-items: center; gap: 12px; }
.ctl-group label {
  font-family: var(--mono); font-size: 9.5px; font-weight: 600;
  letter-spacing: 0.22em; color: var(--ink-dim);
  user-select: none;
}
.ctl-divider { width: 1px; height: 30px; background: rgba(120, 160, 220, 0.15); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 150px; height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(110, 243, 255, 0.5) var(--fill, 0%), rgba(110, 160, 220, 0.18) var(--fill, 0%));
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a1220;
  box-shadow: 0 0 12px rgba(110, 243, 255, 0.6);
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid #0a1220;
  box-shadow: 0 0 12px rgba(110, 243, 255, 0.6);
}

.ctl-buttons { gap: 6px; }
.tbtn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 60px;
  padding: 7px 10px 6px;
  font-size: 15px; line-height: 1;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.18s, background 0.18s, border-color 0.18s;
}
.tbtn span {
  font-family: var(--mono); font-size: 8.5px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.tbtn:hover { color: var(--ink); background: rgba(110, 200, 255, 0.06); }
.tbtn.active {
  color: var(--accent);
  border-color: rgba(110, 243, 255, 0.3);
  background: rgba(110, 243, 255, 0.08);
  text-shadow: 0 0 14px rgba(110, 243, 255, 0.7);
}

/* ============================================================
   HUD + HINT + TOOLTIP
   ============================================================ */
#hud {
  position: fixed; bottom: 26px; right: 26px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.1em; color: var(--ink-dim);
  user-select: none;
}
#hud .hud-sep { margin: 0 7px; opacity: 0.4; }
#hud-fps { color: var(--accent); }

#hint {
  position: fixed; bottom: 92px; left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-dim);
  transition: opacity 1.2s ease;
  user-select: none; pointer-events: none;
}
#hint.done { opacity: 0; }

#tooltip {
  position: fixed; z-index: 20;
  padding: 8px 12px;
  border-radius: 9px;
  pointer-events: none;
  transition: opacity 0.15s ease;
  transform: none;
}
#tooltip strong {
  display: block;
  font-family: var(--disp); font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
}
#tooltip span {
  display: block; margin-top: 2px;
  font-family: var(--mono); font-size: 9px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent);
}

/* ============================================================
   3D LAYER LABELS (CSS2D)
   ============================================================ */
.layer-label {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 11px 5px 6px;
  border-radius: 8px;
  background: rgba(8, 13, 26, 0.72);
  border: 1px solid rgba(110, 200, 255, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--disp);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  user-select: none;
}
.layer-label:hover {
  border-color: rgba(110, 243, 255, 0.55);
  box-shadow: 0 0 18px rgba(110, 243, 255, 0.25);
}
.layer-label .ll-idx {
  font-family: var(--mono); font-size: 9px; font-weight: 600;
  padding: 3px 6px; border-radius: 5px;
  letter-spacing: 0.08em;
  color: #05070d;
}
.layer-label .ll-name {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em;
  color: var(--ink);
}

/* ============================================================
   SOC BLOCK LABELS (CSS2D)
   ============================================================ */
.block-label {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(8, 13, 26, 0.66);
  border: 1px solid rgba(110, 200, 255, 0.16);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-family: var(--disp); font-size: 10px; font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  transform: translateY(-14px);
}
.block-label .bl-dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  box-shadow: 0 0 8px currentColor;
}
.block-label em {
  font-family: var(--mono); font-style: normal; font-size: 9px;
  color: var(--accent-2);
}
.block-label em:empty { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  #stack-panel { display: none; }
  #mode-switch { top: 112px; left: 30px; transform: none; }
  #info-card { width: calc(100vw - 48px); left: 24px; }
  #controls { flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px); }
  #hud, #hint { display: none; }
}
