:root {
  --bg0: #0d0e14;
  --bg1: #14151f;
  --surface: #1b1d29;
  --surface2: #22242f;
  --line: #2e3140;
  --ink: #e8e9f0;
  --ink-dim: #9a9db3;
  --brand: #f08ca0;
  --brand2: #8ea6f5;
  --ok: #6fd6a0;
  --bad: #e5484d;
  --gold: #e8c07a;
  --purple: #b48ef0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg0);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  overflow: hidden;
  user-select: none;
}
.hidden { display: none !important; }
.dim { color: var(--ink-dim); }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- R18 ---------- */
#r18 { align-items: center; justify-content: center; background: #000; z-index: 60; }
.r18-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 36px 44px; max-width: 460px; text-align: center; }
.r18-badge { display: inline-block; border: 2px solid var(--bad); color: var(--bad); font-weight: 700; border-radius: 8px; padding: 2px 12px; margin-bottom: 14px; letter-spacing: 2px; }
.r18-box h1 { font-size: 20px; margin-bottom: 12px; }
.r18-box p { margin-bottom: 10px; line-height: 1.7; font-size: 14px; }
.r18-btns { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }

/* ---------- 标题屏 ---------- */
#screen-title { align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 30%, #1c1f33 0%, var(--bg0) 70%); }
.title-inner { text-align: center; max-width: 560px; width: 92%; }
.title-sub { color: var(--ink-dim); letter-spacing: 6px; font-size: 14px; margin-bottom: 10px; }
.title-main { font-size: 44px; letter-spacing: 4px; line-height: 1.35; margin-bottom: 40px; }
.title-main span { color: var(--brand); font-size: 30px; }
.title-menu { display: flex; flex-direction: column; gap: 14px; margin-bottom: 26px; }
.title-foot { margin-top: 30px; font-size: 12px; letter-spacing: 2px; }
#title-platform { font-size: 12px; }

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: rgba(13, 14, 20, .82);
  border-bottom: 1px solid var(--line); font-size: 13px; z-index: 5;
}
#hud-chapter { color: var(--ink-dim); letter-spacing: 1px; }
.mem-chip { color: var(--gold); border: 1px solid var(--gold); padding: 1px 10px; border-radius: 20px; font-size: 12px; }
.hud-btns { margin-left: auto; display: flex; gap: 8px; }

.mini-btn {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 12px; font-size: 12px; cursor: pointer;
}
.mini-btn:hover { background: var(--surface2); }
.mini-btn.danger { color: var(--bad); border-color: var(--bad); }

/* ---------- 舞台 ---------- */
#stage { position: relative; flex: 1; overflow: hidden; }
#bg { position: absolute; inset: 0; transition: background .5s; }
#bg-label { position: absolute; top: 12px; right: 16px; font-size: 11px; letter-spacing: 2px; opacity: .55; }

.bg-default {
  background:
    linear-gradient(180deg, rgba(13, 14, 20, .16) 0%, rgba(13, 14, 20, .42) 100%),
    url("../assets/bg/default.jpg") center / cover no-repeat #1a1c2e;
}
.bg-office_night { background: linear-gradient(180deg, #0b0d16 0%, #131a2c 55%, #0d0e14 100%); }
.bg-bedroom_morning { background: linear-gradient(180deg, #2c3560 0%, #4a5588 50%, #6a7099 100%); }
.bg-memory_gray { background: linear-gradient(180deg, #2a2a2e 0%, #3a3a40 60%, #232326 100%); }
.bg-classroom_morning { background: linear-gradient(180deg, #35507a 0%, #5d7ba8 55%, #8a97b0 100%); }
.bg-classroom_noon { background: linear-gradient(180deg, #4a6a90 0%, #7d94b4 60%, #a5b0c2 100%); }
.bg-street_dusk { background: linear-gradient(180deg, #59406b 0%, #a06a68 55%, #c98d6b 100%); }
.bg-bedroom_night { background: linear-gradient(180deg, #10121f 0%, #1c2038 60%, #12131f 100%); }
.bg-exam_hall { background: linear-gradient(180deg, #2c3440 0%, #46505e 60%, #2e343e 100%); }
.bg-street_autumn { background: linear-gradient(180deg, #6a4b32 0%, #a8793f 55%, #c99a55 100%); }
.bg-bbq_shop { background: linear-gradient(180deg, #3d2418 0%, #6a4022 55%, #4a2c18 100%); }
.bg-sports_field { background: linear-gradient(180deg, #3d6f9e 0%, #6f9ec4 48%, #a8bfcf 100%); }
.bg-infirmary { background: linear-gradient(180deg, #7d8c96 0%, #a3b0ba 55%, #8b98a2 100%); }
.bg-grandstand { background: linear-gradient(180deg, #4a5f6e 0%, #7a8f9c 50%, #9aa8ae 100%); }
.bg-library { background: linear-gradient(180deg, #4a4238 0%, #7a6c58 50%, #9a8c74 100%); }
.bg-snow_street { background: linear-gradient(180deg, #2b3346 0%, #4d5a70 50%, #7d8ba0 100%); }
.bg-home_living { background: linear-gradient(180deg, #5a4a3c 0%, #8a7660 55%, #a89680 100%); }
.bg-university_gate { background: linear-gradient(180deg, #3a5a7a 0%, #6a8aa8 50%, #9ab0c4 100%); }
.bg-dorm_room { background: linear-gradient(180deg, #4a4a58 0%, #727284 55%, #9a9aac 100%); }
.bg-milk_tea_shop { background: linear-gradient(180deg, #7a5a4a 0%, #b08a70 50%, #d0b098 100%); }
.bg-shared_apartment { background: linear-gradient(180deg, #3e3a48 0%, #6a6478 55%, #928ca0 100%); }
.bg-office_day { background: linear-gradient(180deg, #3a4a5e 0%, #6a7d94 50%, #9aabbc 100%); }
.bg-cafe { background: linear-gradient(180deg, #4a3a30 0%, #7a5f4a 55%, #a8846a 100%); }
.bg-city_night { background: linear-gradient(180deg, #0e1220 0%, #1e2a44 50%, #2e3a56 100%); }
.bg-roof { background: linear-gradient(180deg, #1a2038 0%, #3a4468 45%, #6a6a88 100%); }
.bg-convenience_store { background: linear-gradient(180deg, #2a3448 0%, #465670 50%, #6a7c96 100%); }
.bg-graduation { background: linear-gradient(180deg, #3a4870 0%, #7a7fa0 50%, #c4b09a 100%); }
.bg-hospital { background: linear-gradient(180deg, #4a5a60 0%, #8a9ea0 50%, #c4d0cc 100%); }
.bg-train_station { background: linear-gradient(180deg, #2e3444 0%, #5a6478 50%, #8a90a0 100%); }
.bg-seaside { background: linear-gradient(180deg, #3a6a92 0%, #6aa0b8 45%, #d8c8a0 100%); }

/* 立绘：底部居中，随舞台高度缩放，下缘淡出与对话框衔接 */
#avatar-card {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  height: min(60%, 460px); width: auto; aspect-ratio: 3 / 4; max-width: 44%;
  z-index: 2; pointer-events: none;
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, .5));
  animation: portrait-in .26s ease-out;
}
@keyframes portrait-in { from { opacity: 0; transform: translate(-50%, 8px); } }
#avatar-img, #avatar-initial {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 1px solid var(--pc, var(--line)); border-bottom: none;
  border-radius: 20px 20px 0 0;
  background: rgba(20, 21, 31, .9);
  -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 80%, transparent 100%);
  display: block;
}
#avatar-img { object-fit: cover; object-position: center top; }
#avatar-initial {
  display: flex; align-items: center; justify-content: center;
  background: var(--pc, #555); color: #14151f;
  font-size: 44px; font-weight: 700;
}
#avatar-meta {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  display: flex; align-items: baseline; gap: 6px; white-space: nowrap;
  padding: 4px 14px; border-radius: 999px;
  background: rgba(10, 11, 17, .68);
  border: 1px solid rgba(255, 255, 255, .1);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
#avatar-name { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: var(--pc, var(--ink)); }
#avatar-emotion { font-size: 11px; color: var(--ink-dim); letter-spacing: 2px; }
#avatar-emotion:empty { display: none; }
#avatar-emotion::before { content: "·"; margin-right: 6px; }

/* ---------- 对话框 ---------- */
#dialog {
  position: relative; z-index: 3;
  margin: 0 auto 10px; width: min(920px, 94%);
  background: linear-gradient(180deg, rgba(23, 25, 38, .93) 0%, rgba(13, 14, 20, .95) 100%);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 16px; padding: 22px 26px 18px; min-height: 132px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .42), inset 0 1px 0 rgba(255, 255, 255, .045);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
#name-tag {
  position: absolute; top: -13px; left: 22px;
  margin: 0; padding: 3px 14px;
  font-size: 13px; font-weight: 700; letter-spacing: 1px;
  background: #1b1d29; border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .38);
}
#text { font-size: 16px; line-height: 1.85; min-height: 60px; white-space: pre-wrap; user-select: text; }
#next-hint { position: absolute; right: 22px; bottom: 10px; font-size: 12px; color: var(--ink-dim); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

@media (max-width: 640px) {
  #avatar-card { height: min(54%, 330px); max-width: 66%; }
  #dialog { padding: 20px 18px 16px; min-height: 120px; }
  #text { font-size: 15px; line-height: 1.8; min-height: 54px; }
  #name-tag { left: 14px; }
}

/* ---------- 选项 ---------- */
#choices { display: flex; flex-direction: column; gap: 10px; width: min(920px, 94%); margin: 0 auto 18px; z-index: 4; }
.choice {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 18px; font-size: 15px; cursor: pointer; text-align: left;
  transition: transform .1s, border-color .15s, background .15s;
  font-family: inherit;
}
.choice:hover { border-color: var(--brand); background: var(--surface2); transform: translateY(-1px); }
.choice.disabled { opacity: .42; cursor: not-allowed; transform: none; }
.choice-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.choice-note { font-size: 12px; color: var(--ink-dim); margin-top: 6px; }

.tag { font-size: 11px; border-radius: 6px; padding: 1px 8px; flex-shrink: 0; }
.tag-cost { border: 1px solid var(--ink-dim); color: var(--ink-dim); }
.end-btn { text-align: center; border-color: var(--brand); color: var(--brand); letter-spacing: 2px; }

/* ---------- 浮动提示 ---------- */
#toasts { position: fixed; top: 64px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; }
.toast {
  background: rgba(20, 21, 31, .92); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 16px; font-size: 13px;
  animation: slidein .18s ease-out; transition: opacity .4s, transform .4s;
}
.toast.out { opacity: 0; transform: translateX(14px); }
@keyframes slidein { from { opacity: 0; transform: translateX(14px); } }

/* ---------- 结算 ---------- */
#screen-settle { align-items: center; justify-content: center; background: rgba(8, 9, 14, .96); z-index: 40; }
#settle-body {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  width: min(640px, 92%); max-height: 86vh; overflow-y: auto; padding: 30px 34px;
}
#settle-body h2 { font-size: 20px; letter-spacing: 2px; margin-bottom: 20px; color: var(--brand); }
.settle-rows { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.settle-row {
  display: grid; grid-template-columns: 84px 110px 1fr; align-items: center; gap: 12px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px;
}
.sr-name { font-weight: 700; }
.sr-delta { font-weight: 700; }
.sr-delta.up { color: var(--ok); }
.sr-delta.down { color: var(--bad); }
.neglect { font-size: 11px; color: var(--bad); margin-left: 6px; border: 1px solid var(--bad); border-radius: 5px; padding: 0 5px; }
.sr-comment { font-size: 13px; color: var(--ink-dim); }
.settle-risk { margin: 14px 0; font-size: 14px; }
.risk-badge { border: 1px solid; border-radius: 8px; padding: 2px 12px; font-size: 13px; margin-left: 6px; }
.settle-sub { font-size: 12px; color: var(--ink-dim); margin: 12px 0 8px; letter-spacing: 1px; }
.settle-flags { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.flag-chip { font-size: 12px; border: 1px solid var(--line); background: var(--surface2); border-radius: 6px; padding: 2px 9px; }
.flag-chip.cost { color: var(--purple); border-color: var(--purple); }
.settle-mem { font-size: 12px; color: var(--ink-dim); margin-top: 16px; }
#settle-body .end-btn { width: 100%; margin-top: 22px; }

/* ---------- 面板 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 55; }
.panel-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  width: min(560px, 92%); max-height: 80vh; display: flex; flex-direction: column; padding: 18px 22px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 15px; letter-spacing: 2px; }
#saves-list, #history-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.save-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px;
}
.save-slot { font-size: 12px; color: var(--gold); width: 48px; flex-shrink: 0; letter-spacing: 1px; }
.save-name { font-size: 14px; }
.save-time { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.save-row .mini-btn { margin-left: auto; }
.h-row { font-size: 13px; line-height: 1.7; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.h-who { color: var(--brand2); margin-right: 8px; font-weight: 600; }
.h-text { color: var(--ink-dim); }

/* 移动端适配 */
@media (max-width: 720px) {
  .title-main { font-size: 30px; }
  .title-main span { font-size: 21px; }
  #text { font-size: 15px; }
  .settle-row { grid-template-columns: 64px 90px 1fr; }
  .hud-btns .mini-btn { padding: 3px 8px; }
}
