* {
  box-sizing: border-box;
}

body {
  background: #020617;
  color: #f8fafc;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  width: 100vw;
  margin: 0;
  padding: 0.75rem;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.screen {
  width: 100%;
  max-width: 440px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#map-screen {
  justify-content: space-between;
}

#game-screen {
  justify-content: center;
  gap: 0.85rem;
}

.hud {
  text-align: center;
  width: 100%;
  position: relative;
  flex-shrink: 0;
  z-index: 10;
}

.map-hud {
  background: rgba(2, 6, 23, 0.75);
  padding: 0.5rem;
  border-radius: 12px;
  backdrop-filter: blur(8px);
}

h1 { font-size: 1.35rem; margin: 0 0 0.2rem 0; color: #f8fafc; }
#total-stars, #attempts-left { color: #38bdf8; font-weight: 600; font-size: 0.9rem; }

.nav-btn {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: #334155;
  color: #f8fafc;
  border-radius: 6px;
}

/* JOURNEY MAP CANVAS CONTAINER */
.map-container {
  width: 100%;
  flex: 1;
  max-height: calc(100dvh - 85px);
  background: #000000;
  border: 2px solid #1e293b;
  border-radius: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
}

#map-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  touch-action: manipulation;
}

/* PUZZLE GRID STYLES */
.game-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

canvas#game {
  border: 2px solid #334155;
  border-radius: 12px;
  background: #020617;
  cursor: pointer;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  display: block;
  touch-action: manipulation;
  max-width: 75vw;
  max-height: 75vw;
  width: auto;
  height: auto;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

#status {
  font-weight: 700;
  font-size: 0.9rem;
  color: #94a3b8;
  min-height: 1.2rem;
  text-align: center;
}
.win { color: #22c55e !important; text-shadow: 0 0 12px rgba(34, 197, 94, 0.6); }
.fail { color: #ef4444 !important; text-shadow: 0 0 12px rgba(239, 68, 68, 0.6); }
.warn { color: #f59e0b !important; }

.bottom-btn-group {
  display: flex;
  gap: 0.75rem;
}

button {
  padding: 0.55rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

#fire-btn {
  margin-top: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.85rem;
  background: #ef4444;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  white-space: nowrap;
  width: 100%;
}
#fire-btn:hover:not(:disabled) { background: #dc2626; transform: translateY(-1px); }

#next-btn {
  background: #06b6d4;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}
#next-btn:hover:not(:disabled) { background: #22d3ee; transform: translateY(-1px); }

#restart-btn {
  background: #475569;
  color: #f8fafc;
  display: none;
}
#restart-btn:hover:not(:disabled) { background: #64748b; }

button:disabled {
  background: #334155 !important;
  color: #64748b !important;
  cursor: not-allowed !important;
  box-shadow: none !important;
  transform: none !important;
}

@media (min-width: 520px) {
  .game-layout { display: inline-block; }
  #fire-btn {
    position: absolute;
    top: 0;
    left: calc(100% + 12px);
    margin-top: 0;
    width: auto;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
  }
  canvas#game { max-width: none; max-height: none; }
}