:root {
  --paper: #f3ece4;
  --ink: #2e2a26;
  --sub: #6d5f53;
  --gold: #bfa36f;
  --gold-light: #d8c99e;
  --panel: rgba(255, 252, 247, 0.92);
  --panel-dark: rgba(40, 35, 30, 0.90);
  --shadow: 0 4px 18px rgba(45, 35, 28, 0.22);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Noto Serif SC", "SimSun", "STSong", serif;
  background: #1f1a16;
  color: var(--ink);
  overflow: hidden;
  display: flex; justify-content: center; align-items: center;
}

#game {
  position: relative;
  width: 100vw; height: 100vh;
  max-width: 1920px;
  display: grid;
  grid-template-columns: clamp(200px, 22vw, 300px) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas:
    "left stage";
  background: #2a2420;
}

/* 左侧属性面板 */
#left-panel {
  grid-area: left;
  position: relative;
  background: var(--panel);
  border-right: 1px solid #d8cfc2;
  padding: 18px 16px;
  display: flex; flex-direction: column;
  gap: 10px;
  box-shadow: 4px 0 16px rgba(0,0,0,0.18);
  z-index: 10;
}

@media (min-width: 1024px) {
  #left-panel {
    transform: translateX(0);
  }
}
#left-panel::before {
  content: "";
  position: absolute; inset: 0;
  background: url(".././ui_assets/06_panel_left.webp") center top / cover no-repeat;
  opacity: 0.14;
  pointer-events: none;
}
.panel-title {
  position: relative;
  text-align: center;
  font-size: 20px;
  letter-spacing: 6px;
  color: #4a3f35;
  margin: 4px 0 6px;
  font-weight: normal;
}
.panel-title small {
  display: block;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold);
  margin-top: 2px;
}
.info-row {
  position: relative;
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--sub);
  border-bottom: 1px dashed #d0c6b8;
  padding-bottom: 4px;
}
.info-row b { color: #4a3f35; }

.stat-block {
  position: relative;
  display: grid;
  grid-template-columns: 28px 56px 1fr 34px;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.stat-label {
  font-size: 12px;
  color: #5a4d42;
  text-align: left;
}
.stat-icon {
  width: 26px; height: 26px;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15));
}
.stat-bar {
  height: 10px;
  background: #e3ddd4;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #cfc7ba;
}
.stat-fill {
  height: 100%;
  border-radius: 5px 0 0 5px;
  background: linear-gradient(90deg, #c9a96e, #e3c88d);
  transition: width 0.4s ease;
}
.stat-val { font-size: 13px; text-align: right; color: #5a4d42; }

.divider {
  position: relative;
  height: 1px; background: #d8cfc2;
  margin: 4px 0;
}

.favor-section {
  position: relative;
  flex: 1;
  overflow-y: auto;
}
.favor-title {
  font-size: 13px; color: var(--gold);
  letter-spacing: 3px;
  margin: 8px 0 6px;
  text-align: center;
}
.favor-row {
  display: flex; justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  color: var(--sub);
}
.favor-row b { color: #4a3f35; }
.favor-heart {
  color: #d46a7e;
  letter-spacing: 1px;
}
.favor-heart-pink { color: #e87a9a; }
.favor-heart-orange { color: #e89c5a; }

.state-effect {
  position: relative;
  background: #faf6f0;
  border: 1px solid #e3ddd4;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #6d5f53;
  line-height: 1.5;
  min-height: 44px;
}

/* 顶部菜单 */
#menu-bar {
  position: absolute;
  top: 52px; right: 22px;
  display: flex;
  gap: 10px;
  z-index: 35;
}
#menu-bar button {
  background: rgba(30, 25, 21, 0.72);
  border: 1px solid rgba(216, 201, 158, 0.45);
  color: var(--gold-light);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 2px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition: all .15s;
}
#menu-bar button:hover { background: rgba(70, 58, 47, 0.85); border-color: var(--gold); }

/* 存档/读档界面 */
#save-load-screen {
  position: fixed; inset: 0;
  background: rgba(18, 15, 12, 0.82);
  z-index: 120;
  display: none;
  justify-content: center; align-items: center;
  padding: 40px 20px;
}
#save-load-screen.show { display: flex; }
.save-load-box {
  position: relative;
  width: min(760px, 92vw);
  max-height: min(640px, 90vh);
  background: url(".././ui_assets/01_saveload_bg.webp") center / cover no-repeat;
  border: 1px solid rgba(216, 201, 158, 0.55);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  padding: clamp(24px, 4vh, 40px) clamp(24px, 4vw, 48px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.save-load-box::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(30, 25, 21, 0.42);
  pointer-events: none;
  border-radius: 12px;
}
.save-load-title {
  position: relative;
  text-align: center;
  font-size: 24px;
  letter-spacing: 8px;
  color: var(--gold-light);
  margin-bottom: 24px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
#save-slots {
  position: relative;
  flex: 1;
  overflow-y: auto;
  display: flex; flex-direction: column;
  gap: 14px;
  padding-right: 6px;
}
.save-slot {
  position: relative;
  background: rgba(255, 252, 247, 0.88);
  border: 1px solid rgba(191, 163, 111, 0.45);
  border-radius: 10px;
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 8px 18px;
  align-items: center;
  transition: transform .15s, box-shadow .15s;
}
.save-slot.has-save {
  background: rgba(255, 252, 247, 0.95);
  border-color: rgba(191, 163, 111, 0.75);
}
.save-slot:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.18); }
.slot-title {
  font-size: 17px;
  color: #4a3f35;
  letter-spacing: 3px;
}
.slot-meta {
  grid-column: 1 / 2;
  font-size: 13px;
  color: #6d5f53;
  line-height: 1.6;
}
.slot-actions {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  display: flex; flex-direction: column;
  gap: 8px;
}
.slot-actions button {
  min-width: 72px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 2px;
  border-radius: 5px;
  border: 1px solid var(--gold);
  background: rgba(40, 33, 27, 0.88);
  color: #f7f0e6;
  cursor: pointer;
  transition: all .15s;
}
.slot-actions button:hover:not(:disabled) { background: rgba(70, 58, 47, 0.95); }
.slot-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.slot-actions .delete-btn {
  border-color: #a85d5d;
  color: #e8b8b8;
  background: rgba(50, 30, 30, 0.88);
}
.slot-actions .delete-btn:hover:not(:disabled) { background: rgba(80, 45, 45, 0.95); }

.close-btn {
  position: relative;
  align-self: center;
  margin-top: 20px;
  padding: 10px 36px;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 4px;
  border-radius: 24px;
  border: none;
  background: linear-gradient(180deg, #e3c88d, #c9a96e);
  color: #2e2a26;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform .15s;
}
.close-btn:hover { transform: scale(1.04); }

/* 历史记录浮窗 */
#history-panel {
  position: fixed; inset: 0;
  z-index: 120;
  display: none;
  justify-content: center; align-items: center;
  background: rgba(18, 15, 12, 0.55);
  padding: 40px 20px;
}
#history-panel.show { display: flex; }
.history-box {
  position: relative;
  width: min(640px, 92vw);
  height: min(720px, 86vh);
  background: url(".././ui_assets/06_panel_left.webp") center / cover no-repeat;
  border: 1px solid rgba(216, 201, 158, 0.5);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  padding: clamp(22px, 3vh, 34px) clamp(22px, 3vw, 38px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.history-box::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(30, 25, 21, 0.38);
  pointer-events: none;
  border-radius: 12px;
}
.history-title {
  position: relative;
  text-align: center;
  font-size: 22px;
  letter-spacing: 8px;
  color: var(--gold-light);
  margin-bottom: 18px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
.history-scroll {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 14px;
  background: rgba(255, 252, 247, 0.82);
  border: 1px solid rgba(191, 163, 111, 0.35);
  border-radius: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) #e3ddd4;
}
.history-scroll::-webkit-scrollbar { width: 7px; }
.history-scroll::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 4px; }
.history-scroll::-webkit-scrollbar-track { background: #e3ddd4; border-radius: 4px; }
.history-empty {
  text-align: center;
  color: #6d5f53;
  font-size: 14px;
  padding: 40px 0;
}
.history-turn {
  position: sticky;
  top: 0;
  background: #f3ece4;
  border-bottom: 1px solid #d8cfc2;
  padding: 8px 10px;
  margin: 12px 0 8px;
  font-size: 14px;
  color: #4a3f35;
  letter-spacing: 2px;
  font-weight: bold;
  z-index: 2;
}
.history-turn:first-child { margin-top: 0; }
.history-row {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  font-size: 13px;
  line-height: 1.7;
  color: #4a3f35;
  border-bottom: 1px dashed #e3ddd4;
}
.history-row:last-child { border-bottom: none; }
.history-tag {
  flex-shrink: 0;
  min-width: 42px;
  text-align: center;
  background: rgba(191, 163, 111, 0.22);
  color: #7a6549;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  height: fit-content;
}
.history-text {
  flex: 1;
}
.history-text small {
  display: block;
  color: #8a7b6a;
  font-size: 12px;
  margin-top: 2px;
}
.history-row b { color: #6d5f53; }

.panel-toggle { display: none; }

/* 中央舞台：场景 + 立绘 */
#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: #15120f;
}
#scene {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
  transition: opacity 0.6s ease;
}
#scene.dim { filter: brightness(0.72); }
#character-wrap {
  position: absolute;
  right: 5%; bottom: 0;
  height: clamp(72%, 92vh, 92%);
  max-width: clamp(28%, 42vw, 42%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
  transition: transform 0.4s ease, opacity 0.4s ease;
}
#character-wrap.left { right: auto; left: 5%; }
#character-wrap.center { left: 50%; transform: translateX(-50%); right: auto; }
#character-wrap.hidden { opacity: 0; transform: translateY(20px); }
#character {
  height: 100%;
  width: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.35));
}
#character-name {
  background: rgba(30, 25, 21, 0.72);
  color: var(--gold-light);
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 14px;
  letter-spacing: 3px;
  margin-bottom: 8px;
  white-space: nowrap;
  border: 1px solid rgba(216, 201, 158, 0.35);
  backdrop-filter: blur(2px);
}

.scene-tag {
  position: absolute;
  top: 16px; left: 20px;
  background: rgba(30, 25, 21, 0.78);
  color: var(--gold-light);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 3px;
  backdrop-filter: blur(2px);
}

/* 底部对话框 */
#dialog-wrap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(30,25,21,0) 0%, rgba(30,25,21,0.70) 30%, rgba(30,25,21,0.86) 100%);
  padding: clamp(10px, 1.6vh, 18px) clamp(16px, 3.6vw, 42px) clamp(10px, 1.6vh, 22px);
  display: flex; flex-direction: column;
  justify-content: flex-end;
  z-index: 20;
}
#dialog-box {
  position: relative;
  min-height: clamp(96px, 14vh, 128px);
  background: rgba(255, 252, 247, 0.10);
  border: 1px solid rgba(216, 201, 158, 0.35);
  border-radius: 12px;
  padding: clamp(10px, 1.4vh, 16px) clamp(14px, 1.8vw, 22px);
  color: #f7f0e6;
}
#dialog-box::before {
  content: "";
  position: absolute; inset: 0;
  background: url(".././ui_assets/07_dialog_box.webp") center / 100% 100% no-repeat;
  opacity: 0.18;
  pointer-events: none;
}
#speaker {
  position: relative;
  color: var(--gold);
  font-size: 16px;
  letter-spacing: 3px;
  margin-bottom: 8px;
  min-height: 22px;
}
#dialog-text {
  position: relative;
  font-size: clamp(14px, 1.2vw + 0.4vh, 17px);
  line-height: 1.85;
  min-height: 56px;
}
#dialog-hint {
  position: absolute;
  right: 24px; bottom: 14px;
  font-size: 12px;
  color: #a89b8c;
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%,100%{opacity:0.5} 50%{opacity:1} }

/* 选择按钮区 */
#choices {
  position: absolute;
  left: 0; right: 0;
  bottom: clamp(150px, 22vh, 210px);
  display: flex; flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.2vh, 10px);
  padding: 0 clamp(16px, 4vw, 60px);
  z-index: 30;
  pointer-events: none;
}
#choices.has-choices { pointer-events: auto; }
button.choice {
  width: 100%;
  max-width: min(620px, 86vw);
  background: rgba(40, 33, 27, 0.92);
  border: 1px solid var(--gold);
  color: #f7f0e6;
  padding: clamp(10px, 1.4vh, 12px) clamp(14px, 2vw, 18px);
  text-align: left;
  font-size: clamp(13px, 1vw + 0.3vh, 15px);
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  backdrop-filter: blur(3px);
}
button.choice:hover { background: rgba(70, 58, 47, 0.95); transform: translateX(4px); }
button.choice small {
  display: block;
  color: #b8a07a;
  font-size: 12px;
  margin-top: 4px;
}

/* 顶部回合标题 */
#turn-title {
  position: absolute;
  top: 16px; right: 22px;
  color: #f7f0e6;
  font-size: 16px;
  letter-spacing: 3px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  z-index: 25;
}

/* 开始遮罩 */
#overlay {
  position: fixed; inset: 0;
  background: linear-gradient(rgba(18, 15, 12, 0.55), rgba(18, 15, 12, 0.78)), url(".././char_scene_assets/scenes/01_title_pearl.webp") center / cover no-repeat;
  z-index: 100;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  text-align: center;
  color: #f7f0e6;
}
.title-logo {
  max-width: min(520px, 70vw);
  max-height: 28vh;
  object-fit: contain;
  margin-bottom: 10px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.45));
}
#overlay h1 {
  font-size: 52px; font-weight: normal;
  letter-spacing: 18px;
  margin: 0 0 10px;
  color: var(--gold-light);
}
#overlay p { color: #b8a89a; font-size: 15px; letter-spacing: 2px; margin: 6px 0; }
#overlay .start-btn {
  margin-top: 28px;
  padding: 14px 48px;
  font-size: 18px;
  font-family: inherit;
  color: #2e2a26;
  background: linear-gradient(180deg, #e3c88d, #c9a96e);
  border: none;
  border-radius: 30px;
  cursor: pointer;
  letter-spacing: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  transition: transform .15s;
}
#overlay .start-btn.secondary {
  background: transparent;
  color: var(--gold-light);
  border: 1px solid var(--gold);
  margin-left: 16px;
}
.overlay-btns { display: flex; justify-content: center; align-items: center; }
#overlay .start-btn:hover { transform: scale(1.04); }

/* 浮动效果文字 */
#float-effects {
  position: absolute;
  right: 24px; top: 60px;
  display: flex; flex-direction: column;
  gap: 6px;
  z-index: 25;
  pointer-events: none;
}
.float-text {
  background: rgba(30,25,21,0.75);
  color: var(--gold-light);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 13px;
  animation: floatUp 1.9s ease forwards;
}
@keyframes floatUp {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-34px); }
}

/* 结局展示 */
#game.hidden-for-ending { display: none; }
#ending-screen {
  position: fixed; inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 110;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  text-align: center;
  color: #f7f0e6;
}
#ending-screen.show { display: flex; }
#ending-screen .ending-content {
  width: min(720px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  margin: auto auto 4vh;
  padding: 28px 34px 36px;
  background: rgba(18,15,12,0.72);
  border-radius: 16px;
  border: 1px solid rgba(216, 201, 158, 0.35);
  backdrop-filter: blur(2px);
  scrollbar-width: thin;
  scrollbar-color: var(--gold) rgba(255,255,255,0.1);
}
#ending-screen h2 {
  font-size: 40px; font-weight: normal;
  letter-spacing: 10px;
  color: var(--gold-light);
  margin: 0 0 12px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.7);
}
#ending-screen .ending-category {
  color: var(--gold);
  font-size: 16px;
  letter-spacing: 4px;
  margin-bottom: 14px;
}
#ending-screen .ending-desc {
  max-width: 720px;
  margin: 0 auto 28px;
  font-size: 16px;
  line-height: 1.95;
  color: #f0e8dc;
  text-shadow: 0 1px 5px rgba(0,0,0,0.7);
}
#ending-screen .ending-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 14px;
  max-width: 560px;
  margin: 0 auto 24px;
  font-size: 14px;
  color: #d8c8b6;
}
#ending-screen .ending-content::-webkit-scrollbar { width: 6px; }
#ending-screen .ending-content::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 3px; }
#ending-screen .restart-btn {
  padding: 12px 36px;
  font-size: 16px;
  font-family: inherit;
  color: #2e2a26;
  background: linear-gradient(180deg, #e3c88d, #c9a96e);
  border: none;
  border-radius: 24px;
  cursor: pointer;
  letter-spacing: 3px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
}

@media (max-width: 1024px) {
  #game { grid-template-columns: minmax(180px, 26vw) 1fr; }
  #left-panel {
    padding: 14px 10px; gap: 8px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  #left-panel.open { transform: translateX(0); }
  .panel-title { font-size: 16px; letter-spacing: 4px; }
  .info-row { font-size: 12px; }
  .stat-block { grid-template-columns: 24px 1fr 30px; gap: 4px; }
  .stat-icon { width: 22px; height: 22px; }
  .stat-val { font-size: 12px; }
  .favor-row { font-size: 11px; }
  #ending-screen .ending-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  #game { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "stage"; }
  #left-panel {
    position: absolute;
    left: 0; top: 0;
    width: min(260px, 72vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
  }
  #left-panel.open { transform: translateX(0); }
  .panel-toggle {
    display: block;
    position: absolute;
    left: 100%; top: 12px;
    background: var(--panel);
    border: 1px solid #d8cfc2;
    border-left: none;
    border-radius: 0 6px 6px 0;
    padding: 8px 10px;
    font-size: 13px;
    color: #4a3f35;
    cursor: pointer;
    box-shadow: 2px 0 8px rgba(0,0,0,0.12);
  }
  #scene-tag, #turn-title { font-size: 12px; }
}

@media (max-width: 480px) {
  #dialog-wrap { padding: 8px 12px 12px; }
  #dialog-box { border-radius: 8px; padding: 10px 12px; }
  #dialog-text { font-size: 14px; line-height: 1.7; }
  #speaker { font-size: 14px; }
  #choices { bottom: clamp(130px, 22vh, 180px); padding: 0 12px; }
  button.choice { font-size: 13px; padding: 10px 12px; }
  #character { max-width: 56%; }
  #ending-screen .ending-content { padding: 40px 20px 32px; }
  #ending-screen h2 { font-size: 28px; }
  #ending-screen .ending-stats { grid-template-columns: 1fr; }
}
