/* 暗之地牢 - Dark Dungeon v2 精致版 */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --bg-dark: #0d0d1a;
  --bg-panel: rgba(15,15,30,0.95);
  --border-color: #2a2a4a;
  --border-glow: #4a4a8a;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --accent-red: #ff3355;
  --accent-blue: #3366ff;
  --accent-gold: #ffcc00;
  --accent-green: #33cc66;
  --accent-purple: #aa33ff;
  --hp-color: #ff3355;
  --mp-color: #3366ff;
  --pixel-font: 'Press Start 2P', monospace;
  --body-font: 'VT323', monospace;
}

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

body {
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--body-font);
  font-size: 18px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  image-rendering: pixelated;
}

/* CRT 扫描线效果 */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.15) 0px,
    rgba(0,0,0,0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 9999;
}

/* 暗角效果 */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.6) 100%);
  pointer-events: none;
  z-index: 9998;
}

.screen {
  display: none;
  width: 100vw; height: 100vh;
  position: absolute; top: 0; left: 0;
}
.screen.active { display: flex; flex-direction: column; }

/* ===== 开始画面 ===== */
#start-screen {
  justify-content: center; align-items: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(100,0,50,0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(0,50,100,0.3) 0%, transparent 50%),
    linear-gradient(180deg, #0a0a1a 0%, #150a20 50%, #0a0a1a 100%);
}

.title {
  font-family: var(--pixel-font);
  font-size: 2em;
  color: var(--accent-red);
  text-shadow:
    0 0 10px rgba(255,50,80,0.8),
    0 0 30px rgba(255,50,80,0.4),
    0 0 60px rgba(255,50,80,0.2),
    2px 2px 0 #000, -2px -2px 0 #000;
  animation: titlePulse 3s ease-in-out infinite;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

@keyframes titlePulse {
  0%,100% { text-shadow: 0 0 10px rgba(255,50,80,0.8), 0 0 30px rgba(255,50,80,0.4), 0 0 60px rgba(255,50,80,0.2), 2px 2px 0 #000; }
  50% { text-shadow: 0 0 20px rgba(255,50,80,1), 0 0 50px rgba(255,50,80,0.6), 0 0 80px rgba(255,50,80,0.3), 2px 2px 0 #000; }
}

.subtitle {
  font-family: var(--body-font);
  color: var(--text-secondary);
  font-size: 1.4em;
  margin-bottom: 2em;
  letter-spacing: 8px;
  text-transform: uppercase;
}

.start-info {
  background: rgba(20,20,40,0.6);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 20px 30px;
  margin-bottom: 20px;
  max-width: 350px;
}

.start-info p {
  margin: 8px 0;
  font-size: 1.1em;
  color: var(--text-primary);
  font-family: var(--body-font);
}

.high-score {
  font-family: var(--pixel-font);
  font-size: 0.7em;
  color: var(--accent-gold);
  margin: 15px 0;
  text-shadow: 0 0 10px rgba(255,200,0,0.5);
}

/* 像素风按钮 */
.btn {
  font-family: var(--pixel-font);
  font-size: 0.7em;
  padding: 15px 35px;
  border: 3px solid;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px; right: -3px; bottom: -3px;
  border: 1px solid currentColor;
  opacity: 0.3;
}

.btn.primary {
  background: linear-gradient(180deg, #ff4466 0%, #cc2244 100%);
  color: #fff;
  border-color: #ff6688;
  box-shadow: 0 0 15px rgba(255,50,80,0.4), 4px 4px 0 rgba(0,0,0,0.5);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #ff5577 0%, #dd3355 100%);
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(255,50,80,0.6), 4px 6px 0 rgba(0,0,0,0.5);
}

.btn.primary:active {
  transform: translateY(1px);
  box-shadow: 0 0 10px rgba(255,50,80,0.3), 2px 2px 0 rgba(0,0,0,0.5);
}

.btn.small {
  font-family: var(--body-font);
  font-size: 0.9em;
  padding: 6px 16px;
  background: rgba(40,40,70,0.8);
  color: var(--text-primary);
  border-color: var(--border-color);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.btn.small:hover {
  background: rgba(60,60,100,0.8);
  border-color: var(--border-glow);
}

/* ===== 状态栏 ===== */
#status-bar {
  background: linear-gradient(180deg, rgba(15,15,35,0.98) 0%, rgba(10,10,25,0.95) 100%);
  padding: 6px 12px;
  display: flex; flex-wrap: wrap; gap: 12px;
  font-family: var(--body-font);
  font-size: 1em;
  border-bottom: 2px solid var(--border-color);
  align-items: center;
  backdrop-filter: blur(5px);
}

.stat {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  background: rgba(255,255,255,0.03);
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.05);
}

.bar {
  width: 70px; height: 14px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  display: inline-block;
  position: relative;
}

.bar > span, .bar > div {
  height: 100%; display: block;
  transition: width 0.4s ease;
  position: relative;
}

.bar > span::after, .bar > div::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 100%);
}

#hp-fill { background: linear-gradient(90deg, #cc2233, #ff4455); }
#mp-fill { background: linear-gradient(90deg, #2244cc, #4466ff); }

/* ===== 游戏区域 ===== */
#game-area {
  flex: 1; display: flex; position: relative; min-height: 0;
}

#game-canvas {
  background: #050510;
  flex: 1; display: block;
}

/* 小地图 */
#minimap {
  width: 100px;
  background: rgba(5,5,15,0.9);
  border-left: 2px solid var(--border-color);
  padding: 5px;
  display: flex; flex-wrap: wrap; align-content: flex-start;
}

#minimap .cell {
  display: inline-block; width: 5px; height: 5px; margin: 0;
  border-radius: 1px;
}
#minimap .cell.wall { background: #0a0a15; }
#minimap .cell.seen { background: #2a2a3a; }
#minimap .cell.visited { background: #1a1a2a; }
#minimap .cell.player { background: #00ff88; box-shadow: 0 0 3px #00ff88; }
#minimap .cell.enemy { background: #ff3355; box-shadow: 0 0 3px #ff3355; }
#minimap .cell.stairs { background: #ffcc00; box-shadow: 0 0 3px #ffcc00; }
#minimap .cell.shop { background: #00ccff; box-shadow: 0 0 3px #00ccff; }
#minimap .cell.chest { background: #ff66cc; box-shadow: 0 0 3px #ff66cc; }

/* ===== 日志 ===== */
#log {
  background: linear-gradient(180deg, rgba(10,10,25,0.95) 0%, rgba(5,5,15,0.98) 100%);
  padding: 8px 12px;
  max-height: 80px;
  overflow-y: auto;
  font-family: var(--body-font);
  font-size: 0.9em;
  border-top: 2px solid var(--border-color);
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#log::-webkit-scrollbar { width: 4px; }
#log::-webkit-scrollbar-track { background: transparent; }
#log::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

#log p {
  margin: 3px 0;
  line-height: 1.3;
  animation: logFade 0.3s ease;
}

@keyframes logFade {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

#log .combat { color: var(--accent-red); }
#log .heal { color: var(--accent-green); }
#log .info { color: var(--accent-blue); }
#log .gold { color: var(--accent-gold); }
#log .level { color: var(--accent-purple); }

/* ===== 行动按钮 ===== */
#action-buttons {
  display: none;
  background: linear-gradient(180deg, rgba(15,15,30,0.95) 0%, rgba(10,10,20,0.98) 100%);
  padding: 12px;
  flex-direction: column;
  justify-content: center; align-items: center;
  gap: 6px;
  border-top: 2px solid var(--border-color);
}

.dir-row { display: flex; gap: 6px; }

.dir-btn, .action-btn {
  width: 52px; height: 52px;
  font-size: 1.4em;
  background: linear-gradient(180deg, #2a2a4a 0%, #1a1a3a 100%);
  border: 2px solid #3a3a5a;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  touch-action: manipulation;
  font-family: var(--pixel-font);
  transition: all 0.1s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.dir-btn:active, .action-btn:active {
  transform: scale(0.95);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}

.action-btn {
  width: 62px;
  background: linear-gradient(180deg, #ff4466 0%, #cc2244 100%);
  border-color: #ff6688;
  color: #fff;
}

/* ===== 背包面板 ===== */
#inventory-panel {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-panel);
  border: 2px solid var(--border-glow);
  border-radius: 4px;
  padding: 20px;
  z-index: 100;
  min-width: 300px;
  max-width: 90vw;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 0 30px rgba(0,0,0,0.5), 0 0 60px rgba(70,70,140,0.2);
}

#inventory-panel.show { display: block; }

#inventory-panel::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px; right: -1px; bottom: -1px;
  border: 1px solid rgba(100,100,180,0.3);
  border-radius: 4px;
  pointer-events: none;
}

#inventory-panel h3 {
  font-family: var(--pixel-font);
  font-size: 0.7em;
  color: var(--accent-gold);
  margin-bottom: 15px;
  text-align: center;
  text-shadow: 0 0 10px rgba(255,200,0,0.3);
  letter-spacing: 2px;
}

#inventory-list { margin: 10px 0; }

.inv-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  margin: 6px 0;
  background: rgba(30,30,50,0.6);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-family: var(--body-font);
  font-size: 1em;
  transition: all 0.2s;
}

.inv-item:hover {
  background: rgba(40,40,70,0.6);
  border-color: var(--border-glow);
}

.inv-item .rarity-common { color: #ccccdd; }
.inv-item .rarity-rare { color: #4488ff; text-shadow: 0 0 5px rgba(68,136,255,0.3); }
.inv-item .rarity-epic { color: #aa44ff; text-shadow: 0 0 5px rgba(170,68,255,0.3); }
.inv-item .rarity-legend { color: #ffaa00; text-shadow: 0 0 5px rgba(255,170,0,0.3); }

/* ===== 战斗画面 ===== */
#combat-screen {
  justify-content: center; align-items: center;
  background:
    radial-gradient(ellipse at center, rgba(40,0,0,0.3) 0%, transparent 70%),
    linear-gradient(180deg, #0a0508 0%, #150a0a 50%, #0a0508 100%);
}

#combat-screen.shake {
  animation: screenShake 0.3s ease;
}

@keyframes screenShake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-3px,2px); }
  40% { transform: translate(3px,-2px); }
  60% { transform: translate(-2px,-1px); }
  80% { transform: translate(2px,1px); }
}

#combat-info { text-align: center; margin-bottom: 20px; }

.enemy-emoji {
  font-size: 4em;
  margin: 10px 0;
  animation: enemyFloat 3s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255,50,80,0.4));
}

@keyframes enemyFloat {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.enemy-name {
  font-family: var(--pixel-font);
  font-size: 0.6em;
  color: var(--accent-red);
  letter-spacing: 1px;
}

.enemy-hp { margin-top: 12px; }

.player-hp-combat {
  margin-top: 20px;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--body-font);
  font-size: 1.1em;
}

#combat-log {
  background: rgba(15,15,30,0.9);
  padding: 12px;
  width: 320px;
  max-width: 90vw;
  max-height: 120px;
  overflow-y: auto;
  font-family: var(--body-font);
  font-size: 0.95em;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

#combat-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; margin-top: 20px;
}

.combat-btn {
  font-family: var(--pixel-font);
  font-size: 0.55em;
  padding: 12px 18px;
  background: linear-gradient(180deg, #2a2a4a 0%, #1a1a3a 100%);
  color: var(--text-primary);
  border: 2px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.combat-btn:hover {
  background: linear-gradient(180deg, #3a3a5a 0%, #2a2a4a 100%);
  border-color: var(--border-glow);
  transform: translateY(-1px);
}

.combat-btn:active {
  transform: translateY(1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}

.combat-btn:disabled {
  opacity: 0.4; cursor: not-allowed;
  transform: none !important;
}

/* ===== 商店画面 ===== */
#shop-screen {
  justify-content: center; align-items: center;
  background:
    radial-gradient(ellipse at center, rgba(0,40,0,0.2) 0%, transparent 70%),
    linear-gradient(180deg, #0a0f0a 0%, #0a150a 50%, #0a0f0a 100%);
}

#shop-screen h2 {
  font-family: var(--pixel-font);
  font-size: 0.8em;
  color: var(--accent-gold);
  margin-bottom: 20px;
  text-shadow: 0 0 10px rgba(255,200,0,0.3);
  letter-spacing: 2px;
}

#shop-items {
  max-height: 50vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}

.shop-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 15px;
  background: rgba(25,25,45,0.7);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  width: 340px;
  max-width: 90vw;
  font-family: var(--body-font);
  font-size: 1em;
  transition: all 0.2s;
}

.shop-item:hover {
  background: rgba(35,35,55,0.7);
  border-color: var(--border-glow);
}

.shop-item button {
  font-family: var(--body-font);
  padding: 6px 18px;
  background: linear-gradient(180deg, #ffdd44 0%, #ffcc00 100%);
  color: #000;
  border: 1px solid #ffee66;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: bold;
  transition: all 0.15s;
}

.shop-item button:hover {
  background: linear-gradient(180deg, #ffee66 0%, #ffdd44 100%);
  transform: translateY(-1px);
}

.shop-item button:disabled {
  background: #555; color: #888;
  border-color: #666; cursor: not-allowed;
  transform: none !important;
}

#shop-screen p {
  margin-top: 15px;
  font-family: var(--body-font);
  font-size: 1.2em;
  color: var(--accent-gold);
}

/* ===== 结束画面 ===== */
#end-screen {
  justify-content: center; align-items: center;
  background:
    radial-gradient(ellipse at center, rgba(20,20,40,0.5) 0%, transparent 70%),
    linear-gradient(180deg, #0a0a1a 0%, #150a20 50%, #0a0a1a 100%);
}

#end-screen h1 {
  font-family: var(--pixel-font);
  font-size: 1.5em;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

#end-stats {
  margin: 20px 0;
  font-family: var(--body-font);
  font-size: 1.1em;
  line-height: 2;
  text-align: center;
}

#end-stats p { margin: 5px 0; }

/* ===== 伤害数字弹出 ===== */
.damage-popup {
  position: absolute;
  font-family: var(--pixel-font);
  font-size: 0.8em;
  pointer-events: none;
  animation: damageFloat 1s ease-out forwards;
  z-index: 200;
  text-shadow: 1px 1px 0 #000;
}

.damage-popup.player-damage { color: var(--accent-red); }
.damage-popup.enemy-damage { color: #ffcc00; }
.damage-popup.heal { color: var(--accent-green); }
.damage-popup.levelup { color: var(--accent-purple); font-size: 1em; }

@keyframes damageFloat {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  50% { opacity: 1; transform: translateY(-30px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.8); }
}

/* ===== 手机适配 ===== */
@media (max-width: 600px) {
  .title { font-size: 1.3em; }
  .subtitle { font-size: 0.9em; letter-spacing: 4px; }
  .start-info { padding: 15px 20px; max-width: 280px; }
  .start-info p { font-size: 0.95em; }
  .high-score { font-size: 0.6em; }
  .btn { font-size: 0.6em; padding: 12px 25px; }
  #action-buttons { display: flex; }
  #minimap { display: none; }
  #status-bar {
    font-size: 0.8em; padding: 5px 8px; gap: 8px;
  }
  .stat { padding: 1px 5px; }
  .bar { width: 50px; height: 10px; }
  .enemy-emoji { font-size: 2.5em; }
  .combat-btn { padding: 10px 14px; font-size: 0.5em; }
  #combat-log { width: 280px; font-size: 0.85em; }
  .shop-item { width: 280px; padding: 10px; font-size: 0.9em; }
  #inventory-panel { min-width: 260px; padding: 15px; }
  .inv-item { padding: 8px 10px; }
  .dir-btn, .action-btn { width: 46px; height: 46px; font-size: 1.2em; }
}

@media (max-width: 380px) {
  .title { font-size: 1.1em; }
  #status-bar { font-size: 0.7em; }
  .bar { width: 40px; }
  .dir-btn, .action-btn { width: 42px; height: 42px; font-size: 1em; }
}
