:root {
  color-scheme: dark;
  --moon: #f4f5ff;
  --silver: #d5def7;
  --lunar: #a4b6ed;
  --azure: #526ac4;
  --midnight: #242039;
  --rose: #923c79;
  --scene-w: min(105vw, 174svh);
  background: #151422;
  color: var(--silver);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; }

/* Keep Lunoa. exact at 16:10/16:9, while gently drawing inward toward the scene on ultrawide displays */
header {
  position: absolute; z-index: 2;
  top: clamp(20px, 4vh, 64px);
  left: max(
    clamp(20px, 4vw, 80px),
    calc(50vw - var(--scene-w) / 2 + clamp(24px, 3vw, 56px))
  );
  pointer-events: none;
}
h1 {
  margin: 0; color: var(--silver);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  font-size: clamp(33px, min(3.2vw, 5.4svh), 58px);
  font-weight: 500; line-height: 1; letter-spacing: -.045em;
  -webkit-font-smoothing: auto;
}
.station span, .panel h2 { font-weight: 400; font-style: italic; letter-spacing: .04em; }
h1 span { color: color-mix(in srgb, var(--rose) 55%, var(--lunar)); }

.sky {
  position: relative; isolation: isolate; overflow: hidden;
  width: 100%; min-height: max(100svh, 28rem);
  display: grid; grid-template-columns: minmax(0,1fr); place-items: center;
  background: radial-gradient(ellipse at 50% 49%, #282f57 2%, #20203b 42%, #151422 83%);
}
.sky::before {
  content: ""; position: absolute; inset: -5%;
  background: url("art/companion-moon.jpg") center/cover;
  opacity: .14; filter: blur(32px) brightness(.52); pointer-events: none;
}

/* Container-bound scene locks sigil and label proportions directly to the artwork scale */
.scene {
  position: relative; grid-area: 1/1;
  width: var(--scene-w);
  aspect-ratio: 2162/1080;
  container-type: inline-size;
}

.art {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  filter: brightness(.84) saturate(.92);
  mask-image: radial-gradient(ellipse 53% 63% at 50% 46%, black 48%, #000e 64%, #0008 81%, transparent 100%),
    linear-gradient(to bottom, transparent, black 4.5%, black 83%, transparent);
  mask-composite: intersect;
}

/* Soft dark veil that dims the illustration only while a station caption is open */
.reading-veil {
  position: absolute; inset: -45svh -30vw; pointer-events: none;
  background: radial-gradient(ellipse 68% 72% at 50% 48%, rgba(16, 15, 29, .26) 0%, rgba(16, 15, 29, .42) 55%, rgba(16, 15, 29, .24) 100%);
  opacity: 0;
  transition: opacity .45s ease;
}
body:has(.panel:popover-open) .reading-veil,
.sky.is-reading .reading-veil {
  opacity: 1;
  transition: opacity .3s ease;
}

.orbit,
.orbit-beam-stage {
  position: absolute; width: 53%; aspect-ratio: 1; left: 49%; top: 38%;
  transform: translate(-50%,-50%); border-radius: 50%;
  pointer-events: none;
}
.orbit {
  border: 1px solid #acbdec85;
  mask-image: linear-gradient(transparent 24%, #0006 43%, #000e 70%, #0009);
}
/* Separate mask keeps moonlight crisp on upper-side stations while never crossing her head */
.orbit-beam-stage {
  mask-image: linear-gradient(transparent 22%, #000b 36%, black 46%, black 100%);
}

/* Travelling silver-blue moonlight arc locked to the orbit ring */
.orbit-light {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transform: rotate(90deg);
  transition: opacity .95s ease;
  will-change: transform, opacity;
}
.orbit-light.is-lit {
  opacity: 1;
  transition: opacity .24s ease-out;
}
.orbit-light svg {
  display: block; width: 100%; height: 100%; overflow: visible;
}

button { font: inherit; }
.stations { display: contents; }

.station {
  --disc: clamp(22px, 2.1cqw, 40px);
  position: absolute; z-index: 1; left: var(--x); top: var(--y);
  width: max-content; min-height: 44px;
  display: flex; align-items: center; gap: clamp(.45rem, .68cqw, .78rem);
  appearance: none; background: none; border: 0; padding: 0 4px;
  border-radius: 999px;
  color: var(--silver);
  text-decoration: none; cursor: pointer; text-align: start; font: inherit;
  transition: opacity .22s ease;
}
.station.featured { --disc: clamp(32px, 2.86cqw, 52px); color: var(--moon); }
.left { flex-direction: row-reverse; transform: translate(calc(-100% + var(--disc)/2 + 4px),-50%); }
.right { transform: translate(calc(-1 * var(--disc)/2 - 4px),-50%); }
.nadir { flex-direction: column; gap: .2rem; padding: 4px 8px; border-radius: 12px; transform: translate(-50%,calc(-1 * var(--disc)/2 - 4px)); }

.sigil {
  position: relative;
  width: var(--disc); height: var(--disc); flex-shrink: 0;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  filter: brightness(.92) saturate(.88) drop-shadow(0 0 6px rgba(14, 13, 28, .65));
  opacity: .84;
  transition: opacity .2s ease;
}
.quiet .sigil {
  filter: grayscale(.55) brightness(.86) drop-shadow(0 0 8px rgba(12, 11, 24, .92));
  opacity: .8;
}

/* Soft dark ambient halo beneath thin italic labels for legibility over pale mist */
.station span {
  font-size: clamp(.92rem, 1.2cqw, 1.42rem);
  line-height: 1.4; white-space: nowrap;
  text-shadow:
    0 0 2px #151422,
    0 1px 6px rgba(21, 20, 34, .92),
    0 0 14px rgba(21, 20, 34, .82),
    0 0 28px rgba(21, 20, 34, .58);
  transition: color .2s ease;
}
.featured span { font-size: clamp(1.02rem, 1.4cqw, 1.62rem); }

.station:is(:hover, :focus-visible, .is-open) .sigil { opacity: 1; }
.station:is(:hover, :focus-visible, .is-open) span,
.panel a:hover {
  color: var(--moon);
  text-decoration: underline;
  text-underline-offset: .32em;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--lunar) 85%, transparent);
}
.station.is-open .sigil {
  filter: brightness(1.12) saturate(1.04) drop-shadow(0 0 10px rgba(164, 182, 237, .55));
}

/* Gently quiet non-selected stations while a caption is open */
.sky.is-reading .station:not(.is-open):not(:hover):not(:focus-visible) {
  opacity: .72;
}

/* High-contrast focus ring visible on both pale mist and dark sky */
:focus-visible {
  outline: 2px solid var(--moon);
  outline-offset: 4px;
  box-shadow: 0 0 0 5px rgba(15, 14, 28, .88);
}

/* Default / mobile / compact fallback caption panel */
.panel {
  position: fixed;
  inset: auto 0 max(1rem, calc(env(safe-area-inset-bottom, 0px) + .85rem));
  margin: 0 auto;
  width: min(23rem, 90vw);
  padding: 1rem 3.1rem 1.15rem 1.35rem;
  border: 0;
  border-top: 1px solid #a4b6ed59;
  background: rgba(24, 22, 42, .94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 34px rgba(8, 6, 17, .62);
  color: var(--silver);
  opacity: 0;
  transition: opacity .15s ease, display .15s allow-discrete, overlay .15s allow-discrete;
}
.panel:popover-open {
  opacity: 1;
  transition: opacity .2s ease-out, display .2s allow-discrete, overlay .2s allow-discrete;
}
@starting-style {
  .panel:popover-open { opacity: 0; }
}

.panel h2 { margin: 0 0 .4rem; font-size: 1.2rem; font-weight: 400; color: var(--moon); }
.panel p { margin: 0; line-height: 1.55; }
.panel a { display: inline-block; padding-block: .35rem; color: var(--silver); text-underline-offset: .25em; }
.caption-meta {
  margin-top: .4rem !important;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--lunar) 86%, var(--silver));
}

.close {
  position: absolute; top: .3rem; right: .3rem;
  border: 0; border-radius: 999px; background: none;
  color: var(--lunar); width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 1.35rem; line-height: 1; cursor: pointer;
  opacity: .78;
  transition: opacity .18s ease, color .18s ease;
}
.close:is(:hover, :focus-visible) { opacity: 1; color: var(--moon); }

/* Desktop anchored borderless mode (applied when JS verifies clean space beside its station) */
@media (min-width: 761px) and (min-aspect-ratio: 1/1) {
  .panel.is-anchored {
    margin: 0;
    inset: var(--cap-top, auto) auto auto var(--cap-left, auto);
    width: max-content;
    max-width: min(21rem, 32vw);
    padding: .35rem 2.35rem .45rem .15rem;
    border: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    overflow: visible;
    isolation: isolate;
  }
  /* Oversized feathered dark mist behind text so no rectangular box edge ever shows */
  .panel.is-anchored::before {
    content: "";
    position: absolute;
    inset: -26px -38px -32px -30px;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(ellipse 64% 64% at 46% 48%, rgba(16, 15, 29, .62) 0%, rgba(16, 15, 29, .28) 48%, rgba(16, 15, 29, 0) 76%);
  }
  .panel.is-anchored[data-side="left"] {
    padding: .35rem .15rem .45rem 2.35rem;
    text-align: end;
  }
  .panel.is-anchored[data-side="left"]::before {
    background: radial-gradient(ellipse 64% 64% at 54% 48%, rgba(16, 15, 29, .62) 0%, rgba(16, 15, 29, .28) 48%, rgba(16, 15, 29, 0) 76%);
  }
  .panel.is-anchored[data-side="nadir"] {
    padding: .25rem 2.2rem .35rem 2.2rem;
    text-align: center;
    max-width: min(22rem, 44vw);
  }
  .panel.is-anchored[data-side="nadir"]::before {
    background: radial-gradient(ellipse 64% 64% at 50% 48%, rgba(16, 15, 29, .62) 0%, rgba(16, 15, 29, .26) 48%, rgba(16, 15, 29, 0) 76%);
  }

  /* Visually hide duplicate title when anchored directly beside the lit station label */
  .panel.is-anchored h2 {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }

  .panel.is-anchored p {
    font-size: clamp(.88rem, 1.02vw, .98rem);
    line-height: 1.5;
    color: var(--moon);
    text-shadow:
      0 0 2px #141322,
      0 1px 6px rgba(18, 17, 32, .96),
      0 0 16px rgba(18, 17, 32, .88);
  }
  .panel.is-anchored .caption-meta {
    font-size: .68rem;
    color: var(--lunar);
    text-shadow: 0 1px 6px rgba(18, 17, 32, .95);
  }

  .panel.is-anchored .close {
    top: .08rem; right: -.1rem;
    width: 32px; height: 32px;
    font-size: 1.15rem;
    text-shadow: 0 1px 6px rgba(18, 17, 32, .95);
  }
  .panel.is-anchored[data-side="left"] .close {
    right: auto; left: -.1rem;
  }
  .panel.is-anchored[data-side="nadir"] .close {
    top: 50%; right: .05rem;
    transform: translateY(-50%);
  }
}

/* Tier 2: 4:3 tablets, split-screen desktop windows, and narrower landscapes (1.0 < W/H <= 1.42) */
@media (min-width: 761px) and (min-aspect-ratio: 1/1) and (max-aspect-ratio: 7/5),
       (min-width: 761px) and (max-width: 1080px) and (min-aspect-ratio: 1/1) {
  :root {
    --scene-w: min(96vw, 168svh);
  }
  header {
    left: clamp(20px, 3.6vw, 48px);
  }
}

/* Tier 3 & 4: Portrait tablets (3:4) and mobile phones */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  header {
    top: clamp(18px, 3.5svh, 40px);
    left: clamp(20px, 5vw, 44px);
  }
  h1 {
    font-size: clamp(32px, 6.2vw, 48px);
  }
  .sky {
    display: flex; flex-direction: column; justify-content: center;
    padding-block: clamp(4.2rem, 9.5svh, 6.5rem) 2.2rem;
  }
  .scene {
    width: 100%; aspect-ratio: auto; container-type: normal;
    --scene-height: clamp(220px, min(75vw, 46svh), 495px);
    padding-top: var(--scene-height);
  }
  .art {
    inset: 0 auto auto 50%; transform: translateX(-50%);
    width: calc(var(--scene-height) * 2.002); height: var(--scene-height);
  }
  .orbit {
    width: calc(var(--scene-height) * 1.06);
    top: calc(var(--scene-height) * .38); left: 49%;
  }
  /* Hide orbital arc beam in stacked grid layout */
  .orbit-beam-stage { display: none; }

  .stations {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(88%, 31rem); column-gap: clamp(.85rem, 3.5vw, 1.6rem); row-gap: .15rem;
    margin: clamp(1.1rem, 3svh, 1.8rem) auto 0;
  }
  .station {
    --disc: clamp(22px, 3.6vw, 26px);
    position: static; transform: none; width: 100%;
    flex-direction: row; gap: .6rem; min-height: 46px; padding: 0 4px;
  }
  .station span {
    font-size: clamp(.98rem, 2.5vw, 1.14rem);
    white-space: normal; text-wrap: balance;
  }
  .featured {
    position: absolute; top: calc(var(--scene-height) * .71);
    width: max-content; flex-direction: column; gap: .3rem;
    transform: translate(-50%, calc(-1 * var(--disc) / 2));
    --disc: clamp(28px, 5vw, 38px);
  }
  .featured.left { left: calc(50% - var(--scene-height) * .424); }
  .featured.right { left: calc(50% + var(--scene-height) * .406); }
  .featured span { max-width: 40vw; font-size: clamp(.88rem, 2.55vw, 1.18rem); text-align: center; }
  .featured.left span { transform: translateX(12%); }
  .featured.right span { transform: translateX(-12%); }

  /* Preserve symmetrical left/right pairs & nadir Workspace without changing arc DOM order */
  .station[popovertarget="panel-games"] { order: 1; }
  .station[popovertarget="panel-teyvat"] { order: 2; }
  .station[popovertarget="panel-archive"] { order: 3; }
  .station[popovertarget="panel-journal"] { order: 4; }
  .station[popovertarget="panel-quant"] { order: 5; }
  .station[popovertarget="panel-lab"] { order: 6; }
  .nadir { order: 7; grid-column: 1 / -1; justify-self: center; width: auto; padding-inline: 12px; }
}

/* Short landscape (e.g. mobile landscape or compact desktop strip) */
@media (max-height: 500px) and (min-width: 761px) {
  .sky { min-height: 31rem; }
  :root { --scene-w: min(96vw, 60rem); }
  header { top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .reading-veil,
  .orbit-light,
  .station,
  .sigil,
  .station span,
  .panel,
  .close {
    transition-duration: .12s;
  }
}

.credits { padding: .7rem 1rem; background: #151422; color: #a4abc2; font: .75rem/1.5 system-ui, sans-serif; text-align: center; }
