/* ============ Design tokens ============ */
:root {
  --space: #0a0614; /* deep aubergine space */
  --gold: #f6c453; /* parmesan gold */
  --gold-soft: #ffe2a0;
  --rose: #e2a39b; /* rose gold */
  --pink: #ff4fa3; /* smooch pink */
  --blue: #3ad7ff; /* boop blue */
  --cream: #fff1d6;
  --muted: #c9b3bd;
  --line: rgba(226, 163, 155, 0.3);
  --serif:
    "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --round:
    "Quicksand", "Nunito", "Varela Round", "Trebuchet MS", system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--space);
  color: var(--cream);
  font-family: var(--round);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: inherit;
}

/* ============ 3D stage ============ */
#scene {
  position: fixed;
  inset: 0;
}
#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  outline: none;
}
#scene canvas:active {
  cursor: grabbing;
}
#scene canvas.pointing {
  cursor: pointer;
}
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 55%,
    transparent 55%,
    rgba(5, 2, 10, 0.6) 100%
  );
}

/* ============ Floating world labels ============ */
#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.tag {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 5px 9px;
  border: 1px solid rgba(255, 241, 214, 0.14);
  border-radius: 999px;
  background: rgba(10, 6, 20, 0.55);
  font-family: var(--serif);
  font-size: 13.5px;
  font-weight: 500;
  font-variation-settings:
    "SOFT" 100,
    "opsz" 14;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  transition:
    opacity 0.35s ease,
    border-color 0.2s,
    background-color 0.2s;
  will-change: transform;
}
.tag i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
  flex: none;
}
.tag.minor {
  font-size: 12px;
  padding: 3px 9px 4px 7px;
}
.tag.hot,
.tag:hover {
  border-color: rgba(246, 196, 83, 0.75);
  background: rgba(34, 18, 36, 0.8);
}
.tag.active {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 79, 163, 0.18);
}
.tag.off {
  opacity: 0;
  pointer-events: none;
}

/* ============ Left column: title cartouche + atlas index ============ */
.left {
  position: fixed;
  top: calc(22px + var(--st));
  left: calc(24px + var(--sl));
  bottom: calc(118px + var(--sb));
  width: min(330px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: 20px;
  pointer-events: none;
}
.cartouche h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 650;
  font-size: clamp(32px, 4.3vw, 54px);
  line-height: 0.95;
  letter-spacing: -0.015em;
  font-variation-settings:
    "SOFT" 100,
    "opsz" 144;
  background: linear-gradient(
    105deg,
    #fff4d1 0%,
    var(--gold) 34%,
    var(--rose) 68%,
    var(--pink) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.drip {
  display: block;
  width: clamp(190px, 22vw, 290px);
  height: auto;
  margin: 10px 0 0;
  overflow: visible;
  filter: drop-shadow(0 0 10px rgba(246, 196, 83, 0.35));
}
.drip .d {
  transform-box: fill-box;
  transform-origin: 50% 0;
  transform: scaleY(0.15);
}
.drip .drop {
  opacity: 0;
  transform-box: fill-box;
}
body.ready .drip .d {
  animation: drip 1.8s cubic-bezier(0.3, 0.8, 0.25, 1) forwards;
  animation-delay: var(--delay);
}
body.ready .drip .drop {
  animation: drop 6s ease-in 2.4s infinite;
}
@keyframes drip {
  to {
    transform: scaleY(1);
  }
}
@keyframes drop {
  0%,
  55% {
    opacity: 0;
    transform: translateY(-4px);
  }
  62% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(22px);
  }
}
.cartouche .where {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  font-variation-settings:
    "SOFT" 100,
    "opsz" 18;
  color: var(--rose);
}
.cartouche .by {
  margin: 6px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
  max-width: 34ch;
}

.atlas {
  pointer-events: auto;
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 8px;
  border-radius: 18px;
  border: 1px solid rgba(226, 163, 155, 0.16);
  background: linear-gradient(
    180deg,
    rgba(26, 15, 38, 0.6),
    rgba(12, 7, 22, 0.45)
  );
  scrollbar-width: thin;
  scrollbar-color: rgba(226, 163, 155, 0.35) transparent;
}
.atlas .group,
.atlas .list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.atlas h3 {
  margin: 0 10px 4px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13.5px;
  font-variation-settings: "SOFT" 100;
  color: var(--rose);
}
.atlas button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 14px 6px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 0.2s,
    color 0.2s;
}
.atlas button i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
  flex: none;
}
.atlas button:hover {
  color: var(--cream);
  background: rgba(255, 241, 214, 0.06);
}
.atlas button.active {
  color: var(--gold-soft);
  background: rgba(246, 196, 83, 0.13);
}

/* ============ Ledger entry (info panel) ============ */
.ledger {
  position: fixed;
  z-index: 6;
  top: calc(18px + var(--st));
  right: calc(18px + var(--sr));
  width: min(390px, calc(100vw - 36px));
  max-height: calc(100% - 100px - var(--st) - var(--sb));
  overflow-y: auto;
  padding: 26px 26px 22px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(
    170deg,
    rgba(42, 22, 50, 0.88) 0%,
    rgba(17, 9, 29, 0.92) 55%,
    rgba(12, 7, 22, 0.94) 100%
  );
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 241, 214, 0.07);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transform: translateX(calc(100% + 40px));
  visibility: hidden;
  transition:
    transform 0.6s cubic-bezier(0.2, 0.85, 0.2, 1),
    visibility 0s linear 0.6s;
  scrollbar-width: thin;
  scrollbar-color: rgba(226, 163, 155, 0.35) transparent;
}
.ledger.open {
  transform: none;
  visibility: visible;
  transition:
    transform 0.6s cubic-bezier(0.2, 0.85, 0.2, 1),
    visibility 0s;
}
.ledger-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 241, 214, 0.04);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.ledger-close:hover {
  border-color: var(--gold);
}
.ledger-entry {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--rose);
  font-variation-settings: "SOFT" 100;
}
.ledger h2 {
  margin: 6px 40px 8px 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.01em;
  font-variation-settings:
    "SOFT" 100,
    "opsz" 96;
  color: var(--gold-soft);
}
.ledger-kind {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.ledger-desc p {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  color: #f6e8de;
  font-variation-settings: "opsz" 16;
}
.ledger-stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 18px 0;
  padding: 14px 0;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
}
.ledger-stats dt {
  font-size: 13px;
  font-weight: 700;
  color: var(--rose);
}
.ledger-stats dd {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.4;
}
.ledger-quote {
  margin: 0 0 20px;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--pink);
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  line-height: 1.5;
  font-variation-settings: "SOFT" 100;
  color: var(--gold-soft);
}
.ledger-quote p {
  margin: 0;
}
.ledger-quote cite {
  display: block;
  margin-top: 6px;
  font-family: var(--round);
  font-style: normal;
  font-size: 12.5px;
  color: var(--muted);
}
.ledger-quote[hidden] {
  display: none;
}
.boop-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}
.boop-btn {
  padding: 11px 20px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(
    100deg,
    var(--gold) 0%,
    var(--rose) 55%,
    var(--pink) 100%
  );
  color: #2b0d1e;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(255, 79, 163, 0.28);
  transition:
    transform 0.15s ease,
    box-shadow 0.2s;
}
.boop-btn:hover {
  box-shadow: 0 10px 32px rgba(255, 79, 163, 0.45);
}
.boop-btn:active {
  transform: scale(0.95);
}
.boop-count {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--muted);
}

/* ============ Dock (bottom-left controls) ============ */
.dock {
  position: fixed;
  left: calc(18px + var(--sl));
  bottom: calc(16px + var(--sb));
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 36px);
}
.hint {
  margin: 0 0 0 6px;
  font-size: 12.5px;
  color: var(--muted);
  transition: opacity 0.6s;
}
.hint.gone {
  opacity: 0;
}
.dock-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 22px;
  background: rgba(14, 8, 24, 0.65);
  border: 1px solid rgba(226, 163, 155, 0.18);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.dock button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.2s,
    border-color 0.2s,
    color 0.2s;
}
.dock button:hover {
  background: rgba(255, 241, 214, 0.08);
}
.dock button[aria-pressed="true"] {
  border-color: rgba(246, 196, 83, 0.45);
  color: var(--gold-soft);
}
.speed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.speed input {
  width: 96px;
  accent-color: var(--pink);
}
.speed output {
  min-width: 3.2ch;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

/* ============ SBS weather ticker ============ */
.ticker {
  position: fixed;
  right: calc(20px + var(--sr));
  bottom: calc(22px + var(--sb));
  max-width: min(360px, 34vw);
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
  text-align: right;
}
.ticker b {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 13px;
  color: var(--rose);
  font-variation-settings: "SOFT" 100;
}
.ticker span {
  transition: opacity 0.5s;
}
.ticker span.fade {
  opacity: 0;
}

/* ============ Loader ============ */
.loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 45%, #22122e 0%, var(--space) 70%);
  transition:
    opacity 1.2s ease,
    visibility 0s linear 1.2s;
}
.loader.done {
  opacity: 0;
  visibility: hidden;
}
.loader-inner {
  padding: 24px;
  text-align: center;
}
.loader svg {
  width: 76px;
  height: 76px;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  50% {
    transform: translateY(-8px) rotate(-6deg);
  }
}
.loader-title {
  margin: 18px 0 6px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  font-variation-settings:
    "SOFT" 100,
    "opsz" 48;
  color: var(--gold-soft);
}
.loader-msg {
  margin: 0 auto;
  max-width: 42ch;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: var(--rose);
}
.loader.failed svg {
  animation: none;
  opacity: 0.5;
}

/* ============ Focus rings ============ */
.tag:focus-visible,
.atlas button:focus-visible,
.dock button:focus-visible,
.boop-btn:focus-visible,
.ledger-close:focus-visible,
.speed input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ============ Small screens ============ */
@media (max-width: 760px) {
  .left {
    top: calc(14px + var(--st));
    left: calc(16px + var(--sl));
    bottom: auto;
    width: calc(100vw - 32px);
  }
  .cartouche h1 {
    font-size: 30px;
  }
  .cartouche .by {
    display: none;
  }
  .cartouche .where {
    font-size: 14px;
    margin-top: 6px;
  }
  .drip {
    width: 170px;
    margin-top: 6px;
  }
  .atlas {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: calc(66px + var(--sb));
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 14px;
    border: 0;
    border-radius: 0;
    background: none;
    scrollbar-width: none;
  }
  .atlas .group,
  .atlas .list {
    flex-direction: row;
    gap: 6px;
  }
  .atlas h3 {
    display: none;
  }
  .atlas button {
    width: auto;
    white-space: nowrap;
    padding: 7px 12px;
    border: 1px solid rgba(226, 163, 155, 0.22);
    border-radius: 999px;
    background: rgba(14, 8, 24, 0.75);
  }
  .ledger {
    top: auto;
    left: calc(10px + var(--sl));
    right: calc(10px + var(--sr));
    bottom: calc(68px + var(--sb));
    width: auto;
    max-height: 56%;
    padding: 22px 20px 18px;
    transform: translateY(calc(100% + 30px));
  }
  .ledger.open {
    transform: none;
  }
  .ledger h2 {
    font-size: 28px;
  }
  .ticker,
  .hint {
    display: none;
  }
  .dock {
    left: 0;
    right: 0;
    bottom: calc(10px + var(--sb));
    padding: 0 10px;
    max-width: none;
  }
  .dock-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .speed input {
    width: 72px;
  }
}
@media (max-height: 620px) and (min-width: 761px) {
  .cartouche .by {
    display: none;
  }
  .cartouche h1 {
    font-size: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drip .d {
    transform: none;
  }
  body.ready .drip .d {
    animation: none;
  }
  .drip .drop {
    display: none;
  }
  .loader svg {
    animation: none;
  }
  .ledger,
  .ledger.open {
    transition: visibility 0s;
  }
}
