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

:root {
  --accent: #7ec8ff;
  --accent-dim: #4a90c2;
  --text: #f0f4f8;
  --box-bg: rgba(12, 18, 30, 0.88);
  --gold: #ffd700;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0f1a;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  user-select: none;
}

#game {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 960px;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
}

/* ===== 背景层 ===== */
#bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: background-image 0.8s ease, filter 0.5s;
}

/* ===== 角色立绘层 ===== */
#char-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.char-slot {
  position: absolute;
  bottom: 0;
  width: 190px;
  height: 58%;
  transition: transform 0.6s ease, opacity 0.6s ease, filter 0.4s;
}

#char-left  { left: 7%; }
#char-center{ left: 50%; margin-left: -95px; }
#char-right { right: 7%; }

.char-slot.hidden { opacity: 0; transform: translateY(40px); }
.char-slot.speaking { filter: brightness(1.05) drop-shadow(0 0 18px rgba(126,200,255,0.35)); }
.char-slot.muted { filter: brightness(0.5); }

.char-art {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.char-body { width: 80%; transition: transform 0.3s; }
.char-head {
  position: relative;
  width: 52%;
  aspect-ratio: 1;
  margin-bottom: -6%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  background: linear-gradient(180deg, #ffe8cc 0%, #f5c9a0 100%);
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transition: transform 0.3s;
  overflow: visible;
}
.char-slot.speaking .char-head { animation: talk 0.5s ease-in-out infinite alternate; }
@keyframes talk { from { transform: translateY(0); } to { transform: translateY(-4px); } }

/* 头发：头顶发盖 + 侧发丝 */
.char-hair {
  position: absolute;
  top: -10%;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 40%;
  border-radius: 50% 50% 42% 42% / 62% 62% 38% 38%;
  z-index: 2;
}
.char-hair::before,
.char-hair::after {
  content: '';
  position: absolute;
  top: 30%;
  width: 26%;
  height: 85%;
  background: inherit;
  border-radius: 40% 40% 50% 50%;
}
.char-hair::before { left: -14%; }
.char-hair::after  { right: -14%; }
.char-hair.long {
  height: 46%;
  width: 64%;
}
.char-hair.long::before,
.char-hair.long::after {
  height: 220%;
  top: 55%;
  width: 30%;
}
.char-hair.long::before { left: -16%; }
.char-hair.long::after  { right: -16%; }
.char-hair.spiky {
  clip-path: polygon(20% 0, 35% 15%, 50% 0, 65% 15%, 80% 0, 100% 25%, 85% 45%, 60% 30%, 40% 30%, 15% 45%, 0 25%);
}
.char-hair.spiky::before,
.char-hair.spiky::after { display: none; }

.char-eyes {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 22%;
  z-index: 3;
}
.eye {
  width: 13px; height: 17px;
  border-radius: 50%;
  background: #2b2b3a;
  position: relative;
  overflow: hidden;
}
.eye::after {
  content: '';
  position: absolute; top: 2px; left: 3px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #fff;
}

.char-mouth {
  position: absolute;
  top: 74%;
  left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 8px;
  margin-top: 0;
  border-radius: 0 0 12px 12px;
  background: #b06050;
  z-index: 3;
}
.char-mouth.smile { width: 22px; height: 10px; border-radius: 0 0 50% 50%; }
.char-mouth.sad   { width: 18px; height: 7px; border-radius: 50% 50% 0 0; transform: translate(-50%, 3px); }
.char-mouth.open  { width: 14px; height: 12px; border-radius: 50%; background: #8a3a30; }
.char-mouth.angry { width: 20px; height: 5px; border-radius: 2px; background: #a04040; }

.char-dress {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 52%;
  border-radius: 46% 46% 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.85);
  border-top: 3px solid rgba(255,255,255,0.25);
}

.char-shadow {
  position: absolute;
  bottom: 0;
  width: 90%;
  height: 8%;
  background: radial-gradient(ellipse, rgba(0,0,0,0.55), transparent 70%);
  border-radius: 50%;
}

/* ===== 对话区 ===== */
#dialogue-box {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 3%;
  padding: 18px 24px 22px;
  background: var(--box-bg);
  border: 1px solid rgba(126,200,255,0.25);
  border-radius: 14px;
  min-height: 130px;
  backdrop-filter: blur(6px);
  cursor: pointer;
  animation: box-in 0.3s ease;
  z-index: 20;
}
@keyframes box-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

#speaker-name {
  display: inline-block;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 8px;
  padding: 2px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(126,200,255,0.1);
  border-radius: 4px;
}

#dialogue-text {
  font-size: 1.05rem;
  line-height: 1.8;
  min-height: 76px;
  white-space: pre-wrap;
}

#click-hint {
  position: absolute;
  right: 18px;
  bottom: 8px;
  color: var(--accent);
  animation: hint-bounce 1.2s infinite;
}
@keyframes hint-bounce { 0%,100% { transform: translateY(0); opacity: 0.6; } 50% { transform: translateY(4px); opacity: 1; } }

/* ===== 选项区 ===== */
#choice-box {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 16%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice-btn {
  width: 100%;
  padding: 14px 20px;
  background: rgba(20, 30, 50, 0.92);
  border: 1px solid rgba(126,200,255,0.35);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  animation: box-in 0.35s ease backwards;
}
.choice-btn:nth-child(2) { animation-delay: 0.08s; }
.choice-btn:nth-child(3) { animation-delay: 0.16s; }
.choice-btn:hover {
  background: rgba(60, 110, 160, 0.7);
  border-color: var(--accent);
  transform: translateX(6px);
}

/* ===== 标题/覆盖层 ===== */
#title-screen, .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(40,70,120,0.6), rgba(5,8,16,0.96) 70%);
  z-index: 50;
}

.game-title {
  font-size: 3.4rem;
  letter-spacing: 12px;
  background: linear-gradient(180deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(126,200,255,0.3);
}
.game-subtitle { color: #9ab8d0; letter-spacing: 3px; margin-bottom: 24px; }

.btn-primary {
  min-width: 220px;
  padding: 13px 0;
  font-size: 1.05rem;
  letter-spacing: 4px;
  color: #0a1220;
  background: linear-gradient(180deg, #a8dcff, var(--accent));
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(126,200,255,0.35); }
.btn-secondary {
  min-width: 160px;
  padding: 10px 0;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.hidden { display: none !important; }

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 40;
}
.hud-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(10,16,28,0.7);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

#flag-display {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 12px;
  background: rgba(10,16,28,0.7);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--gold);
  z-index: 40;
}

#menu-overlay button {
  min-width: 200px;
  padding: 12px;
  margin: 4px;
  background: rgba(20,30,50,0.9);
  border: 1px solid rgba(126,200,255,0.3);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}

/* ===== 存档界面 ===== */
#save-screen { z-index: 60; }
#save-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 80%;
  max-width: 560px;
}
.save-slot {
  padding: 14px;
  background: rgba(20,30,50,0.85);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 80px;
  text-align: left;
}
.save-slot:hover { border-color: var(--accent); }
.save-slot.empty { color: #6a7d92; font-style: italic; }
.save-slot .slot-time { display: block; color: #8aa4bd; font-size: 0.78rem; margin-top: 6px; }

/* ===== 结局 ===== */
#ending-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 55;
  animation: ending-in 1.2s ease;
}
@keyframes ending-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; } }
#ending-title {
  font-size: 2.6rem;
  letter-spacing: 8px;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255,215,0,0.4);
}
#ending-desc {
  max-width: 520px;
  text-align: center;
  line-height: 1.9;
  color: #c8d8e8;
  font-size: 1.05rem;
  padding: 0 24px;
}

/* ===== 特效 ===== */
.fx-rain {
  position: absolute;
  top: -10%;
  color: rgba(160,200,255,0.6);
  font-size: 1.2rem;
  animation: rain-fall linear infinite;
}
@keyframes rain-fall { to { transform: translateY(120vh); } }

.fx-flash { position: absolute; inset: 0; background: rgba(255,255,255,0.8); animation: flash 0.4s ease-out forwards; z-index: 10; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* 窄屏适配 */
@media (max-width: 600px) {
  .char-slot { width: 150px; height: 50%; }
  #char-left { left: 4%; }
  #char-center { margin-left: -75px; }
  #char-right { right: 4%; }
  .game-title { font-size: 2.4rem; letter-spacing: 8px; }
  #dialogue-box { min-height: 110px; padding: 14px 16px 18px; bottom: 12%; }
  #dialogue-text { font-size: 0.95rem; }
}
