/* ============ 全局 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark: #14141c;
  --bg-panel: #1e1e2a;
  --bg-panel-2: #262633;
  --border: #3a3a4a;
  --text-main: #e8e8f0;
  --text-dim: #8a8a9a;
  --accent: #c9a227;
  --accent-2: #8b5cf6;
  --hp-color: #e74c3c;
  --xp-color: #2ecc71;
  --cell-size: 20px;

  /* 主题默认色（石之回廊） */
  --t-wall: #5a5a6e;
  --t-wall-bg: #23232f;
  --t-wall-bg-vis: #2e2e3d;
  --t-wall-expl: #1a1a25;
  --t-floor: #56566a;
  --t-floor-vis: #7d7d92;
  --t-expl-bg: #101018;
  --t-vis-bg: #1a1a24;
  --t-vault: #c9a227;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: radial-gradient(ellipse at top, #1c1c2a 0%, var(--bg-dark) 70%);
  color: var(--text-main);
}

#game-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px;
  gap: 10px;
}

/* ============ 顶部栏 ============ */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, var(--bg-panel), #232331);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
}

.title-block h1 {
  font-size: 22px;
  letter-spacing: 6px;
  background: linear-gradient(90deg, var(--accent), #f5d76e, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(201, 162, 39, 0.25);
}

.subtitle { font-size: 10px; letter-spacing: 4px; color: var(--text-dim); }

.hud-block { display: flex; gap: 18px; }
.hud-item { text-align: center; }
.hud-item .label { display: block; font-size: 11px; color: var(--text-dim); }
.hud-item .value { font-size: 20px; font-weight: 700; color: var(--accent); }
.hud-item .value.score { color: #7ee787; }

/* ============ 主区域 ============ */
#main-area { flex: 1; display: flex; gap: 10px; min-height: 0; }

/* ============ 游戏网格 ============ */
#game-board-wrap {
  flex: 1;
  position: relative;
  background: #0c0c12;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

#board-stage { position: relative; display: inline-block; line-height: 0; }

#game-board {
  display: block;
  image-rendering: pixelated;
  border-radius: 6px;
  background: #0a0a10;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 10px 40px rgba(0,0,0,0.5);
}

/* 待机呼吸动画类（角色绘制在 Canvas 内，这里保留给特效层使用） */
@keyframes player-pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }
@keyframes stairs-glow { 0%,100% { text-shadow: 0 0 6px #f5d76e; } 50% { text-shadow: 0 0 16px #f5d76e; } }

/* ============ 楼层主题 ============ */
[data-theme="theme-stone"]  { --t-wall: #5a5a6e; --t-wall-bg: #23232f; --t-wall-bg-vis: #2e2e3d; --t-wall-expl: #4a4a58; --t-floor: #56566a; --t-floor-vis: #7d7d92; }
[data-theme="theme-cavern"] { --t-wall: #3e6a66; --t-wall-bg: #142522; --t-wall-bg-vis: #1c3330; --t-wall-expl: #334f4c; --t-floor: #3a5c58; --t-floor-vis: #5f948e; }
[data-theme="theme-inferno"]{ --t-wall: #8a4436; --t-wall-bg: #2a1612; --t-wall-bg-vis: #3a2018; --t-wall-expl: #6d3a2e; --t-floor: #7a4034; --t-floor-vis: #c4705f; }
[data-theme="theme-necro"]  { --t-wall: #6a4a8a; --t-wall-bg: #1e1428; --t-wall-bg-vis: #2b1d38; --t-wall-expl: #513a6d; --t-floor: #5c4478; --t-floor-vis: #9c7cc4; }
[data-theme="theme-lair"]   { --t-wall: #8a7236; --t-wall-bg: #26200f; --t-wall-bg-vis: #352c15; --t-wall-expl: #6d5c2e; --t-floor: #7a6434; --t-floor-vis: #c4a85f; }

/* ============ 特效层 ============ */
#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}

.fx {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 13px;
  font-family: Consolas, monospace;
  animation: fx-up 0.8s ease-out forwards;
  pointer-events: none;
  white-space: nowrap;
}

.fx-damage { color: #ff6b6b; }
.fx-good { color: #2ecc71; }
.fx-poison { color: #7df9b0; }
.fx-boss { color: #f5d76e; font-size: 16px; letter-spacing: 2px; }
.fx-fire { color: #ff9f1c; font-size: 14px; }

@keyframes fx-up {
  0% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -140%); }
}

.fx-fireball {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff8c0, #ff9f1c 40%, #ff5722);
  box-shadow: 0 0 12px 3px rgba(255, 140, 30, 0.8);
  transform: translate(-50%, -50%);
  transition: transform 0.45s linear;
  animation: none;
}

/* 屏幕震动 */
#board-stage.shake { animation: board-shake 0.3s; }
@keyframes board-shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-4px,2px); }
  40% { transform: translate(4px,-2px); }
  60% { transform: translate(-2px,2px); }
  80% { transform: translate(2px,-2px); }
}

/* ============ 遮罩 ============ */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 14, 0.86);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#overlay.hidden { display: none; }

#overlay-card {
  background: linear-gradient(160deg, var(--bg-panel), #181824);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 44px;
  max-width: 500px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

#overlay-title {
  font-size: 30px;
  letter-spacing: 8px;
  background: linear-gradient(90deg, var(--accent), #f5d76e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 14px;
}

#overlay-desc { color: var(--text-dim); font-size: 13px; line-height: 1.8; margin-bottom: 16px; }
#overlay-stats { color: var(--text-dim); font-size: 13px; line-height: 2.1; margin-bottom: 20px; }
#overlay-stats .highlight { color: var(--accent); font-weight: 700; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #b8860b);
  border: none;
  color: #1a1a10;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 4px;
  padding: 12px 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(201,162,39,0.4); }

/* ============ 侧边栏 ============ */
#sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  flex-shrink: 0;
}

.panel-title {
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.dim { color: var(--text-dim); font-weight: 400; font-size: 12px; }
.hint-text { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }

/* 玩家面板 */
.stat-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.stat-name { color: var(--text-dim); }
.stat-val { font-weight: 700; color: var(--text-main); }
.stat-val.small { font-size: 12px; }

.bar-wrap { margin-bottom: 8px; }
.bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 3px; }
.bar { height: 10px; background: #12121a; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 6px; transition: width 0.3s ease; }
.bar-fill.hp { background: linear-gradient(90deg, #c0392b, var(--hp-color)); }
.bar-fill.xp { background: linear-gradient(90deg, #1e8449, var(--xp-color)); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.stat-cell { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; gap: 6px; }
.stat-cell.wide { grid-column: span 2; }

/* 小地图 */
#minimap-panel { flex-shrink: 0; }
.minimap-wrap { display: flex; align-items: center; gap: 12px; }
#minimap {
  width: 150px;
  height: 84px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #0a0a10;
  image-rendering: pixelated;
}
.minimap-legend { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--text-dim); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.dot-player { background: #4ade80; }
.dot-stairs { background: #f5d76e; }
.dot-monster { background: #ff9f1c; }

/* 背包 */
#inventory-list { list-style: none; max-height: 130px; overflow-y: auto; }
#inventory-list li {
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 5px;
  margin-bottom: 3px;
  background: var(--bg-panel-2);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
#inventory-list li:hover { background: #33334a; border-color: var(--accent); }
#inventory-list li .bonus { color: var(--accent); font-weight: 700; }

/* 日志 */
#log-panel { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
#log-list { flex: 1; overflow-y: auto; font-size: 12px; line-height: 1.8; scrollbar-width: thin; }
#log-list .log-line { color: var(--text-dim); }
#log-list .log-line.damage { color: #ff6b6b; }
#log-list .log-line.good { color: #2ecc71; }
#log-list .log-line.item { color: #f5d76e; }
#log-list .log-line.sys { color: #9b8cff; }

/* 操作 */
.controls-text { font-size: 12px; color: var(--text-dim); line-height: 2; margin-bottom: 10px; }
kbd { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: Consolas, monospace; }

.legend-icon {
  font-family: Consolas, monospace;
  font-weight: 700;
  margin: 0 4px 0 10px;
}
.legend-potion { color: #ff6b6b; }
.legend-scroll { color: #c792ea; }
.legend-weapon { color: #e8d27a; }
.legend-armor { color: #6ec6ff; }
.legend-trap { color: #ff9f1c; }
.legend-stairs { color: #f5d76e; }

.dpad { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 38px); gap: 6px; justify-content: center; }
.dpad-btn {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
}
.dpad-btn:hover { background: #33334a; }
.dpad-btn:active { transform: scale(0.92); background: #3d3d55; }
.dpad-btn.center { color: var(--accent); }

/* ============ 滚动条 ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  #main-area { flex-direction: column; }
  #sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; overflow-y: visible; }
  .panel { flex: 1; min-width: 160px; }
  #log-panel { min-height: 140px; }
  .dpad { display: none; }
}
