/* =========================================================
   山海知音录 — Oriental Modernism × Celestial Cartography × Musical Poetry
   Palette variables are set per season by theme.js from the season config.
   ========================================================= */
:root {
  --night: #0B1525;
  --indigo: #243C4D;
  --mountain: #566B70;
  --moon: #F1EADB;
  --gold: #C8B58C;
  --ink: #8D9C9F;

  --moon-2: rgba(241, 234, 219, 0.72);
  --moon-3: rgba(241, 234, 219, 0.48);
  --line: rgba(241, 234, 219, 0.16);
  --line-2: rgba(241, 234, 219, 0.08);
  --paper: #F1EADB;
  --paper-ink: #1d2733;
  --paper-ink-2: #4c5862;
  --paper-line: rgba(29, 39, 51, 0.14);

  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --latin: "Bodoni Moda", "Didot", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --qiji: "ZY Qiji", var(--serif);
  --kai: "ZY Kai", "Kaiti SC", "STKaiti", "KaiTi", var(--serif);
  /* Visitor-written text uses the complete self-hosted Noto Serif SC (unicode-range slices),
     so any nickname renders in one typeface with real weights */
  --ugc: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: clamp(16px, 3vw, 40px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night); color: var(--moon);
  font-family: var(--serif); font-size: 15px; line-height: 1.8;
  overflow: hidden; -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 50; background: var(--moon); color: var(--night); padding: 6px 12px; font-size: 13px; }
.skip:focus { top: 12px; }

/* ---------- Canvas & paper ---------- */
.sky {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; cursor: grab; outline: none;
}
.sky.is-dragging { cursor: grabbing; }
.sky.is-hovering { cursor: pointer; }
.sky:focus-visible { box-shadow: inset 0 0 0 1px var(--gold); }
/* Rice-paper tooth and fibres over the whole scene, very faint */
.paper {
  position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0.09; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8 0.12' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.1 -0.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
}

/* ---------- Top bar ---------- */
.bar {
  position: fixed; inset: 0 0 auto; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px var(--gutter); pointer-events: none;
  background: linear-gradient(180deg, rgba(11, 21, 37, 0.65), transparent);
}
.bar > * { pointer-events: auto; }
.bar__home { font-family: var(--latin); letter-spacing: 0.32em; font-size: 14px; text-decoration: none; display: flex; align-items: baseline; gap: 10px; }
.bar__home span { font-family: var(--serif); letter-spacing: 0.3em; font-size: 12px; color: var(--moon-3); }
.bar__name { margin: 0; font-family: var(--qiji); font-size: 16px; font-weight: 400; letter-spacing: 0.5em; color: var(--moon-2); display: flex; gap: 14px; align-items: baseline; }
.bar__season { font-size: 12px; letter-spacing: 0.2em; color: var(--gold); }
.bar__tools { display: flex; gap: 6px; }

/* ---------- Quiet text buttons ---------- */
.tool {
  font-size: 13px; letter-spacing: 0.16em; padding: 7px 12px; color: var(--moon-2);
  border: 1px solid transparent; transition: color 0.3s var(--ease), border-color 0.3s var(--ease), background-color 0.3s var(--ease);
}
.tool:hover { color: var(--moon); border-color: var(--line); }
.tool--icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; font-size: 16px; letter-spacing: 0; }
.tool--sound { display: inline-flex; align-items: center; gap: 8px; }
.tool__wave { display: inline-flex; gap: 2px; align-items: flex-end; height: 10px; }
.tool__wave i { width: 2px; height: 3px; background: currentColor; }
.tool--sound[aria-pressed="true"] { color: var(--gold); }
.tool--sound[aria-pressed="true"] .tool__wave i { animation: wave 1.1s var(--ease) infinite alternate; }
.tool--sound[aria-pressed="true"] .tool__wave i:nth-child(2) { animation-delay: -0.35s; }
.tool--sound[aria-pressed="true"] .tool__wave i:nth-child(3) { animation-delay: -0.7s; }
@keyframes wave { from { height: 3px; } to { height: 10px; } }

/* ---------- Hero ---------- */
.hero {
  position: fixed; inset: 0; z-index: 5; pointer-events: none;
  display: grid; grid-template-columns: 1fr auto; align-items: start;
  padding: clamp(88px, 12vh, 140px) clamp(24px, 7vw, 120px) clamp(84px, 12vh, 120px);
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
}
.hero.is-away { opacity: 0; transform: translateY(-12px); visibility: hidden; transition: opacity 0.6s var(--ease), transform 0.6s var(--ease), visibility 0s 0.6s; }
.hero__title {
  grid-column: 2; grid-row: 1 / span 2; margin: 0;
  writing-mode: vertical-rl; display: flex; gap: clamp(18px, 2.4vw, 34px);
  font-family: var(--qiji); font-weight: 400; font-size: clamp(30px, min(3.1vw, 5.2vh), 50px); line-height: 1.1; letter-spacing: 0.26em;
  color: var(--moon); text-shadow: 0 0 30px rgba(11, 21, 37, 0.8);
}
.hero__title span { display: block; white-space: nowrap; }
.hero__title span:last-child { padding-top: 1.8em; }
.hero__aside { grid-column: 1; grid-row: 2; align-self: end; max-width: 30em; pointer-events: auto; }
.hero__sub { margin: 0; font-size: clamp(16px, 1.3vw, 20px); font-weight: 500; letter-spacing: 0.24em; color: var(--moon); }
.hero__motto { margin: 8px 0 0; font-family: var(--qiji); font-size: 16px; letter-spacing: 0.4em; color: var(--gold); }
.hero__actions { display: flex; flex-wrap: wrap; gap: 10px 26px; margin-top: 28px; }
.act {
  position: relative; font-size: 15px; font-weight: 500; letter-spacing: 0.3em; padding: 10px 2px 8px; color: var(--moon);
  border-bottom: 1px solid var(--line); transition: color 0.4s var(--ease), border-color 0.4s var(--ease);
  text-decoration: none; display: inline-block;
}
.act::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--gold);
  transform: scaleX(0); transform-origin: left; transition: transform 0.6s var(--ease-out);
}
.act:hover::after, .act:focus-visible::after { transform: scaleX(1); }
.act--primary { color: var(--gold); border-color: rgba(200, 181, 140, 0.5); }
.hero__count { margin: 22px 0 0; font-size: 12px; letter-spacing: 0.24em; color: var(--moon-3); }

/* ---------- Docks & legend ---------- */
.dock { position: fixed; z-index: 8; bottom: calc(18px + env(safe-area-inset-bottom)); display: flex; gap: 2px; align-items: center; }
.dock--left { left: var(--gutter); }
.legend {
  position: fixed; z-index: 8; right: var(--gutter); bottom: calc(22px + env(safe-area-inset-bottom)); margin: 0;
  display: flex; gap: 18px; font-size: 12px; letter-spacing: 0.14em; color: var(--moon-3);
}
.legend__item { display: inline-flex; align-items: center; gap: 8px; }
.legend__star { width: 7px; height: 7px; border-radius: 50%; background: var(--moon); box-shadow: 0 0 8px 2px rgba(241, 234, 219, 0.5); }
.legend__deco { width: 3px; height: 3px; border-radius: 50%; background: var(--ink); opacity: 0.7; }
.closing {
  position: fixed; z-index: 4; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  margin: 0; font-size: 12px; letter-spacing: 0.6em; color: var(--moon-3); pointer-events: none; white-space: nowrap;
}

/* ---------- Tooltip & notice ---------- */
.tip {
  position: fixed; z-index: 9; left: 0; top: 0; pointer-events: none; transform: translate(-50%, calc(-100% - 14px));
  padding: 6px 12px; background: rgba(11, 21, 37, 0.86); border: 1px solid var(--line);
  font-family: var(--ugc); font-size: 13px; letter-spacing: 0.1em; white-space: nowrap;
}
.tip small { font-family: var(--latin); font-style: italic; color: var(--gold); margin-left: 10px; letter-spacing: 0.04em; }
.notice {
  position: fixed; z-index: 6; left: 50%; top: 42%; transform: translate(-50%, -50%); margin: 0;
  font-size: 16px; letter-spacing: 0.4em; color: var(--moon-2); text-align: center; pointer-events: none;
}

/* ---------- Dialogs (search, list, archive, share) ---------- */
dialog { color: inherit; }
dialog::backdrop { background: rgba(6, 12, 22, 0.62); backdrop-filter: blur(2px); }
.seek, .sheet {
  border: 1px solid var(--line); background: rgba(13, 25, 42, 0.96); padding: clamp(24px, 4vw, 44px);
  width: min(560px, calc(100% - 32px)); max-height: min(80vh, 760px); overflow: auto;
}
.seek[open], .sheet[open] { animation: rise 0.6s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; font-size: 22px; color: var(--moon-3); line-height: 1; }
.close:hover { color: var(--moon); }
.close--dark { color: var(--paper-ink-2); z-index: 2; }
.close--dark:hover { color: var(--paper-ink); }
.close--small { position: static; width: 28px; height: 28px; font-size: 18px; }

.seek__title, .sheet__title { margin: 0; font-family: var(--qiji); font-weight: 400; font-size: 22px; letter-spacing: 0.5em; }
.seek__hint, .sheet__hint { margin: 6px 0 0; font-size: 13px; color: var(--moon-3); letter-spacing: 0.08em; }
.seek__field { display: flex; margin-top: 22px; border-bottom: 1px solid var(--moon-3); }
.seek__input {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--moon); font: inherit; font-size: 18px;
  letter-spacing: 0.12em; padding: 10px 0; outline: none;
}
.seek__input::placeholder { color: var(--moon-3); }
.seek__go { font-size: 15px; letter-spacing: 0.3em; color: var(--gold); padding: 0 4px 0 16px; }
.seek__state { min-height: 1.8em; margin-top: 16px; font-size: 14px; letter-spacing: 0.1em; color: var(--moon-2); }
.seek__state[data-kind="error"] { color: #e3b9a6; }
.seek__state .retry { color: var(--gold); border-bottom: 1px solid currentColor; margin-left: 8px; }
.seek__results { list-style: none; margin: 8px 0 0; padding: 0; }
.seek__results li + li { border-top: 1px solid var(--line-2); }
.result {
  width: 100%; display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; align-items: center; text-align: left;
  padding: 12px 6px; transition: background-color 0.3s var(--ease);
}
.result:hover, .result:focus-visible { background: rgba(241, 234, 219, 0.05); }
.result__avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.result__dot { width: 40px; height: 40px; display: grid; place-items: center; }
.result__dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--moon); box-shadow: 0 0 10px 3px rgba(241, 234, 219, 0.4); }
.result__name { font-family: var(--ugc); font-weight: 600; font-size: 16px; letter-spacing: 0.08em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result__meta { font-family: var(--latin); font-style: italic; font-size: 13px; color: var(--gold); }
.result__month { display: block; font-size: 12px; color: var(--moon-3); letter-spacing: 0.08em; }

.sheet__filter { display: flex; gap: 10px; align-items: center; margin-top: 18px; font-size: 13px; color: var(--moon-3); letter-spacing: 0.1em; }
.sheet__filter input { flex: 1; background: transparent; border: 0; border-bottom: 1px solid var(--line); color: var(--moon); font: inherit; padding: 6px 0; outline: none; }
.sheet__list { list-style: none; padding: 0; margin: 14px 0 0; columns: 2 220px; column-gap: 24px; }
.sheet__list li { break-inside: avoid; }
.sheet__list button { font-family: var(--ugc); width: 100%; display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-2); text-align: left; font-size: 14px; }
.sheet__list button:hover { color: var(--gold); }
.sheet__list small { font-family: var(--latin); font-style: italic; color: var(--moon-3); }
.sheet__pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; font-size: 13px; }

.archive { list-style: none; margin: 18px 0 0; padding: 0; }
.archive li + li { border-top: 1px solid var(--line-2); }
.archive button { width: 100%; text-align: left; padding: 16px 4px; display: grid; gap: 4px; }
.archive button:hover .archive__theme { color: var(--gold); }
.archive__ord { font-family: var(--latin); font-style: italic; color: var(--gold); font-size: 14px; }
.archive__theme { font-size: 18px; letter-spacing: 0.24em; transition: color 0.3s var(--ease); }
.archive__meta { font-size: 12px; color: var(--moon-3); letter-spacing: 0.1em; }
.archive__current { color: var(--gold); margin-left: 8px; font-size: 12px; letter-spacing: 0.2em; }

.sheet--share { width: min(520px, calc(100% - 32px)); }
.share__img { width: 100%; height: auto; display: block; margin-top: 16px; border: 1px solid var(--line); }
.share__actions { display: flex; gap: 24px; margin-top: 18px; }

/* ---------- 知音笺 Letter ---------- */
.letter {
  position: fixed; z-index: 12; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  padding: clamp(64px, 9vh, 96px) 18px 18px; display: flex; outline: none;
  transform: translateX(0); transition: transform 0.7s var(--ease-out), opacity 0.5s var(--ease);
}
.letter[hidden] { display: flex; transform: translateX(104%); opacity: 0; pointer-events: none; visibility: hidden; transition: transform 0.5s var(--ease), opacity 0.4s var(--ease), visibility 0s 0.5s; }
.letter__paper {
  position: relative; flex: 1; overflow: auto; color: var(--paper-ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 30%),
    var(--paper);
  padding: 44px 34px 30px 34px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
}
/* Inner hairline frame and a narrow column rule, like a traditional letter sheet */
.letter__paper::before { content: ""; position: absolute; inset: 10px; border: 1px solid rgba(200, 181, 140, 0.7); pointer-events: none; }
.letter__paper::after {
  content: ""; position: absolute; inset: 10px; pointer-events: none; opacity: 0.35;
  background: repeating-linear-gradient(90deg, transparent 0 46px, rgba(200, 181, 140, 0.35) 46px 47px);
  -webkit-mask: linear-gradient(180deg, #000, transparent 60%); mask: linear-gradient(180deg, #000, transparent 60%);
}
.letter__code {
  position: absolute; top: 60px; right: 22px; margin: 0; writing-mode: vertical-rl; white-space: nowrap;
  font-size: 12px; letter-spacing: 0.32em; color: #8c7547;
}
.letter__season { margin: 0; font-size: 12px; letter-spacing: 0.4em; color: var(--paper-ink-2); }
.letter__head { display: flex; align-items: center; gap: 16px; margin-top: 22px; padding-right: 28px; }
.letter__avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid rgba(140, 117, 71, 0.6); padding: 3px; background: var(--paper); }
.letter__name { font-family: var(--ugc); margin: 0; font-weight: 700; font-size: clamp(24px, 3vw, 30px); letter-spacing: 0.16em; line-height: 1.35; word-break: break-word; }
/* the inscription, as if written on the letter by hand */
.letter__success { margin: 18px 0 0; font-family: var(--kai); font-size: 20px; letter-spacing: 0.1em; line-height: 1.9; color: #2d3a45; white-space: pre-line; }
.letter__message {
  margin: 20px 0 0; padding: 14px 0 14px 18px; border-left: 1px solid #b19a6a;
  font-family: var(--ugc); font-size: 15px; line-height: 2; letter-spacing: 0.06em; color: var(--paper-ink); word-break: break-word;
}
.letter__meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 18px; margin: 20px 0 0; font-size: 13px; }
.letter__meta dt { color: var(--paper-ink-2); letter-spacing: 0.3em; }
.letter__meta dd { margin: 0; letter-spacing: 0.06em; }
.letter__motif { margin: 22px 0 0; padding-top: 14px; border-top: 1px solid var(--paper-line); }
.letter__staff { width: 100%; height: auto; display: block; }
.letter__motif figcaption { margin-top: 6px; font-size: 13px; letter-spacing: 0.3em; color: var(--paper-ink-2); }
.letter__actions { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 22px; }
.act--ink { color: var(--paper-ink); border-color: var(--paper-line); font-size: 14px; letter-spacing: 0.2em; }
.act--ink::after { background: #8c7547; }
.letter__link { display: inline-block; margin-top: 16px; font-size: 13px; color: #6d5a32; word-break: break-all; }

/* ---------- Ensemble player ---------- */
.ensemble {
  position: fixed; z-index: 11; left: 50%; bottom: calc(64px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: grid; grid-template-columns: auto auto auto; grid-template-areas: "title controls close" "source volume mute" "now now now";
  gap: 10px 22px; align-items: center; padding: 16px 22px; width: max-content; max-width: calc(100% - 24px);
  background: rgba(11, 21, 37, 0.88); border: 1px solid var(--line); backdrop-filter: blur(6px);
}
.ensemble[hidden] { display: none; }
.ensemble__title { grid-area: title; }
.ensemble__name { margin: 0; font-size: 14px; letter-spacing: 0.4em; }
.ensemble__part { margin: 0; font-size: 12px; letter-spacing: 0.2em; color: var(--gold); }
.ensemble__controls { grid-area: controls; display: flex; gap: 4px; }
.tool--play { width: 40px; height: 34px; padding: 0; color: var(--gold); border-color: rgba(200, 181, 140, 0.4); letter-spacing: 0; }
.ensemble__source { grid-area: source; display: flex; border: 1px solid var(--line); }
.ensemble__source button { font-size: 12px; letter-spacing: 0.14em; padding: 5px 10px; color: var(--moon-3); }
.ensemble__source [aria-checked="true"] { color: var(--night); background: var(--moon-2); }
.ensemble__volume { grid-area: volume; display: flex; gap: 8px; align-items: center; font-size: 12px; letter-spacing: 0.14em; color: var(--moon-3); }
.ensemble__volume input { width: 110px; accent-color: var(--gold); }
[data-mute] { grid-area: mute; }
[data-mute][aria-pressed="true"] { color: var(--gold); }
.ensemble__now { grid-area: now; margin: 0; font-size: 12px; letter-spacing: 0.14em; color: var(--moon-2); min-height: 1.6em; }
.ensemble .close--small { grid-area: close; justify-self: end; }

.noscript { position: fixed; inset: 40% 0 auto; text-align: center; letter-spacing: 0.3em; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .bar__name { display: none; }
  .hero { grid-template-columns: 1fr; padding-top: 96px; }
  .hero__title { grid-column: 1; grid-row: 1; justify-self: end; font-size: clamp(28px, 7vw, 40px); }
  .hero__aside { grid-row: 2; }
  .legend { display: none; }
  .closing { display: none; }
}
@media (max-width: 560px) {
  body { font-size: 14px; }
  .bar { padding-top: 14px; }
  .bar__home span { display: none; }
  .tool { padding: 7px 8px; letter-spacing: 0.1em; }
  .hero { padding: 86px 22px 92px; }
  .hero__actions { gap: 6px 20px; margin-top: 20px; }
  .act { font-size: 14px; letter-spacing: 0.22em; }
  .dock { left: 8px; right: 8px; justify-content: space-between; }
  .letter { top: auto; height: min(78vh, 680px); width: 100%; padding: 0; }
  .letter[hidden] { transform: translateY(104%); }
  .letter__paper { padding: 36px 24px 24px; }
  .ensemble {
    grid-template-columns: 1fr auto; grid-template-areas: "title close" "controls controls" "source source" "volume mute" "now now";
    bottom: calc(60px + env(safe-area-inset-bottom)); width: calc(100% - 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* 朱砂印 — a small square seal at the foot of the letter, like an artist's mark */
.letter__seal {
  position: absolute; right: 28px; bottom: 24px; width: 58px; height: 58px;
  transform: rotate(-4deg); mix-blend-mode: multiply; opacity: 0.88; pointer-events: none;
}
.letter__seal svg { width: 100%; height: 100%; display: block; }

.letter__actions { padding-right: 70px; }

/* Hero: the two title columns rise one after the other, then the words beneath */
@keyframes hero-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
.hero__title span { animation: hero-in 1.6s var(--ease-out) both; }
.hero__title span:first-child { animation-delay: 0.25s; }
.hero__title span:last-child { animation-delay: 0.9s; }
.hero__aside { animation: hero-in 1.4s var(--ease-out) 1.5s both; }
