/* ===========================================================
   猴子的爱情故事 —— 界面样式
   纯 CSS，无外部依赖，可直接 file:// 打开
   =========================================================== */

:root {
  --accent: #7fd8ff;
  --accent2: #ffb3d1;
  --ink: #eaf2ff;
  --panel: rgba(10, 13, 21, 0.74);
  --panel-solid: rgba(10, 13, 21, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --name-lin: #8fd9ff;
  --name-su: #cbd8ff;
  --name-bai: #ffc2dd;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: #04060b;
  overflow: hidden;
  color: var(--ink);
  font-family: "LXGW WenKai", "霞鹜文楷", "Microsoft YaHei", "PingFang SC",
               "Noto Sans SC", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app { position: fixed; inset: 0; display: grid; place-items: center; }

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;   /* 手机上地址栏收起时不会跳一下 */
  overflow: hidden;
  background: #000;
  cursor: pointer;
}

/* ---------------- 背景层 ---------------- */
.bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: opacity .5s ease;
}
#bg2 { opacity: 0; }

.bg.black     { background: radial-gradient(120% 100% at 50% 42%, #141a2a, #04060b 72%); }

/* 教室：暖色的下午斜光 */
.bg.classroom {
  background:
    radial-gradient(58% 46% at 84% 2%, rgba(255,238,200,.42), transparent 62%),
    radial-gradient(120% 90% at 12% 104%, rgba(24,16,9,.85), transparent 68%),
    linear-gradient(180deg, #5c4c39 0%, #453828 42%, #2e2620 68%, #171310 100%);
}
.bg.classroom::after {
  content: ""; position: absolute; inset: -8%;
  background: linear-gradient(103deg,
    transparent 6%, rgba(255,238,201,.18) 10%, transparent 16%,
    transparent 26%, rgba(255,238,201,.14) 30%, transparent 37%,
    transparent 48%, rgba(255,238,201,.10) 52%, transparent 61%,
    transparent 74%, rgba(255,238,201,.06) 78%, transparent 88%);
  filter: blur(13px);
}

/* 走廊：冷灰蓝，尽头一片光 */
.bg.corridor {
  background:
    radial-gradient(46% 74% at 88% 44%, rgba(255,247,222,.78), transparent 62%),
    radial-gradient(90% 80% at 8% 50%, rgba(20,28,42,.7), transparent 70%),
    linear-gradient(180deg, #5e6b80 0%, #4b5769 52%, #333c4b 100%);
}
.bg.corridor::after {
  content: ""; position: absolute; inset: -6%;
  background: linear-gradient(90deg,
    transparent 52%, rgba(255,248,226,.22) 62%, transparent 70%,
    transparent 78%, rgba(255,248,226,.14) 84%, transparent 92%);
  filter: blur(14px);
}

/* 天台：夏天空，云，栏杆剪影 */
.bg.roof {
  background:
    radial-gradient(60% 40% at 78% 16%, rgba(255,250,226,.85), transparent 62%),
    linear-gradient(180deg, #2f6fb0 0%, #63a6dd 40%, #b9dbef 58%, #efe0c6 70%, #3a3128 71%, #1d1913 100%);
}
.bg.roof::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(20% 7% at 22% 22%, rgba(255,255,255,.9), transparent 70%),
    radial-gradient(26% 8% at 62% 14%, rgba(255,255,255,.75), transparent 72%),
    radial-gradient(15% 5% at 44% 34%, rgba(255,255,255,.55), transparent 72%);
  filter: blur(2px);
}

/* 花园：绿色，散景光斑 */
.bg.garden {
  background:
    radial-gradient(80% 55% at 72% 4%, rgba(255,250,220,.55), transparent 62%),
    radial-gradient(120% 80% at 10% 104%, rgba(8,32,12,.85), transparent 70%),
    linear-gradient(180deg, #86ad6e 0%, #5c8a4c 34%, #34602f 62%, #16301a 100%);
}
.bg.garden::after {
  content: ""; position: absolute; inset: -4%;
  background:
    radial-gradient(7% 6% at 10% 58%, rgba(255,255,255,.85), transparent 68%),
    radial-gradient(6% 5% at 20% 44%, rgba(255,226,238,.9), transparent 68%),
    radial-gradient(9% 7% at 34% 66%, rgba(255,255,255,.6), transparent 70%),
    radial-gradient(7% 6% at 52% 40%, rgba(255,214,232,.75), transparent 68%),
    radial-gradient(10% 8% at 68% 60%, rgba(255,255,255,.5), transparent 72%),
    radial-gradient(8% 7% at 84% 46%, rgba(255,224,238,.7), transparent 68%),
    radial-gradient(14% 11% at 26% 84%, rgba(10,40,16,.9), transparent 72%),
    radial-gradient(16% 12% at 78% 88%, rgba(8,36,14,.92), transparent 72%);
  filter: blur(9px);
}

/* 夜晚的房间 */
.bg.room {
  background:
    radial-gradient(26% 22% at 76% 26%, rgba(255,213,150,.85), transparent 68%),
    radial-gradient(70% 60% at 76% 30%, rgba(255,186,110,.22), transparent 74%),
    linear-gradient(180deg, #302c46 0%, #221f34 55%, #131120 100%);
}
.bg.room::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,220,170,.06) 0 2px, transparent 2px 26px);
  filter: blur(3px);
}

/* 夜晚的街 */
.bg.street {
  background:
    radial-gradient(16% 12% at 18% 30%, rgba(255,208,132,.95), transparent 70%),
    radial-gradient(46% 38% at 18% 32%, rgba(255,184,96,.3), transparent 74%),
    radial-gradient(12% 9% at 74% 40%, rgba(176,220,255,.75), transparent 70%),
    linear-gradient(180deg, #0a1230 0%, #131e46 46%, #241f4a 100%);
}
.bg.street::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(1.1% 1.6% at 12% 12%, rgba(255,255,255,.95), transparent 70%),
    radial-gradient(.9% 1.3% at 40% 7%, rgba(255,255,255,.85), transparent 70%),
    radial-gradient(1% 1.4% at 62% 15%, rgba(255,255,255,.8), transparent 70%),
    radial-gradient(.8% 1.2% at 86% 9%, rgba(255,255,255,.75), transparent 70%),
    linear-gradient(0deg, rgba(255,180,90,.18), transparent 42%);
  filter: blur(1px);
}

/* 小卖部：暖奶油色 */
.bg.shop {
  background:
    radial-gradient(40% 26% at 50% 10%, rgba(255,252,240,.55), transparent 70%),
    radial-gradient(120% 90% at 50% 108%, rgba(78,40,14,.7), transparent 70%),
    linear-gradient(180deg, #c9a577 0%, #ab8354 46%, #6d4c2e 100%);
}
.bg.shop::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255,246,226,.16) 0 1.6%, transparent 1.6% 11%);
  filter: blur(5px);
}

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 45%, rgba(0,0,0,.55) 100%);
  z-index: 5;
}

/* ---------------- 立绘 ---------------- */
#sprites { position: absolute; inset: 0; z-index: 4; }
.slot {
  position: absolute; bottom: 0; height: 90%; width: 38%;
  display: flex; align-items: flex-end; justify-content: center;
  transition: opacity .35s ease, transform .35s ease, filter .35s ease;
  opacity: 0; transform: translateY(16px);
}
.slot.left   { left: 1.5%; }
.slot.center { left: 31%; }
.slot.right  { right: 1.5%; }
.slot.on { opacity: 1; transform: translateY(0); }
.slot img {
  height: 100%; width: auto; max-width: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 26px rgba(0,0,0,.55));
}
.slot.dim img { filter: brightness(.5) saturate(.65) drop-shadow(0 12px 18px rgba(0,0,0,.5)); }
.slot.talk { transform: scale(1.02); }
.slot.on.talk { transform: translateY(0) scale(1.02); }

/* 说话时的地台光 */
.slot.talk::after {
  content: ""; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 70%; height: 50%;
  background: radial-gradient(50% 50% at 50% 100%, rgba(127,216,255,.22), transparent 70%);
  pointer-events: none;
}

/* ---------------- 对话框 ---------------- */
#textwrap {
  position: absolute; left: 3.5%; right: 3.5%; bottom: 3.4%;
  z-index: 8; opacity: 0; transition: opacity .25s;
}
#textwrap.on { opacity: 1; }

#namebox {
  position: absolute; left: 1.6rem; top: -1.05rem; z-index: 2;
  padding: .22rem 1.15rem .28rem;
  font-size: clamp(14px, 1.55vw, 22px);
  letter-spacing: .1em;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(20,26,40,.98), rgba(10,14,24,.98));
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
  color: var(--name-lin);
  display: none;
}
#namebox.on { display: block; }

#textbox {
  position: relative;
  min-height: 22%;
  padding: 1.55rem 2rem 1.3rem;
  background: var(--panel);
  backdrop-filter: blur(9px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.06);
}
#textbox::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  border-radius: 14px 0 0 14px;
  background: linear-gradient(180deg, var(--accent), transparent);
  opacity: .8;
}
#text {
  font-size: clamp(15px, 1.7vw, 25px);
  line-height: 1.85;
  letter-spacing: .03em;
  text-shadow: 0 2px 10px rgba(0,0,0,.6);
  white-space: pre-wrap;
  min-height: 1.85em;
}
#caret {
  position: absolute; right: 1.2rem; bottom: .8rem;
  color: var(--accent); font-size: 1rem;
  animation: bob 1.1s ease-in-out infinite; opacity: 0;
}
#caret.on { opacity: 1; }
@keyframes bob { 0%,100% { transform: translateY(0); opacity:.5 } 50% { transform: translateY(5px); opacity:1 } }

/* ---------------- 选项 ---------------- */
#choices {
  position: absolute; inset: 0; z-index: 9;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; padding: 0 12%;
  background: rgba(3,6,12,.45);
  backdrop-filter: blur(2px);
}
#choices.on { display: flex; }
.choice {
  width: min(760px, 100%);
  padding: .95rem 1.5rem;
  font-size: clamp(14px, 1.5vw, 21px);
  text-align: center;
  color: #f2f7ff;
  background: linear-gradient(180deg, rgba(28,36,56,.92), rgba(14,19,32,.94));
  border: 1px solid rgba(127,216,255,.35);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s, border-color .2s, background .2s;
}
.choice:hover {
  transform: translateY(-2px) scale(1.015);
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(127,216,255,.25);
}
.choice small { display:block; opacity:.55; font-size:.72em; margin-top:.25rem; letter-spacing:.08em; }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute; right: 1rem; top: .85rem; z-index: 10;
  display: flex; gap: .45rem;
  opacity: 0; transition: opacity .3s;
}
#stage:hover #hud, #hud.on { opacity: 1; }
.hbtn {
  padding: .38rem .85rem;
  font-size: clamp(11px, 1.05vw, 15px);
  color: #dbe8ff;
  background: rgba(10,14,24,.72);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .18s, color .18s, border-color .18s;
}
.hbtn:hover { background: rgba(127,216,255,.18); border-color: var(--accent); color: #fff; }
.hbtn.active { background: rgba(127,216,255,.3); border-color: var(--accent); color: #fff; }

#stats {
  position: absolute; left: 1rem; top: .85rem; z-index: 10;
  display: flex; gap: .8rem; align-items: center;
  padding: .35rem .8rem;
  font-size: clamp(11px, 1.05vw, 15px);
  background: rgba(10,14,24,.6);
  border: 1px solid var(--line); border-radius: 9px;
  backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .3s;
}
#stage:hover #stats, #stats.on { opacity: 1; }
.heart { color: var(--accent2); letter-spacing: .12em; }
.heart.blue { color: var(--accent); }

/* ---------------- 覆盖层（标题/存档/回想/结局） ---------------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(180deg, rgba(4,7,14,.86), rgba(4,7,14,.96));
  backdrop-filter: blur(7px);
  padding: 3vh 5vw;
}
.overlay.on { display: flex; }

#title h1 {
  margin: 0; font-size: clamp(26px, 4.6vw, 64px);
  letter-spacing: .2em; font-weight: 700;
  background: linear-gradient(100deg, #bfe9ff, #ffffff 40%, #ffc2dd 75%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 10px 40px rgba(127,216,255,.25);
  text-align: center;
}
#title .sub {
  margin: .9rem 0 2.4rem; letter-spacing: .34em;
  color: #9fb6d4; font-size: clamp(11px, 1.2vw, 16px);
}
.menu { display: flex; flex-direction: column; gap: .7rem; width: min(340px, 76vw); }
.mbtn {
  padding: .78rem 1rem; text-align: center; letter-spacing: .18em;
  font-size: clamp(13px, 1.3vw, 18px);
  color: #e8f3ff; cursor: pointer;
  background: linear-gradient(180deg, rgba(30,40,62,.85), rgba(14,19,32,.9));
  border: 1px solid var(--line); border-radius: 11px;
  transition: transform .16s, border-color .2s, box-shadow .2s;
}
.mbtn:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 10px 26px rgba(127,216,255,.22); }
.mbtn.ghost { opacity: .72; }
#title .foot { position: absolute; bottom: 2.2vh; font-size: 12px; color: #5c6f8c; letter-spacing: .12em; }

.panelhead {
  width: min(900px, 90vw); display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.1rem;
}
.panelhead h2 { margin: 0; font-size: clamp(16px, 1.9vw, 26px); letter-spacing: .2em; font-weight: 600; }

.slots { width: min(900px, 90vw); display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.slotcard {
  padding: .9rem 1rem; min-height: 92px;
  background: rgba(16,22,36,.85); border: 1px solid var(--line); border-radius: 11px;
  cursor: pointer; transition: border-color .2s, transform .15s;
}
.slotcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.slotcard .k { font-size: .72em; letter-spacing: .16em; color: var(--accent); }
.slotcard .v { margin-top: .35rem; font-size: .92em; color: #cfe0f7; line-height: 1.5; }
.slotcard .t { margin-top: .3rem; font-size: .7em; color: #7d90ad; }

#logbody, .panelbody {
  width: min(900px, 90vw); max-height: 68vh; overflow-y: auto;
  padding: 1.2rem 1.4rem; line-height: 1.9;
  background: rgba(12,17,28,.85); border: 1px solid var(--line); border-radius: 12px;
  font-size: clamp(13px, 1.25vw, 17px);
}
#logbody p, .panelbody p { margin: 0 0 .85rem; }
#logbody b, .panelbody b { color: var(--accent); font-weight: 600; margin-right: .5em; }
#logbody b.su { color: var(--name-su); }
#logbody b.bai { color: var(--name-bai); }

.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; width: min(900px, 90vw); }
.gcard {
  position: relative; padding: 1rem 1.2rem; border-radius: 12px;
  background: linear-gradient(120deg, rgba(127,216,255,.14), rgba(255,194,221,.12));
  border: 1px solid var(--line); overflow: hidden;
}
.gcard.locked { filter: grayscale(1); opacity: .45; }
.gcard h3 { margin: 0 0 .35rem; font-size: clamp(14px, 1.4vw, 19px); letter-spacing: .12em; }
.gcard p { margin: 0; font-size: .82em; color: #b9cbe4; line-height: 1.6; }

#ending .big {
  font-size: clamp(24px, 4vw, 52px); letter-spacing: .24em;
  background: linear-gradient(100deg, #bfe9ff, #fff 45%, #ffc2dd);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#ending .desc { margin: 1.4rem 0 2.4rem; max-width: 620px; text-align: center; line-height: 2; color: #cfe0f7; }

/* 小屏 */
@media (max-width: 720px) {
  #textbox { padding: 1.15rem 1.2rem 1rem; }
  .slots { grid-template-columns: repeat(2, 1fr); }
  .gallery { grid-template-columns: 1fr; }
}

/* ===========================================================
   手机 / 触屏
   =========================================================== */
.only-touch { display: none; }

@media (hover: none) {
  /* 触屏没有 hover，HUD 必须常驻，否则按钮根本点不到 */
  #hud, #stats { opacity: 1; }
  .hbtn { padding: .5rem 1rem; font-size: 13px; }
  .hbtn:hover { background: rgba(10,14,24,.72); border-color: var(--line); color: #dbe8ff; }
  .only-desktop { display: none; }
  .only-touch { display: inline; }
  .choice:hover { transform: none; box-shadow: none; }
  .choice:active { border-color: var(--accent); background: rgba(127,216,255,.16); }
}

/* 竖屏：立绘缩到两列放得下，操作区挤成一行可横滑（否则会换行然后跑到屏幕外） */
@media (orientation: portrait) {
  .slot { height: 64%; width: 62%; }
  .slot.left   { left: -6%; }
  .slot.center { left: 19%; }
  .slot.right  { right: -6%; }

  #hud {
    left: .4rem; right: .4rem; top: .4rem;
    gap: .25rem; flex-wrap: nowrap;
    justify-content: flex-start; max-width: none;
    overflow-x: auto; overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #hud::-webkit-scrollbar { display: none; }
  #hud .hbtn {
    padding: .38rem .55rem; font-size: 11.5px;
    white-space: nowrap; flex: 0 0 auto;
  }
  #stats { left: .4rem; top: 2.7rem; font-size: 11px; padding: .24rem .55rem; }

  #textwrap { left: 2.5%; right: 2.5%; bottom: 2.5%; }
  #textbox { padding: 1.05rem 1.1rem .95rem; min-height: 0; }
  #text { font-size: clamp(15px, 4.3vw, 21px); line-height: 1.78; }
  #namebox { left: 1rem; }

  #choices { padding: 0 6%; gap: .7rem; }
  .choice { font-size: clamp(14px, 4vw, 18px); padding: .8rem 1rem; }

  #logbody, .panelbody { max-height: 60vh; padding: 1rem; }
  .overlay { padding: 4vh 5vw; }

  /* 标题页在窄屏上要收紧，否则字距会把内容顶出屏幕 */
  #title h1 { font-size: clamp(20px, 7.4vw, 52px); letter-spacing: .1em; }
  #title .sub { font-size: clamp(9px, 2.6vw, 14px); letter-spacing: .14em; text-align: center; }
  #title .foot {
    left: 6%; right: 6%; bottom: 2.4vh;
    font-size: 10px; letter-spacing: .04em; line-height: 1.7;
    white-space: normal; text-align: center;
  }
  #title .menu { width: min(340px, 84vw); }
  .mbtn { letter-spacing: .1em; }
  #ending .big { font-size: clamp(22px, 7.6vw, 44px); letter-spacing: .14em; }
}

/* 竖屏提示：不挡操作，6 秒后自己淡掉 */
#rotate-hint { display: none; }
@media (orientation: portrait) and (hover: none) {
  #rotate-hint {
    display: block;
    position: absolute; left: 50%; top: 9%;
    transform: translateX(-50%);
    padding: .45rem 1rem; border-radius: 999px;
    background: rgba(8, 12, 20, .8);
    border: 1px solid var(--line);
    color: #cfe0f7; font-size: 13px; letter-spacing: .08em;
    white-space: nowrap;
    pointer-events: none; z-index: 12;
    animation: hintFade 6s ease forwards;
  }
}
@keyframes hintFade {
  0%, 65% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

.fadeout { animation: fadeOut .6s forwards; }
@keyframes fadeOut { to { opacity: 0 } }
.shake { animation: shake .45s; }
@keyframes shake {
  0%,100% { transform: translate(0,0) }
  20% { transform: translate(-9px, 4px) }
  40% { transform: translate(8px, -4px) }
  60% { transform: translate(-6px, -3px) }
  80% { transform: translate(5px, 3px) }
}
.flash::after {
  content: ""; position: absolute; inset: 0; background: #fff; z-index: 30;
  animation: flashAnim .55s forwards; pointer-events: none;
}
@keyframes flashAnim { from { opacity: .92 } to { opacity: 0 } }
