:root {
  --bg: #070b14;
  --bg-deep: #04060c;
  --surface: #0e1524;
  --surface-raise: rgba(18, 26, 42, 0.72);
  --ink: #e8e6de;
  --muted: #8a919e;
  --gold: #c9a96e;
  --gold-soft: rgba(201, 169, 110, 0.55);
  --cyan: #6ec4c0;
  --stroke: rgba(232, 230, 222, 0.10);
  --stroke-strong: rgba(201, 169, 110, 0.35);
  --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --sans: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --step-small: clamp(0.8125rem, 0.79rem + 0.1vw, 0.875rem);
  --step-body: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem);
  --step-lead: clamp(1.125rem, 1rem + 0.55vw, 1.375rem);
  --step-head: clamp(1.35rem, 1.1rem + 1.1vw, 1.85rem);
  --radius: 2px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --rail-h: clamp(148px, 22vh, 188px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

.fx-vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    radial-gradient(ellipse 70% 58% at 50% 40%, transparent 30%, rgba(4, 6, 12, 0.62) 100%),
    linear-gradient(180deg, rgba(7, 11, 20, 0.72) 0%, transparent 16%, transparent 58%, rgba(7, 11, 20, 0.88) 100%);
}

/* ── masthead ── */
.masthead {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: calc(var(--safe-t) + 18px) calc(var(--safe-r) + 24px) 12px calc(var(--safe-l) + 24px);
  pointer-events: none;
}

.mast-left { max-width: min(640px, 72vw); }

.org {
  font-size: var(--step-small);
  color: var(--muted);
  letter-spacing: 0.04em;
  line-height: 1.45;
  margin-bottom: 6px;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: var(--step-head);
  letter-spacing: 0.04em;
  line-height: 1.25;
  color: var(--ink);
}

.mast-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--step-small);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(110, 196, 192, 0.45);
  animation: livepulse 2.4s ease-in-out infinite;
}

@keyframes livepulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(110, 196, 192, 0.35); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(110, 196, 192, 0); }
}

.clock {
  font-variant-numeric: tabular-nums;
  font-size: var(--step-small);
  color: var(--ink);
  letter-spacing: 0.08em;
  opacity: 0.85;
}

/* film title — place-carries-it bottom edge name */
.film-title {
  position: absolute;
  z-index: 15;
  left: calc(var(--safe-l) + 24px);
  bottom: calc(var(--safe-b) + var(--rail-h) + 28px);
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.5rem, 3.8vw, 2.75rem);
  letter-spacing: 0.12em;
  line-height: 1.1;
  color: rgba(232, 230, 222, 0.92);
  pointer-events: none;
  text-shadow: 0 2px 28px rgba(4, 6, 12, 0.65);
  max-width: min(70vw, 720px);
}

/* ── portal rail ── */
.portal-rail {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  transform: translateX(-50%);
  width: min(1120px, calc(100vw - 28px));
  height: var(--rail-h);
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: clamp(10px, 1.6vw, 16px);
  pointer-events: none;
}

.portal {
  pointer-events: auto;
  appearance: none;
  border: 0;
  margin: 0;
  padding: 18px 20px 16px;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  row-gap: 4px;
  align-content: start;
  background: var(--surface-raise);
  backdrop-filter: blur(18px) saturate(1.05);
  -webkit-backdrop-filter: blur(18px) saturate(1.05);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--stroke);
  transform: translate3d(0, 0, 0);
  transition:
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.28s ease,
    box-shadow 0.28s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.portal::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent, var(--gold));
  opacity: 0.35;
  transition: opacity 0.28s ease, width 0.28s ease;
}

.portal--primary {
  background: rgba(22, 30, 46, 0.78);
  box-shadow: inset 0 0 0 1px var(--stroke-strong);
}

.portal--primary::before {
  opacity: 0.85;
  width: 3px;
  background: var(--gold);
}

.portal-kicker {
  grid-column: 1;
  font-size: var(--step-small);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.portal-title {
  grid-column: 1;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
  letter-spacing: 0.08em;
  line-height: 1.2;
  color: var(--ink);
}

.portal-desc {
  grid-column: 1;
  font-size: var(--step-small);
  color: var(--muted);
  line-height: 1.45;
  margin-top: 2px;
  align-self: end;
}

.portal-host {
  grid-column: 1;
  font-size: 0.75rem;
  color: rgba(138, 145, 158, 0.85);
  letter-spacing: 0.04em;
  margin-top: 8px;
}

.portal-go {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  justify-self: end;
  font-size: var(--step-small);
  color: var(--accent, var(--gold));
  letter-spacing: 0.12em;
  opacity: 0.55;
  transition: opacity 0.25s ease, transform 0.25s ease;
  padding-top: 2px;
}

.portal:hover,
.portal:focus-visible,
.portal.is-near {
  transform: translate3d(0, -4px, 0);
  background: rgba(24, 34, 52, 0.88);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--accent, var(--gold)) 45%, transparent),
    0 18px 40px rgba(0, 0, 0, 0.35);
}

.portal:hover::before,
.portal:focus-visible::before,
.portal.is-near::before {
  opacity: 1;
  width: 3px;
}

.portal:hover .portal-go,
.portal:focus-visible .portal-go,
.portal.is-near .portal-go {
  opacity: 1;
  transform: translateX(2px);
}

.portal:focus-visible {
  box-shadow:
    inset 0 0 0 1px var(--gold),
    0 0 0 2px rgba(201, 169, 110, 0.35);
}

.portal.is-diving {
  transform: translate3d(0, -6px, 0) scale(1.02);
}

.portal:active {
  transform: translate3d(0, -1px, 0);
}

/* ── colophon ── */
.colophon {
  position: absolute;
  z-index: 25;
  left: calc(var(--safe-l) + 24px);
  right: calc(var(--safe-r) + 24px);
  bottom: calc(var(--safe-b) + var(--rail-h) + 8px);
  display: none; /* hint lives in film area on desktop via #hint reposition — shown on mobile */
  pointer-events: none;
}

.colophon .mark {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

#hint {
  position: absolute;
  z-index: 18;
  right: calc(var(--safe-r) + 24px);
  bottom: calc(var(--safe-b) + var(--rail-h) + 36px);
  max-width: min(320px, 36vw);
  text-align: right;
  font-size: var(--step-small);
  color: var(--muted);
  line-height: 1.5;
  pointer-events: none;
}

/* ── loader ── */
.loader {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity 0.55s ease, visibility 0.55s ease;
}

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

.loader-bar {
  width: 120px;
  height: 2px;
  background: rgba(232, 230, 222, 0.12);
  overflow: hidden;
  border-radius: 1px;
}

.loader-bar::after {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: var(--gold);
  animation: loadslide 1.1s ease-in-out infinite;
}

@keyframes loadslide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.loader p {
  font-size: var(--step-small);
  color: var(--muted);
  letter-spacing: 0.08em;
}

.dive-veil {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--bg-deep);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.dive-veil.is-on {
  opacity: 0.72;
}

/* ── desktop fine-tune ── */
@media (min-width: 821px) {
  .portal-rail {
    align-items: stretch;
  }
}

/* ── tablet / phone: preserve desktop spirit, restack ── */
@media (max-width: 820px) {
  :root {
    --rail-h: auto;
  }

  .masthead {
    padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
  }

  .mast-left { max-width: 78vw; }

  .org {
    font-size: 0.75rem;
    line-height: 1.4;
  }

  .film-title {
    left: calc(var(--safe-l) + 16px);
    bottom: auto;
    top: 42%;
    font-size: clamp(1.25rem, 6.5vw, 1.85rem);
    max-width: 88vw;
    letter-spacing: 0.1em;
    opacity: 0.92;
  }

  #hint {
    left: calc(var(--safe-l) + 16px);
    right: calc(var(--safe-r) + 16px);
    bottom: calc(var(--safe-b) + 12px);
    top: auto;
    max-width: none;
    text-align: left;
    /* sit above rail — rail is content-sized */
    position: absolute;
    transform: translateY(-100%);
    margin-bottom: 0;
    /* pushed by rail via bottom calc in JS? use CSS approximate */
    bottom: calc(var(--safe-b) + 210px);
    opacity: 0.9;
  }

  .portal-rail {
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100%;
    height: auto;
    padding: 0 calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .portal {
    padding: 14px 16px;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    min-height: 64px;
  }

  .portal-desc,
  .portal-host {
    display: none;
  }

  .portal-kicker {
    font-size: 0.75rem;
  }

  .portal-title {
    font-size: 1.15rem;
  }

  .portal-go {
    grid-row: 1 / span 2;
    align-self: center;
  }

  .portal--primary {
    min-height: 72px;
  }

  .portal--primary .portal-desc {
    display: block;
    grid-column: 1;
    margin-top: 0;
  }
}

@media (max-width: 420px) {
  .mast-right .clock { display: none; }
  .film-title { top: 38%; }
}

@media (prefers-reduced-motion: reduce) {
  .portal,
  .portal-go,
  .live-dot,
  .loader-bar::after {
    animation: none !important;
    transition: none !important;
  }
}
