*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #070708;
  --ink: #f4f1ec;
  --muted: rgba(244, 241, 236, 0.55);
  --faint: rgba(244, 241, 236, 0.22);
  --line: rgba(255, 255, 255, 0.08);
  --panel: rgba(10, 10, 12, 0.72);
  --accent: #e8b86d;
  --accent-2: #7b8cff;
  --danger: #e07a5f;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: Inter, system-ui, sans-serif;
  --rail-w: 220px;
  --hud-w: min(360px, 34vw);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
.stage[hidden] { display: none !important; }
.stage.dragging { cursor: grabbing; }

.veil {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, transparent 40%, rgba(0,0,0,0.45) 100%),
    linear-gradient(90deg, rgba(0,0,0,0.55) 0%, transparent 18%, transparent 72%, rgba(0,0,0,0.5) 100%);
  z-index: 1;
}

.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 22px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.brand:hover { color: var(--ink); border-color: var(--faint); }
.sep { color: var(--faint); font-size: 12px; }
.top h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.top-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font: 500 12px/1 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.ghost:hover, .ghost.active {
  color: var(--ink);
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.07);
}

.rail {
  position: fixed;
  top: 64px;
  left: 16px;
  bottom: 24px;
  width: var(--rail-w);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
}

.moods {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mood {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--faint);
  font: 500 10px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 8px;
  border-radius: 999px;
  cursor: pointer;
}
.mood:hover { color: var(--muted); }
.mood.active {
  color: var(--bg);
  background: var(--ink);
}

.catalog {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.cat-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 13px/1.25 var(--sans);
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.cat-item small {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
}
.cat-item:hover { background: rgba(255,255,255,0.04); color: var(--ink); }
.cat-item.active {
  background: rgba(232, 184, 109, 0.12);
  color: var(--ink);
}
.cat-item.active small { color: var(--accent); }
.cat-item.hidden { display: none; }

.hud {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 24px;
  width: var(--hud-w);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: auto;
}

.kicker {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
#fname {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 3.2vw, 40px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.formula {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}
.formula code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: rgba(244,241,236,0.78);
}

.thought {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  line-height: 1.45;
  color: rgba(244,241,236,0.82);
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.ctrl {
  display: grid;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.ctrl em {
  font-style: normal;
  float: right;
  color: var(--ink);
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}
.ctrl input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.ctrl select {
  appearance: none;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  font: 500 13px/1 var(--sans);
}
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.hidden { display: none !important; }

.hint {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.02em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20,20,22,0.92);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink);
  backdrop-filter: blur(10px);
}

.demo-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 30;
  width: min(520px, calc(100vw - 40px));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(8,8,10,0.88);
  backdrop-filter: blur(14px);
}
.demo-bar[hidden] { display: none !important; }
.demo-progress {
  grid-column: 1 / -1;
  height: 2px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.demo-progress i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 80ms linear;
}
#demo-caption {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: rgba(244,241,236,0.9);
}

.mobile-only { display: none; }

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .veil {
    background:
      radial-gradient(ellipse 90% 70% at 50% 35%, transparent 35%, rgba(0,0,0,0.5) 100%);
  }
  .rail, .hud {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 52vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(110%);
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.panel-open .rail,
  body.panel-open .hud {
    transform: translateY(0);
  }
  .rail { z-index: 25; max-height: 38vh; }
  .hud { z-index: 26; }
  body.panel-open .rail { display: none; }
  body.panel-catalog .rail { display: flex; transform: translateY(0); }
  body.panel-catalog .hud { display: none; }
  .demo-bar { bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .rail, .hud { transition: none; }
}
