/* 深渊回响 — AI Roguelike */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0f;
  --bg2: #12121a;
  --bg3: #1a1a2e;
  --fg: #c8c8d0;
  --fg-dim: #666680;
  --accent: #ff6b35;
  --hp: #e74c3c;
  --xp: #3498db;
  --gold: #ffd700;
  --green: #2ecc71;
  --purple: #a855f7;
  --combat: #ff4757;
  --item: #f1c40f;
  --flavor: #8e8ea0;
  --boss: #ff6348;
  --dialogue: #70a1ff;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 14px;
  overflow: hidden;
  height: 100vh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* === 主菜单 === */
#menu-screen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.menu-box {
  text-align: center;
  max-width: 500px;
  padding: 20px;
}

.title-art {
  color: var(--accent);
  font-size: 12px;
  line-height: 1.3;
  margin-bottom: 30px;
  text-shadow: 0 0 20px rgba(255, 107, 53, 0.3);
  white-space: pre;
}

.class-select p {
  margin-bottom: 15px;
  color: var(--fg-dim);
}

.classes {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.class-btn {
  background: var(--bg3);
  border: 2px solid #333;
  color: var(--fg);
  padding: 12px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 100px;
}

.class-btn:hover, .class-btn.selected {
  border-color: var(--accent);
  background: var(--bg2);
  box-shadow: 0 0 15px rgba(255, 107, 53, 0.2);
}

.class-icon { font-size: 24px; }
.class-name { font-weight: bold; font-size: 14px; }
.class-desc { font-size: 10px; color: var(--fg-dim); }

.name-input {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.name-input label { color: var(--fg-dim); }

.name-input input {
  background: var(--bg3);
  border: 1px solid #333;
  color: var(--fg);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  width: 160px;
}

.name-input input:focus {
  outline: none;
  border-color: var(--accent);
}

.start-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 40px;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.start-btn:hover {
  background: #ff8555;
  box-shadow: 0 0 20px rgba(255, 107, 53, 0.4);
}

/* === 游戏画面 === */
#game-screen {
  padding: 6px;
}

.game-layout {
  display: flex;
  gap: 8px;
  width: 100%;
  height: 100%;
}

.map-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

.map-header {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  color: var(--fg-dim);
  font-size: 12px;
  margin-bottom: 2px;
}

.game-map {
  background: var(--bg2);
  border: 1px solid #222;
  padding: 4px;
  font-size: 14px;
  line-height: 1.1;
  letter-spacing: 0.5px;
  white-space: pre;
  overflow: hidden;
}

.legend {
  display: flex;
  gap: 10px;
  padding: 4px 8px;
  font-size: 10px;
  color: var(--fg-dim);
  flex-wrap: wrap;
}

.info-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  max-width: 320px;
}

/* 状态栏 */
.stat-box {
  background: var(--bg2);
  border: 1px solid #222;
  padding: 8px 10px;
}

.stat-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-weight: bold;
  font-size: 13px;
}

.stat-header span:last-child { color: var(--gold); }

.stat-bars { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-label {
  width: 22px;
  font-size: 10px;
  color: var(--fg-dim);
}

.bar {
  flex: 1;
  height: 12px;
  background: var(--bg);
  border: 1px solid #333;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.hp-bar { background: linear-gradient(90deg, #c0392b, #e74c3c); }
.xp-bar { background: linear-gradient(90deg, #2980b9, #3498db); }
.enemy-bar { background: linear-gradient(90deg, #c0392b, #e74c3c); }

.bar-value {
  font-size: 10px;
  width: 55px;
  text-align: right;
  color: var(--fg-dim);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  font-size: 11px;
  color: var(--fg-dim);
}

.stats-grid b { color: var(--fg); }

.combat-target {
  border-color: var(--combat) !important;
  background: #1a0a0a !important;
}

/* 操作提示 */
.action-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 10px;
  color: var(--fg-dim);
  padding: 2px 0;
}

.action-hints span {
  background: var(--bg3);
  padding: 2px 6px;
  border-radius: 3px;
}

/* 消息日志 */
.message-log {
  flex: 1;
  background: var(--bg2);
  border: 1px solid #222;
  padding: 6px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.4;
  min-height: 100px;
}

.msg { margin-bottom: 2px; }
.msg-info { color: var(--fg); }
.msg-system { color: var(--green); }
.msg-hint { color: var(--fg-dim); font-style: italic; }
.msg-combat { color: var(--combat); }
.msg-item { color: var(--item); }
.msg-flavor { color: var(--flavor); font-style: italic; }
.msg-boss { color: var(--boss); font-weight: bold; }
.msg-dialogue { color: var(--dialogue); }
.msg-death { color: var(--hp); font-weight: bold; font-size: 14px; }
.msg-epitaph { color: var(--fg-dim); font-style: italic; }
.msg-level_up { color: var(--gold); font-weight: bold; }
.msg-victory { color: var(--gold); font-weight: bold; font-size: 14px; }
.msg-warning { color: #ff9f43; }

/* === 手机触屏控制 === */
.mobile-controls {
  display: none;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
}

/* 检测触屏设备 */
@media (hover: none) and (pointer: coarse) {
  .mobile-controls { display: flex !important; }
  .action-hints { display: none; }
  .game-map { font-size: 11px; letter-spacing: 0; line-height: 1.05; padding: 2px; }
  .legend { display: none; }
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.dpad-mid {
  display: flex;
  gap: 2px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  background: var(--bg3);
  border: 2px solid #444;
  color: var(--fg);
  font-size: 20px;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn:active {
  background: var(--accent);
  border-color: var(--accent);
}

.dpad-center {
  background: var(--bg2);
  font-size: 14px;
}

.action-btns {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.action-btn {
  background: var(--bg3);
  border: 1px solid #444;
  color: var(--fg);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}

.action-btn:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* === 背包覆盖层 === */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.inventory-panel {
  background: var(--bg2);
  border: 2px solid #333;
  padding: 16px;
  width: 90vw;
  max-width: 450px;
  max-height: 80vh;
  overflow-y: auto;
}

.inventory-panel h3 {
  margin-bottom: 10px;
  color: var(--gold);
}

.equipment-row {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #222;
  font-size: 11px;
  color: var(--fg-dim);
}

.equipment-row b { color: var(--fg); }

.inventory-list {
  max-height: 250px;
  overflow-y: auto;
}

.inv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 12px;
}

.inv-item:hover, .inv-item:active { background: var(--bg3); }

.inv-item .item-char {
  width: 18px;
  text-align: center;
  font-weight: bold;
}

.inv-item .item-name { flex: 1; }
.inv-item .item-stats { font-size: 10px; color: var(--fg-dim); }

.btn-small {
  background: var(--bg3);
  border: 1px solid #444;
  color: var(--fg);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-small:hover, .btn-small:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.inv-actions {
  margin-top: 10px;
  text-align: right;
}

/* === 对话面板 === */
.dialogue-panel {
  background: var(--bg2);
  border: 2px solid var(--dialogue);
  padding: 16px;
  width: 90vw;
  max-width: 500px;
}

.npc-header {
  font-size: 15px;
  font-weight: bold;
  color: var(--dialogue);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #222;
}

.dialogue-history {
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 10px;
  line-height: 1.5;
  font-size: 13px;
}

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

.dialogue-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid #333;
  color: var(--fg);
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
}

.dialogue-input-row input:focus {
  outline: none;
  border-color: var(--dialogue);
}

/* === 结局画面 === */
.ending-panel {
  text-align: center;
  max-width: 500px;
  padding: 20px;
}

.ending-panel pre {
  color: var(--gold);
  font-size: 13px;
  margin-bottom: 20px;
  white-space: pre;
}

.ending-panel .ending-text {
  margin-bottom: 20px;
  line-height: 1.8;
}

@keyframes player-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* === 小屏幕适配 === */
@media (max-width: 700px) {
  .game-layout {
    flex-direction: column;
  }
  .map-panel {
    flex: none;
  }
  .info-panel {
    max-width: 100%;
    min-width: 0;
    flex: 1;
  }
  .game-map {
    font-size: 10px;
    letter-spacing: 0;
    line-height: 1.0;
    padding: 2px;
  }
  .stat-box { padding: 6px 8px; }
  .message-log { min-height: 60px; }
  .classes { gap: 6px; }
  .class-btn { min-width: 80px; padding: 8px 10px; }
  .title-art { font-size: 9px; }
}
