/* layout.css —— 屏幕与区域布局（移动端优先） */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: fadeIn .32s ease both; }

/* ---------- 开始页 ---------- */
.start-wrap {
  position: relative; z-index: 1;
  width: 100%; max-width: 980px;
  margin: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 12px;
  overflow-y: auto;
  padding: 6px 0 10px;
}
.title-block { text-align: center; position: relative; padding-top: 4px; }
.title-seal {
  position: absolute; left: -4px; top: -10px;
  width: 34px; height: 34px; line-height: 34px;
  font-family: var(--serif); font-size: 20px; color: #fff3dc;
  background: var(--crimson); border: 1px solid #d8695c; border-radius: 3px;
  transform: rotate(-8deg); box-shadow: 0 2px 10px rgba(163,36,36,.5);
}
.game-title { font-family: var(--serif); font-size: clamp(28px, 7vw, 46px); letter-spacing: 5px; color: var(--gold-bright); text-shadow: 0 2px 16px rgba(216,180,90,.28); }
.game-title span { color: var(--crimson-bright); font-size: .8em; margin-left: 4px; }
.game-subtitle { font-family: var(--serif); font-size: clamp(11px, 2.7vw, 14px); letter-spacing: 3px; color: var(--ink-dim); margin-top: 4px; }
.title-line { width: 150px; height: 1px; margin: 10px auto 0; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.start-hint { font-family: var(--serif); font-size: 13px; color: var(--ink-dim); letter-spacing: 1px; text-align: center; }
.char-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; width: 100%; }
.char-detail { width: 100%; min-height: 92px; }
.start-actions { display: flex; gap: 12px; align-items: center; }
.footer-note { font-size: 11px; color: var(--ink-faint); letter-spacing: 1px; }

/* ---------- 章节 / 剧情 / 结局 通用卡片 ---------- */
#screen-chapter, #screen-story, #screen-ending { align-items: center; justify-content: center; }
.chapter-card, .story-card, .ending-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 24px 22px;
  text-align: center;
}
.chapter-index { font-family: var(--serif); color: var(--gold); font-size: 13px; letter-spacing: 6px; }
.chapter-title { font-family: var(--serif); font-size: clamp(26px, 6vw, 36px); color: var(--gold-bright); letter-spacing: 5px; margin: 8px 0 4px; }
.chapter-sub { font-family: var(--serif); font-size: 13px; color: var(--crimson-bright); letter-spacing: 3px; }
.chapter-text, .story-text, .ending-text {
  font-family: var(--serif); font-size: 14px; line-height: 2; color: var(--ink);
  text-align: justify; text-indent: 2em; margin: 12px 0;
}
.chapter-nodes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0 18px; }
.chapter-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.story-label { font-family: var(--serif); color: var(--gold); letter-spacing: 7px; font-size: 13px; }
.story-title { font-family: var(--serif); font-size: clamp(22px, 5vw, 30px); color: var(--gold-bright); letter-spacing: 4px; margin: 8px 0; }
.reward-box { margin: 14px 0 20px; min-height: 58px; }
#btn-continue, #btn-enter, #btn-ending-home { min-width: 190px; }

.ending-seal {
  position: absolute; right: 18px; top: 14px;
  width: 40px; height: 40px; line-height: 40px;
  font-family: var(--serif); font-size: 23px; color: #fff3dc;
  background: var(--crimson); border: 1px solid #d8695c; border-radius: 3px;
  transform: rotate(7deg);
}
.ending-title { font-family: var(--serif); font-size: clamp(22px, 5vw, 30px); color: var(--gold-bright); letter-spacing: 4px; margin: 8px 0 6px; }
.ending-stats { font-size: 12px; color: var(--ink-dim); line-height: 1.8; margin-bottom: 16px; }

/* ---------- 失败页 ---------- */
#screen-defeat { align-items: center; justify-content: center; }
.defeat-card { text-align: center; max-width: 420px; width: 100%; padding: 24px 20px; }
.defeat-glyph { font-family: var(--serif); font-size: 70px; color: var(--crimson-bright); text-shadow: 0 0 30px rgba(163,36,36,.6); line-height: 1; }
.defeat-title { font-family: var(--serif); font-size: 26px; letter-spacing: 6px; color: var(--ink); margin: 14px 0 10px; }
.defeat-text { font-family: var(--serif); font-size: 14px; line-height: 2; color: var(--ink-dim); margin-bottom: 22px; }
.defeat-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ---------- 战斗页 ---------- */
#screen-battle { padding: 0; }
.battle-top {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20,24,34,.95), rgba(12,15,22,.85));
}
.battle-stage-title { font-family: var(--serif); font-size: clamp(14px, 3.6vw, 18px); color: var(--gold-bright); letter-spacing: 2px; }
.battle-chapter-sub { font-size: 11px; color: var(--ink-dim); margin-top: 2px; letter-spacing: 1px; }
.battle-top-right { display: flex; align-items: center; gap: 10px; }
.battle-turn { font-family: var(--serif); font-size: 12px; color: var(--gold); letter-spacing: 1px; }

.battle-main { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.stage-scenery { position: absolute; inset: 0; pointer-events: none; overflow: hidden; opacity: .35; }
.stage-scenery i { position: absolute; bottom: 18%; width: 160px; height: 90px; background: linear-gradient(180deg, rgba(120,140,150,.12), transparent); clip-path: polygon(0 100%, 30% 20%, 55% 80%, 78% 30%, 100% 100%); }
.stage-scenery i:nth-child(1) { left: -20px; }
.stage-scenery i:nth-child(2) { right: -10px; transform: scaleX(-1); bottom: 30%; }
.stage-scenery i:nth-child(3) { left: 40%; bottom: 8%; transform: scale(1.4); opacity: .5; }

.enemy-zone { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: flex-start; padding: 12px 10px 6px; min-height: 100px; }
.mid-zone { position: relative; z-index: 1; display: flex; gap: 8px; padding: 4px 10px 8px; flex: 1 1 auto; min-height: 0; }
.player-panel { flex: 0 0 46%; min-width: 0; align-self: flex-start; }
.log-panel { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 3px; background: rgba(12,16,23,.8); padding: 7px 9px; overflow: hidden; }
.log-head { font-family: var(--serif); font-size: 11px; color: var(--gold-dim); letter-spacing: 4px; border-bottom: 1px solid var(--line); padding-bottom: 3px; margin-bottom: 4px; }
.battle-log { flex: 1 1 auto; min-height: 56px; overflow-y: auto; font-size: 11px; line-height: 1.55; color: var(--ink-dim); padding-right: 4px; }

.hand-zone { position: relative; z-index: 1; flex: 0 0 auto; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: linear-gradient(180deg, rgba(9,11,16,.2), rgba(6,8,12,.9)); }
.hand-head { display: flex; align-items: center; gap: 10px; padding: 5px 12px 2px; font-size: 11px; }
.hand-title { font-family: var(--serif); color: var(--gold); letter-spacing: 4px; flex: 1; }
.pile-count { color: var(--ink-faint); font-size: 11px; }
.hand { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 4px 12px 8px; }
.hand-foot { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 12px max(8px, env(safe-area-inset-bottom)); }
.target-hint { font-size: 10px; color: var(--ink-faint); }

/* ---------- 弹层 ---------- */
.overlay { position: absolute; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; background: rgba(3,5,8,.82); padding: 16px; }
.overlay.active { display: flex; }
.help-card { width: 100%; max-width: 520px; max-height: 90%; overflow-y: auto; padding: 22px 22px 18px; }
.help-card h3 { font-family: var(--serif); font-size: 22px; color: var(--gold-bright); letter-spacing: 4px; text-align: center; margin-bottom: 14px; }
.help-body p { font-size: 12.5px; line-height: 1.9; color: var(--ink-dim); margin-bottom: 10px; }
.help-body b { color: var(--gold); font-family: var(--serif); }
.help-card > .btn { display: block; margin: 16px auto 0; }

/* ---------- 大屏适配 ---------- */
@media (min-width: 720px) and (min-height: 560px) {
  .screen { padding: 18px 24px; }
  .start-wrap { gap: 14px; }
  .char-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .enemy-zone { padding: 18px 20px 8px; }
  .mid-zone { padding: 4px 20px 10px; }
  .player-panel { flex-basis: 32%; }
  .battle-log { max-height: 150px; font-size: 12px; }
  .hand { gap: 12px; padding: 12px 20px; }
  .chapter-card, .story-card, .ending-card { padding: 32px 34px 26px; }
}
@media (max-height: 620px) {
  .enemy-zone { padding-top: 6px; min-height: 78px; }
  .battle-log { max-height: 70px; }
  .start-wrap { gap: 7px; }
  .char-detail { min-height: 70px; }
}
@media (max-width: 360px) {
  .char-grid { grid-template-columns: repeat(2, 1fr); }
  .start-actions { flex-direction: column; }
}
