/* ============ 基础重置 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC", sans-serif;
  background: #1a1a2e;
  color: #fff;
  user-select: none;
}

#game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  background: #000;
  box-shadow: 0 0 40px rgba(0,0,0,0.8);
}

/* ============ 状态栏 ============ */
#statusbar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #2a2a4a, #1a1a3a);
  border-bottom: 2px solid #4a4a7a;
  font-size: 14px;
  flex-shrink: 0;
}
.status-item {
  padding: 4px 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.1);
}

/* ============ 主舞台 ============ */
#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
}
#background {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: background 0.6s;
}

/* ============ 瓦片地图 Canvas ============ */
#camera {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  will-change: transform;
}
#tilemap-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* ============ 演出层：立绘 / CG / 淡入淡出 / 闪白 ============ */
#portrait-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
.portrait {
  position: absolute;
  bottom: 0;
  height: 84%;
  max-width: 46%;
  object-fit: contain;
  object-position: bottom;
  opacity: 0;
  transform-origin: bottom center;
  transform: translateY(16px) scale(1.3);
  transition: opacity .3s ease, transform .3s ease;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.55));
}
.portrait.shown { opacity: 1; transform: translateY(0) scale(1.3); }
.portrait.slot-left { left: 8%; }
.portrait.slot-right { right: 8%; }
.portrait.slot-center { left: 50%; transform: translateX(-50%) translateY(16px) scale(1.3); }
.portrait.slot-center.shown { transform: translateX(-50%) translateY(0) scale(1.3); }

#fx-cg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
  z-index: 7;
}
#fx-cg.shown { opacity: 1; }
/* 长图分格：按宽度铺满，纵向留出可切换的余量 */
#fx-cg.cg-tall {
  background-size: 100% auto;
  background-position: center top;
  background-repeat: no-repeat;
}

#fx-fade,
#fx-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 9;
}
#fx-fade { background: #000; }
#fx-flash { background: #fff; }


/* 交互提示 */
#interact-prompt {
  position: absolute;
  bottom: 170px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  border: 1px solid #ffdd88;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 13px;
  color: #ffdd88;
  z-index: 5;
  animation: promptBlink 1.2s infinite;
}
@keyframes promptBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
#character-layer {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  pointer-events: none;
}
.char-sprite {
  height: 78%;
  transition: all 0.4s ease;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.6));
}
.char-sprite.left { transform: translateX(-20%); }
.char-sprite.right { transform: translateX(20%); }

/* ============ 对话框 ============ */
#dialogue-box {
  position: absolute;
  left: 4%; right: 4%; bottom: 4%;
  z-index: 12;               /* 必须压在立绘 / CG 之上 */
  background: rgba(10, 10, 30, 0.92);
  border: 2px solid #6a6aaa;
  border-radius: 8px;
  padding: 16px 24px;
  min-height: 140px;
  box-shadow: 0 0 24px rgba(100,100,255,0.3);
  cursor: pointer;
}
#speaker-name {
  display: inline-block;
  padding: 4px 14px;
  background: #4a4aaa;
  border-radius: 4px;
  font-weight: bold;
  margin-bottom: 8px;
  font-size: 15px;
}
#dialogue-text {
  font-size: 17px;
  line-height: 1.7;
  min-height: 3em;
  letter-spacing: 1px;
}
#dialogue-text.typing::after {
  content: "▍";
  animation: blink 0.8s infinite;
  color: #aaffcc;
}
@keyframes blink { 50% { opacity: 0; } }
.hint {
  text-align: right;
  font-size: 11px;
  color: #888;
  margin-top: 6px;
}

/* ============ 选项 ============ */
#choices {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.choice-btn {
  padding: 10px 16px;
  background: rgba(80,80,160,0.5);
  border: 1px solid #6a6aaa;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
  transition: all 0.2s;
}
.choice-btn:hover {
  background: rgba(120,120,220,0.8);
  transform: translateX(4px);
}

/* ============ 全屏界面（标题 / 结局） ============ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background: rgba(10,10,40,0.96);
  z-index: 10;
}

/* ============ 标题界面 ============ */
#title-screen {
  background: linear-gradient(180deg, #0a0a3a 0%, #2a1a4a 100%);
}
#title-screen h1 {
  font-size: 72px;
  letter-spacing: 8px;
  color: #ffdd88;
  text-shadow: 0 4px 20px rgba(255,200,100,0.5);
  margin-bottom: 8px;
}
#title-screen .subtitle {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 40px;
  letter-spacing: 4px;
}
.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 40px;
}
.title-buttons button {
  padding: 12px 60px;
  font-size: 18px;
  background: transparent;
  border: 2px solid #6a6aaa;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  letter-spacing: 4px;
}
.title-buttons button:hover {
  background: #6a6aaa;
  box-shadow: 0 0 20px rgba(100,100,255,0.5);
}
#title-screen .credit {
  position: absolute;
  bottom: 20px;
  font-size: 11px;
  color: #666;
}

/* ============ 结局界面 ============ */
#ending-screen h1 {
  font-size: 48px;
  color: #ffaaaa;
  margin-bottom: 20px;
}
#ending-screen p {
  font-size: 18px;
  line-height: 1.8;
  max-width: 600px;
  text-align: center;
  margin-bottom: 30px;
  color: #ddd;
}
#ending-screen button {
  padding: 10px 40px;
  font-size: 16px;
  background: #6a6aaa;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
}

/* ============ 底部操作栏 ============ */
#actionbar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #1a1a3a, #0a0a2a);
  border-top: 2px solid #4a4a7a;
  flex-shrink: 0;
}
#actionbar button {
  flex: 1;
  padding: 10px;
  background: rgba(100,100,180,0.3);
  border: 1px solid #5a5a9a;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}
#actionbar button:hover {
  background: rgba(100,100,180,0.6);
}

/* ============ 弹窗 ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: #1a1a3a;
  border: 2px solid #6a6aaa;
  border-radius: 8px;
  padding: 24px;
  min-width: 360px;
  box-shadow: 0 0 30px rgba(100,100,255,0.3);
}
.modal-content h2 {
  color: #ffdd88;
  margin-bottom: 16px;
  text-align: center;
}
.modal-content button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px;
  background: rgba(100,100,180,0.4);
  border: 1px solid #5a5a9a;
  color: #fff;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
}
.modal-content button:hover {
  background: rgba(100,100,180,0.7);
}
.affection-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.affection-bar {
  flex: 1;
  margin-left: 12px;
  height: 12px;
  background: #333;
  border-radius: 6px;
  overflow: hidden;
  align-self: center;
}
.affection-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #ff6688, #ffaa66);
  transition: width 0.3s;
}

/* ============ Toast 提示 ============ */
#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  border: 1px solid #6a6aaa;
  padding: 10px 24px;
  border-radius: 4px;
  z-index: 200;
  font-size: 14px;
  animation: fadeIn 0.3s;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 自动演示控制条 */
#auto-bar {
  position: fixed; top: 10px; right: 10px; z-index: 150;
  display: flex; align-items: center; gap: 6px;
  background: rgba(20, 20, 32, 0.92); border: 1px solid #6a6aaa;
  border-radius: 8px; padding: 6px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
#auto-bar .auto-label { font-size: 12px; color: #ffd166; margin-right: 2px; }
#auto-bar button {
  background: #2a2a3e; border: 1px solid #4c4c68; color: #d8d8e6;
  padding: 3px 8px; border-radius: 5px; font-size: 12px; cursor: pointer;
}
#auto-bar button:hover { background: #34344c; }
#auto-bar button.active { border-color: #ffd166; color: #ffd166; }
#auto-bar #auto-stop { border-color: #8a4a4a; color: #ffb0b0; }

/* 自动演示开场的特性一览 */
#showcase-card {
  position: absolute;
  top: 16px; left: 16px; z-index: 120;
  width: 388px; max-height: calc(100% - 190px);
  overflow: auto;
  scrollbar-width: thin;
  background: rgba(14, 16, 26, 0.9);
  border: 1px solid #6a6aaa; border-radius: 10px;
  padding: 10px 14px 12px;
  color: #e6e6f0; font-size: 11.5px; line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  animation: sc-in .4s ease;
}
#showcase-card h3 { margin: 0 0 6px; font-size: 13px; color: #ffd166; font-weight: 600; }
#showcase-card h4 { margin: 4px 0 2px; font-size: 12px; color: #9fd4ff; }
#showcase-card .sc-cols { display: flex; gap: 12px; }
#showcase-card .sc-cols > div { flex: 1; }
#showcase-card ul { margin: 2px 0 6px; padding-left: 14px; }
#showcase-card li { list-style: disc; color: #cfd6e6; }
#showcase-card .sc-note { margin: 6px 0 0; color: #9aa3b8; font-size: 11px; }
@keyframes sc-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }
