/* ============================================================
   玄天宗 · 點名召喚台【水墨版】 — style.css
   淡色宣紙底 × 仙俠水墨山水。
   墨：#2b2722；硃砂：#a63e2d；泥金：#8a6f33；黛青：#46656e。
   題款直書、印章、留白——CSS 只做版面與簡單過場，
   美術由 image2 水墨素材、演出由 Blender 墨色影片承擔。
   ============================================================ */

@font-face {
  font-family: "XWWK"; /* 霞鶩文楷 TC 子集（UI 固定字），缺字自動退到楷體 */
  src: url("assets/fonts/wenkai-ui.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #f1ecdd;
  --paper-2: #e7e0cb;
  --paper-deep: #ddd4ba;
  --ink: #2b2722;
  --ink-mid: #5a5347;
  --ink-pale: #968d7b;
  --vermilion: #a63e2d;
  --vermilion-bright: #c14e38;
  --gold: #8a6f33;
  --r-color: #7d8a80;
  --sr-color: #46656e;
  --ssr-color: #a63e2d;
  --hairline: rgba(43, 39, 34, 0.28);
  --font-art: "XWWK", "Kaiti TC", "DFKai-SB", "KaiTi", "BiauKai", "Noto Serif TC", serif;
  --font-kai: "Kaiti TC", "DFKai-SB", "KaiTi", "BiauKai", "Noto Serif TC", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-art);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }
img.missing { visibility: hidden; }

/* ---------- 背景：水墨山水 + 紙紋暈邊 ---------- */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background-color: var(--paper);
  background-image:
    url("assets/images/bg_main.png"),
    radial-gradient(120% 100% at 50% 0%, #f4efe2 0%, #ece5d2 60%, #e2d9c2 100%);
  background-size: cover, cover;
  background-position: center, center;
}
#vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(95% 85% at 50% 45%, transparent 55%, rgba(106, 96, 75, 0.18) 100%),
    linear-gradient(180deg, rgba(106, 96, 75, 0.10) 0%, transparent 14%, transparent 80%, rgba(82, 73, 56, 0.16) 100%);
}
/* 角落墨點飛白 */
#app::before {
  content: "";
  position: fixed; left: -4vmin; bottom: -6vmin; z-index: 1;
  width: 42vmin; height: 42vmin;
  background: url("assets/images/splash_ink.png") center / contain no-repeat;
  opacity: 0.14;
  pointer-events: none;
  transform: scaleX(-1) rotate(8deg);
}

/* ---------- 頂欄（左：功能鈕） ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: flex-start; align-items: center;
  padding: 18px 24px;
}
#topActions { display: flex; gap: 12px; }

/* ---------- 直書題款（右上）＋印章 ---------- */
#titleBlock {
  position: fixed; top: 26px; right: 30px; z-index: 10;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  pointer-events: none;
}
#titleMain {
  writing-mode: vertical-rl;
  font-size: clamp(26px, 4.2vmin, 38px);
  letter-spacing: 0.34em;
  color: var(--ink);
}
#titleSub {
  writing-mode: vertical-rl;
  font-size: clamp(13px, 1.9vmin, 16px);
  letter-spacing: 0.42em;
  color: var(--ink-pale);
}
.seal {
  writing-mode: vertical-rl;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--vermilion);
  color: #f5efdd;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(245, 239, 221, 0.55), 0 1px 4px rgba(43, 39, 34, 0.25);
}
#titleSeal {
  width: 30px; height: 34px;
  font-size: 19px;
  transform: rotate(2deg);
}

/* ---------- 按鈕（墨線文人風） ---------- */
.btn {
  font-family: inherit; cursor: pointer;
  color: var(--ink-mid);
  background: rgba(241, 236, 221, 0.66);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 7px 16px;
  font-size: 15px; letter-spacing: 0.24em; text-indent: 0.24em;
  transition: border-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.12s;
}
.btn:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
  box-shadow: 0 1px 8px rgba(166, 62, 45, 0.18);
}
.btn:active { transform: scale(0.97); }
.btn-gold {
  color: #f5efdd;
  background: linear-gradient(165deg, #3a352d, #2b2722 70%);
  border-color: rgba(43, 39, 34, 0.5);
}
.btn-gold:hover { color: #fff; border-color: var(--vermilion); }

/* ---------- 中央召喚台 ---------- */
#altar {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  padding-top: 24px;
}
#circleWrap {
  position: relative;
  width: min(46vmin, 470px);
  aspect-ratio: 1;
}
#circleWrap::before {
  content: "";
  position: absolute; inset: 7%;
  border-radius: 50%;
  border: 1px solid rgba(43, 39, 34, 0.18);
}
#magicCircle {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain;
  /* 墨筆法陣已摳成真 alpha，正常合成、緩轉 */
  animation: spin 40s linear infinite, breathe 5.2s ease-in-out infinite;
}
#idleCard {
  position: absolute; left: 50%; top: 50%;
  height: 46%;
  transform: translate(-50%, -56%);
  border-radius: 6px;
  box-shadow: 0 5px 22px rgba(43, 39, 34, 0.28);
  animation: floatCard 5.4s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%, 100% { opacity: 0.82; } 50% { opacity: 1; } }
@keyframes floatCard {
  0%, 100% { transform: translate(-50%, -56%); }
  50% { transform: translate(-50%, -61%); }
}

/* 左側直書小題（與右上題款呼應） */
#altarHint {
  position: fixed; left: 34px; top: 50%; transform: translateY(-50%);
  writing-mode: vertical-rl;
  color: var(--ink-pale);
  letter-spacing: 0.6em; font-size: 15px;
}

/* 主召喚鈕：墨匾橫幅（image2 飛白筆刷） */
#btnSummon {
  position: relative;
  width: min(330px, 78vw); height: 86px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; border: none;
  background-color: transparent;
  background-image:
    url("assets/images/btn_summon.png"),
    linear-gradient(172deg, #3a352d, #2b2722 75%);
  background-size: 100% 132%, 100% 100%;
  background-position: center, center;
  background-repeat: no-repeat;
  border-radius: 8px;
  filter: drop-shadow(0 3px 10px rgba(43, 39, 34, 0.30));
  transition: transform 0.15s, filter 0.2s;
}
#btnSummon:hover {
  transform: scale(1.04);
  filter: drop-shadow(0 4px 14px rgba(166, 62, 45, 0.38));
}
#btnSummon:active { transform: scale(0.97); }
.btn-summon-text {
  font-size: 25px; letter-spacing: 0.32em; text-indent: 0.32em;
  color: #f1ecdd;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.btn-summon-sub {
  font-size: 11px; letter-spacing: 0.3em; text-indent: 0.3em;
  color: rgba(241, 236, 221, 0.62);
}
#counter {
  font-size: 14px; letter-spacing: 0.2em;
  color: var(--ink-pale);
}

/* ---------- 已抽紀錄 ---------- */
#logbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px 14px;
}
#logTitle {
  flex: none;
  color: var(--ink-mid);
  font-size: 14px; letter-spacing: 0.32em;
}
#logList {
  display: flex; gap: 8px; align-items: center;
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin; scrollbar-color: rgba(43, 39, 34, 0.3) transparent;
}
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 13px;
  font-size: 13px; letter-spacing: 0.1em;
  color: var(--ink-mid);
  background: rgba(241, 236, 221, 0.8);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  white-space: nowrap;
}
.chip i { font-style: normal; font-size: 11px; opacity: 0.9; }
.chip.R   { border-color: var(--r-color);   color: var(--r-color); }
.chip.SR  { border-color: var(--sr-color);  color: var(--sr-color); }
.chip.SSR {
  border-color: var(--ssr-color); color: var(--ssr-color);
  box-shadow: 0 1px 6px rgba(166, 62, 45, 0.25);
}

/* ---------- 名冊側欄（紙質） ---------- */
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
  width: min(360px, 94vw);
  background: rgba(241, 236, 221, 0.97);
  border-left: 1px solid var(--hairline);
  backdrop-filter: blur(6px);
  padding: 24px 22px;
  display: flex; flex-direction: column; gap: 13px;
  transform: translateX(105%);
  transition: transform 0.3s ease;
  overflow-y: auto;
}
#drawer.open { transform: translateX(0); }
#drawer h2 {
  color: var(--ink); font-size: 20px;
  letter-spacing: 0.4em; font-weight: normal;
}
.drawer-hint { font-size: 13px; color: var(--ink-pale); letter-spacing: 0.08em; }
#rosterInput {
  width: 100%; height: 200px;
  background: rgba(255, 252, 242, 0.7);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  color: var(--ink); font-family: var(--font-kai); font-size: 15px;
  line-height: 1.7; padding: 10px 12px;
  resize: vertical; outline: none;
}
#rosterInput:focus { border-color: var(--vermilion); }
.drawer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.drawer-sep { border-top: 1px dashed rgba(43, 39, 34, 0.22); margin: 4px 0; }
.opt-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 14px; letter-spacing: 0.1em; color: var(--ink-mid);
}
.opt-row input[type="checkbox"] { accent-color: var(--vermilion); width: 16px; height: 16px; }
#weightsRow .w-label { color: var(--ink-mid); letter-spacing: 0.2em; }
.w-item { display: inline-flex; align-items: center; gap: 4px; }
.w-item.ssr { color: var(--ssr-color); }
.w-item.sr  { color: var(--sr-color); }
.w-item.r   { color: var(--r-color); }
.w-item input {
  width: 52px; text-align: center;
  background: rgba(255, 252, 242, 0.7);
  border: 1px solid var(--hairline); border-radius: 3px;
  color: inherit; font-family: inherit; font-size: 14px;
  padding: 3px 2px; outline: none;
}
.drawer-close { margin-top: auto; }

/* ---------- 召喚動畫層（墨色影片 × multiply） ---------- */
#videoLayer {
  position: fixed; inset: 0; z-index: 50;
  opacity: 0; transition: opacity 0.35s ease;
}
#videoLayer.show { opacity: 1; }
#videoDim {
  position: absolute; inset: 0;
  /* 紙帷：畫面收攏為素紙，墨在其上顯影 */
  background: rgba(238, 232, 216, 0.94);
}
#summonVideo {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  /* 白底墨色渲染 → multiply：白變透明、墨上紙 */
  mix-blend-mode: multiply;
}
#fxCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- SSR 爆光疊加（硃砂墨爆 × multiply） ---------- */
#ssrVideo {
  position: fixed; inset: 0; z-index: 65;
  width: 100%; height: 100%; object-fit: cover;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* ---------- 結果層（掛軸式） ---------- */
#resultLayer {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.3s ease;
}
#resultLayer.show { opacity: 1; }
#resultBackdrop {
  position: absolute; inset: 0;
  background: rgba(231, 224, 203, 0.90);
}
#resultStage {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 24px;
}
/* 結果卡後方的淡墨飛白 */
#resultStage::before {
  content: "";
  position: absolute; top: 46%; left: 50%; z-index: -1;
  width: 130%; aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(-12deg);
  background: url("assets/images/splash_ink.png") center / contain no-repeat;
  opacity: 0.10;
}
#resultCard {
  position: relative;
  width: min(320px, 72vw, 52vh);
  aspect-ratio: 2 / 3;
  color: var(--ink-mid);
}
#resultCard.pop { animation: cardPop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes cardPop {
  0% { transform: scale(0.62); opacity: 0; }
  62% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); }
}
#resultCardBg {
  position: absolute; inset: 4.5%;
  border-radius: 6px;
  background:
    radial-gradient(130% 100% at 50% 0%, #f7f3e8 0%, #efe9d8 55%, #e6deca 100%);
  box-shadow: inset 0 0 24px rgba(106, 96, 75, 0.18), 0 6px 24px rgba(43, 39, 34, 0.22);
}
#resultFrame {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: fill;
  pointer-events: none;
}
#resultInner { position: absolute; inset: 10% 12%; }
/* 稀有度 → 印章（右上） */
#resultRarity {
  position: absolute; top: 1%; right: 2%;
  writing-mode: vertical-rl;
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; padding: 9px 6px;
  font-size: 19px; letter-spacing: 0.18em;
  color: #f5efdd;
  background: var(--ink-pale);
  border-radius: 3px;
  transform: rotate(2deg);
  box-shadow: inset 0 0 0 1px rgba(245, 239, 221, 0.55), 0 1px 4px rgba(43, 39, 34, 0.3);
}
#resultCard.R   #resultRarity { background: var(--r-color); }
#resultCard.SR  #resultRarity { background: var(--sr-color); }
#resultCard.SSR #resultRarity { background: var(--ssr-color); }
/* 姓名 → 直書大字（掛軸主題字；字級保 4 字單列不換行） */
#resultName {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  writing-mode: vertical-rl;
  font-family: var(--font-kai);
  font-size: clamp(40px, 8.2vmin, 60px);
  letter-spacing: 0.14em;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 252, 242, 0.6);
}
/* 稱號 → 姓名左側題款小字（避開卡框墨跡、加紙暈保可讀） */
#resultTitle {
  position: absolute; left: 17%; top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  font-size: 16px; letter-spacing: 0.42em;
  color: var(--ink-mid);
  text-shadow: 0 0 8px rgba(247, 243, 232, 0.95), 0 0 3px rgba(247, 243, 232, 1);
}
#resultCard.R   { color: var(--r-color); }
#resultCard.SR  { color: var(--sr-color); }
#resultCard.SSR { color: var(--ssr-color); }
#resultCard.SSR #resultCardBg {
  background:
    radial-gradient(130% 100% at 50% 0%, #f8f2e2 0%, #f1e7cd 55%, #e9dcba 100%);
  box-shadow: inset 0 0 0 1px rgba(138, 111, 51, 0.35), inset 0 0 24px rgba(138, 111, 51, 0.18), 0 6px 26px rgba(166, 62, 45, 0.25);
}
#resultCard.SSR.pop { animation: cardPop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1), sealGlow 2.4s ease-in-out 0.6s infinite; }
@keyframes sealGlow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(166, 62, 45, 0.18)); }
  50% { filter: drop-shadow(0 0 22px rgba(166, 62, 45, 0.38)); }
}
#resultActions { display: flex; gap: 16px; }

body.ssr-shake #app { animation: shake 0.55s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -2px); }
}

/* ---------- 揭曉紅暈 / 提示 ---------- */
#flash {
  position: fixed; inset: 0; z-index: 80; pointer-events: none;
  background: radial-gradient(circle at 50% 48%, rgba(193, 78, 56, 0.42) 0%, rgba(193, 78, 56, 0) 70%);
  opacity: 0;
}
#flash.boom { animation: flashFade 0.7s ease-out; }
@keyframes flashFade { from { opacity: 1; } to { opacity: 0; } }

#toast {
  position: fixed; top: 16%; left: 50%; z-index: 90;
  transform: translateX(-50%);
  background: url("assets/images/result_panel.png") center / 100% 100% no-repeat;
  padding: 22px 64px;
  font-size: 16px; letter-spacing: 0.22em;
  color: var(--ink);
  filter: drop-shadow(0 3px 10px rgba(43, 39, 34, 0.25));
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
#toast.show { opacity: 1; }

/* ---------- 行動裝置 ---------- */
@media (max-width: 760px) {
  #titleBlock { top: 14px; right: 14px; }
  #titleMain { font-size: 22px; }
  #titleSub { display: none; }
  #altarHint { left: 12px; font-size: 12px; }
  .btn { padding: 6px 11px; font-size: 13px; letter-spacing: 0.14em; }
  #circleWrap { width: min(62vmin, 350px); }
  #btnSummon { height: 74px; }
  .btn-summon-text { font-size: 21px; }
  #logbar { padding: 8px 14px 10px; }
  #app::before { width: 56vmin; height: 56vmin; opacity: 0.10; }
}
