/* ============================================================
 * style.css —— 午夜剧场 · 「暗室低语」设计系统
 *
 * 设计原则：UI 是暗处的一声低语——
 *   · 文字常驻可见度 0.45，需要时（活动/悬停）才升到 0.9
 *   · 无底块、无重框：引导交给光（呼吸金点）与 1px 细线
 *   · 唯一的 display 衬线只出现在开场标题一处
 *
 * 分层（自下而上）：
 *   背景幕 → 聚光灯(#spotlight) → 逻辑桌面(#table)
 *   → 前景特效(#fx-fg) → 调色层(#grade)
 *   → UI(字幕/控件/顶栏) → 开场遮罩(#overlay)
 *
 * 坐标约定（与 animator.js 一致）：
 *   #table 为 1200×700 逻辑桌面（竖屏 860×1080），中心为原点；
 *   缩放由 --table-scale 控制，牌尺寸由 --card-w/h 控制。
 * ============================================================ */

/* ---------- 1. tokens ---------- */
:root {
  /* 场景 */
  --stage-bg: #070b08;
  --gold: #d2aa62;
  --gold-strong: #e9d094;
  --gold-dim: #8f7540;
  --gold-line: rgba(210, 170, 98, 0.26);
  --ivory: #ece2c8;

  /* 文字可见性阶梯（brief：降低文字可见性） */
  --whisper: rgba(236, 226, 200, 0.45);   /* 常驻：低语 */
  --speak: rgba(236, 226, 200, 0.90);     /* 需要：清晰 */
  --faint: rgba(236, 226, 200, 0.28);     /* 装饰：将隐 */

  /* 绒布四级 */
  --felt-hi: #2f8155;
  --felt: #1c5939;
  --felt-lo: #0e3d26;
  --felt-edge: #0a3320;

  /* 逻辑桌面（竖屏由媒体查询覆盖） */
  --table-w: 1200px;
  --table-h: 700px;
}

/* ---------- 2. 基础 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  color-scheme: dark;
}

html, body {
  height: 100%;
  height: 100dvh;                     /* iOS 地址栏收放时视口正确 */
  overflow: hidden;
  overscroll-behavior: none;          /* 全屏舞台，禁橡皮筋滚动 */
  background: var(--stage-bg);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--ivory);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;         /* 消除移动端双击延迟 */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- 3. 画布与调色层 ---------- */
#fx-bg, #fx-fg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#fx-fg { z-index: 60; }

#grade {
  position: fixed;
  inset: 0;
  z-index: 65;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='2' seed='9'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.025 0'/%3E%3C/filter%3E%3Crect width='90' height='90' filter='url(%23g)'/%3E%3C/svg%3E") repeat,
    radial-gradient(ellipse 64% 54% at 46% 38%, rgba(255, 196, 120, 0.05) 0%, rgba(255, 196, 120, 0) 55%),
    radial-gradient(ellipse 112% 106% at 50% 46%, rgba(0, 0, 0, 0) 58%, rgba(5, 8, 6, 0.30) 100%);
}

/* ---------- 4. 聚光灯 ---------- */
#spotlight {
  position: fixed;
  inset: 0;
  pointer-events: none;
  transition: opacity 2.4s ease;
}
#spotlight.off { opacity: 0; }

#spotlight .beam {
  position: absolute;
  left: 50%;
  top: -6%;
  width: 52%;
  height: 96%;
  transform: translateX(-50%);
  z-index: 1;
  mix-blend-mode: screen;
  background: linear-gradient(to bottom,
      rgba(255, 233, 190, 0.30) 0%,
      rgba(255, 233, 190, 0.14) 40%,
      rgba(255, 233, 190, 0.03) 100%);
  clip-path: polygon(44% 0, 56% 0, 96% 100%, 4% 100%);
  filter: blur(26px);
}

#spotlight .pool {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 1220px);
  height: min(70vh, 700px);
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse 50% 50% at 50% 50%,
      rgba(255, 236, 192, 0.16) 0%,
      rgba(255, 236, 192, 0.07) 45%,
      rgba(255, 236, 192, 0) 72%);
}

/* ---------- 5. 逻辑桌面与牌桌 ---------- */
#stage {
  position: fixed;
  inset: 0;
  perspective: 1500px;
  perspective-origin: 50% 44%;
}
/* 整叠落定的桌面微震（配合 thud 音效的实体感） */
#stage.thump { animation: stage-thump 0.22s ease-out; }
@keyframes stage-thump {
  40% { transform: translateY(2px); }
}

#table {
  position: absolute;
  left: 50%;
  top: 49%;
  width: var(--table-w);
  height: var(--table-h);
  margin: calc(var(--table-h) / -2) 0 0 calc(var(--table-w) / -2);
  transform: scale(var(--table-scale, 1));
  transform-style: preserve-3d;
}

.table-surface {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1170px;
  height: 676px;
  transform: translate(-50%, -50%);
  border-radius: 50% / 46%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.34 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23w)'/%3E%3C/svg%3E") repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='60'%3E%3Cfilter id='v'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04 0.5' numOctaves='2' seed='11'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='180' height='60' filter='url(%23v)'/%3E%3C/svg%3E") repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='c'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.008 0.016' numOctaves='3' seed='5'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.20 0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23c)'/%3E%3C/svg%3E") repeat,
    radial-gradient(ellipse 60% 54% at 50% 44%, rgba(255, 232, 180, 0.20) 0%, rgba(255, 232, 180, 0) 62%),
    radial-gradient(ellipse 100% 100% at 50% 42%, var(--felt-hi) 0%, var(--felt) 46%, var(--felt-lo) 82%, var(--felt-edge) 100%);
  box-shadow:
    inset 0 0 100px rgba(2, 10, 6, 0.42),
    inset 0 0 22px rgba(2, 10, 6, 0.28),
    0 34px 90px rgba(0, 0, 0, 0.58),
    0 0 0 2px rgba(210, 170, 98, 0.22);
}
.table-surface::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50% / 46%;
  border: 1px solid var(--gold-line);
  pointer-events: none;
}

/* ---------- 6. 选列热区：呼吸金点 + 罗马数字（签名元素） ---------- */
#hotspots {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-style: preserve-3d;
}
.hotspot {
  position: absolute;
  border: none;
  background: transparent;
  cursor: pointer;
}
/* 桌面上方的引导金点：唯一的光学引导 */
.hotspot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -46px;
  width: 7px;
  height: 7px;
  margin-left: -3.5px;
  border-radius: 50%;
  background: var(--gold-strong);
  box-shadow: 0 0 12px rgba(233, 208, 148, 0.8);
  opacity: 0;
  transition: opacity 0.3s;
}
.hotspot.active::before {
  opacity: 1;
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(233, 208, 148, 0.55); }
  50% { box-shadow: 0 0 22px rgba(233, 208, 148, 0.95); }
}
/* 极小的罗马数字（真实序列信息），贴在光点下方 */
.hotspot .hs-label {
  position: absolute;
  left: 50%;
  top: -34px;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 3px;
  text-indent: 3px;
  color: var(--whisper);
  opacity: 0;
  transition: opacity 0.3s, color 0.3s;
}
.hotspot.active .hs-label { opacity: 1; }
.hotspot.active:hover .hs-label { color: var(--speak); }
.hotspot.active:hover::before { background: #fff2d8; }
.hotspot.fading::before, .hotspot.fading .hs-label { opacity: 0; animation: none; }

/* ---------- 7. 台词：无底低语（画外音） ---------- */
#subtitle {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  max-width: min(80vw, 720px);
  z-index: 70;
  pointer-events: none;
  text-align: center;
}
#subtitle p {
  display: inline;
  font-family: "KaiTi", "STKaiti", "FangSong", serif;
  font-weight: 400;
  font-size: clamp(15px, 2.1vmin, 19px);
  line-height: 1.8;
  letter-spacing: 2px;
  color: var(--whisper);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.6);
  transition: color 0.5s ease;
  animation: line-in 0.5s ease both;   /* 每句台词浮现（say() 重触发） */
}
@keyframes line-in {
  from { opacity: 0; transform: translateY(5px); }
}

/* ---------- 8. 控件：细线胶囊，文字半透明 ---------- */
#controls {
  position: fixed;
  left: 50%;
  bottom: max(40px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  text-align: center;
}
.btn {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 5px;
  text-indent: 5px;
  color: rgba(233, 208, 148, 0.72);
  background: rgba(210, 170, 98, 0.04);
  border: 1px solid rgba(210, 170, 98, 0.38);
  border-radius: 999px;
  padding: 10px 38px;
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, background 0.25s;
}
.btn:hover {
  color: var(--speak);
  border-color: rgba(210, 170, 98, 0.75);
  background: rgba(210, 170, 98, 0.09);
}
.btn:active { background: rgba(210, 170, 98, 0.14); }
.btn:focus-visible { outline: 1px solid var(--gold-strong); outline-offset: 3px; }
.btn[hidden] { display: none; }

/* 顶栏：金点剧名 + 三个无字图标钮（触摸目标 ≥44px） */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 70;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 22px 0;
}
#act-name {
  font-size: 11px;
  letter-spacing: 6px;
  color: var(--faint);
}
.topbar-btns { display: flex; gap: 4px; }
.topbar-btns button {
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--whisper);
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: color 0.25s, background 0.25s;
}
/* 语言钮：文字态（EN / 中） */
#btn-lang {
  font-size: 12px;
  letter-spacing: 1px;
  text-indent: 1px;
  font-weight: 500;
}
/* GitHub 链接钮：与圆钮同规格 */
#btn-github {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--whisper);
  border-radius: 50%;
  transition: color 0.25s, background 0.25s;
}
.topbar-btns button:hover,
#btn-github:hover {
  color: var(--speak);
  background: rgba(236, 226, 200, 0.06);
}
.topbar-btns button:active { transform: scale(0.92); }
.topbar-btns button:focus-visible,
#btn-github:focus-visible { outline: 1px solid var(--gold-line); outline-offset: 2px; }

/* 英文语言下的字形适配：衬线换西文、字距收紧 */
html[lang="en"] #overlay h1 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
}
html[lang="en"] #subtitle p {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.4px;
}
html[lang="en"] .btn,
html[lang="en"] #btn-start {
  letter-spacing: 3px;
  text-indent: 3px;
}

/* ---------- 9. 开场遮罩：大留白，一处衬线 ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 30% 22% at 82% 12%, rgba(216, 160, 80, 0.14) 0%, rgba(216, 160, 80, 0) 70%),
    radial-gradient(ellipse 24% 18% at 12% 20%, rgba(196, 140, 70, 0.09) 0%, rgba(196, 140, 70, 0) 70%),
    radial-gradient(ellipse 80% 70% at 50% 45%, #13100d 0%, #090807 72%);
  transition: opacity 1.8s ease, visibility 1.8s;
}
#overlay.hidden { opacity: 0; visibility: hidden; }
.overlay-inner {
  text-align: center;
  animation: overlay-rise 1.1s cubic-bezier(.2,.6,.2,1) both;
}
@keyframes overlay-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.overlay-ornament {
  color: var(--gold-dim);
  font-size: 13px;
  margin-bottom: 34px;
  opacity: 0.7;
}
#overlay h1 {
  font-family: "Songti SC", "STSong", "SimSun", "KaiTi", serif;
  font-weight: 400;
  font-size: clamp(26px, 4.6vmin, 42px);
  letter-spacing: 1.1em;
  text-indent: 1.1em;      /* 视觉居中补偿 */
  text-wrap: balance;
  color: rgba(237, 226, 198, 0.88);
}
.overlay-rule {            /* 标题下的一根 1px 金线：唯一的装饰 */
  width: 56px;
  height: 1px;
  margin: 34px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold-line), transparent);
}

#btn-start {
  margin-top: 64px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 8px;
  text-indent: 8px;
  color: rgba(233, 208, 148, 0.78);
  background: transparent;
  border: 1px solid rgba(210, 170, 98, 0.42);
  border-radius: 999px;
  padding: 15px 58px;
  cursor: pointer;
  transition: color 0.3s, border-color 0.3s, background 0.3s, box-shadow 0.3s;
}
#btn-start:hover {
  color: var(--speak);
  border-color: rgba(233, 208, 148, 0.85);
  background: rgba(210, 170, 98, 0.06);
  box-shadow: 0 0 34px rgba(210, 170, 98, 0.10);
}
#btn-start:focus-visible { outline: 1px solid var(--gold-strong); outline-offset: 4px; }

/* ---------- 10. 揭晓光斑 ---------- */
#reveal-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 380px;
  height: 380px;
  margin: -190px 0 0 -190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 228, 168, 0.28) 0%, rgba(255, 228, 168, 0.08) 40%, rgba(255, 228, 168, 0) 68%);
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}
#reveal-glow.show { transition: opacity 1.1s ease; opacity: 1; }

/* ---------- 11. 响应式与可访问性 ---------- */
@media (max-aspect-ratio: 4/5) {
  :root { --table-w: 860px; --table-h: 1080px; }
  #stage { perspective-origin: 50% 40%; }
  .table-surface { width: 830px; height: 1040px; }
}

@media (max-width: 720px) {
  #subtitle { bottom: 84px; max-width: 88vw; }
  #controls { bottom: 26px; }
  #act-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #spotlight, #reveal-glow { transition-duration: 0.3s; }
  .hotspot.active::before { animation: none; }
  .overlay-inner { animation: none; }
  #stage.thump { animation: none; }
  #subtitle p { animation: none; }
  .card-inner { transition: none; }
}
