/* 《拾遗塔 · 记忆当铺》 —— 界面样式 · 复古地牢风 */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  /* ---- 锈蚀 5 阶（视觉稿 palette.js ZONE 表：白墙→夜蓝渐进，锈蚀程度递进）---- */
  --rust-0: #EFE7D6;  /* 白墙段（未锈）*/
  --rust-1: #E2D6BC;  /* 柏木段（微锈）*/
  --rust-2: #CBD3C3;  /* 松烟段（侵蚀）*/
  --rust-3: #C6CED5;  /* 霜石段（深蚀）*/
  --rust-4: #B9BFD6;  /* 夜蓝段（极限）*/
  --ground-1: #EFE7D6;
  --ground-2: #E2D6BC;
  --ground-3: #CBD3C3;
  --ground-4: #C6CED5;
  --ground-5: #B9BFD6;

  --bg: #14101c;
  --panel: #201a2b;
  --card: #292138;
  --card2: #2f2742;
  --line: #453a58;
  --line-dark: #332a44;
  --text: #f0e6d2;
  --dim: #a89a8c;
  --accent: #e8b54c;
  --accent-dark: #b4862e;
  --good: #8fc866;
  --bad: #e06a5a;
}

html, body { height: 100%; }
body {
  background:
    radial-gradient(1100px 600px at 50% -8%, #2a2138 0%, transparent 60%),
    radial-gradient(900px 500px at 85% 110%, #241c30 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  display: flex; flex-direction: column;
}

header {
  display: flex; align-items: center; justify-content: center;
  padding: 14px 18px 8px; position: relative; gap: 12px; flex-wrap: wrap;
}
h1 {
  font-size: 26px; letter-spacing: 6px; font-weight: 800;
  background: linear-gradient(180deg, #ffe9ad 0%, var(--accent) 55%, var(--accent-dark) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
}
h1 small { font-size: 12px; letter-spacing: 5px; color: var(--dim); -webkit-text-fill-color: var(--dim); margin-left: 8px; }

#continue-bar { display: none; gap: 10px; align-items: center; flex-wrap: wrap; }

main {
  flex: 1; display: flex; gap: 16px;
  justify-content: center; align-items: flex-start;
  padding: 4px 14px 10px; flex-wrap: wrap;
}

.board-wrap { position: relative; }
#board {
  width: 520px; height: 520px; max-width: 96vw;
  border-radius: 6px;
  border: 3px solid #4c3f5e;
  outline: 1px solid #191322;
  box-shadow:
    0 14px 50px rgba(0,0,0,.6),
    0 0 0 1px rgba(232,181,76,.12),
    inset 0 0 24px rgba(0,0,0,.35);
  display: block; background: #cfc3a8;
  image-rendering: pixelated;
}

/* 方向键（触屏） */
.dpad { display: none; margin-top: 10px; justify-content: center; }
.dpad .dp {
  width: 58px; height: 58px; margin: 4px;
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 18px;
}
.dpad .dp:active { transform: translateY(1px); background: var(--line); }
.dpad .up { grid-area: u; } .dpad .down { grid-area: d; }
.dpad .left { grid-area: l; } .dpad .right { grid-area: r; }
@media (pointer: coarse) {
  .dpad { display: grid; grid-template-areas: ". u ." "l d r"; }
}

/* 侧栏 */
.panel { width: 336px; max-width: 96vw; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: linear-gradient(180deg, var(--card2), var(--card) 40%);
  border: 1px solid var(--line);
  border-top-color: #5c4e70;
  border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.floor-card {
  text-align: center; font-size: 16px; font-weight: 700; color: var(--accent);
  letter-spacing: 2px;
  background: linear-gradient(180deg, #3a2f4a, var(--card));
  border-color: #6a563a;
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat {
  text-align: center; padding: 4px 0 2px; border-radius: 8px;
  background: rgba(0,0,0,.16);
}
.stat .ico { font-size: 14px; display: block; filter: saturate(.9); }
.stat b { font-size: 17px; display: block; font-variant-numeric: tabular-nums; }
.stat small { color: var(--dim); font-size: 11px; letter-spacing: 2px; }

.keys { display: flex; align-items: center; gap: 13px; flex-wrap: wrap; }
.key { text-align: center; }
.key span { font-size: 15px; }
.key b { margin-left: 4px; font-variant-numeric: tabular-nums; }
.key small { color: var(--dim); margin-left: 2px; font-size: 11px; }
.specials { margin-left: auto; display: flex; gap: 6px; }
.sp {
  font-size: 17px; cursor: help;
  background: rgba(0,0,0,.22); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 4px;
}

.btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.btn {
  background: linear-gradient(180deg, #443a58, #38304a);
  color: var(--text); border: 1px solid var(--line); border-bottom: 3px solid #241e32;
  border-radius: 8px; padding: 7px 4px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: filter .12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); }
.btn:active:not(:disabled) { transform: translateY(1px); border-bottom-width: 2px; }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #f4c464, var(--accent-dark));
  color: #241a08; font-weight: 700; border-color: #8a6420; border-bottom-color: #6a4c14;
}
.btn.danger { color: #ff9a8a; }
.kbd {
  margin-left: 3px; font-size: 10px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 3px;
}

.log-card { display: flex; flex-direction: column; }
.log-title {
  color: var(--dim); font-size: 11px; margin-bottom: 6px; letter-spacing: 3px;
  border-bottom: 1px dashed var(--line); padding-bottom: 5px;
}
#log { height: 148px; overflow-y: auto; font-size: 12.5px; line-height: 1.6; }
#log .msg { padding: 1px 0 1px 10px; color: var(--dim); position: relative; }
#log .msg::before {
  content: ''; position: absolute; left: 0; top: 9px;
  width: 4px; height: 4px; background: var(--line); border-radius: 1px;
}
#log .msg.good { color: var(--good); }
#log .msg.good::before { background: var(--good); }
#log .msg.bad { color: var(--bad); }
#log .msg.bad::before { background: var(--bad); }
#log .msg.tip { color: var(--accent); }
#log .msg.tip::before { background: var(--accent); }

footer {
  text-align: center; color: #6a5f78; font-size: 12px;
  padding: 6px 0 12px; letter-spacing: 1px;
}

/* 模态框 */
#modal {
  position: fixed; inset: 0; background: rgba(10, 7, 16, .74);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 50;
  padding: 14px;
}
#modal.show { display: flex; }
.dlg {
  background: linear-gradient(180deg, #332a44, #241d31);
  border: 1px solid #6a563a;
  outline: 1px solid rgba(0,0,0,.6);
  border-radius: 14px;
  max-width: 520px; width: 100%; padding: 18px 20px;
  box-shadow: 0 22px 70px rgba(0,0,0,.65), inset 0 1px 0 rgba(255,235,180,.08);
  max-height: 86vh; overflow-y: auto;
}
.dlg.wide { max-width: 680px; }
.dlg-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  font-size: 17px; color: var(--accent);
  border-bottom: 1px solid var(--line); padding-bottom: 10px;
}
.dlg-face { font-size: 30px; }
.dlg p { margin: 7px 0; font-size: 13.5px; line-height: 1.75; color: var(--text); }
.dlg p b { color: var(--accent); }
.dlg-actions { margin-top: 14px; display: flex; gap: 10px; justify-content: flex-end; }
.dlg-actions .btn { padding: 8px 18px; font-size: 13px; }

.shop-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px; border-bottom: 1px dashed var(--line);
}
.shop-row:last-of-type { border-bottom: none; }
.shop-ico { font-size: 22px; }
.shop-name { flex: 1; font-size: 14px; }
.shop-name small { display: block; color: var(--dim); font-size: 11.5px; }
.shop-gold { margin-left: auto; font-size: 13px; color: var(--dim); }
.shop-gold b { color: var(--accent); }
.tip { color: var(--dim) !important; font-size: 12px !important; }

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th, .tbl td { padding: 5px 6px; text-align: center; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--dim); font-weight: 400; }
.tbl tr:hover td { background: rgba(232,181,76,.05); }
.tbl td.mono { color: var(--dim); }
.good { color: var(--good); }
.warn { color: var(--accent); }
.bad { color: var(--bad); }

.fl-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; margin: 8px 0; }
.fl-btn {
  padding: 7px 0; font-size: 12px; border-radius: 7px;
  background: var(--card2); color: var(--text); border: 1px solid var(--line); cursor: pointer;
}
.fl-btn:hover:not(:disabled) { filter: brightness(1.25); }
.fl-btn.off { opacity: .28; cursor: not-allowed; }

.end { text-align: center; }
.end-face { font-size: 46px; margin: 4px 0; }
.end h2 { color: var(--accent); margin: 6px 0 10px; letter-spacing: 3px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 4px; }
.stats div { background: rgba(0,0,0,.22); border-radius: 10px; padding: 8px 4px; }
.stats small { display: block; color: var(--dim); font-size: 11px; }
.stats b { font-size: 16px; color: var(--accent); }

/* 移动端布局 */
@media (max-width: 900px) {
  header { padding-top: 10px; }
  h1 { font-size: 20px; letter-spacing: 3px; }
  #continue-bar { position: static; margin: 4px auto 0; }
  main { flex-direction: column; align-items: center; }
  #board { width: min(96vw, 470px); height: auto; aspect-ratio: 1; }
  .panel { width: min(96vw, 470px); }
  #log { height: 92px; }
  footer { display: none; }
}

/* 三色钥匙标记：emoji 无法着色（蓝/红都渲染成黄铜色），改用配色圆点 */
.kdot { display: inline-block; width: 13px; height: 13px; border-radius: 50%; flex: none;
        box-shadow: inset 0 -2px 0 rgba(0,0,0,.28), 0 0 0 1px rgba(0,0,0,.18); }
.kdot.k-y { background: radial-gradient(circle at 32% 28%, #f8dc8c, #e8b83c 55%, #a87c1c); }
.kdot.k-u { background: radial-gradient(circle at 32% 28%, #9ac0ff, #4a78d8 55%, #2c4c9c); }
.kdot.k-i { background: radial-gradient(circle at 32% 28%, #ffab9a, #d84a3a 55%, #9c281c); }

/* ---------- 阶段 2 新增：刻度色带 / toast / 无障碍 ---------- */
/* M1 记忆刻度档位色带（<75% 上限警戒、<25% 濒临坍缩） */
#st-hp.hp-warn { color: var(--accent); }
#st-hp.hp-danger { color: var(--bad); animation: hp-pulse 1.1s ease-in-out infinite; }
@keyframes hp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* toast 条：打不过 / 共鸣点不足 / 坍缩 都必须有可见提示，不能只抖一下屏幕 */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 18px);
  max-width: min(86vw, 460px); padding: 10px 16px; border-radius: 12px;
  background: rgba(20,16,28,.94); color: var(--text); font-size: 14px; line-height: 1.45;
  border: 1px solid var(--line); box-shadow: 0 8px 26px rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
  z-index: 90;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: var(--bad); color: #ffd9d2; }
#toast.good { border-color: var(--good); color: #e2ffd9; }
#toast.warn { border-color: var(--accent); color: #ffeec2; }

/* 屏幕阅读器专用（视觉隐藏但可被朗读） */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
