/* ============================================================
   转生轮 · 历史投胎
   幽夜 · 鎏金 · 朱砂 —— 与《人生4000周》同族但气质相反：
   A 是宣纸上的账，B 是黑夜里的轮。
   ============================================================ */

:root {
  --night: #14110c;
  --night-2: #1c1812;
  --paper: #f5efe3;
  --paper-dim: rgba(245, 239, 227, 0.66);
  --paper-faint: rgba(245, 239, 227, 0.38);
  --gold: #c9a227;
  --gold-dim: rgba(201, 162, 39, 0.55);
  --cinnabar: #b53a26;
  --cinnabar-bright: #d85539;
  --line: rgba(245, 239, 227, 0.14);
  --serif-display: "Fraunces", "Noto Serif SC", serif;
  --sans: "Noto Sans SC", "Spectral", sans-serif;
  --margin-x: clamp(20px, 6vw, 88px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: radial-gradient(1100px 640px at 50% -8%, #26201732 0%, transparent 60%), var(--night);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 星尘噪点 */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.92 0 0 0 0 0.87 0 0 0 0 0.78 0 0 0 0.035 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: rgba(201, 162, 39, 0.3); }

main, header, footer { position: relative; z-index: 2; }

/* ============ 头部 ============ */
.site-head { display: flex; justify-content: space-between; align-items: baseline; padding: 16px var(--margin-x) 6px; }
.brand { font-family: var(--serif-display); font-weight: 700; font-size: 19px; letter-spacing: 0.04em; color: var(--paper); }
.brand .brand-en { font-size: 11px; letter-spacing: 0.28em; color: var(--gold-dim); margin-left: 12px; font-weight: 500; }
.lang button {
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 13px; letter-spacing: 0.08em;
  color: var(--paper-faint); padding: 4px 8px; border-bottom: 2px solid transparent;
}
.lang button.on { color: var(--gold); border-bottom-color: var(--gold); }
.lang button:hover { color: var(--paper); }

/* ============ 转生轮舞台（首屏自适应：头图+轮盘+按钮 = 一屏） ============ */
.stage {
  max-width: 760px;
  margin: 0 auto;
  min-height: calc(100vh - 88px);
  min-height: calc(100svh - 88px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.6vh, 24px) var(--margin-x) clamp(10px, 2vh, 22px);
  text-align: center;
  animation: rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.kicker { font-size: 11.5px; letter-spacing: 0.32em; color: var(--gold); font-weight: 600; margin-bottom: clamp(8px, 1.4vh, 14px); }
.hero-line {
  font-family: var(--serif-display);
  font-size: clamp(20px, 5vw, 34px);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: 0.01em;
}
.hero-sub { color: var(--paper-dim); font-size: clamp(13px, 1.7vw, 15.5px); margin-top: clamp(4px, 0.8vh, 10px); }

.wheel-box {
  position: relative;
  width: min(92vw, 460px, 47svh);
  margin: clamp(8px, 1.8vh, 26px) auto;
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
}
#wheel-canvas { width: 100%; height: 100%; display: block; }
#label-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
.pointer {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-top: 22px solid var(--cinnabar-bright);
  filter: drop-shadow(0 2px 6px rgba(181, 58, 38, 0.5));
  z-index: 3;
}
.pointer::after {
  content: "";
  position: absolute; top: -10px; left: -8px;
  width: 16px; height: 6px; border-radius: 3px;
  background: var(--cinnabar);
}

.btn {
  font-family: var(--sans);
  font-size: 15px; letter-spacing: 0.14em; font-weight: 600;
  cursor: pointer; border: none;
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, opacity 0.2s;
}
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.btn-primary {
  background: linear-gradient(180deg, #c74a30, var(--cinnabar));
  color: #f8ecd8;
  padding: 16px 46px;
  box-shadow: 0 10px 30px rgba(181, 58, 38, 0.35), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary:hover { background: linear-gradient(180deg, #d85539, var(--cinnabar)); transform: translateY(-2px); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.45; cursor: wait; transform: none; }
.btn-big { font-size: 16px; padding: clamp(12px, 1.8vh, 16px) 52px; letter-spacing: 0.3em; text-indent: 0.3em; }
.btn-ghost { background: transparent; color: var(--paper); border: 1.5px solid var(--line); padding: 13px 26px; }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn-text { background: none; color: var(--paper-faint); padding: 13px 10px; text-decoration: underline; text-underline-offset: 4px; }
.btn-text:hover { color: var(--paper); }

.lives-line { margin-top: clamp(10px, 1.6vh, 18px); font-size: 13px; color: var(--gold-dim); letter-spacing: 0.12em; min-height: 1.5em; }
.odds-note { margin-top: 2px; font-size: 11.5px; color: var(--paper-faint); }

/* ============ 一世演示 ============ */
.life {
  position: fixed; inset: 0;
  background: radial-gradient(900px 540px at 50% 12%, #221c13 0%, var(--night) 62%);
  z-index: 40;
  overflow-y: auto;
  overflow-x: hidden;
  animation: lifefade 0.6s ease both;
}
@keyframes lifefade { from { opacity: 0; } to { opacity: 1; } }
.life.hidden { display: none !important; }
.life-inner { max-width: 640px; margin: 0 auto; padding: clamp(48px, 9vh, 110px) 24px 80px; }

.year-roll {
  text-align: center;
  font-family: var(--serif-display);
  font-weight: 850;
  font-size: clamp(44px, 9vw, 84px);
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
  letter-spacing: 0.02em;
}
.year-roll.era { font-size: clamp(18px, 3.4vw, 26px); color: var(--paper-dim); font-weight: 600; margin-top: 10px; }

.seq { margin-top: clamp(26px, 5vh, 50px); display: grid; gap: 14px; }
.seq-line {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
  font-size: clamp(15px, 2.4vw, 18px);
  color: var(--paper-dim);
}
.seq-line.show { opacity: 1; transform: none; }
.seq-line.age { font-family: var(--serif-display); font-weight: 700; color: var(--paper); font-size: clamp(22px, 4.6vw, 34px); }
.seq-line.event { color: var(--gold); }
.seq-line.event .ev-tag {
  display: inline-block;
  font-size: 0.72em; letter-spacing: 0.18em;
  border: 1px solid var(--gold-dim);
  padding: 2px 10px; margin-right: 10px;
  vertical-align: 2px;
  border-radius: 2px;
}
.seq-line.event.war .ev-tag { border-color: var(--cinnabar-bright); color: var(--cinnabar-bright); }
.seq-line.event.famine .ev-tag { border-color: var(--cinnabar-bright); color: var(--cinnabar-bright); }
.seq-line.birth { font-family: var(--serif-display); font-size: clamp(19px, 3.4vw, 26px); color: var(--paper); font-weight: 700; }
.seq-line.birth .b-dyn { color: var(--gold); }
.seq-line.death {
  font-family: var(--serif-display);
  font-size: clamp(22px, 4.4vw, 34px);
  font-weight: 850;
  color: var(--paper);
  border-left: 4px solid var(--cinnabar-bright);
  padding-left: 16px;
}
.seq-line.death .d-cause { color: var(--cinnabar-bright); }

/* 死亡闪帧 */
.death-flash {
  position: fixed; inset: 0; z-index: 50;
  pointer-events: none;
  background: radial-gradient(700px 420px at 50% 45%, rgba(216, 85, 57, 0.32), rgba(20, 17, 12, 0.9) 75%);
  opacity: 0;
}
.death-flash.on { animation: flash 0.9s ease-out both; }
@keyframes flash {
  0% { opacity: 0; } 18% { opacity: 1; } 100% { opacity: 0; }
}

/* ============ 结算报告 ============ */
.report {
  margin-top: clamp(34px, 6vh, 60px);
  border-top: 1.5px solid var(--line);
  padding-top: 26px;
  animation: rise 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.report.hidden { display: none !important; }
.rep-kicker { font-size: 12px; letter-spacing: 0.34em; color: var(--gold); font-weight: 600; }
.rep-title { font-family: var(--serif-display); font-size: clamp(30px, 6vw, 52px); font-weight: 850; margin-top: 10px; line-height: 1.2; }
.rep-dates { color: var(--paper-dim); font-size: 15px; margin-top: 8px; font-variant-numeric: tabular-nums; }

.rep-stats { margin-top: 26px; }
.stat {
  padding: 18px 0 14px;
  border-bottom: 1px dashed var(--line);
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: var(--d, 0s);
}
.report.show .stat { opacity: 1; transform: none; }
.stat-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.stat-label { font-size: clamp(14px, 2vw, 17px); font-weight: 600; letter-spacing: 0.04em; }
.stat-num {
  margin-left: auto;
  font-family: var(--serif-display);
  font-weight: 800;
  font-size: clamp(30px, 5.2vw, 46px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
  color: var(--paper);
}
.stat-num .stat-unit { font-size: 0.4em; font-weight: 600; color: var(--paper-faint); margin-left: 8px; letter-spacing: 0.06em; }
.stat-num.gold { color: var(--gold); }
.stat-num.red { color: var(--cinnabar-bright); }
.stat-sub { font-size: 12.5px; color: var(--paper-faint); margin-top: 7px; }

.rep-odds {
  margin-top: 22px;
  font-size: 12.5px;
  color: var(--paper-faint);
  letter-spacing: 0.04em;
  line-height: 2;
}
.rep-odds b { color: var(--gold); font-weight: 600; }
.rep-closing { margin-top: 22px; font-family: var(--serif-display); font-size: clamp(18px, 3vw, 24px); font-weight: 600; }
.rep-closing::before { content: "—— "; color: var(--cinnabar-bright); }
.actions { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 30px; align-items: center; }

/* ============ 资源 HUD ============ */
.hud {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px 0 12px;
  margin-bottom: 18px;
  background: linear-gradient(180deg, rgba(20, 17, 12, 0.96) 70%, rgba(20, 17, 12, 0));
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--paper-faint);
}
.hud-row { display: flex; justify-content: center; gap: 26px; }
.hud-row-mini { gap: 18px; margin-top: 2px; }
.hud-mini { font-size: 11px; letter-spacing: 0.08em; }
.hud-mini b {
  font-family: var(--serif-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--gold-dim);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 2ch;
}
.hud-mini b.up { animation: hudup 0.9s ease; color: var(--gold); }
.hud-mini b.down { animation: huddown 0.9s ease; color: var(--cinnabar-bright); }
.click-hint {
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--paper-faint);
  opacity: 0.55;
  margin-top: 4px;
}
.pace-ctl { display: inline-flex; gap: 4px; margin-left: 10px; align-items: center; }
.pace-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--paper-faint);
  font-family: var(--sans);
  font-size: 10.5px;
  padding: 1px 8px;
  cursor: pointer;
  border-radius: 2px;
  letter-spacing: 0.05em;
}
.pace-btn:hover { border-color: var(--gold); color: var(--gold); }
.pace-btn.on { border-color: var(--cinnabar); color: var(--cinnabar-bright); background: rgba(181, 58, 38, 0.08); }
.hud.hidden { display: none !important; }
.hud-item b {
  font-family: var(--serif-display);
  font-weight: 800;
  font-size: 19px;
  color: var(--paper);
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 2ch;
}
.hud-item b.up { animation: hudup 0.9s ease; color: var(--gold); }
.hud-item b.down { animation: huddown 0.9s ease; color: var(--cinnabar-bright); }
@keyframes hudup { 0% { transform: translateY(-6px); } 100% { transform: none; } }
@keyframes huddown { 0% { transform: translateY(6px); } 30% { transform: translateY(2px); } 100% { transform: none; } }

/* ============ 困境抉择卡 ============ */
.scenario {
  border: 1.5px solid var(--gold-dim);
  background: rgba(201, 162, 39, 0.05);
  padding: 20px 22px 18px;
  margin: 10px 0 6px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1), border-color 0.3s;
  border-radius: 3px;
}
.scenario.show { opacity: 1; transform: none; }
.scenario.resolved { border-color: var(--line); background: rgba(245, 239, 227, 0.02); }
.sc-tag {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--cinnabar-bright);
  font-weight: 700;
  margin-bottom: 10px;
}
.sc-setup {
  font-size: clamp(15px, 2.4vw, 17.5px);
  color: var(--paper);
  line-height: 1.8;
  margin-bottom: 12px;
}
.sc-ctx {
  font-size: 12.5px;
  color: rgba(201, 162, 39, 0.85);
  background: rgba(201, 162, 39, 0.06);
  border-left: 2px solid var(--gold-dim);
  padding: 6px 10px;
  margin-bottom: 14px;
  line-height: 1.7;
}
.sc-ctx-label {
  font-weight: 700;
  letter-spacing: 0.14em;
  margin-right: 6px;
}
.sc-choices { display: grid; gap: 10px; }
.choice-btn {
  text-align: left;
  font-family: var(--sans);
  font-size: 14.5px;
  letter-spacing: 0.04em;
  color: var(--paper);
  background: rgba(245, 239, 227, 0.04);
  border: 1px solid var(--line);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  border-radius: 2px;
}
.choice-btn:hover:not(:disabled) { border-color: var(--gold); background: rgba(201, 162, 39, 0.08); transform: translateX(4px); }
.choice-btn:disabled { opacity: 0.35; cursor: default; }
.choice-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* 蛇形年轨：连续无故事岁数的合并行 */
.seq-line.age-run {
  font-family: var(--serif-display);
  font-weight: 600;
  font-size: clamp(14px, 2.4vw, 19px);
  color: rgba(245, 239, 227, 0.42);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.seq-line.age-run .arr { color: var(--gold-dim); font-weight: 400; }

.seq-line.chosen { color: var(--gold); font-weight: 600; }

/* 人生细节口味：比事件更轻的一层 */
.seq-line.flavor {
  font-size: 13.5px;
  color: rgba(245, 239, 227, 0.6);
  line-height: 1.6;
}
.seq-line.flavor::before { content: "· "; color: var(--gold-dim); font-weight: 700; }

/* 结算心性行 */
.attr-line { font-size: 0.62em; font-weight: 700; letter-spacing: 0.05em; color: var(--gold); }

/* ============ 像素图 ============ */
.px { image-rendering: pixelated; }
.px-inline {
  width: 24px; height: 24px;
  vertical-align: -6px;
  margin-right: 8px;
  image-rendering: pixelated;
}
.sc-icon {
  width: 28px; height: 28px;
  vertical-align: -9px;
  margin-right: 9px;
  image-rendering: pixelated;
}
.rep-emblem {
  width: 92px; height: 92px;
  image-rendering: pixelated;
  margin-bottom: 10px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}
.rep-emblem.hidden { display: none !important; }
.seq-line.outcome { color: var(--paper); }
.seq-line.fx-line { font-size: 12.5px; color: var(--paper-faint); letter-spacing: 0.08em; }
.scenario + .seq-line.age { margin-top: 14px; }

/* ============ 页脚 ============ */
.site-foot { padding: 44px var(--margin-x) 36px; font-size: 11.5px; color: var(--paper-faint); border-top: 1px solid var(--line); margin-top: 50px; }

/* ============ 弹层 ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(8, 6, 3, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; z-index: 60;
}
.modal.hidden { display: none !important; }
.modal-card {
  background: var(--night-2);
  border: 1px solid var(--line);
  padding: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.6);
  max-height: 94vh; overflow: auto;
  animation: rise 0.35s cubic-bezier(0.2,0.7,0.2,1) both;
}
.modal-card img { display: block; max-width: min(76vw, 380px); max-height: 62vh; width: auto; height: auto; border: 1px solid var(--line); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.modal-actions .btn { padding: 11px 20px; font-size: 13.5px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 34px;
  transform: translate(-50%, 20px);
  background: var(--paper); color: var(--night);
  font-size: 13.5px; letter-spacing: 0.06em;
  padding: 11px 22px;
  opacity: 0; pointer-events: none;
  transition: all 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  .brand .brand-en { display: none; }
  .btn-big { width: min(88vw, 340px); }
  .stat-num { font-size: 30px; }
  .year-roll { font-size: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .stage, .report, .modal-card, .life { animation: none !important; }
  .seq-line { transition: none; opacity: 1; transform: none; }
  .stat { transition: none; opacity: 1; transform: none; }
}
