/* =========================================================================
   风之谷 · 界面样式（dist/style.css）
   -------------------------------------------------------------------------
   设计目标（docs/VISUAL_SPEC.md）：
     · 温暖绘本、风景为主角；菜单只在需要时出现。
     · 大字号、高可读：电脑关键目标 ≥14px、手机 ≥12px；触控命中区 ≥48px。
     · 手机横屏 HUD 不遮关键落点；触屏按钮避开底部系统区域（env(safe-area-inset)）。
     · 不使用草稿里的 8–12px 小字号与“无脚本占位”观感。
   结构：画布 #world 在最底层；HUD/目标/触屏在上；面板覆盖层最高。
   调色取 VISUAL_SPEC 固定色板，禁止另起霓虹高饱和界面色。
   ========================================================================= */

:root {
  --ink: #384B48;
  --ink-soft: #5d6b62;
  --action: #455C4C;
  --ivory: #F9F7ED;
  --grass: #8C9A78;
  --mist: #B9AAC3;
  --fox: #C9753F;
  --gold: #DCC58B;
  --line: rgba(56, 75, 72, 0.18);
  --panel: rgba(249, 247, 237, 0.94);
  --shadow: 0 24px 60px rgba(44, 54, 50, 0.28);

  --font-serif: "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --font-sans: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;

  --pad-top: calc(14px + env(safe-area-inset-top, 0px));
  --pad-side: calc(18px + env(safe-area-inset-left, 0px));
  --pad-right: calc(18px + env(safe-area-inset-right, 0px));
  --pad-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #efe7dc;
  /* 画布未就绪时也有暖色天光，绝不白屏 */
  background-image: linear-gradient(180deg, #f3d9e0 0%, #f7e3d2 45%, #e9d7c6 100%);
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-synthesis: none;
}

#world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible { outline: 3px solid #9a7f4f; outline-offset: 4px; }
button:disabled { opacity: 0.55; cursor: wait; }

/* ------------------------------ HUD ------------------------------ */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: var(--pad-top) var(--pad-right) 0 var(--pad-side);
  pointer-events: none;
  text-shadow: 0 1px 10px rgba(255, 252, 244, 0.7);
}
.hud > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-serif);
  color: var(--ink);
}
.wind-mark {
  font-family: Georgia, serif;
  font-size: 42px;
  line-height: 1;
  color: #6f7f6c;
  transform: rotate(-12deg);
}
.brand-text {
  font-size: 24px;
  letter-spacing: 6px;
  line-height: 1.05;
}
.brand-text small {
  display: block;
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--ink-soft);
  margin-top: 4px;
}

.chapter {
  text-align: center;
  margin-top: 4px;
  flex: 1 1 auto;
}
.chapter > span {
  display: block;
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 5px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.chapter strong {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 21px;
  letter-spacing: 6px;
}

.tools {
  display: flex;
  align-items: center;
  gap: 10px;
}
.counter {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: Georgia, serif;
  margin-right: 6px;
}
.counter .shard { font-size: 26px; color: #ac9357; align-self: center; }
.counter strong { font-size: 27px; font-weight: 400; letter-spacing: 1px; }
.counter .total { font-size: 14px; color: var(--ink-soft); }

.pill {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(251, 249, 238, 0.72);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
  backdrop-filter: blur(4px);
  white-space: nowrap;
}
.pill:hover { background: rgba(251, 249, 238, 0.92); }
.pill.off { color: #8a6b52; }

/* --------------------------- 目标 / 提示 --------------------------- */
.objective-wrap {
  position: absolute;
  left: var(--pad-side);
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 3;
  max-width: min(46vw, 460px);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px 12px 14px;
  border-radius: 14px;
  background: rgba(249, 247, 237, 0.82);
  border: 1px solid var(--line);
  box-shadow: 0 10px 26px rgba(44, 54, 50, 0.14);
  backdrop-filter: blur(5px);
}
.obj-label {
  flex: none;
  font-size: 12px;
  letter-spacing: 2px;
  color: #7a6a4f;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(220, 197, 139, 0.35);
  margin-top: 2px;
}
.objective-wrap p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0.5px;
}

.interaction {
  position: absolute;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(56, 75, 72, 0.86);
  color: var(--ivory);
  font-size: 16px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}
.interaction kbd, .keys kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(249, 247, 237, 0.18);
  border: 1px solid rgba(249, 247, 237, 0.4);
  font-family: Georgia, serif;
}

.toast {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(86vw, 620px);
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(249, 247, 237, 0.95);
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(44, 54, 50, 0.18);
  font-size: 16px;
  text-align: center;
  animation: toast-in 0.22s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.storage-warning {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top, 0px));
  right: var(--pad-right);
  z-index: 30;
  max-width: min(60vw, 360px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(120, 84, 58, 0.92);
  color: var(--ivory);
  font-size: 14px;
  line-height: 1.45;
}

/* ----------------------------- 标题屏 ----------------------------- */
.intro {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  padding: var(--pad-top) var(--pad-right) var(--pad-bottom) var(--pad-side);
}
.intro::before {
  /* 左侧暖白渐变让文字可读，右侧保留场景可见（风景才是主角）。 */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(249, 247, 237, 0.94) 0%,
    rgba(249, 247, 237, 0.78) 32%,
    rgba(249, 247, 237, 0.18) 60%,
    rgba(249, 247, 237, 0) 78%);
  pointer-events: none;
}
.intro-inner {
  position: relative;
  z-index: 1;
  max-width: min(560px, 62vw);
}
.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 14px;
  letter-spacing: 2px;
  color: #7a6a4f;
}
.eyebrow .rule { display: inline-block; width: 26px; height: 1px; background: #b4a077; }
.intro h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(56px, 9vw, 118px);
  letter-spacing: 12px;
  line-height: 1.02;
  color: var(--ink);
}
.subtitle {
  margin: 8px 0 20px;
  font-family: Georgia, serif;
  font-size: 13px;
  letter-spacing: 5px;
  color: #7d8a7d;
}
.lede {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: clamp(20px, 2.2vw, 28px);
  letter-spacing: 2px;
}
.desc {
  margin: 0 0 26px;
  font-size: 17px;
  line-height: 1.85;
  color: var(--ink-soft);
}
.note {
  margin: 18px 0 0;
  font-size: 14px;
  color: #86907f;
  letter-spacing: 0.5px;
}
.load-message {
  min-height: 20px;
  margin: 14px 0 0;
  font-size: 15px;
  color: #9a5b3a;
}
.edition {
  position: absolute;
  left: var(--pad-side);
  bottom: var(--pad-bottom);
  z-index: 1;
  font-size: 12px;
  letter-spacing: 3px;
  color: #8a8266;
}

/* ----------------------------- 按钮 ----------------------------- */
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 30px;
  border-radius: 999px;
  background: var(--action);
  color: var(--ivory);
  font-size: 18px;
  letter-spacing: 2px;
  box-shadow: 0 12px 26px rgba(69, 92, 76, 0.28);
}
.primary:hover { background: #3c5143; }
.primary:disabled { background: #6f7f72; }

.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 20px;
  border-radius: 999px;
  background: rgba(249, 247, 237, 0.6);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
}
.ghost:hover { background: rgba(249, 247, 237, 0.9); }
.ghost.small { min-height: 42px; font-size: 14px; padding: 0 14px; }
.ghost.current { border-color: #b4975e; color: #7a5c2c; }
.ghost.danger { color: #9a4b32; }
.danger-solid {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  background: #9a4b32;
  color: #fff;
  font-size: 16px;
}

/* --------------------------- 覆盖面板 --------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(56, 75, 72, 0.34);
  backdrop-filter: blur(3px);
}
.panel {
  width: min(560px, 92vw);
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 30px 34px 26px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow);
  text-align: center;
}
.panel h2 {
  margin: 4px 0 10px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(26px, 3.4vw, 36px);
  letter-spacing: 3px;
}
.panel p { font-size: 16px; line-height: 1.8; color: var(--ink-soft); }
.panel .soft { color: #77857b; font-size: 15px; }
.panel .primary { margin-top: 8px; min-width: 200px; }
.panel .ghost { margin-top: 8px; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0 6px; }
.badge {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px dashed var(--line);
  color: #8d8878;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.badge.on { border-style: solid; border-color: #b4975e; color: #7a5c2c; background: rgba(220, 197, 139, 0.22); }

.confirm {
  margin-top: 12px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(154, 75, 50, 0.08);
  border: 1px solid rgba(154, 75, 50, 0.25);
}
.confirm p { margin: 0 0 12px; color: #8a432b; font-size: 15px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.revisit { margin: 12px 0 4px; }
.revisit-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }

.keys { list-style: none; padding: 0; margin: 8px 0 16px; text-align: left; }
.keys li {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.keys b { font-weight: 600; color: var(--ink); }
.keys span { color: var(--ink-soft); text-align: right; }

.help { text-align: left; }
.help h2 { text-align: center; }
.help .primary { display: flex; margin: 10px auto 0; }

.ending { text-align: center; }
.ending-count {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  margin: 16px 0 6px; font-family: Georgia, serif;
}
.ending-count strong { font-size: 46px; font-weight: 400; color: #8a6b39; }
.ending-count span { font-size: 15px; color: var(--ink-soft); }

/* --------------------------- 触屏控制 --------------------------- */
.touch {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.touch .pad {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}
.pad-left { align-items: flex-end; }
.pad-right { align-items: flex-end; }

.tbtn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(249, 247, 237, 0.72);
  border: 1px solid rgba(56, 75, 72, 0.28);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  backdrop-filter: blur(4px);
  box-shadow: 0 8px 20px rgba(44, 54, 50, 0.18);
}
.tbtn span { font-size: 11px; letter-spacing: 1px; color: var(--ink-soft); }
.tbtn:active, .tbtn.is-down { background: rgba(220, 197, 139, 0.85); transform: translateY(1px); }
.tbtn.jump { background: rgba(69, 92, 76, 0.86); color: var(--ivory); width: 76px; height: 76px; }
.tbtn.jump span { color: rgba(249, 247, 237, 0.8); }

/* ----------------------------- 竖屏提示 ----------------------------- */
.portrait {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  background: rgba(243, 217, 224, 0.97);
  color: var(--ink);
}
.portrait .rotate { font-size: 54px; color: #8a7f5c; display: block; margin-bottom: 14px; }
.portrait h2 { font-family: var(--font-serif); font-weight: 400; font-size: 26px; letter-spacing: 3px; margin: 0 0 8px; }
.portrait p { font-size: 16px; color: var(--ink-soft); }

/* ------------------------------ 无脚本 ------------------------------ */
.nojs {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  background: #f3ece1;
  color: var(--ink);
}
.nojs h2 { font-family: var(--font-serif); font-weight: 400; font-size: 30px; letter-spacing: 3px; }
.nojs p { max-width: 560px; font-size: 17px; line-height: 1.9; color: var(--ink-soft); }

/* ============================ 响应式 ============================ */

/* 手机横屏（高度受限）：压缩纵向留白，但字号与命中区保持可读/可点。 */
@media (max-height: 560px) {
  .hud { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .wind-mark { font-size: 30px; }
  .brand-text { font-size: 18px; letter-spacing: 4px; }
  .brand-text small { font-size: 8px; }
  .chapter > span { font-size: 11px; margin-bottom: 2px; }
  .chapter strong { font-size: 16px; letter-spacing: 4px; }
  .counter strong { font-size: 20px; }
  .counter .shard { font-size: 20px; }
  .counter .total { font-size: 12px; }
  .pill { min-height: 40px; padding: 0 12px; font-size: 14px; }

  .intro h1 { font-size: clamp(44px, 8vw, 72px); letter-spacing: 8px; }
  .subtitle { margin-bottom: 12px; font-size: 11px; }
  .lede { font-size: 19px; }
  .desc { font-size: 14px; line-height: 1.7; margin-bottom: 16px; }
  .note { display: none; }
  .primary { min-height: 48px; font-size: 16px; }
  .edition { font-size: 10px; }

  .objective-wrap {
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    max-width: 44vw;
    padding: 8px 12px;
  }
  .objective-wrap p { font-size: 13px; }
  .obj-label { font-size: 11px; }

  .panel { padding: 20px 24px 18px; max-height: 92vh; }
  .panel h2 { font-size: 24px; }
  .panel p { font-size: 14px; }
  .tbtn { width: 62px; height: 62px; font-size: 20px; }
  .tbtn.jump { width: 70px; height: 70px; }
}

/* 触屏设备：目标条上移，避免与底部按钮重叠。 */
@media (pointer: coarse) {
  /* 手机横屏底边被方向/跳跃键占据：目标条改到左上，避开角色与可走落点，单行省略。 */
  .objective-wrap {
    left: var(--pad-side);
    right: auto;
    top: calc(50px + env(safe-area-inset-top, 0px));
    bottom: auto;
    max-width: 38vw;
    padding: 6px 10px;
    gap: 8px;
  }
  .objective-wrap p {
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .obj-label { font-size: 10px; letter-spacing: 1px; padding: 2px 6px; }
  /* 横屏底部 96px 处正好是女孩身体；提示移至画面上半部，避开角色和触控落点。 */
  .interaction { top: 40%; bottom: auto; font-size: 14px; padding: 8px 12px; }
  .toast { top: calc(96px + env(safe-area-inset-top, 0px)); font-size: 14px; padding: 10px 16px; }
}

/* 窄屏（竖屏手机）：提示横屏。仅在小屏竖屏时覆盖，平板竖屏不强拦。 */
@media (orientation: portrait) and (max-width: 900px) {
  .portrait { display: flex; }
}

/* 安全复位后的温和淡入：只遮场景，不截获输入，不闪白。 */
body.recovering::after {
  content: ''; position: fixed; inset: 0; z-index: 8; pointer-events: none;
  background: #eee6d2; opacity: 0; animation: recover-scene 320ms ease-out;
}
@keyframes recover-scene { from { opacity: 0.42; } to { opacity: 0; } }

/* 减少动态偏好：去掉过渡与入场动画，保留必要可读性。 */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 数据态兜底：即使脚本异常，标题态也不显示 HUD/触屏。 */
body[data-screen="title"] .hud,
body[data-screen="title"] .objective-wrap { display: none; }
body[data-screen="ending"] .hud { display: none; }
