/* ==========================================================================
   BAILU · A SMALL WORLD — interactive planet landing preview
   ========================================================================== */

:root {
  --ink: #f7ead8;
  --body: #d3bfa9;
  --muted: #a58d78;
  --dim: #6f5a4a;
  --accent: #f4b860;
  --accent-soft: #b8863f;
  --coral: #e8603c;
  --line: rgba(247, 234, 216, 0.15);
  --line-soft: rgba(247, 234, 216, 0.08);
  --backdrop: url("./backdrop-warm.jpg");

  --serif: "Noto Serif SC", "Source Han Serif SC", "STZhongsong",
    "Songti SC", "STSong", "SimSun", Georgia, serif;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", "DengXian",
    "Hiragino Sans GB", system-ui, sans-serif;
  --mono: "Consolas", "SFMono-Regular", "JetBrains Mono", "Menlo", monospace;

  --pad: clamp(18px, 3.2vw, 52px);
  --ease: cubic-bezier(0.19, 1, 0.22, 1);
}

.theme-cool {
  --ink: #f4f1e6;
  --body: #bcc2d8;
  --muted: #8d95b3;
  --dim: #5a6180;
  --accent: #c8f45c;
  --accent-soft: #8fa93f;
  --coral: #ff7a59;
  --line: rgba(244, 241, 230, 0.14);
  --line-soft: rgba(244, 241, 230, 0.08);
  --backdrop: url("./backdrop.jpg");
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overscroll-behavior: none;
  overflow: hidden;
  background: #120b0c;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--accent);
  color: #1a0e06;
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 6px;
}

.skip {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 60;
  padding: 10px 14px;
  background: var(--ink);
  color: #0a0f05;
  font: 12px/1 var(--mono);
  transform: translateY(-200%);
  transition: transform 0.2s;
}

.skip:focus {
  transform: none;
}

/* --------------------------------------------------------------------------
   Layers
   -------------------------------------------------------------------------- */

.sky {
  position: fixed;
  inset: -3%;
  z-index: 0;
  background:
    radial-gradient(48% 44% at 76% 26%, rgba(255, 150, 90, 0.17), transparent 70%),
    radial-gradient(42% 38% at 13% 80%, rgba(255, 200, 130, 0.1), transparent 72%),
    #120b0c var(--backdrop) center / cover no-repeat;
  filter: saturate(0.95) brightness(0.96) sepia(0.06);
  transform: scale(1.04);
  animation: sky-drift 80s ease-in-out infinite alternate;
}

.media {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
  display: none; /* add <video class="media"> and remove this to use real footage */
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  opacity: 0;
  animation: scene-in 1.8s var(--ease) 0.25s forwards;
}

#scene.is-dragging {
  cursor: grabbing;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 62% 42%, transparent 36%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.42) 0%, transparent 22% 70%, rgba(0, 0, 0, 0.38) 100%);
}

.grain {
  position: fixed;
  inset: -40%;
  z-index: 3;
  pointer-events: none;
  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='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  opacity: 0.045;
  mix-blend-mode: soft-light;
  animation: grain-shift 1.2s steps(4) infinite;
}

.veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #0b0507;
  pointer-events: none;
  animation: veil-out 1.2s ease 0.05s forwards;
}

.fallback-planet {
  display: none;
  position: fixed;
  left: 62%;
  top: 40%;
  width: 42vmin;
  height: 42vmin;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f2cf97, #b58a4e 42%, #10475e 72%);
  box-shadow: 0 0 80px rgba(80, 210, 190, 0.25);
  opacity: 0.9;
}

.no-webgl #scene {
  display: none;
}

.no-webgl .fallback-planet {
  display: block;
}

/* --------------------------------------------------------------------------
   UI
   -------------------------------------------------------------------------- */

.ui {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.topbar {
  position: absolute;
  top: max(var(--pad), env(safe-area-inset-top));
  left: var(--pad);
  right: var(--pad);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  animation: fade-down 1s var(--ease) 0.7s forwards;
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  pointer-events: auto;
}

.brand-mark {
  width: 6px;
  height: 6px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(127, 227, 205, 0.9);
}

.brand-sub {
  color: var(--dim);
}

.coords {
  margin: 0;
  justify-self: center;
  white-space: nowrap;
  color: var(--dim);
}

.coords b {
  color: var(--muted);
  font-weight: 400;
}

.clock {
  margin: 0;
  justify-self: end;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.clock .tz {
  color: var(--dim);
  font-size: 8.5px;
}

/* title ------------------------------------------------------------------- */

.title-block {
  position: absolute;
  left: var(--pad);
  bottom: clamp(112px, 15vh, 160px);
  width: min(38vw, 500px);
  opacity: 0;
  animation: fade-up 1.1s var(--ease) 0.9s forwards;
}

.kicker {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 clamp(14px, 2.4vh, 24px);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--muted);
}

.kicker::before {
  content: "";
  width: clamp(26px, 4vw, 54px);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent));
}

.title {
  display: flex;
  align-items: flex-end;
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(58px, 7.8vw, 118px);
  line-height: 1;
  letter-spacing: 0.02em;
}

.mask {
  display: inline-flex;
  overflow: hidden;
  padding: 0.08em 0 0.12em;
  margin: -0.08em 0 -0.12em;
}

.ch {
  display: block;
  background: linear-gradient(
    178deg,
    #fff9ec 0%,
    #ffe6c7 40%,
    #ffc98a 74%,
    #f2b45e 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transform: translateY(112%);
  animation: char-rise 1.3s var(--ease) forwards;
}

.mask:nth-child(1) .ch {
  animation-delay: 0.95s;
}

.mask:nth-child(2) .ch {
  animation-delay: 1.07s;
}

.title .dot {
  width: 0.075em;
  height: 0.075em;
  margin-left: 0.12em;
  margin-bottom: 0.16em;
  background: var(--coral);
  box-shadow: 0 0 26px rgba(255, 122, 89, 0.6);
  transform: scale(0);
  animation: dot-in 0.7s var(--ease) 1.45s forwards;
}

.latin {
  margin: clamp(14px, 2.2vh, 22px) 0 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
}

.latin b {
  color: var(--accent);
  font-weight: 400;
}

.lede {
  margin: 14px 0 0;
  max-width: 22em;
  font-size: clamp(12.5px, 1vw, 14px);
  line-height: 1.85;
  letter-spacing: 0.03em;
  color: var(--body);
}

/* entries ----------------------------------------------------------------- */

.entries {
  position: absolute;
  right: var(--pad);
  bottom: clamp(86px, 10vh, 108px);
  width: min(330px, 30vw);
  border-top: 1px solid var(--line);
  pointer-events: auto;
  opacity: 0;
  animation: fade-up 1.1s var(--ease) 1.15s forwards;
}

.entry {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 12px;
  padding: 15px 10px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  background: linear-gradient(
    90deg,
    rgba(18, 11, 9, 0.58) 0%,
    rgba(18, 11, 9, 0.24) 70%,
    rgba(18, 11, 9, 0.1) 100%
  );
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  transition: padding 0.45s var(--ease);
}

.entry::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(127, 227, 205, 0.14),
    rgba(127, 227, 205, 0.02) 60%,
    transparent
  );
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.55s var(--ease);
  pointer-events: none;
}

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

.entry-idx {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  color: var(--dim);
  transition: color 0.3s;
}

.entry-text {
  display: flex;
  align-items: baseline;
  gap: 11px;
  min-width: 0;
}

.entry-text b {
  font-size: 15.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  transition: transform 0.45s var(--ease);
}

.entry-text i {
  font-family: var(--mono);
  font-style: normal;
  font-size: 8px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
  transition: color 0.3s;
}

.entry-arrow {
  justify-self: end;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  transition: transform 0.45s var(--ease), color 0.3s;
}

.entry:hover::before,
.entry:focus-visible::before {
  transform: scaleX(1);
}

.entry.is-poked::before {
  transform: scaleX(1);
  transition-duration: 0.15s;
}

.entry:hover::after,
.entry:focus-visible::after {
  height: 54%;
}

.entry:hover {
  padding-left: 18px;
}

.entry:hover .entry-idx,
.entry:hover .entry-text i {
  color: var(--accent);
}

.entry:hover .entry-arrow,
.entry:focus-visible .entry-arrow {
  color: var(--accent);
  transform: translate(3px, -3px);
}

/* 备案模式：公安备案审核期间只留静态入口，「中继」不出现。
   去掉 <html data-filing="on"> 即可恢复。 */
[data-filing="on"] .entry[data-route="/relay"] {
  display: none;
}

/* bottom bar -------------------------------------------------------------- */

.bottombar {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: max(var(--pad), env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  opacity: 0;
  animation: fade-up 1s var(--ease) 1.35s forwards;
}

.beian {
  color: inherit;
  text-decoration: none;
  letter-spacing: 0.08em;
  transition: color 0.3s;
}

.beian:hover,
.beian:focus-visible {
  color: var(--accent);
}

.hint {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  transition: opacity 0.6s ease, transform 0.6s var(--ease);
}
.hint .drag-icon {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 16px;
  border: 1px solid currentColor;
  border-radius: 6px;
  opacity: 0.8;
}

.hint .drag-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 1px;
  height: 4px;
  background: currentColor;
  transform: translateX(-50%);
  animation: wheel 2.4s ease-in-out infinite;
}

.hint.is-dismissed {
  opacity: 0;
  transform: translateY(6px);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.status i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(127, 227, 205, 0.9);
  animation: pulse 3.4s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

@keyframes char-rise {
  from {
    transform: translateY(112%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes dot-in {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-down {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scene-in {
  from {
    opacity: 0;
    transform: scale(1.04);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes veil-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    visibility: hidden;
  }
}

@keyframes sky-drift {
  from {
    transform: scale(1.04) translate3d(-0.6%, -0.4%, 0);
  }
  to {
    transform: scale(1.07) translate3d(0.6%, 0.5%, 0);
  }
}

@keyframes grain-shift {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-4%, 3%);
  }
  50% {
    transform: translate(3%, -5%);
  }
  75% {
    transform: translate(-3%, -2%);
  }
  100% {
    transform: translate(4%, 4%);
  }
}

@keyframes wheel {
  0%,
  100% {
    transform: translate(-50%, 0);
    opacity: 0.3;
  }
  50% {
    transform: translate(-50%, 4px);
    opacity: 0.9;
  }
}

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

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .coords {
    display: none;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .title-block {
    width: auto;
    right: var(--pad);
    bottom: 186px;
  }

  .title {
    font-size: clamp(48px, 12.5vw, 84px);
  }

  .entries {
    left: var(--pad);
    right: var(--pad);
    bottom: 78px;
    width: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--line);
  }

  .entry {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 11px 10px 12px;
    border-bottom: 0;
    border-left: 1px solid var(--line);
    background: linear-gradient(
      180deg,
      rgba(18, 11, 9, 0.55),
      rgba(18, 11, 9, 0.22)
    );
  }

  .entry:first-child {
    border-left: 0;
  }

  .entry-idx {
    display: block;
  }

  .entry-text {
    display: block;
  }

  .entry-text i {
    display: none;
  }

  .entry-text b {
    display: block;
    font-size: 14px;
  }

  .entry-arrow {
    position: absolute;
    right: 9px;
    top: 9px;
    font-size: 11px;
  }

  .entry:hover {
    padding-left: 10px;
  }

  .bottombar {
    font-size: 8px;
  }

  .hint {
    display: none;
  }

  .fallback-planet {
    left: 50%;
    top: 36%;
  }
}

@media (max-width: 600px) {
  .title-block {
    bottom: 174px;
  }

  .kicker {
    margin-bottom: 14px;
    font-size: 8.5px;
    letter-spacing: 0.2em;
  }

  .latin {
    font-size: 8px;
    letter-spacing: 0.24em;
  }

  .lede {
    font-size: 12px;
  }

  .foot-note {
    display: none;
  }
}

@media (max-height: 700px) and (min-width: 901px) {
  .title-block {
    bottom: 96px;
  }

  .title {
    font-size: clamp(52px, 6.8vw, 100px);
  }

  .kicker {
    margin-bottom: 14px;
  }

  .entries {
    bottom: 82px;
  }
}

@media (max-height: 640px) and (max-width: 900px) {
  .kicker,
  .lede {
    display: none;
  }

  .title-block {
    bottom: 168px;
  }

  .title {
    font-size: clamp(44px, 11vw, 68px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }

  .veil {
    display: none;
  }

  .ch {
    transform: none;
  }

  .sky,
  .grain {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   Moon view (résumé)
   -------------------------------------------------------------------------- */

.ui {
  transition: opacity 0.55s var(--ease) 0.32s, transform 0.65s var(--ease) 0.32s;
}

body.is-moon .ui,
body.is-memory .ui {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.4s var(--ease), transform 0.5s var(--ease);
}

/* children set pointer-events themselves, so cut them explicitly */
body.is-moon .entries,
body.is-moon .brand,
body.is-memory .entries,
body.is-memory .brand {
  pointer-events: none;
}

body.is-moon .fallback-planet {
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}

.moon-view {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(0, 46%) minmax(0, 54%);
  grid-template-rows: auto 1fr auto;
  padding: max(var(--pad), env(safe-area-inset-top)) var(--pad)
    max(var(--pad), env(safe-area-inset-bottom));
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--ease), visibility 0s linear 0.4s;
}

.moon-view.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.55s var(--ease) 0.08s;
}

/* head --------------------------------------------------------------------- */

.moon-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.moon-back,
.mem-back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px 10px 12px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 24, 0.42);
  color: var(--ink);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 0.3s, color 0.3s, background 0.3s;
}

.moon-back-arrow,
.mem-back-arrow {
  font-size: 12px;
  line-height: 1;
}

.moon-back:hover,
.moon-back:focus-visible,
.mem-back:hover,
.mem-back:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(10, 16, 34, 0.6);
}

.moon-crumb,
.mem-crumb {
  margin: 0;
  color: var(--dim);
}

.moon-crumb span,
.mem-crumb span {
  color: var(--accent);
}

/* dossier ------------------------------------------------------------------ */

.moon-dossier {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  max-width: 430px;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s var(--ease), transform 0.75s var(--ease);
}

.moon-view.is-open .moon-dossier {
  opacity: 1;
  transform: none;
  transition-delay: 0.62s;
}

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

.moon-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(38px, 4.4vw, 62px);
  line-height: 1;
  letter-spacing: 0.14em;
  color: var(--ink);
}

.moon-role {
  margin: 15px 0 0;
  font-size: 13.5px;
  letter-spacing: 0.06em;
  color: var(--body);
}

.moon-note {
  margin: 9px 0 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--dim);
}

.moon-rows {
  margin: 30px 0 0;
  border-top: 1px solid var(--line);
}

.moon-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}

.moon-row dt {
  padding-top: 3px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.moon-row dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--body);
}

.moon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.moon-btn {
  padding: 11px 18px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}

.moon-btn.is-ghost {
  border-color: var(--line);
  color: var(--muted);
}

.moon-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* foot --------------------------------------------------------------------- */

.moon-foot {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

@media (max-width: 900px) {
  .moon-view {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .moon-dossier {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
    max-width: none;
    max-height: 56vh;
    overflow-y: auto;
    padding-bottom: 4px;
  }

  .moon-title {
    font-size: clamp(32px, 9vw, 44px);
  }

  .moon-rows {
    margin-top: 22px;
  }

  .moon-row {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 0;
  }

  .moon-foot {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Memory view (star field)
   -------------------------------------------------------------------------- */

.mem-view {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s var(--ease), visibility 0s linear 0.45s;
}

.mem-view.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s var(--ease) 0.05s;
}

.mem-head {
  position: absolute;
  top: max(var(--pad), env(safe-area-inset-top));
  left: var(--pad);
  right: var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

/* gate --------------------------------------------------------------------- */

.mem-gate {
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(440px, 84vw);
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: auto;
  transition: opacity 0.85s var(--ease), transform 1s var(--ease),
    filter 0.85s var(--ease);
}

.mem-view.is-unlocked .mem-gate {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96);
  filter: blur(6px);
  pointer-events: none;
}

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

.mem-gate-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(44px, 5.2vw, 72px);
  line-height: 1;
  letter-spacing: 0.16em;
  color: var(--ink);
}

.mem-gate-line {
  margin: 18px 0 26px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--body);
}

.mem-form {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.mem-input {
  width: 168px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 24, 0.5);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.42em;
  text-align: center;
  outline-offset: 4px;
  transition: border-color 0.3s, background 0.3s;
}

.mem-input:focus {
  border-color: var(--accent);
  background: rgba(10, 16, 34, 0.66);
}

.mem-submit {
  padding: 12px 20px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}

.mem-submit:hover,
.mem-submit:focus-visible {
  background: var(--accent);
  color: #0a0f05;
}

.mem-gate-hint {
  margin: 16px 0 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--dim);
  min-height: 12px;
}

.mem-gate.is-wrong {
  animation: mem-shake 0.42s ease;
}

@keyframes mem-shake {
  0%,
  100% {
    transform: translate(-50%, -50%);
  }
  20% {
    transform: translate(calc(-50% - 9px), -50%);
  }
  45% {
    transform: translate(calc(-50% + 8px), -50%);
  }
  70% {
    transform: translate(calc(-50% - 5px), -50%);
  }
  88% {
    transform: translate(calc(-50% + 3px), -50%);
  }
}

/* stars -------------------------------------------------------------------- */

.mem-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mem-nodes {
  position: absolute;
  inset: 0;
}

.mem-node {
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.mem-node::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 1px solid transparent;
  transition: border-color 0.28s, background 0.28s, transform 0.28s;
}

.mem-node:hover::before,
.mem-node:focus-visible::before,
.mem-node.is-active::before {
  border-color: var(--accent);
  background: rgba(200, 244, 92, 0.12);
  transform: scale(1.3);
}

.mem-node:focus-visible {
  outline: none;
}

.mem-node-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 2px);
  padding-top: 4px;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.3s, color 0.25s;
}

.mem-node:hover .mem-node-label,
.mem-node:focus-visible .mem-node-label,
.mem-node.is-active .mem-node-label {
  opacity: 1;
  transform: translate(-50%, 6px);
  color: var(--ink);
}

.mem-node.is-dim {
  cursor: default;
}

/* bottom bar ---------------------------------------------------------------- */

.mem-bar {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: max(var(--pad), env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.mem-years {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  pointer-events: auto;
}

.mem-year {
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: rgba(5, 8, 23, 0.55);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.3s, color 0.3s, background 0.3s;
}

.mem-year:hover {
  color: var(--ink);
  border-color: var(--line);
}

.mem-year.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(200, 244, 92, 0.08);
}

.mem-count {
  margin: 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}

.mem-count b {
  color: var(--ink);
  font-weight: 400;
}

/* card ---------------------------------------------------------------------- */

.mem-card {
  position: absolute;
  right: var(--pad);
  top: 50%;
  width: min(340px, 32vw);
  padding-bottom: 18px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 24, 0.74);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  transform: translate(18px, -46%);
  pointer-events: none;
  transition: opacity 0.45s var(--ease), transform 0.55s var(--ease);
}

.mem-card.is-open {
  opacity: 1;
  transform: translate(0, -50%);
  pointer-events: auto;
}

.mem-card-date {
  margin: 18px 20px 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--accent);
}

.mem-card-title {
  margin: 10px 20px 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 21px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.mem-card-text {
  margin: 10px 20px 0;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--body);
}

.mem-card-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 20px 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.mem-nav {
  width: 34px;
  height: 30px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}

.mem-nav:hover,
.mem-nav:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.mem-card-idx {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.mem-card-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: rgba(5, 8, 23, 0.6);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}

.mem-card-close:hover,
.mem-card-close:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 900px) {
  .mem-gate {
    top: 40%;
    width: 86vw;
  }

  .mem-card {
    left: var(--pad);
    right: var(--pad);
    top: auto;
    bottom: calc(74px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 52vh;
    overflow-y: auto;
    transform: translate(0, 18px);
  }

  .mem-card.is-open {
    transform: none;
  }

  .mem-card-title {
    font-size: 18px;
  }

  .mem-bar {
    align-items: center;
  }

  .mem-count {
    display: none;
  }

  .mem-node-label {
    font-size: 8px;
  }
}

/* --------------------------------------------------------------------------
   Cool theme (add ?theme=cool)
   -------------------------------------------------------------------------- */

.theme-cool .sky {
  background:
    radial-gradient(48% 44% at 76% 26%, rgba(88, 112, 255, 0.18), transparent 70%),
    radial-gradient(42% 38% at 13% 80%, rgba(255, 122, 89, 0.08), transparent 72%),
    #050817 var(--backdrop) center / cover no-repeat;
  filter: saturate(0.9) brightness(0.92);
}

.theme-cool .veil {
  background: #01030a;
}

.theme-cool .title .ch {
  background: linear-gradient(
    178deg,
    #fff9ec 0%,
    #eceefb 40%,
    #cdd6f7 74%,
    #b6c4f2 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.theme-cool .entry {
  background: linear-gradient(
    90deg,
    rgba(5, 8, 23, 0.58) 0%,
    rgba(5, 8, 23, 0.24) 70%,
    rgba(5, 8, 23, 0.1) 100%
  );
}

@media (max-width: 900px) {
  .theme-cool .entry {
    background: linear-gradient(
      180deg,
      rgba(5, 8, 23, 0.55),
      rgba(5, 8, 23, 0.22)
    );
  }
}

.theme-cool .fallback-planet {
  background: radial-gradient(circle at 32% 28%, #9ed36a, #14418c 46%, #06122e 72%);
}

/* --------------------------------------------------------------------------
   时光 · 一封信
   The letter is real geometry in the scene; only the little postmark and the
   sheet it dissolves into live in the DOM.
   -------------------------------------------------------------------------- */

.title-block,
.topbar,
.bottombar,
.entries {
  transition: opacity 0.55s var(--ease);
}

body.is-letter .title-block,
body.is-letter .topbar,
body.is-letter .bottombar,
body.is-letter .entries {
  opacity: 0;
  pointer-events: none;
}

.letter-ui {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--ease), visibility 0s linear 0.4s;
}

.letter-ui.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.45s var(--ease);
}

/* the date, written on the paper ------------------------------------------- */

.letter-form {
  position: absolute;
  left: 0;
  top: 0;
  width: 148px;
  margin: 0;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.4s var(--ease) 0.15s;
}

.letter-ui.is-open .letter-form {
  opacity: 1;
}

.letter-date {
  width: 100%;
  padding: 6px 2px 5px;
  border: 0;
  border-bottom: 1px dashed rgba(124, 62, 46, 0.42);
  background: transparent;
  color: #8f3a2b;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.12em;
  text-align: center;
  caret-color: #8f3a2b;
  border-radius: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.letter-date::placeholder {
  color: rgba(124, 62, 46, 0.3);
  letter-spacing: 0.18em;
}

.letter-date:focus-visible {
  outline: none;
  border-bottom-style: solid;
  border-bottom-color: rgba(143, 58, 43, 0.85);
}

/* the postmark: the same field, inked --------------------------------------- */

.letter-form.is-stamped .letter-date {
  border: 1px solid rgba(143, 58, 43, 0.55);
  border-radius: 3px;
  padding: 7px 6px 6px;
  background: rgba(143, 58, 43, 0.05);
  animation: letterStamp 0.3s var(--ease) both;
}

.letter-form.is-stamped {
  transform: rotate(-1.4deg);
}

.letter-form.is-wrong {
  animation: letterShake 0.45s ease-in-out;
}

.letter-cap {
  position: absolute;
  left: 0;
  top: 0;
  width: 240px;
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(240, 226, 200, 0.6);
  text-shadow: 0 1px 14px rgba(4, 8, 20, 0.85);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s var(--ease) 0.2s;
}

.letter-ui.is-open .letter-cap {
  opacity: 1;
}

@keyframes letterStamp {
  from {
    transform: scale(1.14) rotate(-3.5deg);
    opacity: 0.2;
  }
  60% {
    transform: scale(0.99) rotate(0.4deg);
    opacity: 1;
  }
  to {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes letterShake {
  0%,
  100% {
    transform: translateX(0);
  }
  18% {
    transform: translateX(-3px);
  }
  36% {
    transform: translateX(3px);
  }
  54% {
    transform: translateX(-2px);
  }
  72% {
    transform: translateX(2px);
  }
}

/* the sheet the letter turns into ------------------------------------------ */

.paper {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: max(var(--pad), env(safe-area-inset-top)) var(--pad)
    max(var(--pad), env(safe-area-inset-bottom));
  background-color: #f8f0e0;
  background-image: var(--paper-tile, none);
  background-size: 192px 192px;
  background-position: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.45s linear, visibility 0s linear 0.45s;
}

.paper.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.45s linear;
}

.paper-back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 15px 10px 12px;
  border: 1px solid rgba(96, 68, 44, 0.26);
  background: rgba(255, 252, 244, 0.42);
  color: #6b4a30;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.3s, background 0.3s;
}

.paper-back-arrow {
  font-size: 12px;
  line-height: 1;
}

.paper-back:hover,
.paper-back:focus-visible {
  border-color: rgba(96, 68, 44, 0.5);
  background: rgba(255, 252, 244, 0.78);
}

@media (max-width: 560px) {
  .letter-form {
    width: 112px;
  }

  .letter-date {
    font-size: 12px;
    padding: 5px 2px 4px;
  }

  .letter-cap {
    width: 200px;
    font-size: 8.5px;
    letter-spacing: 0.14em;
  }

  .paper {
    background-size: 160px 160px;
  }
}

