/* ===== 调色板：界面与 Canvas 场景共用（场景读取 --sc-*） ===== */
:root {
  --paper: #f8f2e9; --paper-a: rgb(248 242 233 / .95); --paper-b: rgb(248 242 233 / .8);
  --ink: #1d272c; --muted: #4a565b; --line: #d6cab8; --vermilion: #b2341d; --on-red: #fff7ee;
  --moss: #4a5f3f; --wood: #ecdcc0; --wood-edge: #a07c52; --wood-ink: #33261a; --sea-ink: #24505f;
  --danger: #9d2e22; --wake: rgb(36 80 95 / .32);
  --sc-sky0: #b7c3d6; --sc-sky1: #efc7b6; --sc-sky2: #f9d9ae;
  --sc-late0: #a6c3dd; --sc-late1: #e3dccd; --sc-late2: #fbeccc;
  --sc-sun: #fff0c8; --sc-isle: #93a0b0; --sc-sea0: #cfc8c2; --sc-sea1: #557f92; --sc-foam: #ffffff;
  --sc-torii: #c23a21; --sc-toriitop: #2b2523; --sc-stone: #8e897c; --sc-moss: #5f7550;
  --sc-glow: #ffc879; --sc-mist: #f5ede4; --sc-mote: #ffe3a6; --sc-rain: #5c6f7d; --sc-dark: 0;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif SC", "Songti SC", "STSong", serif;
  --sans: "Hiragino Sans", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --paper: #1c1a23; --paper-a: rgb(28 26 35 / .94); --paper-b: rgb(28 26 35 / .78);
    --ink: #efe6d8; --muted: #c4b9ab; --line: #423b4d; --vermilion: #f0704f; --on-red: #1c1a23;
    --moss: #a3b892; --wood: #3b2d24; --wood-edge: #8a6845; --wood-ink: #f2e4cd; --sea-ink: #a2c7d5;
    --danger: #ff9e8f; --wake: rgb(255 183 90 / .16);
    --sc-sky0: #29244a; --sc-sky1: #6c3e5d; --sc-sky2: #d47b50;
    --sc-late0: #0e1229; --sc-late1: #211f44; --sc-late2: #5b3a4f;
    --sc-sun: #ffb66e; --sc-isle: #2a283c; --sc-sea0: #6b4757; --sc-sea1: #0f1a29; --sc-foam: #d9d0e2;
    --sc-torii: #b33a24; --sc-toriitop: #141114; --sc-stone: #5a5560; --sc-moss: #5d6e4c;
    --sc-glow: #ffb75a; --sc-mist: #5f5470; --sc-mote: #f3e48a; --sc-rain: #9aa6c4; --sc-dark: 1;
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --paper: #1c1a23; --paper-a: rgb(28 26 35 / .94); --paper-b: rgb(28 26 35 / .78);
  --ink: #efe6d8; --muted: #c4b9ab; --line: #423b4d; --vermilion: #f0704f; --on-red: #1c1a23;
  --moss: #a3b892; --wood: #3b2d24; --wood-edge: #8a6845; --wood-ink: #f2e4cd; --sea-ink: #a2c7d5;
  --danger: #ff9e8f; --wake: rgb(255 183 90 / .16);
  --sc-sky0: #29244a; --sc-sky1: #6c3e5d; --sc-sky2: #d47b50;
  --sc-late0: #0e1229; --sc-late1: #211f44; --sc-late2: #5b3a4f;
  --sc-sun: #ffb66e; --sc-isle: #2a283c; --sc-sea0: #6b4757; --sc-sea1: #0f1a29; --sc-foam: #d9d0e2;
  --sc-torii: #b33a24; --sc-toriitop: #141114; --sc-stone: #5a5560; --sc-moss: #5d6e4c;
  --sc-glow: #ffb75a; --sc-mist: #5f5470; --sc-mote: #f3e48a; --sc-rain: #9aa6c4; --sc-dark: 1;
  color-scheme: dark;
}

/* ===== 基础 ===== */
*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth; scroll-padding-top: calc(var(--bar-h, 64px) + 16px);
  /* 无脚本或首帧前的场景底色；Canvas 绘制后覆盖其上 */
  background: linear-gradient(var(--sc-sky0), var(--sc-sky1) 30%, var(--sc-sky2) 49%, var(--sc-sea0) 50%, var(--sc-sea1)) fixed;
}
body { margin: 0; min-height: 100vh; font-family: var(--sans); font-size: 15px; line-height: 1.7; color: var(--ink); font-synthesis: none; -webkit-text-size-adjust: 100%; }
#scene { position: fixed; inset: 0 auto auto 0; width: 100%; height: 100vh; height: 100lvh; z-index: -1; display: block; pointer-events: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
button, a, input, textarea, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--vermilion); outline-offset: 3px; }
::selection { background: var(--vermilion); color: var(--on-red); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 40; background: var(--paper); padding: 12px; }
.skip:focus { top: 12px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: clamp(20px, 2vw, 25px); line-height: 1.35; letter-spacing: .04em; }
h3 { font-size: 16px; line-height: 1.5; }

/* ===== 顶栏与灯笼导航 ===== */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; column-gap: clamp(10px, 2vw, 28px); row-gap: 0; padding: 8px clamp(16px, 4vw, 48px); background: var(--paper-a); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; font-family: var(--serif); font-size: 19px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.lantern-nav { display: flex; gap: 2px; margin-inline: auto; min-width: 0; max-width: 100%; }
.nav-item { position: relative; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; font-size: 14px; color: var(--muted); text-decoration: none; white-space: nowrap; transition: color .25s; }
.nav-item:hover, .nav-item.active { color: var(--ink); }
.nav-item.active::after { content: ""; position: absolute; inset: auto 12px 5px; height: 2px; background: var(--vermilion); }
.lamp { width: 11px; height: 15px; flex-shrink: 0; border: 1.5px solid currentColor; border-top-width: 4px; border-radius: 2px 2px 1px 1px; transition: background .3s, box-shadow .3s; }
.nav-item:hover .lamp, .nav-item:focus-visible .lamp, .nav-item.active .lamp { background: var(--sc-glow); box-shadow: 0 0 10px 2px var(--sc-glow); }
.controls { display: flex; align-items: center; gap: 6px; }
/* 折叠级别 1：导航独占第二行，均分；级别 2：听雨/明暗只留图标 */
.topbar.is-stacked .controls { margin-left: auto; }
.topbar.is-stacked .lantern-nav { order: 3; flex: 1 0 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; container-type: inline-size; }
.topbar.is-stacked .nav-item { justify-content: center; padding-inline: 4px; font-size: 13px; }
.topbar.is-stacked .nav-item.active::after { inset-inline: 8px; }
.topbar.is-compact .rain-label, .topbar.is-compact .theme-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.topbar.is-compact .chip { padding-inline: 11px; }
@container (max-width: 420px) {
  .nav-item { flex-direction: column; gap: 3px; min-height: 52px; padding-block: 6px 9px; font-size: 12.5px; white-space: normal; text-align: center; line-height: 1.25; }
  .nav-item.active::after { bottom: 3px; }
}
.chip { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 6px 13px; border: 1px solid var(--line); border-radius: 2px; background: var(--paper-a); color: var(--ink); font-size: 13px; line-height: 1.2; white-space: nowrap; transition: border-color .2s, background .2s, color .2s; }
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed=true] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.rain-glyph { width: 12px; height: 14px; background: repeating-linear-gradient(105deg, currentColor 0 1.5px, transparent 1.5px 4px); opacity: .85; }
.theme-glyph { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid currentColor; background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
#theme[data-mode=light] .theme-glyph { background: transparent; }
#theme[data-mode=dark] .theme-glyph { background: currentColor; }
.ambient { position: relative; }
.ambient summary { list-style: none; cursor: pointer; }
.ambient summary::-webkit-details-marker { display: none; }
.ambient[open] summary { border-color: var(--ink); }
.ambient-panel { position: absolute; right: 0; top: calc(100% + 8px); width: min(300px, calc(100vw - 32px)); max-width: calc(100vw - 24px); translate: var(--panel-shift, 0) 0; padding: 16px 18px; background: var(--paper); border: 1px solid var(--line); border-top: 3px solid var(--ink); box-shadow: 0 18px 40px -18px var(--wake); display: grid; gap: 6px; z-index: 30; }
.ambient-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px 0 4px; font-family: var(--serif); font-size: 15px; }
.ambient-head .chip { min-height: 40px; }
@media (max-width: 640px) {
  .ambient-panel { position: fixed; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); top: auto; width: auto; max-width: none; max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; translate: none; z-index: 45; box-shadow: 0 -12px 40px -12px rgb(0 0 0 / .35); }
}
.ambient-panel label { display: flex; justify-content: space-between; font-size: 13px; }
.ambient-panel output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; min-height: 32px; accent-color: var(--vermilion); margin: 0 0 6px; }
.ambient-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ambient-status { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 13px; color: var(--muted); cursor: pointer; }
.ambient-panel .check { justify-content: flex-start; }
input[type=checkbox] { accent-color: var(--vermilion); width: 18px; height: 18px; flex-shrink: 0; margin: 0; }

/* ===== 主体 ===== */
main { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 48px) 32px; }
.text-button { background: none; border: 0; min-height: 44px; padding: 8px 4px; font-size: 14px; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 5px; }
.text-button:hover { text-decoration-color: var(--vermilion); }
.primary { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 22px; border: 0; border-radius: 2px; background: var(--vermilion); color: var(--on-red); font-family: var(--serif); font-size: 16px; letter-spacing: .08em; text-decoration: none; white-space: nowrap; transition: filter .2s; }
.primary:hover { filter: brightness(1.08) saturate(1.1); }

/* 开场：问候随海雾散开浮现（全页唯一的编排动画） */
.hero { display: grid; grid-template-columns: max-content minmax(0, 36rem); gap: clamp(16px, 3vw, 36px); align-items: start; padding-block: clamp(44px, 13vh, 150px) clamp(36px, 10vh, 110px); }
.plaque { writing-mode: vertical-rl; justify-self: start; width: calc(1em + 18px); margin: 6px 0 0; padding: 14px 7px; font-family: var(--serif); font-size: 15px; letter-spacing: .22em; background: var(--paper-b); border: 2px solid var(--vermilion); box-shadow: inset 0 0 0 3px var(--paper-b), inset 0 0 0 4px var(--vermilion); }
h1 { font-size: clamp(30px, 4.4vw, 56px); line-height: 1.3; letter-spacing: .03em; text-wrap: balance; text-shadow: 0 0 22px var(--sc-sky1), 0 0 3px var(--sc-sky1); }
.subtitle { margin: 16px 0 0; max-width: 30em; font-family: var(--serif); font-size: clamp(16px, 1.6vw, 20px); text-shadow: 0 0 14px var(--sc-sky1), 0 0 2px var(--sc-sky1); }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin-top: 28px; }
.hint { display: inline-block; margin: 18px 0 0; padding: 4px 10px; font-size: 13px; background: var(--paper-b); border-left: 3px solid var(--sc-glow); }
.hero > * { animation: surface 1.8s cubic-bezier(.2, .7, .2, 1) both; }
.hero > :nth-child(2) { animation-delay: .5s; }
@keyframes surface { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } }

.sheet { position: relative; background: var(--paper-a); }
.slab::after { content: ""; position: absolute; inset: 100% 5% auto; height: 22px; background: radial-gradient(ellipse at 50% 0, var(--wake), transparent 70%); pointer-events: none; }
.heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.slab { margin-top: clamp(32px, 5vw, 56px); padding: clamp(18px, 2.6vw, 32px); border-left: 6px solid var(--moss); }
.stone-lamp { position: absolute; left: 4px; top: 2px; width: 18px; height: 26px; border: 2px solid var(--muted); border-top-width: 6px; border-radius: 3px 3px 1px 1px; background: linear-gradient(transparent 30%, var(--line) 30% 70%, transparent 70%) center / 8px 100% no-repeat; }

h1, .brand span { overflow-wrap: anywhere; }
.public-project { position: relative; padding-left: 40px; }
.public-project a { display: inline-flex; align-items: center; min-height: 44px; text-underline-offset: .2em; }
.public-project p { margin: 0; color: var(--muted); }
@media (max-width: 760px) {
  .topbar { padding-block: 6px 0; }
  .hero { padding-block: 32px 40px; gap: 14px; }
}
@media (max-width: 420px) {
  .brand span { font-size: 17px; }
  .plaque { font-size: 13px; padding: 10px 5px; }
  .hero-actions { gap: 4px 14px; }
}
@media (max-width: 699px) and (orientation: portrait) {
  .hero { min-height: calc(100svh - var(--bar-h, 108px)); align-content: start; padding-block: 22px 24px; }
  h1 { font-size: clamp(26px, 7.6vw, 32px); }
  .hero-actions { margin-top: 18px; }
  .hero-actions .primary { min-height: 44px; padding-inline: 16px; font-size: 15px; }
  .hint { margin-top: 12px; font-size: 12.5px; line-height: 1.6; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
