/*
 * 玩家端樣式。
 *
 * 播放器是**沉浸式**的：影片鋪滿整個視窗，畫面上沒有任何播放器 UI。
 * 右上角只有關閉與靜音兩顆圓鈕，其餘一律疊在影片上（劇情文字、選項）。
 *
 * 沒有播放/暫停鍵、音量滑桿、重播鍵、字幕開關、語言選單、金幣列 ——
 * 這些都會破壞沉浸感。功能改以手勢與自動行為提供，見 public/js/player.js。
 *
 * 參考：reference/chat-2.mp4
 */

:root {
  --bg: #0a0a0d;
  --panel: #1b1d27;
  --line: #2b2e3d;
  --txt: #e6e8f0;
  --dim: #9aa0b4;
  --accent: #c9a227;
  --danger: #e05260;

  /* 疊加層 */
  --sheet: rgba(16, 16, 20, .72);
  --sheet-line: rgba(255, 255, 255, .14);
  --glass: rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/*
 * [hidden] 必須贏過各元件自己的 display 宣告。
 *
 * .btn 與 .choice 都設了 display，而那會覆蓋瀏覽器預設的
 * [hidden]{display:none} —— 結果是 JS 明明設了 hidden，
 * 元素還是畫在畫面上。實測時踩過一次。
 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.65 -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ================================================================
   播放器：全屏沉浸
   ================================================================ */

.player {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  /* 行動瀏覽器網址列會吃掉 vh；dvh 才是真正可見高度 */
  height: 100vh;
  height: 100dvh;
}

/* 影片鋪滿，不留黑邊 */
.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}

/*
 * 點擊層。
 *
 * 播放中點一下暫停／再點繼續；播畢後點一下重播（spec §5.5 重播免費 ——
 * 重播完全不呼叫 API，所以不可能扣款）。刻意不畫任何按鈕。
 */
.tap-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* 字幕：加底色，避免壓在亮畫面上讀不到。位置由 JS 依疊加層高度調整。 */
.player video::cue {
  background: rgba(0, 0, 0, .72);
  color: #fff;
  font-size: .85em;
}

/* ---------- 右上角唯二的兩顆鈕 ---------- */

.corner {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.corner button,
.corner a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.corner button:hover,
.corner a:hover { background: rgba(0, 0, 0, .62); text-decoration: none; }
.corner svg { width: 21px; height: 21px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 底部疊加：劇情文字與選項 ---------- */

.overlay-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 60px 16px max(20px, env(safe-area-inset-bottom));
  /*
   * 由下往上的暗角。
   *
   * 必須夠深 —— 影片可能是任何亮度，實測用彩條測試片時淺色漸層
   * 完全壓不住，文字直接糊在亮黃與亮青上。寧可暗一點。
   */
  background: linear-gradient(to top,
    rgba(0, 0, 0, .90) 0%,
    rgba(0, 0, 0, .80) 42%,
    rgba(0, 0, 0, .56) 70%,
    rgba(0, 0, 0, .22) 88%,
    transparent 100%);
  pointer-events: none;      /* 空白處的點擊要能穿透到 .tap-layer */
}

.overlay-bottom > * { pointer-events: auto; }

.speaker {
  text-align: center;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}

.body-text {
  margin: 0 0 4px;
  text-align: center;
  font-size: 15px;
  color: rgba(255, 255, 255, .88);
  white-space: pre-wrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .95);
}

/*
 * 問題。畫面可能是任何亮度，所以靠多層陰影做出描邊效果，
 * 而不是只靠底下的暗角。
 */
.prompt {
  margin: 14px 4px 16px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  text-shadow:
    0 0 3px rgba(0, 0, 0, .95),
    0 1px 3px rgba(0, 0, 0, .95),
    0 0 14px rgba(0, 0, 0, .65);
}

/* ---------- 選項 ---------- */

.choices { display: grid; gap: 12px; }

/*
 * 膠囊樣式，文字置中，**不在每一列重複價格**。
 *
 * 同一節點的選項同價，所以金幣數由 .cost-once 統一顯示一次
 * （使用者指示）。價格不一致時才退回逐列顯示，見 .choice .cost。
 */
.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 14px 22px;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 999px;
  background: rgba(10, 10, 14, .42);
  backdrop-filter: blur(10px);
  color: #fff;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.choice:hover:not(:disabled) {
  background: rgba(30, 30, 38, .62);
  border-color: rgba(255, 255, 255, .6);
}

.choice:disabled { opacity: .5; cursor: default; }

.choice .text {
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}

/* 買不起：整列變暗並轉紅邊，價格另由 .cost-once 標紅 */
.choice.unaffordable {
  border-color: rgba(224, 82, 96, .55);
  color: rgba(255, 255, 255, .72);
}

/*
 * 逐列價格：只有在同一節點的選項價格不一致時才會出現。
 * 那代表統一顯示會說謊，寧可把每一列的實際價格標出來。
 */
.choice .cost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  margin-left: auto;
  padding: 6px 12px;
  border: 1px solid rgba(201, 162, 39, .75);
  border-radius: 999px;
  background: rgba(201, 162, 39, .16);
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.choice .cost img { width: 16px; height: 16px; display: block; }
.choice.has-cost { justify-content: flex-start; }
.choice.has-cost .text { flex: 1; text-align: left; }
.choice.unaffordable .cost {
  border-color: rgba(224, 82, 96, .7);
  background: rgba(224, 82, 96, .12);
  color: var(--danger);
}

/* ---------- 本次選擇的金幣數（只顯示一次） ---------- */

.cost-once {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 18px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9);
}

.cost-once img { width: 26px; height: 26px; display: block; }
.cost-once.unaffordable { color: var(--danger); }

/* ---------- 餘額（只在選項階段出現） ---------- */

.balance {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px 7px 9px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.balance img { width: 19px; height: 19px; display: block; }

/* ---------- 覆蓋層：載入中、失敗、結局 ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 28px;
  text-align: center;
  background: rgba(6, 6, 9, .86);
  backdrop-filter: blur(4px);
}

.overlay .title { color: #fff; font-size: 18px; font-weight: 600; }
.overlay p { margin: 0; color: var(--dim); font-size: 14px; max-width: 22em; }

/* 載入中不擋畫面，只放一個小轉圈 */
.overlay.quiet { background: rgba(0, 0, 0, .25); backdrop-filter: none; }

.spinner {
  width: 30px; height: 30px;
  border: 3px solid rgba(255, 255, 255, .2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 提示條（金幣不足、連線失敗等） ---------- */

.notice {
  margin: 0 0 12px;
  padding: 14px 16px;
  border: 1px solid var(--sheet-line);
  border-radius: 16px;
  background: var(--sheet);
  backdrop-filter: blur(12px);
  font-size: 14px;
}

.notice.warn { border-color: rgba(201, 162, 39, .7); }
.notice.error { border-color: rgba(224, 82, 96, .7); }
.notice .title { font-weight: 600; margin-bottom: 4px; color: #fff; }
.notice p { margin: 0; color: var(--dim); font-size: 13px; }
.notice .actions { margin-top: 11px; display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--sheet-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { background: rgba(255, 255, 255, .18); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1600; font-weight: 600; }

/* ---------- 桌機：把舞台收成直式，不要把直式影片拉寬 ---------- */

@media (min-width: 700px) {
  .player {
    position: relative;
    width: min(440px, calc((100dvh - 32px) * 9 / 16));
    height: calc(100dvh - 32px);
    margin: 16px auto;
    border-radius: 16px;
    border: 1px solid var(--line);
  }
  body { background: #07070a; }
}

/* ================================================================
   角色列表
   ================================================================ */

.list { max-width: 620px; margin: 0 auto; padding: 24px 16px 60px; }
.list h1 { font-size: 20px; margin: 0 0 18px; }

.card {
  display: block;
  padding: 15px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--txt);
}

.card:hover { border-color: #3a3e52; text-decoration: none; }
.card .name { font-size: 16px; font-weight: 600; }
.card .meta { color: var(--dim); font-size: 13px; margin-top: 3px; }
.card .summary { color: var(--dim); font-size: 14px; margin-top: 7px; }
.card .stories { margin-top: 11px; display: grid; gap: 7px; }

.story-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #161824;
  color: var(--txt);
  font-size: 14px;
}

.story-link:hover { background: #1d2030; text-decoration: none; }
.story-link .arrow { margin-left: auto; color: var(--dim); }

.empty { color: var(--dim); padding: 30px 0; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
