/* ═══════════ 逃离地牢 · Escape the Dungeon ═══════════ */

:root {
  --bg-dark: #131a14;
  --bg-dark2: #1c261d;
  --paper: #f4efe3;
  --paper-dim: #e8e1cf;
  --ink: #24211a;
  --ink-soft: #6b6355;
  --accent: #e8a020;
  --devil-red: #d43a2f;
  --safe-green: #4f8f4f;
  --cell-white: #f7f3ea;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, sans-serif;
  background:
    radial-gradient(ellipse at 50% -20%, #2a3a2b 0%, transparent 60%),
    radial-gradient(ellipse at 80% 110%, #24301f 0%, transparent 55%),
    var(--bg-dark);
  color: var(--paper);
  overflow: hidden;
}

/* 石壁噪点纹理 */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.screen { position: relative; z-index: 1; height: 100vh; display: flex; }
.hidden { display: none !important; }

/* ═══════════ 开场 ═══════════ */
#intro { align-items: center; justify-content: center; }

.intro-card {
  max-width: 620px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 44px 52px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6), 0 0 0 6px rgba(244,239,227,.08);
  text-align: center;
  animation: rise .6s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }

.intro-emojis img { width: 56px; height: 56px; margin: 0 8px; }
.devil-bob { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-8px) rotate(6deg); } }

.intro-card h1 {
  font-size: 44px; letter-spacing: .12em; margin: 14px 0 20px;
  font-weight: 900;
}
.story { text-align: justify; line-height: 1.85; margin-bottom: 12px; color: #3a352a; font-size: 15px; }
.devil-line { color: var(--devil-red); font-weight: 600; }

.btn-big {
  margin-top: 18px;
  font-size: 19px; font-weight: 700;
  padding: 14px 42px;
  border: none; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  transition: transform .12s, box-shadow .12s;
  font-family: inherit;
}
.btn-big:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(0,0,0,.25); }
.btn-big:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn-big:disabled { opacity: .35; cursor: default; transform: none; }

.btn-ghost {
  display: inline-block; margin-top: 14px; margin-left: 10px;
  background: none; border: 2px solid rgba(0,0,0,.2); border-radius: 999px;
  padding: 10px 22px; font-size: 14px; cursor: pointer; color: inherit;
  font-family: inherit;
}
.btn-ghost:hover { border-color: rgba(0,0,0,.5); }
.btn-ghost.small { padding: 6px 12px; font-size: 12px; margin: 0; border-color: rgba(244,239,227,.25); color: var(--paper-dim); }
.btn-ghost.small:hover { border-color: rgba(244,239,227,.6); }

/* ═══════════ 主界面布局 ═══════════ */
#game { gap: 0; }

#sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--paper);
  color: var(--ink);
  display: flex; flex-direction: column;
  padding: 20px 18px 14px;
  gap: 14px;
  box-shadow: 8px 0 40px rgba(0,0,0,.45);
  overflow-y: auto;
}

.side-header { display: flex; align-items: center; justify-content: space-between; }
.side-header h1 { font-size: 24px; font-weight: 900; letter-spacing: .08em; }
.round-badge {
  background: var(--ink); color: var(--paper);
  font-size: 13px; font-weight: 700;
  padding: 5px 12px; border-radius: 999px;
}

/* 角色卡 */
#char-cards { display: flex; flex-direction: column; gap: 8px; }
.char-card {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 2px solid transparent; border-radius: 14px;
  padding: 9px 12px;
  transition: border-color .3s, box-shadow .3s, opacity .3s;
}
.char-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,160,32,.25); }
.char-card.dead { opacity: .45; filter: grayscale(1); }
.char-card.escaped { border-color: var(--safe-green); background: #eef7ee; }
.char-face { width: 36px; height: 36px; }
.char-info { flex: 1; }
.char-name { font-weight: 800; font-size: 15px; }
.char-pos { font-size: 12px; color: var(--ink-soft); }
.char-status { font-size: 18px; min-width: 22px; text-align: center; }
.tag-you, .tag-ai {
  font-size: 10px; font-weight: 700; vertical-align: 2px;
  padding: 2px 7px; border-radius: 999px; margin-left: 4px;
}
.tag-you { background: var(--accent); color: #fff; }
.tag-ai { background: #b7b0a0; color: #fff; }
.devil-card { background: #fdeeec; }
.devil-card .char-name { color: var(--devil-red); }
.devil-card.dormant { opacity: .55; filter: saturate(.4); }
.devil-card.raging { animation: rage .8s ease-in-out infinite; border-color: var(--devil-red); }
@keyframes rage { 0%,100% { box-shadow: 0 0 0 0 rgba(212,58,47,.4); } 50% { box-shadow: 0 0 0 5px rgba(212,58,47,.15); } }

/* 图例 */
.legend { background: #fff; border-radius: 14px; padding: 10px 14px; }
.legend-title { font-size: 12px; font-weight: 800; letter-spacing: .1em; color: var(--ink-soft); margin-bottom: 6px; text-transform: uppercase; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.legend-row img { width: 18px; height: 18px; }

/* 日志 */
#log-panel { flex: 1; min-height: 90px; display: flex; flex-direction: column; background: #fff; border-radius: 14px; padding: 10px 14px; }
#log { flex: 1; overflow-y: auto; font-size: 12.5px; line-height: 1.5; }
.log-entry { padding: 3px 0; border-bottom: 1px dashed #eee; color: #4a4437; animation: logIn .3s ease-out; }
.log-entry.important { color: var(--devil-red); font-weight: 700; }
.log-entry.good { color: var(--safe-green); font-weight: 600; }
@keyframes logIn { from { opacity: 0; transform: translateX(-6px); } }

.side-footer { display: flex; gap: 8px; }

/* ═══════════ 棋盘 ═══════════ */
#board-wrap {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 10px 20px 12px;
  overflow: hidden;
}

#board-scale { position: relative; width: min(96%, calc((100vh - 252px) * 720 / 660)); }
#board-svg { width: 100%; height: auto; display: block; }

.cell-blob { fill: var(--cell-white); stroke: rgba(0,0,0,.18); stroke-width: 1.5; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.cell-blob.start { fill: #b9b3a4; }
.cell-blob.door-blob { fill: var(--accent); }
.cell-num { font-size: 17px; font-weight: 700; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.path-line { stroke: rgba(244,239,227,.5); stroke-width: 2.5; fill: none; }
.floor-label { font-size: 13px; font-weight: 800; fill: rgba(244,239,227,.35); letter-spacing: .15em; }
.escape-label { font-size: 13px; font-weight: 800; fill: var(--accent); }

.box-icon { pointer-events: none; }
.box-pop { animation: boxPop .5s ease-out forwards; }
@keyframes boxPop { 0% { opacity: 1; } 60% { opacity: 1; transform: scale(1.5); } 100% { opacity: 0; transform: scale(.2); } }

.cell-glow { fill: none; stroke: var(--accent); stroke-width: 3; opacity: 0; }
.cell-glow.on { opacity: 1; animation: glowPulse 1s ease-in-out infinite; }
@keyframes glowPulse { 0%,100% { stroke-opacity: .9; } 50% { stroke-opacity: .3; } }

/* 棋子层 */
#token-layer { position: absolute; inset: 0; pointer-events: none; }
.token {
  position: absolute; width: 7.5%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  transition: left .28s cubic-bezier(.4,0,.4,1.3), top .28s cubic-bezier(.4,0,.4,1.3);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.4));
  z-index: 5;
}
.token img { width: 100%; height: 100%; }
.token.hop img { animation: hop .28s ease-out; }
@keyframes hop { 0% { transform: translateY(0); } 50% { transform: translateY(-42%) scale(1.08); } 100% { transform: translateY(0); } }
.token.devil-token { z-index: 6; width: 8.5%; }
.token.devil-token img { animation: devilIdle 1.2s ease-in-out infinite; }
@keyframes devilIdle { 0%,100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.token.gone { opacity: 0; transform: translate(-50%, -50%) scale(.2); transition: all .5s; }
.token.victory img { animation: cheer .5s ease-in-out infinite; }
@keyframes cheer { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-25%); } }

/* ═══════════ 骰子面板 ═══════════ */
#dice-panel {
  margin-top: 8px;
  width: 560px; max-width: 96%;
  background: rgba(20, 26, 20, .88);
  border: 1px solid rgba(244,239,227,.15);
  border-radius: 20px;
  padding: 8px 20px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "banner banner" "canvas roll" "result roll";
  align-items: center;
  column-gap: 16px;
  text-align: center;
  z-index: 20;
}
#turn-banner { grid-area: banner; font-size: 15px; font-weight: 700; letter-spacing: .05em; margin-bottom: 2px; }
#turn-banner.devil-turn { color: #ff8d84; }
#dice-canvas { grid-area: canvas; width: 280px; height: 120px; display: block; margin: 0 auto; }
#dice-result { grid-area: result; font-size: 14px; font-weight: 700; min-height: 20px; color: var(--accent); }
#dice-panel .btn-big { grid-area: roll; margin: 0; padding: 12px 30px; font-size: 17px; background: var(--accent); color: var(--ink); }

/* ═══════════ 弹窗 ═══════════ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 10, .55);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .25s;
}
@keyframes fadeIn { from { opacity: 0; } }

.modal-card {
  background: var(--paper); color: var(--ink);
  border-radius: 22px; padding: 34px 44px;
  max-width: 560px; text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
  animation: popIn .35s cubic-bezier(.3,1.6,.6,1);
}
@keyframes popIn { from { opacity: 0; transform: scale(.7); } }

.event-card img { width: 76px; height: 76px; }
.event-card h2 { font-size: 26px; margin: 12px 0 8px; }
.event-card p { font-size: 16px; color: #4a4437; }
.event-card.devil-event { background: #2a1512; color: #ffd9d5; }
.event-card.devil-event h2 { color: #ff8d84; }
.event-card.devil-event p { color: #e8b5b0; }

.rules-card { text-align: left; max-height: 86vh; overflow-y: auto; }
.rules-card h2 { text-align: center; margin-bottom: 16px; }
.rules-list { list-style: none; }
.rules-list li { padding: 5px 0; font-size: 14.5px; line-height: 1.6; }
.fortune-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 6px; }
.fortune-grid div { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 8px 12px; font-size: 13.5px; }
.fortune-grid img { width: 22px; height: 22px; }
.rules-card .btn-big { display: block; margin: 14px auto 0; }

.end-card img { width: 90px; height: 90px; }
.end-card h2 { font-size: 32px; margin: 14px 0 10px; }
.end-card p { font-size: 16px; color: #4a4437; line-height: 1.7; }

/* 震屏 */
.shake { animation: shake .45s; }
@keyframes shake {
  0%,100% { transform: translate(0); }
  20% { transform: translate(-7px, 3px); }
  40% { transform: translate(6px, -4px); }
  60% { transform: translate(-5px, -3px); }
  80% { transform: translate(4px, 3px); }
}

@media (max-width: 980px) {
  #sidebar { width: 240px; }
  #dice-panel { width: 340px; }
}
