/* babmdungeon – dark fantasy theme (mirrors mdungeon) */
:root {
  color-scheme: dark;
  --bg: #0a0a0f;
  --panel: #111118;
  --border: #2a2a3a;
  --text: #c8c8d8;
  --accent: #d4a44a;
  --accent2: #6a8ccc;
  --danger: #cc4444;
  --torch: #e8a020;
}

* { box-sizing: border-box; margin: 0; padding: 0;
    -webkit-user-select: none; user-select: none; }

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.5 'Segoe UI', system-ui, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Splash / menu screens ── */
.screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; padding: 24px; text-align: center;
}
.screen h1 {
  font-size: clamp(36px, 8vw, 72px); font-weight: 900;
  letter-spacing: .06em; color: var(--accent);
  text-shadow: 0 0 30px rgba(212,164,74,.35);
  margin-bottom: 8px;
}
.screen h2 {
  font-size: 20px; font-weight: 400; color: #888;
  margin-bottom: 32px;
}
.screen p { max-width: 600px; margin: 0 auto 16px; line-height: 1.7; }

.btn-row { margin-bottom: 12px; }
.btn {
  display: inline-block; padding: 14px 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 18px; font-weight: 700;
  cursor: pointer; transition: all .15s;
  text-decoration: none; margin: 4px;
}
.btn:hover { background: #1a1a28; border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn.primary:hover { background: #e8b860; }

.version { font-size: 12px; color: #555; margin-top: 24px; }

/* ── Game page ── */
#renderCanvas {
  width: 100%; height: 100%;
  outline: none; touch-action: none;
}

.game-wrap {
  position: relative; width: 100vw; height: 100vh; overflow: hidden;
}

/* On desktop / landscape, prevent body scroll */
@media (pointer: fine), (orientation: landscape) {
  html, body { overflow: hidden; }
}

/* HUD overlay */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: rgba(10,10,15,.75);
  border-bottom: 1px solid var(--border);
  z-index: 10; pointer-events: none;
  font-size: 14px;
}
.hud > * { pointer-events: auto; }
.hud .title { font-weight: 900; color: var(--accent); font-size: 18px; letter-spacing: .05em; }
.hud .stats { color: var(--text); }
.hud .compass { color: var(--accent2); font-weight: 700; font-size: 16px; }

/* Message log */
.msg-log {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 8px 16px;
  background: rgba(10,10,15,.75);
  border-top: 1px solid var(--border);
  z-index: 10; pointer-events: none;
  max-height: 140px; overflow-y: auto;
  font-size: 13px; color: var(--accent);
}
.msg-log .msg { margin: 2px 0; }

/* Full-screen map overlay */
.minimap-wrap {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  z-index: 200;
  background: rgba(6,6,12,.92);
  display: none;
  justify-content: center;
  align-items: center;
}
.minimap-wrap canvas {
  display: block;
  max-width: 90vmin;
  max-height: 90vmin;
  image-rendering: pixelated;
}
.map-title {
  position: absolute; top: 18px; left: 50%;
  transform: translateX(-50%);
  color: #d4a44a; font-size: 1.3rem; font-weight: bold;
  text-shadow: 0 0 8px #000;
  pointer-events: none;
}
.map-hint {
  position: absolute; bottom: 18px; left: 50%;
  transform: translateX(-50%);
  color: #888; font-size: 0.85rem;
  pointer-events: none;
}

/* Touch controls are now screen-zone taps on the canvas — no D-pad needed */

/* Combat: monsters rendered in 3D, no overlay */

/* Overlay panels (shop / inventory) */
.overlay-panel {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 90vw); max-height: 80vh;
  background: rgba(12, 12, 20, 0.95);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 20px;
  z-index: 50;
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(212,164,74,.2);
}
.overlay-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: #888;
  font-size: 28px; line-height: 1; cursor: pointer;
  padding: 0 4px; z-index: 1;
}
.overlay-close:hover { color: #fff; }
.overlay-title {
  font-size: 22px; font-weight: 900; color: var(--accent);
  text-align: center; letter-spacing: .04em;
}
.overlay-gold {
  text-align: center; font-size: 14px; color: #aaa;
}
.overlay-items {
  display: flex; flex-direction: column; gap: 6px;
}
.overlay-empty {
  text-align: center; color: #666; font-style: italic; padding: 20px;
}
.overlay-hint {
  text-align: center; font-size: 12px; color: #555; margin-top: 8px;
}
.shop-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px;
  background: rgba(30,30,45,.6);
  border: 1px solid var(--border);
}
.shop-name {
  font-weight: 700; color: var(--text); flex: 0 0 auto; min-width: 120px;
}
.shop-desc {
  flex: 1; font-size: 12px; color: #888;
}
.shop-cost {
  font-weight: 700; color: var(--accent); flex: 0 0 auto;
}
.shop-buy {
  padding: 4px 14px; border-radius: 4px;
  border: 1px solid var(--accent); background: transparent;
  color: var(--accent); font-weight: 700; cursor: pointer;
  font-size: 13px; transition: all .15s; flex: 0 0 auto;
}
.shop-buy:hover:not(:disabled) {
  background: var(--accent); color: #000;
}
.shop-buy:disabled {
  opacity: 0.35; cursor: not-allowed;
}
.overlay-actions {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.combine-hint {
  font-size: 12px; color: #888;
}

/* Grid inventory */
.inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 4px;
}
.inv-cell {
  aspect-ratio: 1;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: default; position: relative;
  font-size: 12px;
  background: rgba(20,20,30,.5);
}
.inv-cell.filled {
  border-color: #5a4a2a;
  background: rgba(30,25,15,.8);
  cursor: pointer;
}
.inv-cell.filled:hover {
  background: rgba(60,50,25,.9);
  border-color: var(--accent);
}
.inv-cell.loaded {
  border-color: #6a9a4a;
  background: rgba(25,40,15,.85);
  box-shadow: 0 0 6px rgba(100,200,60,.35);
}
.inv-cell.loaded::after {
  content: '1';
  position: absolute; top: 2px; left: 4px;
  font-size: 9px; color: #8c8; font-weight: bold;
}
.inv-cell .inv-icon {
  font-size: 26px; line-height: 1;
}
.inv-cell .inv-label {
  font-size: 10px; color: #ccccaa;
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%;
  text-align: center;
}

/* Crosshair — removed */

/* Loot popup */
.loot-popup-host {
  position: fixed;
  inset: 0;
  z-index: 260;
  pointer-events: none;
}
.loot-popup {
  position: fixed;
  top: max(90px, calc(24px + env(safe-area-inset-top)));
  left: 50%;
  min-width: 150px;
  max-width: min(260px, 78vw);
  transform: translateX(-50%);
  background: rgba(14, 14, 24, 0.94);
  border: 1px solid #4e6ea0;
  border-radius: 8px;
  padding: 8px 10px;
  color: #dce7ff;
  font: 12px/1.25 'Segoe UI', system-ui, sans-serif;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  animation: loot-popup-fade 3s ease forwards;
}
.loot-popup-title {
  color: #a8cbff; font-weight: 700; margin-bottom: 4px;
}
.loot-popup-line {
  margin: 1px 0;
}
.loot-popup-item {
  display: flex; align-items: center; gap: 6px;
}
.loot-popup-icon {
  font-size: 18px; line-height: 1;
}
.loot-popup-none {
  color: #888; font-style: italic;
}
@keyframes loot-popup-fade {
  0%  { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  78% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100%{ opacity: 0; transform: translateX(-50%) translateY(-12px); }
}

/* Mobile: canvas uses full viewport now (no D-pad to reserve space for) */

/* ── Mobile portrait layout ──
   Shrink the 3D canvas to a widescreen-ish aspect so side doors are visible,
   then show the message log in a dedicated area below. */
@media (pointer: coarse) and (orientation: portrait) {
  .game-wrap {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: visible;
  }
  .game-wrap > #renderCanvas {
    width: 100% !important;
    height: 55vh !important;
    flex-shrink: 0;
  }
  .msg-log {
    position: relative;
    bottom: auto; left: auto; right: auto;
    flex: 1 1 auto;
    max-height: none;
    overflow-y: auto;
    background: var(--bg);
    border-top: 1px solid var(--border);
    font-size: 13px;
    padding: 8px 16px;
    pointer-events: auto;
  }
  .hud {
    position: relative;
    flex-shrink: 0;
  }

  /* Map overlay: same size as the 3D canvas, not fullscreen */
  .minimap-wrap {
    position: absolute;
    top: 0; left: 0;
    width: 100vw;
    height: 55vh;
    z-index: 200;
  }
  .minimap-wrap canvas {
    max-width: 80vw;
    max-height: 46vh;
  }
  .map-hint { display: none; }

  /* Hint in the msg-log area */
  .msg-log::after {
    content: 'Tap here to toggle map';
    display: block;
    text-align: center;
    color: #444;
    font-size: 11px;
    margin-top: 6px;
  }
}
