/* ============================================================
   不存在的同学 — 全局视觉规范（暗色调悬疑）
   设计令牌 / 基础组件 / 标题画面 / HUD / 弹窗 / Toast
   ============================================================ */

/* ---------- 设计令牌 ---------- */
:root {
  /* 色彩 */
  --bg:        #0d1117;   /* 深夜蓝黑 */
  --bg-deep:   #080b10;
  --panel:     #161b26;
  --panel-2:   #1d2433;
  --line:      #2a3346;
  --ink:       #e8e6e3;   /* 主文字 */
  --ink-dim:   #8b93a7;   /* 次级文字 */
  --accent:    #5eead4;   /* 异常青光：时空异常/焦点 */
  --accent-dim:rgba(94,234,212,.16);
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --gold:      #d4af37;   /* 线索高亮 */
  --gold-dim:  rgba(212,175,55,.18);

  /* 字体 */
  --font-title: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --font-body:  'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono:  'JetBrains Mono', Consolas, monospace;

  /* 字号阶梯 */
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 15px; --fs-lg: 18px;
  --fs-xl: 24px; --fs-2xl: 34px; --fs-3xl: 52px;

  /* 间距 */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  /* 圆角与阴影 */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px;
  --shadow-panel: 0 6px 24px rgba(0,0,0,.55);
  --shadow-modal: 0 16px 64px rgba(0,0,0,.75);
  --shadow-glow:  0 0 18px rgba(94,234,212,.35);
}

/* ---------- 基础重置 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.65;
  overflow: hidden;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
code {
  font-family: var(--font-mono);
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  color: var(--accent);
}

/* 全局噪点纹理 */
#app::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 990;
  opacity: .05;
  background-image: repeating-linear-gradient(0deg, #fff 0 1px, transparent 1px 3px),
                    repeating-linear-gradient(90deg, #fff 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

/* ---------- 屏幕容器 ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  padding: 10px 22px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  letter-spacing: .08em;
  transition: border-color .18s, background .18s, box-shadow .18s, transform .1s;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #202a3d;
  box-shadow: var(--shadow-glow);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #134e4a, #1d3557);
  border-color: var(--accent);
  color: #d9fff7;
}
.btn-ghost { background: transparent; }
.btn-mini { padding: 4px 12px; font-size: var(--fs-sm); }
.btn-danger { border-color: var(--danger); color: #ffb4b4; }

/* ---------- 加载画面 ---------- */
#screen-loading { align-items: center; justify-content: center; background: var(--bg-deep); z-index: 50; }
.loading-box { text-align: center; width: min(420px, 86vw); }
.loading-title { font-family: var(--font-title); font-size: var(--fs-2xl); letter-spacing: .3em; }
.loading-sub { color: var(--ink-dim); margin: var(--sp-3) 0 var(--sp-5); font-size: var(--fs-sm); letter-spacing: .2em; }
.loading-bar {
  height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden;
}
#loading-progress {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  transition: width .3s;
}
.loading-error {
  margin-top: var(--sp-5);
  padding: var(--sp-4);
  border: 1px solid var(--danger);
  border-radius: var(--r-md);
  color: #ffb4b4;
  font-size: var(--fs-sm);
  text-align: left;
  background: rgba(239,68,68,.08);
}

/* ---------- 标题画面 ---------- */
#screen-title {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse 80% 60% at 50% 110%, rgba(94,234,212,.08), transparent 60%),
    radial-gradient(ellipse 60% 40% at 20% -10%, rgba(56,189,248,.06), transparent 60%),
    var(--bg-deep);
  z-index: 40;
}
.title-vignette {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 180px 60px rgba(0,0,0,.85);
}
.title-content { position: relative; text-align: center; animation: fadeUp 1.2s ease both; }
.title-date {
  color: var(--ink-dim); font-size: var(--fs-sm); letter-spacing: .35em; margin-bottom: var(--sp-4);
}
.title-name {
  font-family: var(--font-title);
  font-size: clamp(44px, 8vw, 84px);
  font-weight: 600;
  letter-spacing: .22em;
  text-shadow: 0 0 32px rgba(94,234,212,.25);
  animation: titleFlicker 6s infinite;
}
.title-tag {
  margin-top: var(--sp-3);
  color: var(--accent);
  letter-spacing: .5em;
  font-size: var(--fs-lg);
  opacity: .85;
}
.title-menu {
  margin-top: var(--sp-7);
  display: flex; flex-direction: column; gap: var(--sp-3);
  width: 240px; margin-left: auto; margin-right: auto;
}
.title-tip { margin-top: var(--sp-6); color: var(--ink-dim); font-size: var(--fs-xs); letter-spacing: .1em; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes titleFlicker {
  0%, 91%, 95%, 100% { opacity: 1; }
  92% { opacity: .55; }
  93.5% { opacity: .9; }
  94% { opacity: .5; }
}

/* ---------- HUD ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-2) var(--sp-4);
  background: linear-gradient(180deg, rgba(8,11,16,.85), transparent);
  z-index: 30;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.topbar-left, .topbar-right { display: flex; gap: var(--sp-2); align-items: center; }
.hud-chip {
  padding: 3px 12px;
  background: rgba(13,17,23,.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--fs-sm);
  color: var(--ink-dim);
  letter-spacing: .05em;
}
.hud-chip.hud-world { color: var(--accent); border-color: rgba(94,234,212,.4); }
.hud-chip.hud-world.world-b { color: #c084fc; border-color: rgba(192,132,252,.45); }
.hud-chip.hud-coin { color: var(--gold); border-color: rgba(212,175,55,.45); }

/* ---------- Toast ---------- */
#toast-layer {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 80; pointer-events: none; width: max-content; max-width: 80vw;
}
.toast {
  padding: var(--sp-2) var(--sp-5);
  background: rgba(22,27,38,.94);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-panel);
  animation: toastIn .35s ease both;
}
.toast.toast-gold { border-left-color: var(--gold); }
.toast.toast-warn { border-left-color: var(--warn); }
.toast.toast-out { animation: toastOut .35s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px); } }

/* ---------- 弹窗 ---------- */
#modal-layer {
  position: absolute; inset: 0;
  background: rgba(5,7,10,.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 70;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow: auto;
  padding: var(--sp-5);
  animation: modalIn .25s ease both;
}
.modal.modal-wide { width: min(880px, 94vw); }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--sp-3);
}
.modal-title { font-family: var(--font-title); font-size: var(--fs-lg); letter-spacing: .1em; }
.modal-body { font-size: var(--fs-md); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-5); }

/* ---------- 结局画面 ---------- */
#screen-ending {
  align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(ellipse at 50% 40%, #10151f, var(--bg-deep) 75%);
  z-index: 45;
  padding: var(--sp-6);
}
.ending-inner { max-width: 640px; animation: fadeUp 1.4s ease both; }
.ending-label { color: var(--accent); letter-spacing: .5em; font-size: var(--fs-sm); }
.ending-title {
  font-family: var(--font-title);
  font-size: var(--fs-2xl);
  margin: var(--sp-4) 0 var(--sp-5);
  letter-spacing: .15em;
}
.ending-text { color: var(--ink-dim); line-height: 2; white-space: pre-line; margin-bottom: var(--sp-6); }

/* ---------- 通用动画 ---------- */
.flicker { animation: flickerAnim 3s infinite; }
@keyframes flickerAnim {
  0%, 88%, 100% { opacity: 1; }
  90% { opacity: .4; }
  92% { opacity: .95; }
  95% { opacity: .5; }
}
.fade-in { animation: fadeIn .4s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 存档槽位 ---------- */
.save-slot {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-3);
  background: var(--panel-2);
}
.save-slot .save-info { flex: 1; font-size: var(--fs-sm); color: var(--ink-dim); }
.save-slot .save-info b { color: var(--ink); display: block; font-size: var(--fs-md); }
.save-slot .save-actions { display: flex; gap: var(--sp-2); }

/* ---------- 空状态 ---------- */
.empty-state {
  text-align: center; color: var(--ink-dim);
  padding: var(--sp-6) var(--sp-4);
  font-size: var(--fs-sm);
}
.empty-state .empty-icon { font-size: 32px; opacity: .5; margin-bottom: var(--sp-2); }

/* ============================================================
   窄屏适配（≤640px 手机 / ≤420px 小屏）
   ============================================================ */
@media (max-width: 640px) {
  /* 顶部状态条：压缩 chip、隐藏次要时间 */
  #topbar { padding: var(--sp-1) var(--sp-2); }
  .hud-chip { font-size: 11px; padding: 2px 8px; letter-spacing: 0; }
  .hud-time { display: none; }
  #btn-menu { font-size: var(--fs-sm); padding: 3px 10px; }

  /* 场景导航：可换行、上移避开背包栏 */
  #place-nav {
    bottom: 60px;
    max-width: 94vw;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--sp-1);
  }
  .place-btn { padding: 4px 11px; font-size: 12px; }

  /* 背包栏：槽位缩小 */
  #inventory-bar { padding: 6px; gap: 6px; bottom: 6px; }
  .inv-slot { width: 40px; height: 40px; font-size: 20px; }

  /* 帮助按钮：上移避开背包栏 */
  #help-btn { width: 44px; height: 44px; right: var(--sp-2); bottom: 58px; font-size: 19px; }

  /* 对话层：整体上移、更紧凑 */
  #dialog-layer { bottom: 70px; padding: 0 var(--sp-2); }
  #dialog-box { min-height: 108px; padding: var(--sp-3) var(--sp-4); }
  #dialog-text { font-size: 15px; min-height: 52px; line-height: 1.75; }
  #speaker-name { left: var(--sp-3); top: -13px; padding: 1px 12px; font-size: var(--fs-xs); }
  #narration-box { font-size: 15px; padding: var(--sp-3) var(--sp-4); }
  .choice-btn { font-size: 14px; padding: var(--sp-2) var(--sp-3); }

  /* 立绘缩小、贴近底部 */
  .portrait-slot { bottom: 130px; width: min(220px, 40vw); height: min(340px, 44vh); }
  #portrait-left { left: 2vw; }
  #portrait-right { right: 2vw; }
  .portrait-fallback { width: 120px; height: 120px; font-size: 44px; }

  /* 帮助面板：全宽覆盖 */
  #help-panel { width: 100vw; }
  .help-body { padding: var(--sp-3); }
  .help-search { padding: var(--sp-2) var(--sp-3); }
  .help-search-result { max-height: 110px; padding: var(--sp-2) var(--sp-3); }

  /* 弹窗与谜题：压缩内边距与控件尺寸 */
  .modal { padding: var(--sp-4); }
  .modal-head { margin-bottom: var(--sp-3); }
  .puzzle-desc { margin-bottom: var(--sp-3); }
  .padlock { gap: var(--sp-2); }
  .padlock input { width: 48px; height: 62px; font-size: 26px; }
  .acrostic-row input { width: 36px; height: 36px; font-size: 17px; }
  .acrostic-row .book-title { font-size: 13px; }
  .spot-diff { gap: var(--sp-2); }
  .diff-photo { width: min(340px, 86vw); aspect-ratio: 340 / 220; }
  .maze-grid { grid-template-columns: repeat(3, 52px); }
  .maze-cell { width: 52px; height: 52px; font-size: 18px; }
  .maze-controls { grid-template-columns: repeat(3, 44px); }
  .jigsaw-slot { min-height: 52px; }
  .tuner-row label { width: 72px; font-size: 13px; }
  .tuner-row output { width: 52px; }

  /* 标题与结局 */
  .title-menu { width: min(240px, 72vw); }
  .ending-inner { max-width: 94vw; }
  .ending-title { font-size: 22px; }

  /* 提示信息 */
  .toast { font-size: 12px; padding: var(--sp-2) var(--sp-4); }
  .save-slot { flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
  .save-slot .save-actions { align-self: flex-end; }
}

@media (max-width: 420px) {
  #hud-world { display: none; }   /* 超窄屏只保留章节与提示币 */
  .hud-chip.hud-coin { font-size: 10px; }
  .inv-slot { width: 36px; height: 36px; font-size: 18px; }
  .portrait-slot { width: min(180px, 44vw); height: min(290px, 42vh); }
  .padlock input { width: 42px; height: 56px; font-size: 23px; }
  .diff-photo { width: 92vw; }
  .choice-box { width: 96vw; }
  #dialog-box { min-height: 100px; }
  .acrostic-row { gap: var(--sp-2); }
  .acrostic-row input { width: 32px; height: 32px; }
}
