@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/press-start-2p.ttf') format('truetype');
  font-display: swap;
}

:root {
  --pixel-font: 'Press Start 2P', 'Courier New', monospace;
  --bg: #1a1410;
  --panel: #261d16;
  --ink: #f2e6d0;
  --muted: #b6a387;
  --accent: #d8a24a;
  --green: #5bbf5b;
  --red: #d44;
  --line: #4a3a2a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #120d09; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-family: var(--pixel-font); font-size: 13px; margin: 0; letter-spacing: .5px; color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.dbg { font-size: 13px; color: var(--muted); }
button {
  background: var(--accent); color: #201608; border: none; padding: 8px 14px;
  border-radius: 6px; font-weight: 600; cursor: pointer;
}
button.secondary { background: #3a2e22; color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }

.layout {
  display: grid; grid-template-columns: minmax(280px, 1fr) 360px;
  gap: 18px; padding: 18px; align-items: start;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.board-wrap { display: flex; justify-content: center; }
.board {
  position: relative; width: 100%; max-width: 520px;
  border: 2px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #000;
}
.board-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  image-rendering: pixelated; user-select: none; pointer-events: none;
}
.board-overlay { position: absolute; inset: 0; }

/* tessere e pezzi: posizionati in % via JS */
.board-overlay > div { position: absolute; }

.tile-reachable { background: rgba(91, 191, 91, .28); outline: 1px solid rgba(91,191,91,.6); cursor: pointer; }
.tile-obstacle { outline: 2px dashed rgba(255,80,80,.4); }

.piece {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--pixel-font);
  font-weight: 400; font-size: clamp(15px, 4.6vw, 30px);
  line-height: 1; text-shadow: 0 2px 0 rgba(0,0,0,.45);
  border-radius: 6px; transition: left .2s, top .2s;
}
.piece.adventurer {
  background: radial-gradient(circle at 35% 30%, #7be07b, #2f9b2f);
  color: #05230a; box-shadow: 0 0 0 2px #0b3d12, 0 2px 6px rgba(0,0,0,.5);
  transform: scale(.84); z-index: 5;
}
.piece.monster {
  background: radial-gradient(circle at 35% 30%, #ff6b6b, #b01e1e);
  color: #2a0606; box-shadow: 0 0 0 2px #4d0d0d, 0 2px 6px rgba(0,0,0,.5);
  transform: scale(.84); cursor: default; z-index: 4;
}
.piece.monster.targetable { cursor: pointer; box-shadow: 0 0 0 3px var(--accent), 0 0 12px var(--accent); }
.piece.monster.moving { z-index: 6; }

/* overlay debug */
.debug-area { outline: 2px solid #39f; }
.debug-cell {
  outline: 1px solid rgba(80,160,255,.5);
  color: #cfe6ff; font-size: 10px; display: flex; align-items: flex-start; justify-content: flex-start;
  padding: 1px 2px; pointer-events: none;
}

/* pannello laterale */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.status-line { font-size: 15px; margin-bottom: 6px; }
.hp { color: var(--red); font-weight: 700; margin-bottom: 6px; }
.monster-info { font-size: 13px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.stat {
  display: flex; justify-content: space-between; background: #1d160f;
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line);
}
.stat-name { color: var(--muted); font-size: 13px; }
.stat span:last-child { font-weight: 800; }

.phase-area { min-height: 80px; margin: 8px 0 14px; }
.phase-area h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }

.dice { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.die {
  width: 44px; height: 44px; border-radius: 8px; background: #efe6d2; color: #201608;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--pixel-font); font-size: 18px; line-height: 1;
  border: 2px solid #b8a275;
}
/* Fase Energia: drag-and-drop */
.energy-ui { margin: 8px 0; }
.zone-label, .slot-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.pool {
  display: flex; gap: 8px; flex-wrap: wrap; min-height: 52px; padding: 6px;
  border: 1px dashed var(--line); border-radius: 8px; background: #1d160f;
}
.die.draggable { cursor: grab; }
.die.draggable:active { cursor: grabbing; }
.die.dragging { opacity: .4; }
.dropzone.over { border-color: var(--accent); background: #2a2012; }
.slot.over .slot-drop { border-color: var(--accent); background: #2a2012; }

.energy-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.slot { text-align: center; }
.slot-drop {
  display: flex; align-items: center; justify-content: center;
  height: 52px; border: 2px solid var(--line); border-radius: 8px; background: #1d160f;
}
.slot-drop.empty { color: var(--muted); font-size: 22px; border-style: dashed; }
.slot.fixed .slot-drop.fixed-val {
  font-family: var(--pixel-font); font-size: 18px; color: var(--accent);
  border-style: solid; background: #241a0f;
}

.hint { font-size: 12px; color: var(--muted); margin: 6px 0; }

.log-wrap h3 { font-size: 14px; color: var(--accent); margin: 6px 0; }
.log { list-style: none; padding: 0; margin: 0; max-height: 220px; overflow-y: auto; font-size: 12.5px; }
.log li { padding: 3px 0; border-bottom: 1px solid #2c2218; color: var(--muted); }

/* modale */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }

/* pannello di calibrazione (debug) */
#calib {
  position: fixed; left: 12px; bottom: 12px; z-index: 60;
  background: #0e0a07; border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; color: var(--ink); box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
#calib[hidden] { display: none; }
.calib-title { color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.calib-row { display: flex; gap: 8px; }
.calib-row label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.calib-row input { width: 56px; padding: 3px 4px; border-radius: 4px; border: 1px solid var(--line); background: #1d160f; color: var(--ink); }
.calib-out { margin-top: 6px; color: var(--muted); font-family: monospace; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; max-width: 460px; width: 90%; }
.modal h2 { margin: 0 0 12px; }
.modal .options { display: grid; gap: 10px; margin-top: 12px; }
.modal .options button { text-align: left; }
