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

:root {
  --bg: #2d2d2d;
  --panel: #3a3a3a;
  --border: #555;
  --text: #e0e0e0;
  --highlight: #4a9;
  --danger: #c44;
  --tile-size: 64px;
  --tile-gap: 2px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', monospace;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Player bar */
.player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
}
.player-badge.active { border-color: var(--highlight); background: rgba(68,170,153,0.15); }
.player-badge img { width: 24px; height: 24px; image-rendering: pixelated; }
.player-badge .hearts { color: #e44; font-size: 11px; }
.player-badge .hearts .lost { opacity: 0.3; }

.turn-indicator {
  margin-left: auto;
  font-weight: bold;
  color: var(--highlight);
  font-size: 14px;
}

/* Board viewport */
.board-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
}

.dungeon-board {
  display: inline-grid;
  gap: var(--tile-gap);
  padding: 200px;
  min-width: 100%;
  min-height: 100%;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  position: relative;
  border: 1px solid #444;
  image-rendering: pixelated;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
}

.tile.empty { background: transparent; border-color: transparent; cursor: default; }
.tile.revealed { background: #555; }
.tile.corridor { background: #666; }
.tile.room { background: #7a6a5a; }
.tile.healing_fountain { background: #4a8a7a; }
.tile.nether_portal { background: #6a4a8a; }
.tile.dead_end { background: #555; }
.tile.t_junction { background: #666; }
.tile.crossroads { background: #777; }
.tile.explorable { border: 2px dashed var(--highlight); background: rgba(68,170,153,0.1); cursor: pointer; }
.tile.valid-move { border: 2px solid var(--highlight); cursor: pointer; }
.tile.valid-move:hover { background: rgba(68,170,153,0.3); }

.tile-connections {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tile-connections .conn {
  position: absolute;
  background: #888;
}
.tile-connections .conn.north { top: 0; left: 25%; right: 25%; height: 25%; }
.tile-connections .conn.south { bottom: 0; left: 25%; right: 25%; height: 25%; }
.tile-connections .conn.east { right: 0; top: 25%; bottom: 25%; width: 25%; }
.tile-connections .conn.west { left: 0; top: 25%; bottom: 25%; width: 25%; }

.tile-center {
  position: absolute;
  top: 25%; left: 25%; right: 25%; bottom: 25%;
  background: #888;
}

.tile-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  z-index: 2;
}

.player-token {
  position: absolute;
  width: 24px;
  height: 24px;
  z-index: 10;
  image-rendering: pixelated;
  border-radius: 2px;
  border: 1px solid #fff;
  transition: all 0.2s;
}
.player-token:nth-child(1) { top: 2px; left: 2px; }
.player-token:nth-child(2) { top: 2px; right: 2px; }
.player-token:nth-child(3) { bottom: 2px; left: 2px; }
.player-token:nth-child(4) { bottom: 2px; right: 2px; }
.player-token:nth-child(5) { top: 50%; left: 50%; transform: translate(-50%,-50%); }

.tile-label {
  font-size: 8px;
  color: #ccc;
  position: absolute;
  bottom: 1px;
  left: 2px;
  z-index: 3;
  pointer-events: none;
}

.unresolved-marker {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: #fa0;
  border-radius: 50%;
  z-index: 5;
}

/* Action bar */
.action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 2px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.action-bar button {
  padding: 6px 14px;
  background: #555;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.action-bar button:hover { background: #666; }
.action-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
.action-bar button.primary { background: var(--highlight); color: #000; font-weight: bold; }

.action-info {
  margin-left: auto;
  font-size: 13px;
  color: #aaa;
}

.quick-inv {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #bbb;
}
.quick-inv span { display: flex; align-items: center; gap: 3px; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }

.overlay-panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 24px 32px;
  max-width: 500px;
  width: 90%;
  text-align: center;
}
.overlay-panel h2 { margin-bottom: 16px; font-size: 20px; }
.overlay-panel p { margin-bottom: 12px; font-size: 14px; }
.overlay-panel button {
  padding: 8px 20px;
  background: var(--highlight);
  color: #000;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  margin: 4px;
}
.overlay-panel button:hover { opacity: 0.9; }
.overlay-panel button.secondary { background: #666; color: var(--text); }

/* Setup screen */
.setup-screen {
  padding: 20px;
  max-width: 600px;
  width: 90%;
}
.setup-screen h1 { font-size: 28px; margin-bottom: 20px; color: var(--highlight); }
.setup-screen label { display: block; margin: 8px 0 4px; font-size: 13px; }
.setup-screen input, .setup-screen select {
  width: 100%;
  padding: 6px 10px;
  background: #444;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 4px;
}
.player-setup { margin: 12px 0; padding: 10px; background: #333; border-radius: 4px; }

/* Combat overlay */
.combat-panel { max-width: 450px; }
.combat-panel .vs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 16px 0;
  font-size: 24px;
}
.combat-panel .vs img { width: 48px; height: 48px; image-rendering: pixelated; }
.monster-strength {
  font-size: 18px;
  margin: 8px 0 16px;
  color: #f88;
}
.roll-btn {
  font-size: 22px;
  padding: 14px 32px;
  background: var(--highlight);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s;
}
.roll-btn:hover { transform: scale(1.05); }
.roll-btn:active { transform: scale(0.95); }
.combat-result { font-size: 18px; margin: 12px 0; font-weight: bold; }
.combat-result.win { color: #4c4; }
.combat-result.lose { color: #c44; }
.combat-result.tie { color: #cc4; }

/* Inventory overlay */
.inventory-panel {
  text-align: left;
  max-width: 400px;
}
.inventory-panel h3 { margin: 10px 0 6px; color: var(--highlight); font-size: 14px; }
.inventory-panel ul { list-style: none; padding: 0; }
.inventory-panel li { padding: 3px 0; font-size: 13px; }
.inventory-panel .empty { color: #777; font-style: italic; }

/* Turn transition */
.turn-transition h2 { font-size: 24px; margin-bottom: 8px; }
.turn-transition .char-icon { width: 64px; height: 64px; image-rendering: pixelated; margin: 16px 0; }

/* Scoreboard */
.scoreboard { text-align: left; }
.scoreboard table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.scoreboard th, .scoreboard td { padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.scoreboard th { color: var(--highlight); }
.scoreboard tr:first-child td { font-weight: bold; }

/* Responsive */
@media (max-width: 600px) {
  :root { --tile-size: 48px; }
  .player-badge { font-size: 11px; padding: 3px 6px; }
  .player-token { width: 18px; height: 18px; }
}
