/* ================================================================
   PULOTIS — GAME.CSS
   Game Layout, Dungeon Canvas, HUD, Mobile Controls
   ================================================================ */

/* ── GAME SCREEN ────────────────────────────────────── */
#screen-game {
  display: none;
  align-items: stretch;
  justify-content: stretch;
  background: var(--obsidian);
  padding: 0;
}
#screen-game.active {
  display: flex;
  flex-direction: column;
}
.game-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* ── TOP BAR ────────────────────────────────────────── */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.2rem;
  background: var(--obsidian-mid);
  border-bottom: 1px solid var(--border);
  min-height: 58px;
  flex-shrink: 0;
  gap: 0.5rem;
}
.player-name-display {
  font-family: var(--font-display);
  font-size: 1.32rem;
  color: var(--amber-bright);
  letter-spacing: 0.05em;
}
.player-class-display {
  font-family: var(--font-mono);
  font-size: 0.97rem;
  color: var(--text-dim);
  margin-left: 0.5rem;
}
.topbar-center { text-align: center; }
.depth-label {
  font-family: var(--font-mono);
  font-size: 0.81rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  display: block;
}
.depth-value {
  font-family: var(--font-display);
  font-size: 1.69rem;
  color: var(--amber);
  font-weight: 600;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 1.0rem;
  color: var(--text-secondary);
  flex-wrap: nowrap;
}

/* ── GAME BODY ──────────────────────────────────────── */
.game-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── STATS PANEL (LEFT) ─────────────────────────────── */
.stats-panel {
  width: 195px;
  flex-shrink: 0;
  background: var(--obsidian-mid);
  border-right: 1px solid var(--border);
  padding: 0.9rem 0.7rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* HP / MP bars */
.stat-block { display: flex; flex-direction: column; gap: 0.45rem; }
.stat-label-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
  letter-spacing: 0.05em;
}
.hp-bar-track, .mp-bar-track {
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blood) 0%, var(--blood-bright) 100%);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 100%;
}
.mp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--mana) 0%, var(--mana-bright) 100%);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 100%;
}

/* Stat list */
.stat-list { display: flex; flex-direction: column; gap: 2px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.22rem 0.35rem;
  border-radius: 3px;
  transition: background 0.15s;
}
.stat-row:hover { background: rgba(255,255,255,0.04); }
.stat-row.gold-row .stat-val { color: #d4af37; }
.stat-name {
  font-family: var(--font-mono);
  font-size: 0.90rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.stat-val {
  font-family: var(--font-display);
  font-size: 1.19rem;
  color: var(--amber-bright);
}

/* Inventory */
.inventory-panel { border-top: 1px solid var(--border); padding-top: 0.6rem; }
.inv-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.inv-item {
  font-family: var(--font-body);
  font-size: 1.06rem;
  color: var(--text-secondary);
  padding: 0.2rem 0;
  line-height: 1.4;
}

/* ── DUNGEON CENTER ─────────────────────────────────── */
.dungeon-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0.6rem;
  gap: 0.7rem;
  background: radial-gradient(ellipse 60% 60% at 50% 50%, rgba(200,146,42,0.04) 0%, transparent 70%);
}

/* Dungeon frame — much larger now */
.dungeon-frame {
  position: relative;
  background: #04040a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 0 60px rgba(0,0,0,0.9),
    inset 0 0 80px rgba(0,0,0,0.9),
    0 0 0 1px rgba(200,146,42,0.10);
  flex-shrink: 0;
}
.dungeon-corner {
  position: absolute;
  width: 16px; height: 16px;
  border-color: var(--amber);
  border-style: solid; z-index: 2;
}
.dungeon-corner.tl { top:-1px; left:-1px; border-width:2px 0 0 2px; }
.dungeon-corner.tr { top:-1px; right:-1px; border-width:2px 2px 0 0; }
.dungeon-corner.bl { bottom:-1px; left:-1px; border-width:0 0 2px 2px; }
.dungeon-corner.br { bottom:-1px; right:-1px; border-width:0 2px 2px 0; }

/* Canvas container — fills as much space as possible */
.dungeon-grid {
  position: relative; z-index: 1;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fill available center space generously */
  /* 13:9 wide viewport — width drives size */
  width:  calc(100% - 4px);
  /* Height = width * 9/13 */
  height: min(calc((100% - 4px) * 9 / 13), calc(100dvh - 240px));
  min-width:  320px;
  min-height: 200px;
}
#dungeon-canvas {
  display: block;
  width:  100% !important;
  height: 100% !important;
  border-radius: 2px;
}

/* ── D-PAD MOBILE CONTROLS ──────────────────────────── */
.dpad-container {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-shrink: 0;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
  align-items: center;
  justify-items: center;
}
.dpad-btn {
  width: 48px; height: 48px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.dpad-btn:active {
  background: var(--amber-glow); border-color: var(--amber);
  color: var(--amber-bright); transform: scale(0.92);
}
#dpad-n { grid-column:2; grid-row:1; }
#dpad-w { grid-column:1; grid-row:2; }
.dpad-center { grid-column:2; grid-row:2; color:var(--text-dim); font-size:0.75rem; }
#dpad-e { grid-column:3; grid-row:2; }
#dpad-s { grid-column:2; grid-row:3; }

.action-btns { display: flex; flex-direction: column; gap: 0.5rem; }
.btn-action {
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn-action:hover, .btn-action:active {
  border-color: var(--amber); color: var(--amber-bright); background: var(--amber-glow);
}

/* ── LOG PANEL (RIGHT) ──────────────────────────────── */
.log-panel {
  width: 230px;
  flex-shrink: 0;
  background: var(--obsidian-mid);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.log-header {
  padding: 0.6rem 0.9rem;
  font-family: var(--font-display);
  font-size: 0.88rem;
  letter-spacing: 0.2em;
  color: var(--amber-dim);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.log-messages {
  flex: 1; overflow-y: auto; padding: 0.6rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.log-msg {
  font-size: 1.04rem;
  color: var(--text-secondary);
  line-height: 1.45;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  animation: msgFade 0.3s ease;
}
@keyframes msgFade { from { opacity:0; transform:translateX(4px); } to { opacity:1; transform:none; } }
.log-msg.danger   { color: #f07070; }
.log-msg.success  { color: #70e080; }
.log-msg.magic    { color: var(--mana-bright); }
.log-msg.treasure { color: #e4bf47; }
.log-msg.system   { color: var(--amber); font-style: italic; }

/* Minimap */
.minimap-container { padding: 0.6rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.minimap-label {
  font-family: var(--font-mono); font-size: 0.58rem;
  letter-spacing: 0.15em; color: var(--text-dim); margin-bottom: 0.35rem;
}
#minimap {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--border); border-radius: 2px;
  image-rendering: pixelated;
}

/* ── GAME MENU PANEL ────────────────────────────────── */
.game-menu-panel {
  background: var(--obsidian-card);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  width: min(460px, 95vw);
  text-align: center;
  box-shadow: var(--shadow-deep), var(--shadow-amber);
}
.game-menu-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  color: var(--amber-bright);
  margin-bottom: 0.3rem;
}
.game-menu-subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 1.8rem;
  letter-spacing: 0.08em;
}
.game-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
}
.btn-quit-save {
  display: block; width: 100%; max-width: 360px;
  margin: 0.5rem auto;
  padding: 1rem 2rem;
  background: linear-gradient(135deg, rgba(74,144,217,0.15), rgba(74,144,217,0.05));
  border: 1px solid #4a90d9;
  color: #88ccff;
  font-family: var(--font-display);
  font-size: 0.88rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s;
}
.btn-quit-save:hover {
  border-color: #88ccff;
  box-shadow: 0 0 20px rgba(74,144,217,0.3);
  transform: translateY(-1px);
}

/* ── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .dungeon-grid {
    width:  calc(100% - 4px);
    height: min(calc((100% - 4px) * 9 / 13), calc(100dvh - 240px));
  }
}
@media (max-width: 900px) {
  .stats-panel { width: 145px; }
  .log-panel   { width: 170px; }
  .dungeon-grid {
    width:  calc(100% - 4px);
    height: min(calc((100% - 4px) * 9 / 13), calc(100dvh - 240px));
  }
}
@media (max-width: 700px) {
  .stats-panel { width: 120px; padding: 0.5rem 0.4rem; }
  .log-panel   { width: 130px; }
  .stat-val    { font-size: 0.82rem; }
  .dungeon-grid {
    width:  calc(100% - 4px);
    height: min(calc((100% - 4px) * 9 / 13), calc(100dvh - 240px));
  }
}
@media (max-width: 520px) {
  .game-body { flex-direction: column; overflow: hidden; }
  .stats-panel {
    width: 100%; height: auto; flex-direction: row;
    border-right: none; border-bottom: 1px solid var(--border);
    flex-wrap: wrap; padding: 0.3rem 0.5rem; gap: 0.3rem; overflow: visible;
  }
  .stat-block { flex-direction: row; gap: 0.5rem; flex: 1; min-width: 140px; }
  .stat-hp-bar, .stat-mp-bar { flex: 1; }
  .stat-list  { flex-direction: row; flex-wrap: wrap; gap: 0; flex: 2; }
  .stat-row   { flex: 0 0 auto; padding: 0.1rem 0.4rem; }
  .inventory-panel { display: none; }
  .log-panel {
    width: 100%; height: 80px;
    border-left: none; border-top: 1px solid var(--border); flex-direction: row;
  }
  .log-header { display: none; }
  .minimap-container { display: none; }
  .dungeon-center { flex: 1; padding: 0.3rem; }
  .dungeon-grid { width: 100%; height: 100%; }
}
@media (max-width: 380px) {
  .dpad-btn { width: 42px; height: 42px; }
  .game-topbar { padding: 0.3rem 0.6rem; min-height: 44px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .game-topbar { min-height: 38px; padding: 0.25rem 0.8rem; }
  .stats-panel { width: 120px; }
  .log-panel   { width: 150px; }
  .dpad-btn    { width: 40px; height: 40px; }
}

/* Ensure dungeon frame never overflows the center */
.dungeon-frame {
  max-width: calc(100% - 1px);
  max-height: calc(100dvh - 240px);
}

/* ── BUFF BAR ────────────────────────────────────────── */
.buff-section, .potion-section {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.2rem;
}
.buff-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 20px;
}
.buff-tag {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  border: 1px solid;
  border-radius: 3px;
  font-size: 0.7rem;
  background: rgba(255,255,255,0.04);
  cursor: default;
}
.buff-name { font-family: var(--font-mono); font-size: 0.62rem; }

/* ── POTION BAG ──────────────────────────────────────── */
.potion-bag { display: flex; flex-direction: column; gap: 2px; }
.potion-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  background: rgba(74,144,217,0.08);
  border: 1px solid rgba(74,144,217,0.3);
  border-radius: 3px;
  color: #88ccff;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}
.potion-btn:hover { background: rgba(74,144,217,0.2); border-color: #4a90d9; }
.potion-btn span { font-family: var(--font-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.potion-empty { font-size: 0.7rem; color: var(--text-dim); font-style: italic; }

/* ── SAVE CODE MODAL ─────────────────────────────────── */
.save-code-panel {
  background: var(--obsidian-card);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 1.8rem;
  width: min(500px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-deep), var(--shadow-amber);
}
.save-code-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
  line-height: 1.5;
}
.save-code-area {
  width: 100%;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.6rem;
  resize: vertical;
  outline: none;
  letter-spacing: 0.02em;
  word-break: break-all;
  margin-bottom: 0.6rem;
}
.save-code-area:focus { border-color: var(--amber); }
