/* =========================================================
   路人勇者的扮演遊戲 — 視覺小說樣式
   純 CSS 氛圍，無外部美術素材。色調：神秘紫藍 × 暗金。
   ========================================================= */

:root {
  --bg-0: #0a0712;
  --bg-1: #15102a;
  --ink: #f2ecff;
  --ink-dim: #b6abd4;
  --accent: #c8a2ff;      /* 主角色：變身之紫 */
  --gold: #e8c473;        /* 暗金點綴 */
  --danger: #ff6b8b;
  --box-bg: rgba(14, 10, 28, 0.82);
  --box-edge: rgba(200, 162, 255, 0.35);
  --font: "Noto Serif TC", "Songti TC", "PingFang TC", "Microsoft JhengHei", serif;
  --ui-font: "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  overflow: hidden;
}

/* ---------- 畫面切換 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.screen.is-active { display: flex; opacity: 1; }

/* ---------- 標題畫面 ---------- */
#title-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background:
    radial-gradient(120% 80% at 50% -10%, #2a1d52 0%, var(--bg-1) 45%, var(--bg-0) 100%);
}
#title-screen::-webkit-scrollbar { display: none; }
.title-aura {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(40% 30% at 50% 38%, rgba(200,162,255,0.22), transparent 70%);
  animation: breathe 7s ease-in-out infinite;
  pointer-events: none;
}
@keyframes breathe { 0%,100%{opacity:.55;transform:scale(1);} 50%{opacity:1;transform:scale(1.06);} }

.title-inner { position: relative; z-index: 1; padding: 16px 24px; }
.title-kicker { letter-spacing: .4em; color: var(--gold); font-size: 14px; margin-bottom: 12px; }
.title-main {
  font-size: clamp(38px, 9vw, 76px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: .04em;
  text-shadow: 0 0 28px rgba(200,162,255,0.45);
}
.title-sub {
  margin: 14px auto 22px;
  max-width: 30em;
  color: var(--ink-dim);
  font-size: clamp(13px, 2.6vw, 17px);
  line-height: 1.9;
}
.title-menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-foot { margin-top: 18px; font-size: 12px; color: rgba(182,171,212,0.5); font-family: var(--ui-font); }
.title-foot + .title-foot { margin-top: 10px; }
.ext-link { color: var(--gold); text-decoration: none; border-bottom: 1px dashed rgba(232,196,115,0.5); padding-bottom: 1px; transition: color .2s; }
.ext-link:hover { color: #f4d98a; }
.ext-link.link-game { color: var(--accent); border-bottom-color: rgba(200,162,255,0.5); }
.ext-link.link-game:hover { color: #ddc4ff; }
.settings-link { font-family: var(--ui-font); font-size: 13px; text-align: center; margin-bottom: 18px; }
.serial-badge { display: inline-block; font-size: 10px; letter-spacing: .1em; padding: 2px 7px; border-radius: 999px; background: rgba(80,220,120,0.15); color: #7de8a0; border: 1px solid rgba(80,220,120,0.3); vertical-align: middle; margin-left: 6px; }

/* ---------- 按鈕 ---------- */
.menu-btn {
  font-family: var(--ui-font);
  font-size: 16px;
  color: var(--ink);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--box-edge);
  border-radius: 999px;
  padding: 12px 34px;
  min-width: 220px;
  cursor: pointer;
  transition: all .2s ease;
  backdrop-filter: blur(6px);
}
.menu-btn:hover { background: rgba(200,162,255,0.16); transform: translateY(-1px); }
.menu-btn.primary { background: linear-gradient(135deg, var(--accent), #8a6fd6); color: #1a1230; border: none; font-weight: 700; }
.menu-btn.primary:hover { box-shadow: 0 6px 24px rgba(200,162,255,0.4); }
.menu-btn.danger { color: var(--danger); border-color: rgba(255,107,139,0.4); min-width: auto; padding: 10px 20px; }
.menu-btn.danger:hover { background: rgba(255,107,139,0.12); }

.icon-btn {
  font-family: var(--ui-font);
  background: none; border: none; color: var(--ink-dim);
  font-size: 15px; cursor: pointer; padding: 8px 12px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- 章節選擇 ---------- */
.sub-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(200,162,255,0.12);
  background: var(--bg-1);
}
.sub-header h2 { font-size: 20px; font-weight: 700; }
.sub-header .spacer { flex: 1; }
#chapter-screen { background: linear-gradient(180deg, var(--bg-1), var(--bg-0)); }
.chapter-list { list-style: none; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chapter-card {
  font-family: var(--ui-font);
  text-align: left;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--box-edge);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  color: var(--ink);
  transition: all .2s ease;
}
.chapter-card:hover { background: rgba(200,162,255,0.12); transform: translateX(4px); }
.chapter-card .ch-no { color: var(--gold); font-size: 13px; letter-spacing: .15em; }
.chapter-card .ch-title { font-size: 18px; font-weight: 700; margin-top: 4px; }
.chapter-card .ch-note { font-size: 13px; color: var(--ink-dim); margin-top: 6px; }
.chapter-card.locked { opacity: .45; cursor: not-allowed; border-left-color: #555; }
.chapter-card.locked:hover { transform: none; background: rgba(255,255,255,0.03); }

/* ---------- 遊戲畫面 ---------- */
#game-screen { background: var(--bg-0); }

.bg-layer {
  position: absolute; inset: 0;
  transition: background 1.2s ease, filter 1.2s ease;
  background: radial-gradient(120% 90% at 50% 30%, #241a44, var(--bg-0));
}
/* 氛圍主題 */
.bg-layer.bg-dawn   { background: radial-gradient(120% 90% at 50% 20%, #4a3a6b, #1a1430 70%); }
.bg-layer.bg-palace { background: linear-gradient(180deg, #3a2c5e, #1d1638 80%); }
.bg-layer.bg-night  { background: radial-gradient(100% 80% at 70% 10%, #1b2350, #07060f 70%); }
.bg-layer.bg-danger { background: radial-gradient(120% 100% at 50% 120%, #5e1f33, #120610 70%); }
.bg-layer.bg-memory { background: radial-gradient(80% 80% at 50% 50%, #2b4a5e, #0c1622 70%); filter: blur(0.5px); }
.bg-layer.bg-void   { background: radial-gradient(60% 60% at 50% 50%, #1a1530, #000 80%); }

/* 漂浮微光粒子 */
.bg-layer::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 70% 60%, rgba(200,162,255,0.6), transparent),
    radial-gradient(1.5px 1.5px at 45% 80%, rgba(232,196,115,0.4), transparent),
    radial-gradient(1px 1px at 85% 25%, rgba(255,255,255,0.4), transparent);
  background-size: 100% 100%;
  animation: drift 18s ease-in-out infinite alternate;
  opacity: .7;
}
@keyframes drift { from{transform:translateY(0);} to{transform:translateY(-16px);} }

.stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.focus-orb {
  width: min(46vw, 320px); height: min(46vw, 320px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200,162,255,0.25), transparent 65%);
  filter: blur(8px);
  opacity: 0; transform: scale(.8);
  transition: opacity 1s ease, transform 1s ease, background 1s ease;
}
.focus-orb.show { opacity: 1; transform: scale(1); }

/* HUD */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  font-family: var(--ui-font);
}
.hud-right { display: flex; gap: 8px; }
.hud-btn {
  font-family: var(--ui-font);
  background: rgba(10,7,18,0.55); color: var(--ink-dim);
  border: 1px solid rgba(200,162,255,0.2); border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; backdrop-filter: blur(4px);
  transition: all .2s;
}
.hud-btn:hover { color: var(--ink); border-color: var(--accent); }
.hud-btn.on { background: var(--accent); color: #1a1230; border-color: var(--accent); }
.chapter-tag {
  position: absolute; top: 52px; left: 16px;
  font-size: 12px; color: var(--gold); letter-spacing: .12em;
  font-family: var(--ui-font); pointer-events: none;
}

/* 對話框 */
.dialogue-box {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  margin: 16px; padding: 22px 26px 26px;
  min-height: 30vh;
  background: var(--box-bg);
  border: 1px solid var(--box-edge);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
  cursor: pointer;
}
.speaker {
  display: inline-block;
  font-family: var(--ui-font);
  font-size: 17px; font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  padding-bottom: 4px;
  min-height: 1.2em;
  border-bottom: 2px solid currentColor;
  letter-spacing: .05em;
}
.speaker:empty { border: none; }
.dialogue-text {
  font-size: clamp(17px, 3.2vw, 22px);
  line-height: 2;
  letter-spacing: .03em;
  min-height: 4em;
  white-space: pre-wrap;
}
.continue-hint {
  position: absolute; right: 24px; bottom: 16px;
  color: var(--accent); font-size: 14px;
  animation: bob 1.1s ease-in-out infinite; opacity: 0;
}
.continue-hint.show { opacity: .9; }
@keyframes bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(5px);} }

/* 選項層 */
.choice-layer {
  position: absolute; inset: 0; z-index: 6;
  display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  padding: 24px;
  background: rgba(8,5,16,0.55);
  backdrop-filter: blur(3px);
}
.choice-layer.show { display: flex; }
.choice-prompt {
  font-family: var(--ui-font); color: var(--gold);
  font-size: 15px; letter-spacing: .1em; margin-bottom: 8px; text-align: center;
}
.choice-btn {
  font-family: var(--ui-font);
  width: min(90%, 520px);
  font-size: 16px; line-height: 1.6;
  color: var(--ink);
  background: rgba(20,14,38,0.9);
  border: 1px solid var(--box-edge);
  border-radius: 12px;
  padding: 16px 22px; cursor: pointer;
  transition: all .2s ease;
  animation: rise .4s ease backwards;
}
.choice-btn:hover { background: rgba(200,162,255,0.18); border-color: var(--accent); transform: scale(1.02); }
@keyframes rise { from{opacity:0;transform:translateY(14px);} to{opacity:1;transform:translateY(0);} }

/* ---------- 設定 overlay ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,3,12,0.7); backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.panel {
  width: min(92%, 420px);
  background: var(--bg-1);
  border: 1px solid var(--box-edge);
  border-radius: 18px; padding: 26px;
  font-family: var(--ui-font);
}
.panel h3 { font-size: 20px; margin-bottom: 20px; color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; font-size: 14px; color: var(--ink-dim); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.field.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.panel-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }

/* ---------- 響應式 ---------- */
@media (max-width: 600px) {
  .dialogue-box { min-height: 34vh; margin: 10px; padding: 18px 18px 22px; }
  .menu-btn { min-width: 200px; }
  .focus-orb { width: 70vw; height: 70vw; }
}

/* 桌面：滑鼠提示可點 */
@media (min-width: 900px) {
  #game-screen { cursor: default; }
}

/* ===== v0.5.0 封面＋視覺特效 ===== */

/* --- 封面橫幅 --- */
.cover-banner {
  position: relative;
  width: min(460px, 92vw);
  margin: 0 auto 18px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(200,162,255,0.22),
    0 6px 28px rgba(0,0,0,0.55),
    0 0 60px rgba(200,162,255,0.08);
  animation: cover-fade-in .9s ease both, cover-float 9s .9s ease-in-out infinite;
}
.cover-img { width: 100%; display: block; }
.cover-banner::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 42%;
  background: linear-gradient(to bottom, transparent, var(--bg-0));
  pointer-events: none;
}
@keyframes cover-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes cover-float {
  0%,100% { transform: translateY(0)    rotate(0deg);    }
  38%      { transform: translateY(-5px)  rotate(-.14deg); }
  72%      { transform: translateY(-8px)  rotate(.14deg);  }
}

/* --- 標題漸層閃光 --- */
.title-main {
  background: linear-gradient(
    120deg,
    var(--ink) 0%,
    var(--accent) 28%,
    var(--gold)   48%,
    var(--accent) 68%,
    var(--ink) 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 8s ease-in-out infinite, fade-up-title .8s .4s ease both;
}
@keyframes shimmer {
  0%   { background-position:  200% 0; }
  50%  { background-position:    0% 0; }
  100% { background-position: -200% 0; }
}
@keyframes fade-up-title {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0);    }
}

/* --- 元素進場（錯開） --- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0);    }
}
.title-kicker { animation: fade-up .6s .12s ease both; }
.title-sub    { animation: fade-up .6s .55s ease both; }
.title-menu   { animation: fade-up .7s .70s ease both; }
.title-foot   { animation: fade-up .5s .85s ease both; }

/* --- 開始按鈕光暈脈動 --- */
.menu-btn.primary {
  animation: btn-pulse 3.2s 2s ease-in-out infinite;
}
@keyframes btn-pulse {
  0%,100% { box-shadow: 0 6px 24px rgba(200,162,255,.0); }
  50%      { box-shadow: 0 6px 24px rgba(200,162,255,.35), 0 0 0 3px rgba(200,162,255,.15); }
}

/* --- 浮游粒子 --- */
.tp {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  animation: ptcl linear infinite;
}
@keyframes ptcl {
  0%   { transform: translateY(0)    scale(0);   opacity: 0; }
  12%  { transform: translateY(-8px)  scale(1);   opacity: 1; }
  88%  { transform: translateY(-55px) scale(.75); opacity: .4; }
  100% { transform: translateY(-76px) scale(0);   opacity: 0; }
}

@media (max-width: 600px) {
  .cover-banner { margin-bottom: 18px; }
}

/* ===== v0.6.0 遊戲內容特效 ===== */

/* 打字游標 */
#dialogue-text.typing::after {
  content: "▌";
  color: var(--accent);
  animation: cursor-blink .65s step-end infinite;
  margin-left: 1px;
}
@keyframes cursor-blink {
  0%,100% { opacity: .9; }
  50%      { opacity: 0;  }
}

/* 角色名滑入 */
.speaker-in { animation: speaker-slide .3s ease both; }
@keyframes speaker-slide {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0);     }
}

/* 對話框新台詞微光 */
.line-in { animation: line-glow .35s ease; }
@keyframes line-glow {
  0%   { box-shadow: 0 -10px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(200,162,255,.55); }
  100% { box-shadow: 0 -10px 40px rgba(0,0,0,.5); }
}

/* 場景切換閃光層 */
.scene-flash {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none; opacity: 0;
}
.scene-flash.flash-in { animation: s-flash .45s ease-out; }
@keyframes s-flash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* danger 場景輕震 */
@keyframes danger-shake {
  0%,100% { transform: translateX(0) rotate(0);      }
  18%      { transform: translateX(-5px) rotate(-.15deg); }
  36%      { transform: translateX(4px) rotate(.12deg);  }
  60%      { transform: translateX(-3px);              }
  82%      { transform: translateX(2px);               }
}
.danger-shake { animation: danger-shake .42s ease; }

/* 章節標籤進場 */
.chapter-in { animation: chapter-slide .65s ease both; }
@keyframes chapter-slide {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0);     }
}

/* 遊戲內浮游粒子 */
.gp {
  position: absolute; border-radius: 50%;
  pointer-events: none; z-index: 1;
  animation: gp-float linear infinite;
}
@keyframes gp-float {
  0%   { transform: translateY(0)     scale(0);   opacity: 0;  }
  12%  { transform: translateY(-8px)  scale(1);   opacity: .5; }
  88%  { transform: translateY(-48px) scale(.7);  opacity: .2; }
  100% { transform: translateY(-65px) scale(0);   opacity: 0;  }
}

/* ===== v0.9.0 場景視覺強化 ===== */

/* CRT 掃描線薄膜 */
#game-screen::before {
  content:''; position:absolute; inset:0; z-index:30; pointer-events:none;
  background:repeating-linear-gradient(to bottom,
    transparent 0px, transparent 3px, rgba(0,0,0,0.05) 3px, rgba(0,0,0,0.05) 4px);
}

/* 確保星點粒子在暗角之下 */
.bg-layer::after { z-index:1; }

/* 暗角層 - 覆蓋粒子之上 */
.bg-layer::before {
  content:''; position:absolute; inset:0; z-index:2; pointer-events:none;
  background:radial-gradient(ellipse 85% 75% at 50% 50%, transparent 35%, rgba(0,0,0,0.68) 100%);
  transition:background 0.9s ease, opacity 0.6s ease;
}

/* 各場景彩色暗角 */
.bg-layer.bg-danger::before {
  background:radial-gradient(ellipse 75% 65% at 50% 50%, transparent 12%, rgba(120,0,20,0.78) 100%);
  animation:vignette-pulse 1.9s ease-in-out infinite;
}
@keyframes vignette-pulse { 0%,100%{opacity:1} 50%{opacity:.42} }

.bg-layer.bg-void::before {
  background:radial-gradient(ellipse 52% 48% at 50% 50%, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0.97) 100%);
}
.bg-layer.bg-memory::before {
  background:radial-gradient(ellipse 85% 75% at 50% 50%, transparent 28%, rgba(10,40,135,0.70) 100%);
  animation:memory-breathe 5s ease-in-out infinite;
}
@keyframes memory-breathe { 0%,100%{opacity:.72} 50%{opacity:1} }

.bg-layer.bg-dawn::before   { background:radial-gradient(ellipse 85% 75% at 50% 50%, transparent 40%, rgba(90,45,0,0.55) 100%); }
.bg-layer.bg-palace::before { background:radial-gradient(ellipse 85% 75% at 50% 50%, transparent 34%, rgba(55,15,112,0.64) 100%); }
.bg-layer.bg-night::before  { background:radial-gradient(ellipse 85% 75% at 50% 50%, transparent 28%, rgba(0,4,48,0.82) 100%); }

/* 場景對話框彩色光邊（data-bg 驅動） */
#game-screen[data-bg="danger"] .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.65),0 0 0 1px rgba(220,40,40,.48); }
#game-screen[data-bg="memory"] .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(60,110,235,.42); }
#game-screen[data-bg="void"]   .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.9), 0 0 0 1px rgba(90,30,185,.58); }
#game-screen[data-bg="dawn"]   .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.4), 0 0 0 1px rgba(200,140,50,.32); }
#game-screen[data-bg="palace"] .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(140,80,225,.38); }
#game-screen[data-bg="night"]  .dialogue-box { box-shadow:0 -10px 40px rgba(0,0,0,.72),0 0 0 1px rgba(50,80,185,.32); }
