/* 魔女的殘香：配色取自角色設定圖（見企劃書「UI 風格與配色」） */
:root {
  --bg: #1A1524;
  --panel: #2A2236;
  --panel-2: #332a42;
  --line: #56485E;
  --text: #ECE8F0;
  --muted: #B6A8B8;
  --primary: #E6D8FB;   /* 愛蜜莉雅 */
  --rem: #A8C7FC;       /* 雷姆 */
  --ram: #FBBAD2;       /* 拉姆 */
  --gold: #FCF2C7;      /* 碧翠絲 */
  --danger: #963D58;
  --danger-text: #D66A8A;
  --scent-1: #A8A6D6;   /* 莎緹拉 */
  --scent-2: #6B4FA0;
  --serif: 'Noto Serif TC', serif;
  --sans: 'Noto Sans TC', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(107, 79, 160, .28), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(150, 61, 88, .18), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* ───── 按鈕 ───── */
.btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 22px; font-size: 15px; cursor: pointer;
  transition: border-color .2s, background .2s, color .2s;
}
.btn:hover { border-color: var(--primary); background: rgba(230, 216, 251, .06); }
.btn.primary { background: var(--primary); color: #241c30; border-color: var(--primary); font-weight: 700; }
.btn.primary:hover { background: #f1e8ff; }
.btn.danger { color: var(--danger-text); border-color: var(--danger); }
.btn.small { padding: 6px 14px; font-size: 13px; }

/* ───── 標題 ───── */
#title { align-items: center; justify-content: center; text-align: center; padding: 40px 20px; }
.title-inner { max-width: 560px; }
.title-kicker { color: var(--muted); font-size: 13px; letter-spacing: .2em; }
#title h1 {
  font-family: var(--serif); font-weight: 900; font-size: clamp(44px, 9vw, 76px);
  margin: 12px 0 8px; letter-spacing: .12em;
  background: linear-gradient(180deg, #fff 0%, var(--primary) 55%, var(--scent-1) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(168, 166, 214, .25);
}
.title-lead { color: var(--muted); font-family: var(--serif); }
.title-menu { display: flex; flex-direction: column; gap: 12px; width: 240px; margin: 36px auto 16px; }
.title-progress { color: var(--gold); font-size: 13px; min-height: 1.5em; }
.disclaimer { color: #8a7d8c; font-size: 12px; margin-top: 40px; }

/* ───── 遊戲畫面 ───── */
#game { align-items: stretch; }
#status {
  width: 280px; flex-shrink: 0; padding: 24px 20px;
  background: rgba(42, 34, 54, .72); border-right: 1px solid var(--line);
  overflow-y: auto; max-height: 100vh; position: sticky; top: 0;
}
.chapter { display: flex; align-items: baseline; gap: 10px; margin-bottom: 18px; }
.chapter span { color: var(--muted); font-size: 13px; }
.chapter strong { font-family: var(--serif); font-size: 26px; color: var(--primary); }
.stat-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; border-bottom: 1px dashed rgba(86, 72, 94, .6); }
.stat-row span { color: var(--muted); }
.danger { color: var(--danger-text); }
.meter { margin-top: 14px; }
.meter-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.meter-head b { color: var(--text); }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 4px; }
.fill.sanity { height: 100%; background: linear-gradient(90deg, var(--rem), var(--primary)); transition: width .6s; }
.scent { display: flex; gap: 4px; margin-top: 6px; }
.scent i { flex: 1; height: 10px; border-radius: 2px; background: var(--bg); border: 1px solid var(--line); }
.scent i.on {
  border-color: transparent;
  background: color-mix(in srgb, var(--scent-2) calc(var(--i) * 11%), var(--scent-1));
  box-shadow: 0 0 8px rgba(107, 79, 160, .6);
}
.section-title { margin: 20px 0 6px; font-size: 13px; color: var(--muted); letter-spacing: .1em; }
.section-title small { color: var(--gold); margin-left: 4px; }
.bond { display: flex; justify-content: space-between; font-size: 14px; }
.bond b { color: var(--ram); font-size: 11px; letter-spacing: 2px; }
.who { display: inline-flex; align-items: center; gap: 6px; }
.icon.mini { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.icon.mini.dot { width: 10px; height: 10px; margin: 0 6px; border-radius: 50%; background: var(--c); }
.icon.portrait { display: block; width: 88px; height: 88px; object-fit: contain; margin: 0 0 8px -6px; }
.icon.portrait.dot { width: 28px; height: 6px; margin: 0 0 8px; border-radius: 3px; background: var(--c); }
.card.char.locked .icon.portrait:not(.dot) { filter: brightness(0) opacity(.35); }
.card.char.locked .icon.portrait.dot { background: var(--line); }
.susp { display: flex; justify-content: space-between; font-size: 14px; }
.susp b { color: var(--gold); font-size: 12px; letter-spacing: 2px; font-weight: 400; }
.susp.near b { color: var(--ram); }
.susp.over b { color: var(--danger-text); }
.know { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.know li { padding: 5px 0 5px 12px; border-left: 2px solid var(--line); margin-bottom: 4px; color: var(--muted); line-height: 1.5; }
.know li.new { border-left-color: var(--gold); color: var(--gold); }
.know li.empty { border: 0; padding-left: 0; font-style: italic; }
.side-actions { display: flex; gap: 8px; margin-top: 24px; }

#story { flex: 1; padding: 56px clamp(20px, 6vw, 80px) 80px; max-height: 100vh; overflow-y: auto; }
#text, #choices, #cast { max-width: 680px; margin: 0 auto; }
#cast { display: flex; flex-wrap: wrap; gap: 14px; min-height: 0; margin-bottom: 20px; }
#cast:empty { display: none; }
.cast-member { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; animation: fadeIn .6s ease both; }
.cast-member:nth-child(2) { animation-delay: .08s; } .cast-member:nth-child(3) { animation-delay: .16s; }
.cast-member:nth-child(4) { animation-delay: .24s; } .cast-member:nth-child(5) { animation-delay: .32s; }
.icon.cast { width: 76px; height: 76px; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0,0,0,.35)); }
.icon.cast.dot { width: 14px; height: 14px; margin: 31px; border-radius: 50%; background: var(--c); filter: none; }
.cast-member figcaption { font-size: 12px; letter-spacing: .05em; }
#text p { font-family: var(--serif); font-size: 18px; line-height: 2; margin: 0 0 1.1em; }
.seen-tag { display: inline-block; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; margin-bottom: 14px; }
#choices { display: flex; flex-direction: column; gap: 10px; margin-top: 32px; }
.choice {
  text-align: left; background: rgba(42, 34, 54, .8); color: var(--text);
  border: 1px solid var(--line); border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 14px 18px; font-size: 16px; cursor: pointer;
  transition: transform .15s, border-color .2s, background .2s;
}
.choice:hover:not(:disabled) { transform: translateX(4px); background: var(--panel-2); border-color: var(--primary); }
.choice.tag-escape { border-left-color: var(--rem); }
.choice.tag-if { border-left-color: var(--ram); }
.choice.tag-prophet { border-left-color: var(--gold); border-color: rgba(252, 242, 199, .35); background: rgba(252, 242, 199, .05); }
.choice.tag-prophet:hover:not(:disabled) { border-color: var(--gold); }
.choice .badge { display: inline-block; font-size: 11px; font-weight: 700; color: #2a2236; background: var(--gold); border-radius: 4px; padding: 0 6px; margin-right: 8px; vertical-align: 2px; }
.gold { color: var(--gold); }
.choice.tag-taboo { border-left-color: var(--scent-2); color: var(--scent-1); }
.choice.locked { opacity: .55; cursor: not-allowed; border-left-color: var(--line); }
.choice.locked small { display: block; color: var(--muted); font-size: 12px; }

.fade { opacity: 0; animation: fadeIn .7s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ───── 疊層 ───── */
#overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 24px; z-index: 10; overflow-y: auto; }
#overlay.show { display: flex; animation: fadeIn .5s ease; }
#overlay.name-bg { background: rgba(16, 12, 22, .82); backdrop-filter: blur(4px); }
#overlay.death-bg { background: radial-gradient(ellipse at center, #140c14 30%, #000 100%); animation: fadeIn 1.2s ease; }
#overlay.taboo-bg { background: radial-gradient(ellipse at center, rgba(20, 10, 30, .9), rgba(60, 30, 90, .95)); }
#overlay.ending-bg { background: radial-gradient(ellipse at 50% 30%, #2c2340, #0f0b16); }
#overlay.rewind-bg { background: #000; }

.name-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(420px, 100%); }
.name-box h2 { font-family: var(--serif); margin: 0 0 4px; color: var(--primary); }
.name-box input[type=text], #name-input {
  width: 100%; margin: 16px 0; padding: 12px 14px; font-size: 18px; font-family: var(--serif);
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
#name-input:focus { border-color: var(--primary); }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.muted { color: var(--muted); font-size: 14px; }
.warn { color: var(--danger-text); font-size: 13px; }
.center { text-align: center; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-top: 12px; }

.death, .ending, .taboo { max-width: 560px; text-align: center; font-family: var(--serif); }
.death-label, .ending-label { font-size: 13px; letter-spacing: .4em; color: var(--danger-text); }
.death h2 { font-size: 40px; margin: 8px 0 24px; color: var(--danger-text); text-shadow: 0 0 30px rgba(150, 61, 88, .6); }
.death p, .ending p, .taboo p { font-size: 17px; line-height: 2; }
.lessons { margin: 28px auto; text-align: left; border: 1px solid rgba(252, 242, 199, .3); border-radius: 8px; padding: 14px 20px; background: rgba(252, 242, 199, .04); }
.lessons h3 { margin: 0 0 6px; font-size: 14px; color: var(--gold); font-family: var(--sans); }
.lessons ul { margin: 0; padding-left: 20px; color: var(--gold); font-family: var(--sans); font-size: 15px; }
.death-stats { color: var(--muted); font-family: var(--sans); font-size: 13px; margin: 16px 0 24px; }
.taboo p { color: var(--scent-1); }
.taboo p:nth-child(4) { color: var(--primary); font-size: 22px; letter-spacing: .3em; }
.taboo .btn { margin-top: 20px; }
.ending-label { color: var(--gold); }
.ending.cat-if .ending-label { color: var(--ram); }
.ending.cat-escape .ending-label { color: var(--rem); }
.ending.cat-giveup .ending-label { color: var(--scent-1); }
.ending h2 { font-size: 40px; margin: 8px 0 24px; color: var(--primary); }
.ending .btn { margin-top: 24px; }

/* 死亡回歸演出 */
.rewind { text-align: center; }
.clock { width: 120px; height: 120px; margin: 0 auto 24px; border-radius: 50%; border: 2px solid var(--scent-1); position: relative; box-shadow: 0 0 40px var(--scent-2), inset 0 0 30px var(--scent-2); }
.clock i { position: absolute; left: 50%; bottom: 50%; width: 2px; background: var(--primary); transform-origin: bottom center; }
.clock i:first-child { height: 40px; animation: spinBack 2s linear; }
.clock i:last-child { height: 28px; width: 3px; animation: spinBack 6s linear; }
@keyframes spinBack { from { transform: rotate(0); } to { transform: rotate(-1080deg); } }
.rewind-text { font-family: var(--serif); font-size: 34px; letter-spacing: .5em; color: var(--primary); animation: pulse 2.2s ease; }
.rewind-sub { color: var(--muted); margin-top: 8px; }
@keyframes pulse { 0% { opacity: 0; filter: blur(8px); } 40% { opacity: 1; filter: blur(0); } 100% { opacity: .2; filter: blur(4px); } }
#overlay.rewind-bg::before {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(107, 79, 160, .55) 100%);
  animation: vignette 2.2s ease;
}
@keyframes vignette { from { opacity: 0; } 50% { opacity: 1; } to { opacity: 0; } }

/* ───── 圖鑑 ───── */
#codex { justify-content: center; padding: 40px 20px; }
.codex-inner { width: min(900px, 100%); }
.codex-head { display: flex; justify-content: space-between; align-items: center; }
.codex-head h2 { font-family: var(--serif); color: var(--primary); margin: 0; }
.tabs { display: flex; gap: 6px; margin: 20px 0; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; color: var(--muted); padding: 10px 16px; font-size: 15px; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
#codex-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card h3 { margin: 4px 0; font-family: var(--serif); font-size: 18px; color: var(--primary); }
.card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.card-tag { font-size: 11px; letter-spacing: .2em; color: var(--gold); }
.card.cat-if .card-tag { color: var(--ram); }
.card.cat-escape .card-tag { color: var(--rem); }
.card.cat-giveup .card-tag { color: var(--scent-1); }
.card.death-card .card-tag, .card.death-card h3 { color: var(--danger-text); }
.card.locked { opacity: .5; }
.card.locked h3 { color: var(--muted); }
.card.future { opacity: .3; border-style: dashed; }
.log { grid-column: 1 / -1; list-style: none; padding: 0; margin: 0; }
.log li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin-bottom: 8px; font-size: 14px; }
.log-head time { float: right; color: var(--muted); font-size: 12px; }
.log-learn { color: var(--gold); font-size: 13px; margin-top: 4px; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--panel); border: 1px solid var(--gold); color: var(--gold);
  padding: 10px 20px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s; z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───── 手機 ───── */
@media (max-width: 760px) {
  #game { flex-direction: column; }
  #status { width: auto; max-height: none; position: static; border-right: 0; border-top: 1px solid var(--line); padding: 16px; order: 2; }
  #story { max-height: none; padding: 28px 20px 60px; }
  #text p { font-size: 17px; }
  .icon.cast { width: 56px; height: 56px; }
}
