/* ══════════════════════════════════════════
   愛我 · Love Me — 少女漫畫風介面
   ══════════════════════════════════════════ */

:root {
  --blush: #ffd3e2;
  --blush-deep: #f7a8c4;
  --rose: #e4568a;
  --rose-dark: #b93a68;
  --gold: #f4d9a6;
  --gold-deep: #d9ab5f;
  --lavender: #c8b6e2;
  --lavender-deep: #9b83c4;
  --navy: #1b1b3a;
  --navy-soft: #2e2b4f;
  --cream: #fff7f2;
  --ink: #3a2b33;
  --ink-soft: #6d5860;

  --shadow-soft: 0 8px 32px rgba(180, 110, 140, .18);
  --shadow-lift: 0 14px 44px rgba(120, 60, 90, .28);
  --glow-rose: 0 0 24px rgba(228, 86, 138, .45);

  --dialogue-h: clamp(150px, 26vh, 240px);
  --ease: cubic-bezier(.22, .8, .3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 屬性只是 UA 樣式的 display:none，任何作者寫的 display 都會蓋過它。
   .chapter-card 有 display:grid、.choices 有 display:flex，結果兩層都在
   hidden 的狀態下整片蓋住畫面、把點擊全部吃掉，玩家會卡在一片深藍上進不了遊戲。
   這條規則是全域保險，不要拿掉。 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--navy);
}

body {
  font-family: "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; }
input { font: inherit; }

/* ── 畫面切換 ───────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  opacity: 0;
  transition: opacity .5s var(--ease);
}
.screen.active { display: block; opacity: 1; }
.screen.fading { opacity: 0; }

/* ══════════════════════════════════════════
   飄落花瓣 & 閃光
   ══════════════════════════════════════════ */
#petals, #sparkleLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.petal {
  position: absolute;
  top: -6vh;
  border-radius: 60% 10% 60% 10%;
  background: linear-gradient(140deg, #fff0f5, var(--blush-deep));
  opacity: .75;
  animation: petal-fall linear infinite;
  will-change: transform;
}
@keyframes petal-fall {
  0%   { transform: translate3d(0, -10vh, 0) rotate(0deg); }
  100% { transform: translate3d(var(--drift, 40px), 110vh, 0) rotate(720deg); }
}

.sparkle {
  position: absolute;
  width: 14px; height: 14px;
  background: radial-gradient(circle, #fff 0%, var(--gold) 45%, transparent 70%);
  animation: sparkle-pop .9s var(--ease) forwards;
}
.sparkle::before, .sparkle::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  clip-path: polygon(50% 0, 56% 44%, 100% 50%, 56% 56%, 50% 100%, 44% 56%, 0 50%, 44% 44%);
}
.sparkle::after { transform: rotate(45deg) scale(.6); opacity: .8; }
@keyframes sparkle-pop {
  0%   { transform: scale(0) rotate(0deg); opacity: 0; }
  35%  { transform: scale(1.3) rotate(60deg); opacity: 1; }
  100% { transform: scale(.2) rotate(140deg); opacity: 0; }
}

/* ══════════════════════════════════════════
   標題畫面
   ══════════════════════════════════════════ */
#titleScreen {
  background:
    radial-gradient(ellipse 80% 60% at 50% 12%, rgba(255, 211, 226, .95), transparent 68%),
    radial-gradient(ellipse 70% 50% at 12% 88%, rgba(200, 182, 226, .8), transparent 70%),
    radial-gradient(ellipse 70% 50% at 88% 82%, rgba(244, 217, 166, .7), transparent 70%),
    linear-gradient(170deg, #fff7f2 0%, #ffe6ef 45%, #f3e3f7 100%);
}

.title-glow {
  position: absolute;
  top: -18vh; left: 50%;
  width: 90vmin; height: 90vmin;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255,255,255,.9), transparent 62%);
  animation: breathe 7s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: .75; }
  50%      { transform: translateX(-50%) scale(1.12); opacity: 1; }
}

.title-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5vh 24px calc(4vh + env(safe-area-inset-bottom));
  text-align: center;
  overflow-y: auto;
}

.title-kr {
  font-family: "Noto Serif TC", serif;
  font-size: 13px;
  letter-spacing: .5em;
  color: var(--lavender-deep);
  text-indent: .5em;
  margin-bottom: 6px;
  animation: fade-up .9s var(--ease) both;
}

.title-main {
  font-family: "Noto Serif TC", serif;
  font-weight: 900;
  font-size: clamp(66px, 20vw, 132px);
  line-height: 1;
  letter-spacing: .04em;
  background: linear-gradient(165deg, #ffffff 0%, var(--blush) 22%, var(--rose) 58%, var(--lavender-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 5px 14px rgba(228, 86, 138, .35));
  animation: fade-up 1s var(--ease) .08s both;
}
.title-heart {
  display: inline-block;
  font-size: .4em;
  vertical-align: .5em;
  margin: 0 -.08em;
  filter: drop-shadow(0 0 10px rgba(228,86,138,.7));
  animation: heartbeat 1.6s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.3); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.22); }
}

.title-en {
  font-size: 12px;
  letter-spacing: .55em;
  color: var(--gold-deep);
  text-indent: .55em;
  margin-top: 4px;
  animation: fade-up 1s var(--ease) .16s both;
}

.title-tagline {
  margin: 22px 0 30px;
  font-family: "Noto Serif TC", serif;
  font-size: clamp(14px, 3.6vw, 17px);
  line-height: 2;
  color: var(--ink-soft);
  animation: fade-up 1s var(--ease) .24s both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: min(300px, 82vw);
  animation: fade-up 1s var(--ease) .32s both;
}

.title-credit {
  margin-top: 26px;
  font-size: 11px;
  letter-spacing: .12em;
  color: rgba(109, 88, 96, .55);
}

/* ══════════════════════════════════════════
   按鈕
   ══════════════════════════════════════════ */
.btn {
  position: relative;
  overflow: hidden;
  padding: 14px 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  border: 1.5px solid rgba(228, 86, 138, .28);
  color: var(--rose-dark);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: .08em;
  box-shadow: var(--shadow-soft);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), background .22s;
}
.btn:hover:not(:disabled), .btn:focus-visible:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  background: #fff;
  outline: none;
}
.btn:active:not(:disabled) { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--rose) 0%, #f07ba6 55%, var(--blush-deep) 100%);
  border-color: transparent;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(228, 86, 138, .42);
}
.btn-primary:hover { background: linear-gradient(135deg, #f0679a 0%, #ff92b8 55%, #ffc2d8 100%); }

.btn-ghost {
  background: transparent;
  border-color: rgba(109, 88, 96, .25);
  color: var(--ink-soft);
  box-shadow: none;
}

.btn-shine {
  position: absolute;
  top: 0; left: -140%;
  width: 60%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.7), transparent);
  animation: shine 3.4s var(--ease) infinite;
}
@keyframes shine {
  0%   { left: -140%; }
  55%  { left: 160%; }
  100% { left: 160%; }
}

.pill {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(228, 86, 138, .14);
  font-size: 11px;
  letter-spacing: .04em;
}

/* ══════════════════════════════════════════
   面板（命名 / 覆蓋層）
   ══════════════════════════════════════════ */
#nameScreen {
  background: linear-gradient(170deg, #fff7f2, #ffe6ef 55%, #f3e3f7);
  display: none;
  place-items: center;
  padding: 24px;
}
#nameScreen.active { display: grid; }

.panel {
  width: min(440px, 92vw);
  padding: 34px 28px;
  border-radius: 26px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(14px);
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-lift);
  text-align: center;
  animation: fade-up .55s var(--ease) both;
}

.panel-title {
  font-family: "Noto Serif TC", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--rose-dark);
  margin-bottom: 10px;
}
.panel-sub {
  font-size: 13.5px;
  line-height: 1.95;
  color: var(--ink-soft);
  margin-bottom: 26px;
}

.field { display: block; text-align: left; }
.field-label {
  display: block;
  font-size: 12px;
  letter-spacing: .16em;
  color: var(--lavender-deep);
  margin-bottom: 7px;
}
.field input {
  width: 100%;
  padding: 13px 18px;
  border-radius: 16px;
  border: 1.5px solid rgba(228, 86, 138, .3);
  background: #fff;
  color: var(--ink);
  font-size: 17px;
  text-align: center;
  letter-spacing: .1em;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  outline: none;
  border-color: var(--rose);
  box-shadow: 0 0 0 4px rgba(228, 86, 138, .14);
}
.field-hint {
  margin-top: 9px;
  font-size: 11.5px;
  color: rgba(109, 88, 96, .65);
}

.panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 26px;
}
.panel-actions .btn { flex: 1; padding: 13px 14px; }

/* ══════════════════════════════════════════
   遊戲畫面
   ══════════════════════════════════════════ */
#gameScreen { background: var(--navy); }

.bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: opacity .8s var(--ease), transform 9s linear;
  transform: scale(1.06);
}
.bg-layer.kenburns { transform: scale(1.14); }

.bg-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 120% 80% at 50% 30%, transparent 40%, rgba(27, 27, 58, .45) 100%),
    linear-gradient(to top, rgba(27, 27, 58, .72) 0%, rgba(27, 27, 58, .1) 42%, transparent 62%);
  pointer-events: none;
}

/* 立繪 */
.portrait-layer {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dialogue-h) - 26px);
  transform: translateX(-50%);
  width: min(430px, 78vw);
  height: min(62vh, 560px);
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* 立繪後面墊一層柔光。這樣即使圖本身帶著自己的漸層底，
   邊緣化開的地方看起來也像是打在人物身上的光，而不是沒切乾淨的破綻。 */
.portrait-layer::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6%;
  width: 118%;
  height: 104%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse 46% 48% at 50% 42%, rgba(255, 240, 246, .42), rgba(255, 211, 226, .16) 58%, transparent 76%);
  filter: blur(6px);
}

/* 生成的立繪帶著自己的漸層底，直接疊上去會像貼了一張長方形卡片。
   用羽化遮罩把四邊化開，看起來就像人物從場景的光暈裡浮出來。 */
.portrait {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, .45)) saturate(1.05);
  animation: portrait-in .55s var(--ease) both;
  /* 只化開左右兩側和頭頂上方那一點點；人物本身（中間偏下）完全不動 */
  -webkit-mask-image:
    linear-gradient(to right, transparent 0%, #000 17%, #000 83%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, #000 9%, #000 100%);
  mask-image:
    linear-gradient(to right, transparent 0%, #000 17%, #000 83%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, #000 9%, #000 100%);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
@keyframes portrait-in {
  from { opacity: 0; transform: translateY(22px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.portrait.leaving { animation: portrait-out .32s var(--ease) both; }
@keyframes portrait-out {
  to { opacity: 0; transform: translateY(14px) scale(.98); }
}

/* 立繪還沒生成時的替代卡 */
.portrait-fallback {
  width: min(300px, 62vw);
  aspect-ratio: 3 / 4;
  border-radius: 26px 26px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding-bottom: 26px;
  background: linear-gradient(175deg, rgba(255,255,255,.16), var(--pc, #888) 88%);
  border: 1.5px solid rgba(255, 255, 255, .3);
  border-bottom: none;
  box-shadow: 0 -8px 40px rgba(0,0,0,.35);
  animation: portrait-in .55s var(--ease) both;
}
.portrait-fallback .pf-name {
  font-family: "Noto Serif TC", serif;
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .2em;
  text-indent: .2em;
  text-shadow: 0 2px 14px rgba(0,0,0,.5);
}
.portrait-fallback .pf-role {
  font-size: 11.5px;
  letter-spacing: .3em;
  text-indent: .3em;
  color: rgba(255, 255, 255, .78);
}
.portrait-fallback .pf-eyes {
  font-size: 40px;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 12px rgba(255,255,255,.8));
  animation: heartbeat 2.4s ease-in-out infinite;
}

/* HUD */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(27, 27, 58, .6), transparent);
}
.hud-right { display: flex; gap: 6px; }

.hud-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  color: #fff;
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px);
  transition: background .2s, transform .2s var(--ease);
}
.hud-btn:hover { background: rgba(255, 255, 255, .26); transform: scale(1.08); }
.hud-btn.on {
  background: var(--rose);
  border-color: transparent;
  box-shadow: var(--glow-rose);
}

.hud-chapter {
  flex: 1;
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .6);
  line-height: 1.3;
  overflow: hidden;
}
.hud-chapter span {
  display: block;
  font-family: "Noto Serif TC", serif;
  font-size: 14px;
  letter-spacing: .22em;
  text-indent: .22em;
}
.hud-chapter small {
  display: block;
  font-size: 10.5px;
  letter-spacing: .1em;
  opacity: .78;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 對話框 */
.dialogue {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  min-height: var(--dialogue-h);
  padding: 30px clamp(20px, 6vw, 54px) calc(24px + env(safe-area-inset-bottom));
  background:
    linear-gradient(to bottom, rgba(255, 247, 242, .93), rgba(255, 236, 243, .97));
  backdrop-filter: blur(16px);
  border-top: 2px solid rgba(255, 255, 255, .85);
  box-shadow: 0 -12px 44px rgba(90, 40, 70, .35);
}
.dialogue::before {
  content: "";
  position: absolute;
  top: -2px; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--rose), var(--lavender), transparent);
}

.speaker {
  position: absolute;
  top: -17px;
  left: clamp(18px, 5.5vw, 48px);
  padding: 7px 22px;
  border-radius: 999px;
  font-family: "Noto Serif TC", serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .14em;
  text-indent: .14em;
  color: #fff;
  background: var(--sp, var(--rose));
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  border: 1.5px solid rgba(255, 255, 255, .6);
  animation: fade-up .3s var(--ease) both;
}
.speaker::after {
  content: "💗";
  margin-left: 8px;
  font-size: 11px;
  vertical-align: 1px;
}

.dialogue-text {
  font-family: "Noto Serif TC", serif;
  font-size: clamp(16px, 4.3vw, 20px);
  line-height: 2.05;
  color: var(--ink);
  letter-spacing: .03em;
  white-space: pre-wrap;
  word-break: break-word;
}
.dialogue.narration .dialogue-text {
  color: var(--ink-soft);
  font-style: normal;
}
.dialogue.system .dialogue-text {
  font-family: "Noto Sans TC", sans-serif;
  font-size: clamp(14px, 3.8vw, 16px);
  line-height: 1.85;
  color: var(--lavender-deep);
  background: rgba(200, 182, 226, .16);
  border-left: 3px solid var(--lavender);
  padding: 12px 16px;
  border-radius: 0 12px 12px 0;
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--rose);
  animation: blink .7s steps(2) infinite;
}
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.next-arrow {
  position: absolute;
  right: clamp(18px, 5.5vw, 44px);
  bottom: calc(14px + env(safe-area-inset-bottom));
  font-size: 14px;
  color: var(--rose);
  animation: bob 1.1s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: .55; }
  50%      { transform: translateY(5px); opacity: 1; }
}

.advance-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
}

/* 選項 */
.choices {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 70px 20px calc(24px + env(safe-area-inset-bottom));
  background: rgba(27, 27, 58, .58);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}

.choice {
  position: relative;
  width: min(560px, 92vw);
  padding: 17px 26px;
  border-radius: 20px;
  text-align: left;
  background: linear-gradient(135deg, rgba(255, 255, 255, .96), rgba(255, 236, 243, .96));
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  font-size: clamp(14.5px, 3.8vw, 16.5px);
  line-height: 1.75;
  transition: transform .24s var(--ease), box-shadow .24s var(--ease), border-color .24s;
  animation: choice-in .45s var(--ease) both;
}
@keyframes choice-in {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
.choice:hover, .choice:focus-visible {
  transform: translateY(-3px) scale(1.015);
  border-color: var(--rose);
  box-shadow: 0 16px 40px rgba(228, 86, 138, .4);
  outline: none;
}
.choice::before {
  content: "💗";
  position: absolute;
  left: -2px; top: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 20px;
  transition: transform .26s var(--ease);
  filter: drop-shadow(0 0 8px rgba(228, 86, 138, .8));
}
.choice:hover::before, .choice:focus-visible::before { transform: translate(-50%, -50%) scale(1); }

.choice-hint {
  display: block;
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--lavender-deep);
  letter-spacing: .04em;
}
.choice-locked {
  opacity: .62;
  filter: saturate(.6);
}

/* 章節卡 */
.chapter-card {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, rgba(27, 27, 58, .96), rgba(46, 43, 79, .96));
  animation: fade-in .5s var(--ease) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.chapter-card.out { animation: fade-out .5s var(--ease) both; }
@keyframes fade-out { to { opacity: 0; } }

.chapter-card-inner {
  text-align: center;
  padding: 0 30px;
  animation: fade-up .8s var(--ease) .1s both;
}
.chapter-card h2 {
  font-family: "Noto Serif TC", serif;
  font-size: clamp(30px, 9vw, 48px);
  font-weight: 900;
  letter-spacing: .3em;
  text-indent: .3em;
  margin: 20px 0 12px;
  background: linear-gradient(140deg, #fff, var(--blush) 40%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chapter-card p {
  font-family: "Noto Serif TC", serif;
  font-size: clamp(14px, 4vw, 18px);
  letter-spacing: .18em;
  text-indent: .18em;
  color: rgba(255, 255, 255, .82);
  margin-bottom: 20px;
}
.chapter-rule {
  width: 130px;
  height: 1px;
  margin: 0 auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

/* ══════════════════════════════════════════
   結局畫面
   ══════════════════════════════════════════ */
#endingScreen {
  background:
    radial-gradient(ellipse 90% 60% at 50% 20%, rgba(255, 211, 226, .5), transparent 70%),
    linear-gradient(165deg, #2e2b4f, #1b1b3a 60%, #3a2340);
  display: none;
  place-items: center;
  padding: 30px 22px;
}
#endingScreen.active { display: grid; }

.ending-wrap {
  text-align: center;
  width: min(520px, 94vw);
  animation: fade-up .9s var(--ease) both;
}
.ending-rank {
  display: inline-block;
  padding: 6px 26px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .34em;
  text-indent: .34em;
  color: var(--navy);
  background: linear-gradient(120deg, var(--gold), #fff2d6, var(--gold-deep));
  box-shadow: 0 0 30px rgba(244, 217, 166, .55);
  margin-bottom: 22px;
}
.ending-rank[data-rank="BITTER"] { background: linear-gradient(120deg, var(--lavender), #e6ddf3); }
.ending-rank[data-rank="NORMAL"] { background: linear-gradient(120deg, #d9d9e6, #f2f2f7); }

.ending-title {
  font-family: "Noto Serif TC", serif;
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 900;
  letter-spacing: .16em;
  text-indent: .16em;
  background: linear-gradient(140deg, #fff, var(--blush) 45%, var(--lavender) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 10px;
}
.ending-char {
  font-size: 14px;
  letter-spacing: .24em;
  text-indent: .24em;
  color: var(--blush);
  margin-bottom: 30px;
}

.ending-stats {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 32px;
  padding: 20px 22px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .14);
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: rgba(255, 255, 255, .9);
}
.stat-row .stat-name { width: 68px; text-align: left; letter-spacing: .08em; flex: none; }
.stat-bar {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
  overflow: hidden;
}
.stat-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sc, var(--rose)), #fff);
  box-shadow: 0 0 12px var(--sc, var(--rose));
  transition: width 1.2s var(--ease);
}
.stat-row .stat-val { width: 34px; text-align: right; font-size: 12px; opacity: .8; flex: none; }

/* ══════════════════════════════════════════
   覆蓋層（選單 / 圖鑑 / 好感度 / 回顧）
   ══════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(27, 27, 58, .68);
  backdrop-filter: blur(10px);
  animation: fade-in .28s var(--ease) both;
}
.overlay[hidden] { display: none; }

.overlay-panel {
  position: relative;
  width: min(620px, 94vw);
  max-height: min(84vh, 760px);
  display: flex;
  flex-direction: column;
  padding: 30px 26px 26px;
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(255, 247, 242, .97), rgba(255, 236, 243, .97));
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-lift);
  animation: fade-up .35s var(--ease) both;
}

.overlay-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  background: rgba(228, 86, 138, .1);
  transition: background .2s, transform .2s;
}
.overlay-close:hover { background: rgba(228, 86, 138, .24); transform: rotate(90deg); }

.overlay-title {
  font-family: "Noto Serif TC", serif;
  font-size: 21px;
  font-weight: 700;
  color: var(--rose-dark);
  letter-spacing: .16em;
  text-indent: .16em;
  margin-bottom: 20px;
  text-align: center;
  flex: none;
}
.overlay-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}
.overlay-body::-webkit-scrollbar { width: 6px; }
.overlay-body::-webkit-scrollbar-thumb { background: rgba(228, 86, 138, .3); border-radius: 999px; }

.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-list .btn { width: 100%; }

/* 好感度條 */
.aff-list { display: flex; flex-direction: column; gap: 14px; }
.aff-row {
  display: flex;
  align-items: center;
  gap: 13px;
}
.aff-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-family: "Noto Serif TC", serif;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: var(--ac, var(--rose));
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  border: 2px solid rgba(255, 255, 255, .8);
}
.aff-meta { flex: 1; min-width: 0; }
.aff-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}
.aff-name em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--ink-soft);
  letter-spacing: .06em;
}
.aff-bar {
  height: 9px;
  border-radius: 999px;
  background: rgba(228, 86, 138, .13);
  overflow: hidden;
}
.aff-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ac, var(--rose)), #ffd3e2);
  transition: width .9s var(--ease);
}
.aff-hearts { margin-top: 5px; font-size: 12px; letter-spacing: 2px; }

/* 角色圖鑑 */
.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 13px;
}
.cast-card {
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-soft);
  text-align: left;
  transition: transform .24s var(--ease), box-shadow .24s var(--ease);
  display: flex;
  flex-direction: column;
}
.cast-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
.cast-thumb {
  aspect-ratio: 3 / 4;
  background: linear-gradient(170deg, rgba(255,255,255,.2), var(--cc, #ccc));
  background-size: cover;
  background-position: center top;
  display: grid;
  place-items: center;
  font-size: 34px;
}
.cast-body { padding: 11px 13px 14px; }
.cast-name {
  font-family: "Noto Serif TC", serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: .08em;
}
.cast-role {
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: .1em;
  margin: 3px 0 7px;
}
.cast-quote {
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--rose-dark);
}

.cast-detail p { font-size: 14px; line-height: 2; color: var(--ink); margin-bottom: 14px; }
.cast-detail dt {
  font-size: 11.5px;
  letter-spacing: .18em;
  color: var(--lavender-deep);
  margin-bottom: 4px;
}
.cast-detail dd { font-size: 13.5px; line-height: 1.9; color: var(--ink-soft); margin-bottom: 14px; }

/* 結局收藏 */
.ending-grid { display: flex; flex-direction: column; gap: 10px; }
.ending-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 17px;
  border-radius: 17px;
  background: #fff;
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-soft);
}
.ending-item.locked { background: rgba(255, 255, 255, .45); opacity: .62; }
.ending-badge {
  flex: none;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--navy);
  background: linear-gradient(120deg, var(--gold), #fff3da);
}
.ending-item.locked .ending-badge { background: #e2dde4; color: #9a8f97; }
.ending-item-name {
  font-family: "Noto Serif TC", serif;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}
.ending-item-char { font-size: 11.5px; color: var(--ink-soft); letter-spacing: .1em; margin-top: 2px; }

/* 回顧 */
.backlog-row {
  padding: 12px 0;
  border-bottom: 1px dashed rgba(228, 86, 138, .2);
}
.backlog-row:last-child { border-bottom: none; }
.backlog-who {
  font-size: 11.5px;
  letter-spacing: .16em;
  color: var(--bc, var(--rose));
  margin-bottom: 4px;
  font-weight: 700;
}
.backlog-what {
  font-family: "Noto Serif TC", serif;
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink);
}

/* 設定 */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px dashed rgba(228, 86, 138, .2);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 14px; color: var(--ink); }
.setting-label small { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.seg { display: flex; gap: 5px; flex: none; }
.seg button {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  background: rgba(228, 86, 138, .1);
  color: var(--rose-dark);
  transition: background .2s;
}
.seg button.on { background: var(--rose); color: #fff; }

/* 存檔格 */
.slot {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 14px 17px;
  border-radius: 17px;
  background: #fff;
  border: 1.5px solid rgba(228, 86, 138, .22);
  box-shadow: var(--shadow-soft);
  text-align: left;
  transition: transform .2s var(--ease), border-color .2s;
}
.slot:hover { transform: translateY(-2px); border-color: var(--rose); }
.slot-no {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--lavender-deep);
}
.slot-info { flex: 1; min-width: 0; }
.slot-title { font-size: 14px; color: var(--ink); }
.slot-sub { font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.slot.empty .slot-title { color: var(--ink-soft); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  padding: 12px 24px;
  border-radius: 999px;
  background: rgba(27, 27, 58, .92);
  color: #fff;
  font-size: 13.5px;
  letter-spacing: .06em;
  box-shadow: var(--shadow-lift);
  animation: toast-in .34s var(--ease) both;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 好感度提示（+5 💗） */
.aff-pop {
  position: fixed;
  z-index: 85;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--pop, var(--rose));
  box-shadow: var(--glow-rose);
  pointer-events: none;
  animation: aff-float 1.7s var(--ease) forwards;
}
@keyframes aff-float {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(.85); }
  18%  { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  70%  { opacity: 1; transform: translate(-50%, -26px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50px) scale(.94); }
}

/* ── 桌機微調 ───────────────────────────── */
@media (min-width: 860px) {
  :root { --dialogue-h: 210px; }
  .portrait-layer { left: 30%; width: min(460px, 40vw); }
  .dialogue { padding-left: 8vw; padding-right: 8vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .petal { display: none; }
}
