:root {
  --bg: #100e0b;
  --bg-2: #18150f;
  --paper: rgba(28, 24, 18, 0.92);
  --ink: #f0e6d4;
  --muted: #a89880;
  --line: rgba(215, 181, 109, 0.28);
  --gold: #d7b56d;
  --gold-dim: #8c7344;
  --mythic: #ff6b4a;
  --mythic-2: #ffd27a;
  --mythic-3: #c9a0ff;
  --cinnabar: #c4564a;
  --jade: #8eae86;
  --moon: #c9d4e4;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", "STSong", serif;
  --sans: "Noto Sans TC", "PingFang TC", "Noto Sans CJK TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  font-family: var(--sans);
  background: var(--bg);
  line-height: 1.65;
}
button, input { font-family: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.ink-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 480px at 10% -10%, rgba(215, 181, 109, 0.16), transparent 60%),
    radial-gradient(700px 500px at 110% 10%, rgba(196, 86, 74, 0.12), transparent 55%),
    radial-gradient(800px 600px at 50% 120%, rgba(142, 174, 134, 0.08), transparent 50%),
    linear-gradient(180deg, #14110d, #0c0b09 70%);
  z-index: -1;
}
.ink-wash::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image: radial-gradient(rgba(240, 230, 212, 0.18) 0.6px, transparent 0.6px);
  background-size: 3px 3px;
  mix-blend-mode: overlay;
}

.screen { min-height: 100vh; }

/* —— 開局封面：星門仙都 ——
   直幅：xingmen-portrait-web.jpg（來源：portrait-native，真直幅構圖，非橫幅裁切）
   橫幅：xingmen-landscape-1920.jpg（來源：landscape-3840x2160）
   熱區百分比相對「圖框」而非視窗，避免 object-fit 錯位。
*/
#screen-title {
  position: fixed;
  inset: 0;
  z-index: 40;
  margin: 0;
  padding: 0;
  max-width: none;
  min-height: 100vh;
  min-height: 100dvh;
  background: #050810;
  overflow: hidden;
}
#screen-title.hidden { display: none !important; }
.title-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050810;
}
.title-frame {
  position: relative;
  display: none;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
}
.title-art {
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.title-hotspot {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 2;
  min-height: 0;
  -webkit-tap-highlight-color: transparent;
}
.title-hotspot:focus-visible {
  outline: 2px solid rgba(215, 181, 109, 0.85);
  outline-offset: 4px;
  border-radius: 4px;
}
.title-hotspot:hover,
.title-hotspot:active {
  background: rgba(215, 181, 109, 0.08);
  box-shadow: 0 0 24px rgba(215, 181, 109, 0.22);
}

/* 橫幅：桌面／橫向（寬≥高） */
.title-hotspot-landscape {
  /* 對準橫幅圖中「踏入輪迴」：約 64% 高、水平置中 */
  left: 19.17%;
  top: 54.54%;
  width: 61.72%;
  height: 19.72%;
}
/* 直幅：手機／直向（高>寬）——原生直幅構圖 */
.title-hotspot-portrait {
  /* 對準原生直幅「踏入輪迴」：約 78–79% 高、水平置中 */
  left: 14.72%;
  top: 72.97%;
  width: 72.22%;
  height: 12.66%;
}

@media (orientation: landscape), (min-aspect-ratio: 1/1) {
  .title-frame-landscape { display: inline-block; }
  .title-frame-portrait { display: none; }
}
@media (orientation: portrait) and (max-aspect-ratio: 0.999/1) {
  .title-frame-landscape { display: none; }
  .title-frame-portrait { display: inline-block; }
}
/* 窄屏直向優先直幅（即使桌面縮很窄） */
@media (max-width: 720px) and (orientation: portrait) {
  .title-frame-landscape { display: none; }
  .title-frame-portrait { display: inline-block; }
}


#screen-birth {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 20px 72px;
}
.mast { display: flex; gap: 18px; align-items: center; }
.seal, .tomb-seal {
  width: 72px;
  height: 72px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--cinnabar);
  font-family: var(--serif);
  font-size: 32px;
  box-shadow: inset 0 0 0 4px rgba(215, 181, 109, 0.25);
  flex: none;
}
.seal-btn {
  background: transparent;
  color: var(--cinnabar);
  padding: 0;
}
.eyebrow {
  margin: 0;
  letter-spacing: 0.22em;
  text-transform: none;
  color: var(--gold);
  font-size: 12px;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: 0.06em; }
h1 { margin: 0; font-size: clamp(40px, 7vw, 68px); line-height: 1.05; }
.subtitle { margin: 4px 0 0; color: var(--muted); letter-spacing: 0.4em; }
.lead, .prose { font-family: var(--serif); font-size: 17px; color: #efe6d6; }
.prose, .event { white-space: pre-line; }
.lead { max-width: 40em; }

.birth-card, .choice-card, .memorial-card, .stone-card, .tomb {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.birth-card { margin-top: 22px; }
.identity-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin: 10px 0 14px;
}
.identity-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
}
.identity-form input {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  width: 100%;
}
.identity-form input:focus { outline: 1px solid var(--gold); border-color: var(--gold); }
.loadout { display: grid; gap: 8px; margin-top: 12px; }
.loadout-row {
  display: flex; justify-content: space-between; gap: 10px; align-items: flex-start;
  margin: 0; font-size: 13px; padding: 6px 8px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer;
}
.loadout-row:hover, .loadout-row:focus-visible {
  border-color: rgba(215, 181, 109, 0.35);
  background: rgba(215, 181, 109, 0.06);
  outline: none;
}
.loadout-row > span { color: var(--muted); flex: none; padding-top: 2px; }
.loadout-val { text-align: right; min-width: 0; }
.loadout strong { font-family: var(--serif); font-weight: 500; display: block; }
.fx-short {
  display: block; font-style: normal; font-size: 11px; color: var(--jade);
  margin-top: 2px; letter-spacing: 0.02em; line-height: 1.35;
}
.fx-short.is-empty { color: var(--muted); }
/* 卡面能力短標位：出身／靈根／天賦 */
.roll .fx-short {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(142, 174, 134, 0.35);
  background: rgba(142, 174, 134, 0.1);
  color: #b7d4af;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.roll .fx-short.is-empty {
  border-color: rgba(168, 152, 128, 0.25);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
}
.roll.roll-epic .fx-short {
  border-color: rgba(231, 196, 255, 0.45);
  background: rgba(186, 120, 255, 0.12);
  color: #e7c4ff;
}
.roll.roll-legendary .fx-short,
.roll.roll-gold .fx-short {
  border-color: rgba(215, 181, 109, 0.5);
  background: rgba(215, 181, 109, 0.12);
  color: #f0d9a0;
}
.roll.roll-mythic .fx-short {
  border-color: rgba(255, 107, 74, 0.55);
  background:
    linear-gradient(135deg, rgba(255, 107, 74, 0.16), rgba(201, 160, 255, 0.14) 55%, rgba(255, 210, 122, 0.12));
  color: #ffd2a8;
}
.tag {
  cursor: pointer;
  position: relative;
}
.tag.has-tip:hover, .tag.has-tip:focus-visible {
  border-color: var(--gold);
  background: rgba(215, 181, 109, 0.12);
  outline: none;
}
.daqian-tooltip {
  position: fixed;
  z-index: 80;
  max-width: min(280px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(215, 181, 109, 0.45);
  background: rgba(22, 18, 14, 0.96);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.55;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  pointer-events: none;
  white-space: pre-wrap;
}
.daqian-tooltip strong {
  display: block;
  color: var(--gold);
  font-family: var(--serif);
  font-weight: 500;
  margin-bottom: 4px;
  font-size: 13px;
}
.daqian-tooltip.pinned { pointer-events: auto; }
.odds { margin: 0 0 8px; color: var(--gold); letter-spacing: 0.08em; }
.roll-grid { display: grid; gap: 12px; }
.roll {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
}
.roll header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.roll .k { color: var(--muted); font-size: 12px; letter-spacing: 0.14em; }
.roll strong { font-family: var(--serif); font-size: 20px; }
.roll p { margin: 6px 0 0; color: var(--muted); }
.roll.tippable { cursor: pointer; }
.roll.tippable:hover, .roll.tippable:focus-visible {
  border-color: rgba(215, 181, 109, 0.45);
  background: rgba(215, 181, 109, 0.05);
  outline: none;
}
.rarity {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
}
.rarity-common { color: var(--muted); border-color: rgba(168, 152, 128, 0.35); }
.rarity-uncommon { color: var(--moon); border-color: rgba(201, 212, 228, 0.4); }
.rarity-rare { color: var(--jade); border-color: rgba(142, 174, 134, 0.5); }
.rarity-epic { color: #e7c4ff; border-color: rgba(231, 196, 255, 0.45); }
.rarity-legendary { color: var(--gold); border-color: var(--gold); }
.rarity-mythic {
  color: #ffc39a;
  border-color: transparent;
  background:
    linear-gradient(var(--paper), var(--paper)) padding-box,
    linear-gradient(120deg, #ff6b4a, #ffd27a 40%, #c9a0ff 75%, #ff6b4a) border-box;
  border: 1px solid transparent;
  box-shadow: 0 0 16px rgba(255, 107, 74, 0.35), 0 0 22px rgba(201, 160, 255, 0.22);
}
.flare-mythic { animation: glow 2.8s ease-in-out infinite; }
.flare-destiny { animation: glow-mythic 2.8s ease-in-out infinite; }
.flare-epic { animation: glow-epic 2.8s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 rgba(215, 181, 109, 0); }
  50% { box-shadow: 0 0 32px rgba(215, 181, 109, 0.28); }
}
@keyframes glow-epic {
  0%, 100% { box-shadow: 0 0 0 rgba(186, 120, 255, 0); }
  50% { box-shadow: 0 0 28px rgba(186, 120, 255, 0.32); }
}

/* 開局紫／金稀有出場 */
.roll.roll-epic {
  position: relative;
  overflow: hidden;
  border-color: rgba(231, 196, 255, 0.75);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(186, 120, 255, 0.28), transparent 55%),
    rgba(255, 255, 255, 0.03);
  box-shadow: 0 0 0 1px rgba(186, 120, 255, 0.18), 0 0 22px rgba(154, 90, 230, 0.22);
}
.roll.roll-gold,
.roll.roll-legendary {
  position: relative;
  overflow: hidden;
  border-color: rgba(215, 181, 109, 0.9);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 220, 140, 0.32), transparent 55%),
    rgba(255, 255, 255, 0.03);
  box-shadow: 0 0 0 1px rgba(215, 181, 109, 0.28), 0 0 26px rgba(215, 181, 109, 0.28);
}
/* 逆天：赤金＋虹邊，明顯高於傳說金 */
.roll.roll-mythic {
  position: relative;
  overflow: hidden;
  border: 1.5px solid transparent;
  background:
    radial-gradient(120% 90% at 50% -15%, rgba(255, 107, 74, 0.28), transparent 50%),
    radial-gradient(90% 70% at 100% 100%, rgba(201, 160, 255, 0.22), transparent 55%),
    linear-gradient(rgba(28, 24, 18, 0.96), rgba(28, 24, 18, 0.96)) padding-box,
    linear-gradient(125deg, #ff6b4a, #ffd27a 35%, #c9a0ff 70%, #ff8a5c) border-box;
  box-shadow:
    0 0 0 1px rgba(255, 107, 74, 0.25),
    0 0 28px rgba(255, 107, 74, 0.28),
    0 0 40px rgba(201, 160, 255, 0.18);
}
.roll .roll-sparkle {
  pointer-events: none;
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.55) 0 1px, transparent 2px),
    radial-gradient(circle at 70% 20%, rgba(255,255,255,0.4) 0 1.5px, transparent 3px),
    radial-gradient(circle at 40% 75%, rgba(255,255,255,0.35) 0 1px, transparent 2px),
    radial-gradient(circle at 85% 65%, rgba(255,255,255,0.5) 0 1px, transparent 2px);
  opacity: 0;
  mix-blend-mode: screen;
}
.roll.roll-epic .roll-sparkle {
  background:
    radial-gradient(circle at 18% 28%, rgba(240,210,255,0.85) 0 1.5px, transparent 3px),
    radial-gradient(circle at 72% 18%, rgba(200,150,255,0.7) 0 2px, transparent 4px),
    radial-gradient(circle at 42% 78%, rgba(255,220,255,0.55) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 62%, rgba(186,120,255,0.75) 0 1.5px, transparent 3px);
}
.roll.roll-gold .roll-sparkle {
  background:
    radial-gradient(circle at 18% 28%, rgba(255,240,190,0.95) 0 1.5px, transparent 3px),
    radial-gradient(circle at 72% 18%, rgba(255,214,120,0.8) 0 2px, transparent 4px),
    radial-gradient(circle at 42% 78%, rgba(255,250,220,0.6) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 62%, rgba(215,181,109,0.85) 0 1.5px, transparent 3px);
}
.roll.roll-mythic .roll-sparkle {
  background:
    radial-gradient(circle at 16% 26%, rgba(255,180,140,0.95) 0 1.5px, transparent 3px),
    radial-gradient(circle at 74% 16%, rgba(255,210,122,0.85) 0 2px, transparent 4px),
    radial-gradient(circle at 40% 80%, rgba(220,180,255,0.7) 0 1.5px, transparent 3px),
    radial-gradient(circle at 88% 60%, rgba(255,107,74,0.9) 0 1.5px, transparent 3px);
}
.roll.fx-pop {
  animation: roll-pop 0.85s cubic-bezier(0.16, 1.05, 0.3, 1) both;
}
.roll.fx-pop .roll-sparkle {
  animation: sparkle-drift 1.1s ease-out both;
}
.roll.fx-flash {
  animation: roll-flash 0.28s ease-out both;
}
.roll.fx-flash .roll-sparkle {
  animation: sparkle-blink 0.3s ease-out both;
}
.roll.roll-epic.fx-pop,
.roll.roll-epic.fx-flash {
  animation-name: roll-pop-epic, border-pulse-epic;
  animation-duration: 0.85s, 1.2s;
  animation-timing-function: cubic-bezier(0.16, 1.05, 0.3, 1), ease-in-out;
  animation-fill-mode: both, none;
}
.roll.roll-epic.fx-flash {
  animation-duration: 0.28s, 0.4s;
  animation-name: roll-flash-epic, border-pulse-epic;
}
.roll.roll-gold.fx-pop,
.roll.roll-legendary.fx-pop {
  animation-name: roll-pop-gold, border-pulse-gold;
  animation-duration: 0.9s, 1.35s;
  animation-timing-function: cubic-bezier(0.16, 1.05, 0.3, 1), ease-in-out;
  animation-fill-mode: both, none;
}
.roll.roll-gold.fx-flash,
.roll.roll-legendary.fx-flash {
  animation-name: roll-flash-gold, border-pulse-gold;
  animation-duration: 0.3s, 0.45s;
}
.roll.roll-mythic.fx-pop {
  animation-name: roll-pop-mythic, border-pulse-mythic;
  animation-duration: 0.95s, 1.45s;
  animation-timing-function: cubic-bezier(0.16, 1.05, 0.3, 1), ease-in-out;
  animation-fill-mode: both, none;
}
.roll.roll-mythic.fx-flash {
  animation-name: roll-flash-mythic, border-pulse-mythic;
  animation-duration: 0.32s, 0.5s;
}
@keyframes roll-pop {
  0% { transform: scale(0.86); opacity: 0.35; }
  60% { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes roll-pop-epic {
  0% { transform: scale(0.84) rotate(-0.4deg); filter: brightness(1.4) saturate(1.3); }
  55% { transform: scale(1.05) rotate(0.3deg); }
  100% { transform: scale(1) rotate(0); filter: none; }
}
@keyframes roll-pop-gold {
  0% { transform: scale(0.8) rotate(-0.6deg); filter: brightness(1.55) saturate(1.25); }
  50% { transform: scale(1.07) rotate(0.4deg); }
  100% { transform: scale(1) rotate(0); filter: none; }
}
@keyframes roll-flash {
  0% { transform: scale(1.02); filter: brightness(1.25); }
  100% { transform: scale(1); filter: none; }
}
@keyframes roll-flash-epic {
  0% { transform: scale(1.03); box-shadow: 0 0 28px rgba(186, 120, 255, 0.55); }
  100% { transform: scale(1); }
}
@keyframes roll-flash-gold {
  0% { transform: scale(1.04); box-shadow: 0 0 34px rgba(255, 214, 120, 0.65); }
@keyframes roll-pop-mythic {
  0% { transform: scale(0.78) rotate(-0.8deg); filter: brightness(1.65) saturate(1.35) hue-rotate(-8deg); }
  50% { transform: scale(1.08) rotate(0.5deg); }
  100% { transform: scale(1) rotate(0); filter: none; }
}
@keyframes roll-flash-mythic {
  0% { filter: brightness(1.8) saturate(1.5); }
  100% { filter: none; }
}
@keyframes border-pulse-mythic {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 107, 74, 0.2), 0 0 20px rgba(255, 107, 74, 0.18); }
  50% { box-shadow: 0 0 0 1px rgba(201, 160, 255, 0.55), 0 0 36px rgba(255, 107, 74, 0.4), 0 0 48px rgba(201, 160, 255, 0.28); }
}

  100% { transform: scale(1); }
}
@keyframes border-pulse-epic {
  0%, 100% { border-color: rgba(231, 196, 255, 0.55); }
  50% { border-color: rgba(255, 230, 255, 1); }
}
@keyframes border-pulse-gold {
  0%, 100% { border-color: rgba(215, 181, 109, 0.7); }
  50% { border-color: rgba(255, 236, 170, 1); }
}
@keyframes sparkle-drift {
  0% { opacity: 0; transform: translateY(8px) scale(0.9); }
  25% { opacity: 0.95; }
  100% { opacity: 0; transform: translateY(-18px) scale(1.15); }
}
@keyframes sparkle-blink {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

.birth-card.birth-fx-epic {
  animation: birth-halo-epic 1.05s ease-out;
}
.birth-card.birth-fx-gold {
  animation: birth-halo-gold 1.2s ease-out;
}
.birth-card.birth-fx-flash.birth-fx-epic {
  animation-duration: 0.35s;
}
.birth-card.birth-fx-flash.birth-fx-gold {
  animation-duration: 0.4s;
}
@keyframes birth-halo-epic {
  0% { box-shadow: 0 0 0 rgba(186, 120, 255, 0); }
  35% { box-shadow: 0 0 48px rgba(186, 120, 255, 0.35); }
  100% { box-shadow: 0 0 0 rgba(186, 120, 255, 0); }
}
@keyframes birth-halo-gold {
  0% { box-shadow: 0 0 0 rgba(215, 181, 109, 0); }
  35% { box-shadow: 0 0 56px rgba(255, 214, 120, 0.42); }
  100% { box-shadow: 0 0 0 rgba(215, 181, 109, 0); }
}

.rarity-fx-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  opacity: 0;
  transition: opacity 0.2s ease;
  mix-blend-mode: screen;
}
.rarity-fx-overlay.active { opacity: 1; }
.rarity-fx-overlay.is-epic {
  background:
    radial-gradient(circle at 50% 30%, rgba(186, 120, 255, 0.28), transparent 42%),
    radial-gradient(circle at 20% 80%, rgba(140, 80, 220, 0.16), transparent 35%),
    radial-gradient(circle at 80% 70%, rgba(230, 190, 255, 0.14), transparent 30%);
}
.rarity-fx-overlay.is-gold {
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 220, 140, 0.32), transparent 44%),
    radial-gradient(circle at 18% 78%, rgba(215, 181, 109, 0.18), transparent 36%),
    radial-gradient(circle at 82% 68%, rgba(255, 240, 190, 0.16), transparent 32%);
}
.rarity-fx-overlay.is-flash { transition: opacity 0.12s ease; }
.rarity-fx-overlay.is-full.active {
  animation: overlay-breathe 1.05s ease-out;
}
.rarity-fx-overlay.is-flash.active {
  animation: overlay-blink 0.32s ease-out;
}
@keyframes overlay-breathe {
  0% { opacity: 0; }
  25% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes overlay-blink {
  0% { opacity: 0.85; }
  100% { opacity: 0; }
}

.legend-farm {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.16);
}
.legend-farm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.legend-farm-status {
  margin: 10px 0 0;
  min-height: 1.4em;
  color: var(--gold);
}
.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0 0;
}
.mini-stats div { background: rgba(0,0,0,0.18); border-radius: 10px; padding: 8px; }
.mini-stats dt { color: var(--muted); font-size: 12px; }
.mini-stats dd { margin: 2px 0 0; font-family: var(--serif); font-size: 18px; }

.birth-actions, .dock { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.birth-actions { margin-top: 18px; }
.btn, .speeds button, .focus-row button, .choice-options button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.btn:hover, .speeds button:hover, .focus-row button:hover, .choice-options button:hover {
  border-color: var(--gold);
}
.btn.primary, .speeds button.active, .focus-row button.active {
  background: var(--gold);
  color: #1a140c;
  border-color: var(--gold);
  font-weight: 700;
}
.btn.ghost { background: transparent; }
.btn.danger { color: #f0c2bc; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.life-top, .life-layout, .dock { width: min(1180px, calc(100% - 28px)); margin-left: auto; margin-right: auto; }
.life-top {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 18px 0 8px;
}
.who { flex: 1; min-width: 0; }
.who h2 { margin: 0; font-size: 28px; }
.meta, .hint, .span-note, .chronicle-head p { color: var(--muted); margin: 0; }
.age-block { text-align: right; }
.age-num { font-family: var(--serif); font-size: 52px; line-height: 0.9; }
.age-unit { margin-left: 4px; color: var(--muted); }

.life-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 16px;
  align-items: start;
}
.panel, .chronicle {
  background: rgba(18, 16, 12, 0.78);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.panel { padding: 16px; position: sticky; top: 12px; }
.realm-name { font-family: var(--serif); font-size: 28px; margin: 0 0 8px; }
.ladder { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 14px; list-style: none; }
.ladder li {
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
}
.ladder li.on { color: var(--gold); border-color: var(--gold); }
.bar-block { margin: 8px 0; }
.bar-label, .wealth-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.wealth-line strong { color: var(--ink); font-size: 18px; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,0.06); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--cinnabar); border-radius: inherit; transition: width 0.35s ease; }
.bar i.jade { background: var(--jade); }
.bar i.moon { background: var(--moon); }
.bar i.gold { background: var(--gold); }
.bar i.low { background: var(--cinnabar); }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--gold);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.focus-set { border: 0; margin: 14px 0 0; padding: 0; }
.focus-set legend { color: var(--muted); font-size: 12px; letter-spacing: 0.14em; margin-bottom: 8px; }
.focus-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.focus-row button { border-radius: 12px; padding: 8px; }
.focus-set .hint { margin-top: 8px; min-height: 2.2em; }

/* 網頁版：方針鈕置於歲月錄上方，sticky 免往下拉 */
.chronicle-focus {
  margin: 0;
  padding: 10px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 6;
  background: linear-gradient(180deg, rgba(18, 16, 12, 0.98) 70%, rgba(18, 16, 12, 0.88));
  border-bottom: 1px solid rgba(215, 181, 109, 0.22);
}
@media (min-width: 700px) {
  .chronicle-focus .focus-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

.chronicle { min-height: 62vh; display: flex; flex-direction: column; }
.chronicle-head { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px 0; align-items: baseline; }
.chronicle-head h3 { margin: 0; }
.log {
  padding: 8px 16px 18px;
  overflow: auto;
  max-height: calc(100vh - 230px);
}
.year-card {
  border-top: 1px solid rgba(215, 181, 109, 0.14);
  padding: 14px 0;
  animation: rise 0.45s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.year-card header { display: flex; justify-content: space-between; gap: 8px; color: var(--gold); font-size: 13px; }
.year-card .prose { margin: 8px 0; }
.year-card .event { margin: 8px 0; font-family: var(--serif); }

.event-cg-wrap {
  margin: 10px 0 12px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(215, 181, 109, 0.28);
  background: rgba(8, 7, 6, 0.45);
  max-width: 100%;
}
.event-cg {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  object-position: center;
}
.choice-cg {
  margin: 0 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(215, 181, 109, 0.28);
  max-height: 220px;
}
.event-cg-cap {
  padding: 6px 10px 8px;
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 0.08em;
}
@media (max-width: 700px) {
  .event-cg { max-height: 180px; }
  .choice-cg { max-height: 150px; }
}

.deltas { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; list-style: none; }
.deltas li { font-size: 12px; color: var(--muted); }
.deltas .up { color: var(--jade); }
.deltas .down { color: #e7a097; }
.year-card.is-death { box-shadow: inset 3px 0 0 var(--cinnabar); }
.year-card.is-ascend { box-shadow: inset 3px 0 0 var(--gold); }
.choice-line { color: var(--gold); }

.dock {
  position: sticky;
  bottom: 0;
  padding: 12px 0 16px;
  background: linear-gradient(180deg, transparent, rgba(16, 14, 11, 0.95) 30%);
}
.speeds { display: flex; flex-wrap: wrap; gap: 6px; }
.speeds button { padding: 8px 12px; font-size: 13px; }
.speeds button[aria-pressed="true"], .speeds button.active { background: var(--gold); color: #1a140c; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 6, 0.88);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}
#choice-modal.overlay { pointer-events: none; background: rgba(8, 7, 6, 0.45); }
#choice-modal .choice-card { pointer-events: auto; }
#choice-modal.is-minimized {
  background: transparent;
  place-items: end center;
  padding: 0 18px 88px;
  pointer-events: none;
}
#choice-modal.is-minimized .choice-card { display: none; }
#choice-modal.is-minimized .choice-dock {
  display: flex;
  pointer-events: auto;
}
.choice-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.choice-card-head .eyebrow { margin: 0; }
.choice-min-btn { padding: 6px 12px; font-size: 12px; flex: none; }
.choice-dock {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(420px, 100%);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(215, 181, 109, 0.5);
  background: rgba(22, 18, 14, 0.94);
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
}
.choice-dock .hint { margin: 0; text-align: center; font-size: 12px; }
.focus-set { position: relative; z-index: 6; }
.chronicle-focus.focus-set { z-index: 6; }
@media (min-width: 861px) {
  #choice-modal.overlay { justify-items: end; padding-right: 4vw; }
  #choice-modal.is-minimized { justify-items: center; padding-right: 18px; }
}
.choice-card, .tomb, .memorial-card, .stone-card { width: min(680px, 100%); max-height: min(88vh, 900px); overflow: auto; }
.choice-options { display: grid; gap: 10px; }
.choice-options button {
  border-radius: 14px;
  text-align: left;
  padding: 12px 14px;
}
.choice-options button small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.choice-options button.suggested { border-color: var(--gold); outline: 2px solid var(--gold); }
.auto-toggle { display: inline-flex; align-items: center; gap: 8px; }
.auto-toggle input { width: 18px; height: 18px; accent-color: #d7b56d; }
.auto-toggle input:checked + span { color: var(--gold); font-weight: 700; }

.tomb { text-align: center; }
.tomb-seal { margin: 0 auto 8px; }
.tomb.is-ascend .tomb-seal { color: var(--gold); }
.tomb.is-demonic { box-shadow: inset 0 0 0 1px rgba(196, 86, 74, 0.55); }
.tomb.is-righteous .tomb-seal { color: var(--jade); }
.tomb.is-mortal .tomb-seal { color: var(--moon); }

#ending.is-minimized {
  background: transparent !important;
  place-items: end center;
  align-content: end;
  padding: 0 18px calc(72px + env(safe-area-inset-bottom, 0px));
  pointer-events: none !important;
  z-index: 30;
}
#ending.is-minimized .tomb {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  max-height: 0 !important;
  overflow: hidden !important;
}
#ending.is-minimized .ending-cast,
#ending.is-minimized .ending-cast-card,
#ending.is-minimized .ending-mainline-card {
  display: none !important;
}
#ending.is-minimized .ending-dock {
  display: flex !important;
  pointer-events: auto !important;
  position: relative;
  z-index: 31;
}
.tomb-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}
.tomb-card-head .tomb-seal { margin: 0; }
.ending-dock {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(420px, 100%);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(215, 181, 109, 0.5);
  background: rgba(22, 18, 14, 0.94);
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
}
.ending-dock .hint { margin: 0; text-align: center; font-size: 12px; }
@media (min-width: 861px) {
  #ending.is-minimized { justify-items: center; padding-right: 18px; }
}

#ending-dao { margin: 0 0 8px; letter-spacing: 0.18em; }
.epitaph { font-family: var(--serif); font-size: 20px; }

.ending-portrait-frame { margin: 10px auto 6px; }
.ending-portrait-img {
  width: 180px;
  height: auto;
  aspect-ratio: 2 / 3;
  border: 4px solid #d7b56d;
  box-shadow: 4px 4px 0 #000;
  object-fit: contain;
  object-position: center top;
  background: #120e0b;
  display: block;
  margin: 0 auto;
}
.ending-portrait {
  width: 180px;
  height: 180px;
  border: 4px solid #d7b56d;
  box-shadow: 4px 4px 0 #000;
  object-fit: contain;
  background: #120e0b;
  display: block;
  margin: 0 auto;
}
.ending-reflection {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.7;
  color: var(--muted);
  text-align: left;
  margin: 10px 0 4px;
  padding: 10px 12px;
  border-left: 2px solid rgba(215, 181, 109, 0.55);
  background: rgba(0, 0, 0, 0.18);
}
.memory-reflection { color: #cbb896 !important; font-style: italic; }

.ending-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; text-align: left; margin: 12px 0; }
.ending-facts div { border-top: 1px solid var(--line); padding-top: 6px; }
.ending-facts dt { color: var(--muted); font-size: 12px; }
.ending-facts dd { margin: 2px 0 0; }
.highlights { text-align: left; margin: 8px 0 16px; padding-left: 18px; color: var(--muted); }
.highlights li { margin: 4px 0; }

.memorial-card { width: min(860px, 100%); }
.memorial-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.memorial-list { display: grid; gap: 10px; margin: 12px 0; }
.memory {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  color: inherit;
  width: 100%;
  cursor: pointer;
}
.memory input { width: 18px; height: 18px; margin-top: 4px; accent-color: #d7b56d; }
.compare-wrap { overflow-x: auto; margin: 8px 0 4px; }
.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
.compare-table th, .compare-table td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.compare-table th { color: var(--gold); font-weight: 500; white-space: nowrap; }
.memory strong { font-family: var(--serif); font-size: 18px; }
.memory p { margin: 4px 0 0; color: var(--muted); }
.memory.ascended { border-color: rgba(215, 181, 109, 0.7); }
code { font-family: ui-monospace, monospace; color: var(--gold); }

.portrait-frame {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 2;
}
.pixel-portrait,
.portrait-img {
  background: #120e0b;
  flex: none;
  border: 4px solid #d7b56d;
  box-shadow: 4px 4px 0 #000;
  display: block;
  cursor: pointer;
}
.pixel-portrait {
  width: 210px;
  height: 210px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.portrait-img {
  width: 168px;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  object-position: center top;
}
.portrait-img[hidden],
.pixel-portrait[hidden] { display: none !important; }
.stage-caption {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.pixel-icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  vertical-align: -3px;
  margin-right: 4px;
}
.bar-label span:first-child { display: inline-flex; align-items: center; }
.path-block { margin-top: 8px; }
.path-head { display: flex; gap: 14px; align-items: center; }
.path-kicker { margin: 0 0 6px; color: var(--gold); letter-spacing: 0.14em; font-size: 12px; }
.path-row, .choice-focus { display: flex; flex-wrap: wrap; gap: 8px; }
.path-row button, .choice-focus button {
  border: 4px solid #1a140c;
  background: #1c1814;
  color: var(--ink);
  box-shadow: 3px 3px 0 #000;
  padding: 6px 8px;
  font-size: 14px;
}
.path-row button.affinity { box-shadow: 3px 3px 0 #000, inset 0 0 0 2px #d7b56d; }
.path-row button.active, .choice-focus button.active {
  background: var(--gold);
  color: #1a140c;
}
.stat-help { margin-top: 10px; color: var(--muted); font-size: 13px; }
.stat-help summary { cursor: pointer; color: var(--gold); letter-spacing: 0.08em; }
.stat-help ul { margin: 8px 0 0; padding-left: 18px; }
.stat-help li { margin: 4px 0; }
.birth-card, .choice-card, .memorial-card, .stone-card, .tomb, .panel, .chronicle {
  border-radius: 0;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(215, 181, 109, 0.35);
}
.btn, .speeds button, .focus-row button, .choice-options button, .path-row button, .choice-focus button {
  border-radius: 0;
}
.focus-row button, .choice-options button, .btn, .speeds button {
  box-shadow: 3px 3px 0 #000;
  border-width: 2px;
}

@media (max-width: 860px) {
  .life-layout { grid-template-columns: 1fr; }
  .panel { position: relative; z-index: 40; }
  .log { max-height: none; }
  .chronicle { min-height: 0; }
  .age-num { font-size: 40px; }
  .mini-stats { grid-template-columns: 1fr 1fr; }
  .life-top { align-items: flex-start; }
  #screen-birth { padding-top: 28px; }
  .identity-form { grid-template-columns: 1fr; }
  .path-head { align-items: flex-start; }
  .pixel-portrait { width: 150px; height: 150px; }
  .portrait-img { width: 120px; height: auto; aspect-ratio: 2 / 3; }
}
@media print {
  body { background: #fff; }
  .ink-wash, #screen-title, #screen-birth, #screen-life, #choice-modal, #memorial, #boot-error, .no-print { display: none !important; }
  #ending {
    position: static;
    display: block !important;
    background: #fff;
    padding: 0;
    inset: auto;
    pointer-events: auto !important;
  }
  #ending.is-minimized .tomb { display: block !important; }
  #ending-dock, #btn-ending-minimize { display: none !important; }
  .tomb {
    width: 100%;
    max-height: none;
    color: #1a140c;
    background: #fff;
    box-shadow: none;
    border-color: #1a140c;
  }
  .epitaph, .lead, .prose, h1, h2, h3, .meta, .highlights { color: #1a140c; }
  .ending-facts dt, .highlights, .tag { color: #5c5144; }
  .tag { border-color: #5c5144; }
}
@media (prefers-reduced-motion: reduce) {
  .year-card, .flare-mythic, .flare-epic, .bar i,
  .roll.fx-pop, .roll.fx-flash, .roll .roll-sparkle,
  .birth-card.birth-fx-epic, .birth-card.birth-fx-gold,
  .rarity-fx-overlay, .rarity-fx-overlay.active { animation: none !important; transition: none !important; }
}


/* 開局對質與懺悔默念 */
.heart-block { margin-top: 16px; padding-top: 12px; border-top: 1px dashed rgba(0,0,0,.18); }
.heart-q { margin: 12px 0; }
.heart-q p { margin: 0 0 8px; color: var(--ink); }
.heart-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.heart-opts button {
  font: inherit; cursor: pointer; padding: 6px 12px;
  background: #f4efe4; border: 2px solid #1a1714; box-shadow: 2px 2px 0 #000;
}
.heart-opts button.active {
  background: #1a1714; color: #f4efe4;
}
.birth-confession, .memorial-confession {
  margin: 14px 0 0; padding: 10px 12px;
  border-left: 3px solid #8a6a3a; background: rgba(215,181,109,.12);
  color: var(--ink); line-height: 1.7;
}
.memory-confession { margin: 6px 0 0; color: var(--muted); font-size: .92em; }


/* —— 立繪放大與人物資訊 —— */
.portrait-frame.is-clickable { cursor: pointer; }
.portrait-frame.is-clickable:focus-within .portrait-img,
.portrait-frame.is-clickable:hover .portrait-img,
.portrait-frame.is-clickable:hover .pixel-portrait {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.portrait-hint {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
#portrait-modal.overlay { z-index: 60; }
.portrait-sheet {
  width: min(720px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 8px 8px 0 rgba(0,0,0,0.45), 0 0 0 4px rgba(215,181,109,0.35);
  padding: 18px 18px 20px;
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1fr;
  gap: 18px;
  align-items: start;
}
.portrait-sheet-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.portrait-sheet-img,
.portrait-sheet-canvas {
  width: min(280px, 70vw);
  height: auto;
  aspect-ratio: 2 / 3;
  background: #120e0b;
  border: 4px solid #d7b56d;
  box-shadow: 4px 4px 0 #000;
  object-fit: contain;
  object-position: center top;
  display: block;
}
.portrait-sheet-canvas {
  /* 像素備援仍繪正方形，contain 於直式框內 */
  object-fit: contain;
}
.portrait-sheet-canvas { image-rendering: pixelated; }
.portrait-sheet-img[hidden],
.portrait-sheet-canvas[hidden] { display: none !important; }
.portrait-sheet-body { min-width: 0; }
.portrait-sheet-body h3 {
  margin: 4px 0 6px;
  font-size: clamp(22px, 4vw, 30px);
}
.portrait-sheet-meta { margin: 0 0 10px; color: var(--muted); }
.portrait-sheet-blurb {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.7;
  margin: 0 0 12px;
  color: #efe6d6;
}
.portrait-sheet-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin: 0 0 14px;
}
.portrait-sheet-facts div {
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.portrait-sheet-facts dt { color: var(--muted); font-size: 12px; }
.portrait-sheet-facts dd { margin: 2px 0 0; }
.portrait-sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .portrait-sheet { grid-template-columns: 1fr; }
  .portrait-sheet-img, .portrait-sheet-canvas {
    width: min(220px, 72vw);
    height: auto;
    aspect-ratio: 2 / 3;
  }
}


/* —— 聽雨／BGM（置頂右上，較顯眼） —— */
.bgm-dock {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: 14px;
  z-index: 90;
  font-size: 13px;
}
.bgm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--gold-dim, var(--gold));
  background: rgba(20, 16, 12, 0.94);
  color: var(--gold);
  letter-spacing: 0.18em;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.45), 0 0 0 1px rgba(215,181,109,0.25);
  font-weight: 600;
}
.bgm-toggle:hover { border-color: var(--gold); background: rgba(30, 24, 16, 0.96); }
.bgm-toggle-state {
  color: var(--muted);
  letter-spacing: 0.08em;
  font-size: 12px;
}
.bgm-toggle.is-playing .bgm-toggle-state { color: var(--jade); }
.bgm-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  bottom: auto;
  width: min(300px, calc(100vw - 28px));
  max-height: min(70vh, 520px);
  overflow: auto;
  padding: 12px 14px 14px;
  background: rgba(18, 14, 10, 0.96);
  border: 1px solid var(--line);
  box-shadow: 6px 6px 0 rgba(0,0,0,0.5), 0 0 0 3px rgba(215,181,109,0.2);
}
.bgm-panel-title {
  margin: 0 0 2px;
  font-family: var(--serif);
  color: var(--gold);
  letter-spacing: 0.2em;
}
.bgm-panel-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.bgm-track-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  max-height: 220px;
  overflow: auto;
}
.bgm-track {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.03);
  color: var(--ink);
}
.bgm-track:hover { border-color: var(--line); background: rgba(215,181,109,0.06); }
.bgm-track.is-active {
  border-color: var(--gold-dim);
  background: rgba(215,181,109,0.12);
  color: var(--gold);
}
.bgm-track-title { display: block; letter-spacing: 0.12em; }
.bgm-track-blurb {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.bgm-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.bgm-controls .btn { padding: 6px 10px; font-size: 12px; }
.bgm-vol {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  flex: 1 1 120px;
}
.bgm-vol input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
  min-width: 80px;
}
.bgm-now {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
}
@media (max-width: 640px) {
  .bgm-dock {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 10px;
    bottom: auto;
  }
  .bgm-toggle { padding: 9px 12px; font-size: 12px; }
}


/* —— 手機適配 —— */
.mobile-life-bar { display: none; }
.panel-mobile-head { display: none; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  -webkit-tap-highlight-color: rgba(215, 181, 109, 0.18);
  touch-action: manipulation;
}
button, .tag, .loadout-row, .speeds button, .focus-row button, .choice-options button, .path-row button {
  touch-action: manipulation;
  min-height: 40px;
}
.tag { min-height: 28px; display: inline-flex; align-items: center; }
.daqian-tooltip {
  max-width: min(320px, calc(100vw - 20px));
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
  word-break: break-word;
}

@media (max-width: 860px) {
  body { font-size: 16px; }
  .lead, .prose, .event { font-size: 16px; line-height: 1.75; }
  .hint { font-size: 13px; }

  #screen-birth {
    padding: 20px 14px calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .mast { gap: 12px; }
  .seal, .tomb-seal { width: 56px; height: 56px; font-size: 26px; }
  .subtitle { letter-spacing: 0.22em; font-size: 13px; }
  .birth-card, .choice-card, .memorial-card, .stone-card, .tomb {
    padding: 16px;
  }
  .birth-actions { gap: 8px; }
  .birth-actions .btn, .legend-farm-actions .btn {
    flex: 1 1 calc(50% - 8px);
    min-height: 44px;
    justify-content: center;
  }
  .legend-farm { padding: 12px; }
  .roll-grid { gap: 8px; }
  .path-head { flex-direction: column; }

  .life-top {
    width: min(1180px, calc(100% - 20px));
    padding: 12px 0 6px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .life-top .portrait-frame { order: 0; }
  .life-top .seal-btn { width: 48px; height: 48px; font-size: 22px; }
  .who h2 { font-size: 22px; }
  .age-num { font-size: 36px; }
  .life-top .pixel-portrait { width: 88px; height: 88px; }
  .life-top .portrait-img { width: 72px; height: auto; aspect-ratio: 2 / 3; }
  .portrait-hint { font-size: 10px; }

  .mobile-life-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(1180px, calc(100% - 20px));
    margin: 0 auto 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    background: rgba(18, 16, 12, 0.92);
    box-shadow: 3px 3px 0 rgba(0,0,0,0.4);
    position: sticky;
    top: 0;
    z-index: 45;
  }
  .mobile-panel-btn {
    flex: none;
    min-height: 40px;
    padding: 8px 12px;
    letter-spacing: 0.08em;
  }
  .mobile-life-summary {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
  }
  .mobile-life-summary strong { color: var(--gold); font-weight: 600; }

  .life-layout {
    width: min(1180px, calc(100% - 20px));
    grid-template-columns: 1fr;
    gap: 12px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  .panel {
    display: none;
    position: fixed;
    inset: auto 10px calc(78px + env(safe-area-inset-bottom, 0px)) 10px;
    top: 58px;
    z-index: 55;
    max-height: calc(100vh - 150px - env(safe-area-inset-bottom, 0px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    background: rgba(16, 14, 11, 0.97);
    box-shadow: 0 16px 40px rgba(0,0,0,0.55), 0 0 0 3px rgba(215,181,109,0.25);
  }
  body.panel-open .panel { display: block; }
  .panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 50;
  }
  body.panel-open .panel-backdrop { display: block; }
  .panel-backdrop.hidden { display: none !important; }
  .panel-mobile-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    position: sticky;
    top: -14px;
    background: rgba(16, 14, 11, 0.98);
    padding: 4px 0 8px;
    z-index: 1;
  }
  .panel-close-btn { min-height: 36px; padding: 6px 12px; flex: none; }

  .chronicle { min-height: 0; }
  .log {
    max-height: none;
    padding: 8px 12px 18px;
  }
  .year-card { padding: 12px 0; }
  .event-cg { max-height: 160px; }
  .choice-cg { max-height: 140px; }

  .dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(12, 10, 8, 0.96);
    border-top: 1px solid var(--line);
    z-index: 60;
    gap: 8px;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
  }
  .speeds { width: 100%; }
  .speeds button {
    flex: 1 1 auto;
    min-height: 40px;
    padding: 8px 8px;
    font-size: 12px;
  }
  .dock .btn, .dock .auto-toggle {
    min-height: 44px;
  }
  .dock .btn.primary { flex: 1 1 140px; }
  .auto-toggle { font-size: 13px; }

  #choice-modal.overlay {
    padding: 10px;
    align-items: end;
  }
  #choice-modal .choice-card {
    width: 100%;
    max-height: min(78vh, 720px);
    padding-bottom: 16px;
  }
  #choice-modal.is-minimized {
    padding: 0 10px calc(92px + env(safe-area-inset-bottom, 0px));
  }
  #ending.is-minimized {
    padding: 0 10px calc(92px + env(safe-area-inset-bottom, 0px));
  }
  .ending-dock {
    width: 100%;
    padding: 12px;
  }
  .ending-dock .btn { width: 100%; min-height: 48px; }
  #btn-ending-minimize { min-height: 40px; }
  .choice-options button {
    min-height: 52px;
    padding: 12px 14px;
    font-size: 15px;
  }
  .choice-min-btn { min-height: 40px; }
  .choice-dock {
    width: 100%;
    padding: 12px;
  }
  .choice-dock .btn { width: 100%; min-height: 48px; }

  .ending-facts, .portrait-sheet-facts { grid-template-columns: 1fr; }
  .bgm-dock {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 10px;
    bottom: auto;
  }
  .identity-form { grid-template-columns: 1fr; }
  .mini-stats { grid-template-columns: 1fr 1fr; }
  .focus-row { grid-template-columns: 1fr 1fr; }
  .focus-row button { min-height: 44px; }
  .loadout-row { padding: 10px 8px; min-height: 48px; }
  .tag { padding: 6px 10px; font-size: 13px; }
}

@media (max-width: 420px) {
  .speeds button { font-size: 11px; padding: 8px 4px; letter-spacing: 0; }
  .who h2 { font-size: 20px; }
  .age-num { font-size: 32px; }
  .mobile-life-summary { font-size: 11px; }
}



/* —— 性別／固有羈絆 —— */
.gender-block { margin: 0.85rem 0 0.4rem; }
.gender-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.gender-btn.is-on {
  background: linear-gradient(135deg, #3a2a14, #6b4e22);
  color: #f3e2b0;
  border-color: #d7b56d;
  box-shadow: 0 0 0 1px rgba(215, 181, 109, 0.35);
}
.cast-panel { margin-top: 0.85rem; padding-top: 0.55rem; border-top: 1px solid rgba(215, 181, 109, 0.18); }
.cast-bond-list { list-style: none; margin: 0.35rem 0 0; padding: 0; display: grid; gap: 0.4rem; }
.cast-bond-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.5rem;
  padding: 0.45rem 0.55rem; border-radius: 8px;
  background: rgba(20, 16, 12, 0.45); border: 1px solid rgba(215, 181, 109, 0.14);
  font-size: 0.82rem;
}
.cast-bond-item .cast-name { font-weight: 600; color: #e8d4a0; overflow-wrap: anywhere; min-width: 0; }
.cast-bond-item .cast-meta { color: #9a8b6e; grid-column: 1 / -1; overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
.cast-bond-item .cast-nums { color: #cbb888; text-align: right; white-space: nowrap; }
.cast-bond-item.is-ended { opacity: 0.78; }
.cast-bond-item .cast-ending-tag {
  grid-column: 1 / -1; color: #d7b56d; font-size: 0.78rem;
}
.ending-cast { margin: 0.8rem 0 1rem; display: grid; gap: 0.75rem; }
.ending-cast-card {
  border: 1px solid rgba(215, 181, 109, 0.28); border-radius: 12px;
  padding: 0.75rem; background: rgba(12, 10, 8, 0.55);
}
.ending-cast-card h4 { margin: 0 0 0.35rem; color: #f0d9a0; font-size: 1rem; }
.ending-cast-card .ending-cast-kind { color: #a8946c; font-size: 0.8rem; margin-bottom: 0.35rem; }
.ending-cast-cg {
  width: 100%; max-height: 420px; object-fit: contain; border-radius: 8px;
  margin: 0.4rem 0; background: #1a1612; display: block;
}
.ending-cast-cg.is-missing {
  display: flex; align-items: center; justify-content: center;
  min-height: 120px; color: #8a7a5c; font-size: 0.85rem;
  border: 1px dashed rgba(215,181,109,0.35);
}
.ending-cast-ph {
  min-height: 120px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px dashed rgba(215,181,109,0.35);
  color: #8a7a5c; font-size: 0.85rem; margin: 0.4rem 0; background: #14110e;
}

.cast-bond-item{display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;}
.cast-thumb{
  width: 36px;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  object-position: center top;
  border-radius: 6px;
  border: 1px solid rgba(255,215,140,.35);
  background: #120f0c;
}
.cast-meet-art .cast-portrait{max-height:280px;object-fit:contain;}


/* —— 宿緣／靈寵面板與標籤冊 —— */
.bond-panel {
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(215, 181, 109, 0.18);
}
.bond-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.bond-col h4 {
  margin: 0 0 0.2rem;
  font-size: 0.92rem;
  color: #e8d4a0;
  letter-spacing: 0.04em;
}
.bond-col .hint { margin: 0; font-size: 0.78rem; color: #9a8b6e; }
.bond-card { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.bond-card:hover, .bond-card:focus {
  outline: none;
  border-color: rgba(215, 181, 109, 0.45);
  background: rgba(40, 30, 18, 0.65);
}
.tag-more {
  cursor: pointer;
  background: rgba(215, 181, 109, 0.18) !important;
  border: 1px dashed rgba(215, 181, 109, 0.45);
  color: #f0d9a0 !important;
}
.tag-more:hover, .tag-more:focus {
  background: rgba(215, 181, 109, 0.32) !important;
}
.tags-sheet {
  width: min(520px, 94vw);
  max-height: min(78vh, 640px);
  overflow: auto;
  padding: 1.1rem 1.2rem 1rem;
}
.tags-modal-list {
  max-height: 52vh;
  overflow: auto;
  margin: 0.6rem 0 0.9rem;
  padding-right: 0.2rem;
}
.bond-sheet {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  gap: 0.85rem;
  width: min(720px, 96vw);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 1rem;
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(28, 22, 16, 0.96), rgba(12, 10, 8, 0.96));
  border: 1px solid rgba(215, 181, 109, 0.32);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}
.bond-sheet-visual {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.bond-sheet-img {
  width: 100%;
  max-width: 280px;
  height: auto;
  aspect-ratio: 2 / 3;
  max-height: min(60vh, 520px);
  object-fit: contain;
  object-position: center top;
  border-radius: 10px;
  border: 1px solid rgba(215, 181, 109, 0.28);
  background: #120f0c;
  display: block;
}
.bond-sheet-body { min-width: 0; }
.bond-sheet-body h3 { margin: 0.15rem 0 0.35rem; color: #f3e2b0; }
.bond-log-title {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.9rem;
  color: #d7b56d;
}
.bond-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  max-height: 42vh;
  overflow: auto;
}
.bond-log-item {
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  background: rgba(20, 16, 12, 0.5);
  border: 1px solid rgba(215, 181, 109, 0.14);
}
.bond-log-head {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.2rem;
  font-size: 0.78rem;
  color: #a8946c;
}
.bond-log-beat {
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: rgba(215, 181, 109, 0.12);
  color: #e8d4a0;
}
.bond-log-text {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.45;
  color: #e6dcc4;
}
.bond-log-empty { color: #8a7a5c; font-size: 0.85rem; padding: 0.4rem 0; }
.bond-cg-btn { margin-top: 0.35rem; font-size: 0.78rem; padding: 0.25rem 0.55rem; }

@media (max-width: 720px) {
  .bond-cols { grid-template-columns: 1fr; }
  .bond-sheet {
    grid-template-columns: 1fr;
    max-height: 90vh;
  }
  .bond-sheet-img { max-height: min(56vh, 480px); }
  .bond-log { max-height: 36vh; }
}


/* 宿緣結局標籤：真道侶／好羈絆／壞仇人 */
.cast-ending-tag.ending-true { color: #f0d78c; border-color: rgba(240, 215, 140, 0.45); }
.cast-ending-tag.ending-good { color: #9ec9a8; border-color: rgba(158, 201, 168, 0.4); }
.cast-ending-tag.ending-bad { color: #d98989; border-color: rgba(217, 137, 137, 0.45); }
#row-rivals strong { color: #e0a0a0; }
#row-companion #slot-companion-label { min-width: 2.5em; }


/* 破境把握提示 */
.breakthrough-chance {
  margin: 10px 0 6px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(215, 181, 109, 0.45);
  background: linear-gradient(135deg, rgba(60, 42, 18, 0.55), rgba(28, 22, 14, 0.7));
  color: var(--gold);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.04em;
  text-align: center;
}
.breakthrough-chance.hidden { display: none; }
.breakthrough-chance .bt-sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
  font-family: inherit;
}
.choice-options button .bt-rate {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 11px;
  opacity: 0.9;
}

/* mobile-scroll-clear-dock：結算／羈絆全開時壓過底欄，並留足捲動到底的內距 */
#ending.overlay:not(.hidden):not(.is-minimized) {
  z-index: 70;
  align-items: stretch;
  justify-items: center;
  padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px));
}
#ending.overlay:not(.hidden):not(.is-minimized) .tomb {
  max-height: calc(100dvh - 20px - env(safe-area-inset-bottom, 0px));
  max-height: calc(100vh - 20px - env(safe-area-inset-bottom, 0px));
  width: min(680px, 100%);
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}
#bond-modal.overlay:not(.hidden) {
  z-index: 80;
  align-items: stretch;
  justify-items: center;
  padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px));
}
#bond-modal.overlay:not(.hidden) .bond-sheet {
  max-height: calc(100dvh - 20px - env(safe-area-inset-bottom, 0px));
  max-height: calc(100vh - 20px - env(safe-area-inset-bottom, 0px));
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 860px) {
  /* 全開結算／開羈絆時隱藏生命底欄，避免蓋住「再入輪迴」等鈕 */
  body:has(#ending:not(.hidden):not(.is-minimized)) .dock,
  body:has(#bond-modal:not(.hidden)) .dock {
    visibility: hidden;
    pointer-events: none;
  }
  /* 開羈絆時一併讓縮小墓誌條別搶點／擋字 */
  body:has(#bond-modal:not(.hidden)) #ending.is-minimized {
    visibility: hidden;
    pointer-events: none;
  }
  /* 縮小結算回看時，歲月錄與墓誌條要清過兩層底欄 */
  #ending.is-minimized {
    padding: 0 10px calc(168px + env(safe-area-inset-bottom, 0px));
    z-index: 61;
  }
  body:has(#ending.is-minimized) .life-layout {
    padding-bottom: calc(200px + env(safe-area-inset-bottom, 0px));
  }
  .bond-sheet {
    grid-template-columns: 1fr;
    max-height: calc(100dvh - 20px - env(safe-area-inset-bottom, 0px));
    max-height: calc(100vh - 20px - env(safe-area-inset-bottom, 0px));
  }
  .bond-log {
    max-height: none; /* 改由整張 bond-sheet 捲，避免內層捲不到底 */
  }
  .tomb .birth-actions {
    padding-bottom: 8px;
  }
  /* Netlify 角標別擋操作列 */
  body.screen-life a[href*="netlify.com"] img,
  body #nfd-notification,
  iframe[title*="Netlify" i] {
    bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* 歲月錄內固有結局卡：勿 sticky／勿蓋住方針列 */
.year-card .cast-ending-cg,
.year-card .event-cg-wrap {
  position: relative;
  z-index: 1;
}
.cast-bond-item,
.bond-card {
  position: relative;
  z-index: 1;
}

/* 法寶／功法品階：整列 #row-manual／#row-armament 外框色線＋淡光（天紅／地金／玄紫／黃藍）
   內建 52px item-frame PNG 先隱藏；四張 PNG 保留不重裁，日後可作裝飾。 */
.item-grade {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
.item-grade-tian {
  border-color: #e85d5d;
  box-shadow: 0 0 0 1px rgba(232,93,93,0.28), 0 0 14px rgba(232,93,93,0.22), inset 0 0 12px rgba(232,93,93,0.08);
}
.item-grade-di {
  border-color: #d7b56d;
  box-shadow: 0 0 0 1px rgba(215,181,109,0.28), 0 0 14px rgba(215,181,109,0.22), inset 0 0 12px rgba(215,181,109,0.08);
}
.item-grade-xuan {
  border-color: #b48cff;
  box-shadow: 0 0 0 1px rgba(180,140,255,0.28), 0 0 14px rgba(180,140,255,0.22), inset 0 0 12px rgba(180,140,255,0.08);
}
.item-grade-huang {
  border-color: #6db0e8;
  box-shadow: 0 0 0 1px rgba(109,176,232,0.28), 0 0 14px rgba(109,176,232,0.22), inset 0 0 12px rgba(109,176,232,0.08);
}
/* hover／focus 勿蓋掉品階色線 */
.loadout-row.item-grade-tian:hover,
.loadout-row.item-grade-tian:focus-visible {
  border-color: #e85d5d;
  box-shadow: 0 0 0 1px rgba(232,93,93,0.35), 0 0 16px rgba(232,93,93,0.28), inset 0 0 14px rgba(232,93,93,0.1);
  background: rgba(232,93,93,0.06);
}
.loadout-row.item-grade-di:hover,
.loadout-row.item-grade-di:focus-visible {
  border-color: #d7b56d;
  box-shadow: 0 0 0 1px rgba(215,181,109,0.35), 0 0 16px rgba(215,181,109,0.28), inset 0 0 14px rgba(215,181,109,0.1);
  background: rgba(215,181,109,0.08);
}
.loadout-row.item-grade-xuan:hover,
.loadout-row.item-grade-xuan:focus-visible {
  border-color: #b48cff;
  box-shadow: 0 0 0 1px rgba(180,140,255,0.35), 0 0 16px rgba(180,140,255,0.28), inset 0 0 14px rgba(180,140,255,0.1);
  background: rgba(180,140,255,0.07);
}
.loadout-row.item-grade-huang:hover,
.loadout-row.item-grade-huang:focus-visible {
  border-color: #6db0e8;
  box-shadow: 0 0 0 1px rgba(109,176,232,0.35), 0 0 16px rgba(109,176,232,0.28), inset 0 0 14px rgba(109,176,232,0.1);
  background: rgba(109,176,232,0.07);
}
.item-grade-tag { font-size: 0.75rem; letter-spacing: 0.08em; margin-left: 0.35rem; opacity: 0.9; }
.item-grade-tian .item-grade-tag { color: #e85d5d; }
.item-grade-di .item-grade-tag { color: #d7b56d; }
.item-grade-xuan .item-grade-tag { color: #b48cff; }
.item-grade-huang .item-grade-tag { color: #6db0e8; }

/* 52px PNG 邊框圖：先隱藏（資源保留，不重裁） */
.item-frame-wrap {
  display: none !important;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  margin-right: 0.45rem;
  position: relative;
}
.item-frame {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.loadout-val { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.35rem; }

/* bond-replay-layer：重溫 CG 必須蓋在宿緣冊之上；宿緣／靈寵立繪一律直式 contain */
#portrait-modal.overlay:not(.hidden) { z-index: 95; }
#bond-modal .bond-sheet-visual {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: transparent;
}
#bond-modal .bond-sheet-img {
  width: min(100%, 300px);
  height: auto;
  aspect-ratio: 2 / 3;
  max-height: min(60vh, 560px);
  object-fit: contain;
  object-position: center top;
  background: #120f0c;
}
@media (max-width: 860px) {
  #bond-modal .bond-sheet-img {
    width: min(100%, 78vw);
    max-height: min(58vh, 520px);
  }
}

/* 歲月錄內宿緣／靈寵立繪：contain，不裁切 */
.cast-meet-art .cast-portrait,
.year-card .cast-portrait {
  width: 100%;
  height: auto;
  max-height: min(52vh, 420px);
  object-fit: contain;
  object-position: center top;
  background: #120f0c;
}

/* ── 手機：右緣「方針」浮鈕＋側滑抽屜（桌面不顯示） ── */
.policy-handle, .policy-drawer, .policy-backdrop { display: none; }
@media (max-width: 768px) {
  .chronicle-focus .focus-row { display: none; }
  .chronicle-focus { min-height: 0; }
  .policy-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    position: fixed;
    right: calc(6px + env(safe-area-inset-right, 0px));
    bottom: calc(30vh + 96px + env(safe-area-inset-bottom, 0px));
    width: 48px;
    height: 48px;
    padding: 0;
    border: 1px solid var(--gold);
    border-radius: 12px;
    background: rgba(18, 15, 11, 0.94);
    color: var(--gold);
    box-shadow: 0 6px 18px rgba(0,0,0,0.5), 0 0 0 2px rgba(215,181,109,0.18);
    z-index: 58;
    cursor: pointer;
    line-height: 1.1;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  .policy-handle small, .policy-handle span {
    font-size: 14px; font-weight: 600; letter-spacing: 0.04em; color: var(--gold);
  }
  /* 有方針：只顯示兩字簡稱；無方針：只顯示「方針」 */
  .policy-handle.has-policy small { display: none; }
  .policy-handle:not(.has-policy) span { display: none; }
  body.policy-open .policy-handle { background: var(--gold); color: #1a140c; }
  body.policy-open .policy-handle small,
  body.policy-open .policy-handle span { color: #1a140c; }

  .policy-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 64;
  }
  .policy-backdrop[hidden] { display: none; }
  .policy-drawer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: fixed;
    top: calc(64px + env(safe-area-inset-top, 0px));
    right: 0;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    width: min(78vw, 300px);
    max-height: calc(100vh - 170px);
    margin: auto 0;
    height: max-content;
    overflow: auto;
    padding: 14px calc(14px + env(safe-area-inset-right, 0px)) 14px 14px;
    background: rgba(16, 14, 11, 0.98);
    border: 1px solid var(--gold);
    border-right: 0;
    border-radius: 14px 0 0 14px;
    box-shadow: -10px 0 32px rgba(0,0,0,0.6);
    z-index: 65;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  body.policy-open .policy-drawer {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.22s ease, visibility 0s;
  }
  .policy-drawer-head { display: flex; align-items: center; justify-content: space-between; }
  .policy-drawer-head h4 { margin: 0; color: var(--gold); letter-spacing: 0.16em; font-size: 15px; }
  .policy-drawer-close {
    width: 44px; height: 44px; border: 0; background: transparent;
    color: var(--muted); font-size: 18px; cursor: pointer;
  }
  .policy-drawer-row { display: flex; flex-direction: column; gap: 8px; }
  .policy-drawer-row button {
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    color: inherit;
    font: inherit;
    font-size: 15px;
    letter-spacing: 0.1em;
    cursor: pointer;
  }
  .policy-drawer-row button.active { background: var(--gold); color: #1a140c; border-color: var(--gold); }
  .policy-drawer .hint { margin: 0; font-size: 12px; line-height: 1.5; }

  /* 全屏彈窗／結算／側欄開啟時讓位 */
  body:has(.overlay:not(.hidden):not(.is-minimized)) .policy-handle,
  body:has(.overlay:not(.hidden):not(.is-minimized)) .policy-drawer,
  body:has(.overlay:not(.hidden):not(.is-minimized)) .policy-backdrop,
  body.panel-open .policy-handle,
  #screen-life.hidden .policy-handle,
  #screen-life.hidden .policy-drawer,
  #screen-life.hidden .policy-backdrop {
    display: none !important;
  }
  body:has(#ending.is-minimized) .policy-handle { bottom: calc(30vh + 170px + env(safe-area-inset-bottom, 0px)); }
}
