/* ------------------------------------------------------------------
   Spark — Specimen Cabinet
   ------------------------------------------------------------------ */

:root {
  --bg: #0a0908;
  --bg-warm: #12100d;
  --ink: #f3eee5;
  --ink-dim: rgba(243, 238, 229, 0.58);
  --ink-faint: rgba(243, 238, 229, 0.34);
  --ink-ghost: rgba(243, 238, 229, 0.16);
  --accent: #e8b06a;
  --accent-soft: rgba(232, 176, 106, 0.16);
  --line: rgba(243, 238, 229, 0.14);
  --line-soft: rgba(243, 238, 229, 0.08);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --pad: clamp(20px, 2.6vw, 40px);
  --ease: cubic-bezier(0.22, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  cursor: grab;
  filter: brightness(var(--exposure, 1)) saturate(var(--saturate, 1))
    contrast(var(--contrast, 1));
}

#stage:active {
  cursor: grabbing;
}

/* --- filmic overlays ------------------------------------------------ */

.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.fx-vignette {
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 38%, rgba(0, 0, 0, 0.42) 78%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(to bottom, rgba(10, 9, 8, 0.72), transparent 16%, transparent 78%, rgba(10, 9, 8, 0.6));
}

.fx-grain {
  z-index: 3;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

.fx-wash {
  z-index: 1;
  mix-blend-mode: screen;
  opacity: 0.85;
  background: radial-gradient(
    72% 58% at 50% 56%,
    var(--wash, transparent) 0%,
    transparent 72%
  );
  transition: background 0.6s var(--ease);
}

/* --- top bar -------------------------------------------------------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: calc(var(--pad) * 0.7) var(--pad);
  pointer-events: none;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.brand-mark {
  width: 17px;
  height: 17px;
  fill: var(--accent);
  animation: mark-spin 26s linear infinite;
}

@keyframes mark-spin {
  to {
    transform: rotate(360deg);
  }
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.32em;
  color: var(--ink);
}

.brand-rule {
  width: 28px;
  height: 1px;
  background: var(--line);
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 26px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.ghost-link {
  text-decoration: none;
  color: var(--ink-dim);
  transition: color 0.3s var(--ease);
}

.ghost-link:hover {
  color: var(--accent);
}

/* --- index ---------------------------------------------------------- */

.index {
  position: fixed;
  z-index: 10;
  left: var(--pad);
  top: 50%;
  transform: translateY(-50%);
  width: 224px;
  text-shadow:
    0 1px 16px rgba(0, 0, 0, 0.95),
    0 0 4px rgba(0, 0, 0, 0.8);
}

.index::before {
  content: "";
  position: absolute;
  inset: -18px -38px -18px -18px;
  z-index: -1;
  border-radius: 16px;
  background: linear-gradient(
    90deg,
    rgba(10, 9, 8, 0.9) 0%,
    rgba(10, 9, 8, 0.8) 82%,
    rgba(10, 9, 8, 0) 100%
  );
  pointer-events: none;
}

.index-label {
  margin: 0 0 20px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.index ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line-soft);
}

.index li {
  border-bottom: 1px solid var(--line-soft);
}

.index button {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 0;
  text-align: left;
  color: var(--ink-dim);
  transition:
    color 0.35s var(--ease),
    transform 0.35s var(--ease);
}

.index button::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--accent);
  transform: translateY(-50%);
  transition: height 0.35s var(--ease);
}

.index button:hover {
  color: var(--ink);
  transform: translateX(4px);
}

.index .idx {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  transition: color 0.35s var(--ease);
}

.index .name {
  font-size: 12.5px;
  letter-spacing: 0.015em;
  font-weight: 400;
}

.index .cat {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(243, 238, 229, 0.24);
  transition: color 0.35s var(--ease);
}

.index button[aria-current="true"] {
  color: var(--ink);
}

.index button[aria-current="true"]::before {
  height: 22px;
}

.index button[aria-current="true"] .idx {
  color: var(--accent);
}

.index button[aria-current="true"] .cat {
  color: var(--accent);
}

/* --- info ----------------------------------------------------------- */

.info {
  position: fixed;
  z-index: 10;
  left: var(--pad);
  bottom: var(--pad);
  width: min(360px, calc(100vw - var(--pad) * 2));
  pointer-events: none;
}

.info-kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
}

.info-kicker .slash {
  color: var(--ink-ghost);
}

#info-number {
  color: var(--ink-faint);
}

.info h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(46px, 5.2vw, 68px);
  line-height: 0.92;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.info-blurb {
  margin: 14px 0 0;
  max-width: 300px;
  font-size: 12.5px;
  font-weight: 300;
  line-height: 1.65;
  color: var(--ink-dim);
}

.info-meta {
  margin: 16px 0 0;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(243, 238, 229, 0.27);
}

/* --- hud ------------------------------------------------------------ */

.hud {
  position: fixed;
  z-index: 10;
  right: var(--pad);
  bottom: var(--pad);
  display: flex;
  align-items: center;
  gap: 18px;
}

.hint {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.hint .key {
  margin-left: 8px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 8px;
  color: var(--ink-dim);
}

.hint .key:first-child {
  margin-left: 0;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: rgba(10, 9, 8, 0.4);
  backdrop-filter: blur(8px);
  transition:
    color 0.3s var(--ease),
    border-color 0.3s var(--ease),
    background 0.3s var(--ease);
}

.back:hover {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.back[hidden] {
  display: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-dim);
  background: rgba(10, 9, 8, 0.4);
  backdrop-filter: blur(8px);
  transition:
    color 0.3s var(--ease),
    border-color 0.3s var(--ease),
    background 0.3s var(--ease);
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--ink-ghost);
}

.icon-btn[aria-pressed="false"] {
  color: var(--ink-faint);
}

.icon-btn[aria-pressed="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

/* --- atmosphere ----------------------------------------------------- */

.atmo-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: rgba(10, 9, 8, 0.4);
  backdrop-filter: blur(8px);
  transition:
    color 0.3s var(--ease),
    border-color 0.3s var(--ease),
    background 0.3s var(--ease);
}

.atmo-btn:hover {
  color: var(--ink);
  border-color: var(--ink-ghost);
}

.atmo-btn[aria-expanded="true"] {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
}

.atmo-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 0 10px var(--accent-soft);
  flex: 0 0 auto;
}

.atmo-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 12;
  width: 274px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(14, 12, 10, 0.92);
  backdrop-filter: blur(22px) saturate(1.2);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.6);
}

.atmo-panel[hidden] {
  display: none;
}

.atmo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.atmo-head p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.atmo-close {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--ink-faint);
  font-size: 16px;
  line-height: 1;
}

.atmo-close:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.atmo-list {
  display: grid;
  gap: 2px;
}

.atmo-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  border-radius: 9px;
  text-align: left;
  color: var(--ink-dim);
  transition:
    color 0.25s var(--ease),
    background 0.25s var(--ease);
}

.atmo-option:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
}

.atmo-option.is-active {
  color: var(--ink);
  background: var(--accent-soft);
}

.atmo-option-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  flex: 0 0 auto;
}

.atmo-option-name {
  font-size: 12px;
  letter-spacing: 0.01em;
}

.atmo-check {
  margin-left: auto;
  font-size: 10px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}

.atmo-option.is-active .atmo-check {
  opacity: 1;
}

.atmo-sliders {
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 12px;
}

.slider-row {
  display: grid;
  grid-template-columns: 56px 1fr 30px;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.slider-row output {
  text-align: right;
  color: var(--ink-dim);
  font-size: 8px;
}

.slider-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  outline: none;
  cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (min-width: 861px) {
  .index ul {
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    scrollbar-width: none;
  }

  .index ul::-webkit-scrollbar {
    display: none;
  }
}

@media (min-width: 861px) and (max-height: 780px) {
  .index {
    top: 96px;
    transform: none;
  }

  .index button {
    padding: 8px 0;
  }

  .index ul {
    max-height: calc(100vh - 390px);
  }
}

/* --- loader --------------------------------------------------------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition:
    opacity 0.9s var(--ease),
    visibility 0.9s;
  padding: var(--pad);
}

.loader.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-inner {
  width: min(380px, 100%);
}

.loader-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink);
}

.loader-brand svg {
  width: 20px;
  height: 20px;
  fill: var(--accent);
  animation: mark-spin 8s linear infinite;
}

.loader-title {
  margin: 28px 0 46px;
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.progress {
  position: relative;
  height: 1px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(232, 176, 106, 0.7);
  transition: width 0.5s var(--ease);
}

.loader-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

#loader-pct {
  color: var(--ink-dim);
}

.loader-note {
  margin-top: 56px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-ghost);
}

/* --- error ---------------------------------------------------------- */

.error-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: var(--pad);
  background: var(--bg);
  text-align: center;
}

.error-panel[hidden] {
  display: none;
}

.error-kicker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
}

.error-panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 400;
}

.error-panel p {
  max-width: 420px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-dim);
}

.error-panel button {
  justify-self: center;
  margin-top: 10px;
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}

.error-panel button:hover {
  border-color: var(--accent);
}

/* --- responsive ----------------------------------------------------- */

@media (max-width: 1100px) {
  .index {
    width: 190px;
  }

  .hint {
    display: none;
  }
}

@media (max-width: 860px) {
  .topbar {
    padding: 18px 20px;
  }

  .brand-sub,
  .brand-rule,
  .stat {
    display: none;
  }

  .index {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    transform: none;
    padding: 34px 16px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(10, 9, 8, 0.96) 45%, transparent);
    text-shadow: none;
  }

  .index::before {
    display: none;
  }

  .index-label {
    display: none;
  }

  .index ul {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border: 0;
    padding: 2px;
    scrollbar-width: none;
  }

  .index ul::-webkit-scrollbar {
    display: none;
  }

  .index li {
    border: 0;
    flex: 0 0 auto;
  }

  .index button {
    display: flex;
    gap: 0;
    width: auto;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
    background: rgba(18, 16, 13, 0.5);
  }

  .index button::before,
  .index .idx,
  .index .cat {
    display: none;
  }

  .index button[aria-current="true"] {
    border-color: rgba(232, 176, 106, 0.5);
    background: var(--accent-soft);
    color: var(--accent);
  }

  .index .name {
    font-size: 11px;
  }

  .info {
    bottom: 118px;
    left: 20px;
    right: 20px;
    width: auto;
  }

  .info h1 {
    font-size: clamp(38px, 11vw, 52px);
  }

  .info-blurb {
    max-width: 360px;
    font-size: 11.5px;
    line-height: 1.55;
  }

  .info-meta {
    margin-top: 12px;
  }

  .hud {
    right: 20px;
    bottom: 116px;
  }

  .icon-btn {
    display: none;
  }

  .atmo-btn {
    height: 34px;
    padding: 0 12px 0 10px;
    font-size: 8px;
  }

  .atmo-panel {
    width: min(300px, calc(100vw - 40px));
  }

  .back {
    display: none;
    padding: 8px 13px;
    font-size: 8px;
  }

  .loader-title {
    margin-bottom: 36px;
    font-size: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark,
  .loader-brand svg,
  .dot {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

/* --- entrance ------------------------------------------------------- */

.topbar,
.index,
.info,
.hud {
  transition: opacity 1.1s var(--ease);
}

body:not(.ready) .topbar,
body:not(.ready) .index,
body:not(.ready) .info,
body:not(.ready) .hud {
  opacity: 0;
}

