* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: #0d0d1a;
  color: #c8c8d4;
  font-family: "Courier New", "Lucida Console", monospace;
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}

/* ── HUD ── */

#hud {
  display: flex;
  justify-content: center;
  gap: 20px;
  width: 100%;
  padding: 6px 0;
  border-bottom: 2px solid #2a2a40;
  flex-shrink: 0;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.2rem;
  font-weight: bold;
  position: relative;
  transition: filter 0.35s ease-out;
}

.stat-icon {
  font-size: 1.3rem;
}

#hp { color: #e05555; }
#atk { color: #e0c050; }
#def { color: #5599dd; }
#level { color: #bb88dd; }

/* ── BOARD ── */

#board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: 100%;
  flex-shrink: 0;
}

.tile {
  aspect-ratio: 1;
  border: 2px solid #2a2a40;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.75rem;
  cursor: default;
  position: relative;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  background: #14142a;
}

.tile .icon {
  font-size: 1.5rem;
  line-height: 1;
}

.tile .label {
  font-size: 0.65rem;
  color: #999;
  font-weight: bold;
}

/* ── Tile types ── */

.tile[data-type="enemy"] {
  background: #2a1520;
  border-color: #5a2030;
}

.tile[data-type="weapon"] {
  background: #1a1a28;
  border-color: #8a7a30;
}

.tile[data-type="shield"] {
  background: #141a28;
  border-color: #3060a0;
}

.tile[data-type="potion"] {
  background: #1a2018;
  border-color: #308040;
}

.tile[data-type="exit"] {
  background: #202010;
  border-color: #aa9030;
}

.tile[data-type="start"] {
  background: #1a1a2a;
}

/* ── Player tile ── */

.tile.player {
  border-color: #ffffff;
  box-shadow: 0 0 12px 2px rgba(255, 255, 255, 0.25);
  background: #1e1e3a;
}

/* ── Visited tile ── */

.tile.visited {
  opacity: 0.3;
  pointer-events: none;
}

/* ── Cleared tile (defeated enemy) ── */

.tile.cleared {
  opacity: 0.3;
}

/* ── Combat target (live enemy) ── */

.tile.combat {
  cursor: pointer;
}

.tile.combat:hover {
  transform: scale(1.06);
  border-color: #cc4444;
  box-shadow: 0 0 8px 1px rgba(204, 68, 68, 0.3);
}

.tile.combat:active {
  transform: scale(0.97);
}

/* ── Hit animation ── */

@keyframes hit-flash {
  0%   { filter: brightness(1); transform: translateX(0); }
  20%  { filter: brightness(2.5); transform: translateX(-4px); }
  40%  { filter: brightness(1.8); transform: translateX(4px); }
  60%  { filter: brightness(1.3); transform: translateX(-2px); }
  80%  { filter: brightness(1.1); transform: translateX(1px); }
  100% { filter: brightness(1); transform: translateX(0); }
}

.tile.anim-hit {
  animation: hit-flash 0.3s ease-out;
}

/* ── Available move ── */

.tile.available {
  cursor: pointer;
  border-color: #555570;
}

.tile.available:hover {
  transform: scale(1.06);
  border-color: #aaaacc;
  box-shadow: 0 0 8px 1px rgba(170, 170, 204, 0.2);
}

.tile.available:active {
  transform: scale(0.97);
}

/* ── Combat log ── */

#log-container {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid #2a2a40;
  border-radius: 4px;
  background: #0a0a18;
  padding: 6px;
  font-size: 0.75rem;
  line-height: 1.4;
}

#log-container::-webkit-scrollbar {
  width: 6px;
}

#log-container::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

#log {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}

.log-entry {
  padding: 1px 0;
  border-bottom: 1px solid #1a1a30;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-combat { color: #e05555; }
.log-item { color: #e0c050; }
.log-heal { color: #55cc77; }
.log-info { color: #8888aa; }
.log-win { color: #ffdd44; }
.log-lose { color: #ff4444; }

/* ── Restart button ── */

#restart {
  padding: 6px 20px;
  font-family: inherit;
  font-size: 0.85rem;
  background: #1a1a30;
  color: #aaa;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

#restart:hover {
  background: #2a2a50;
  color: #ddd;
}

/* ── Overlay ── */

#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-content {
  background: #14142a;
  border: 2px solid #333;
  border-radius: 8px;
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#overlay-title {
  font-size: 1.8rem;
  letter-spacing: 2px;
}

#overlay-message {
  font-size: 1rem;
  color: #999;
}

#overlay-restart {
  margin-top: 8px;
  padding: 10px 28px;
  font-family: inherit;
  font-size: 1rem;
  background: #2a2a50;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

#overlay-restart:hover {
  background: #3a3a70;
}
