/* ========================================================
   Safari Frenzy — Retro Game Boy / Pokémon Red-Blue vibe
   ======================================================== */

:root {
  --bg-deep: #0a1f12;
  --bg-mid: #122e1c;
  --bg-frame: #1a3a25;
  --bg-card: #234a32;
  --grass-light: #7bc950;
  --grass-mid: #5c8a3e;
  --grass-dark: #2c5d2a;
  --pkmn-red: #e63946;
  --pkmn-red-dark: #a4262e;
  --pkmn-yellow: #fcbf49;
  --pkmn-blue: #5dade2;
  --cream: #fff3d6;
  --off-white: #cfd8c8;
  --ink: #0f1011;
  --shadow-deep: rgba(0, 0, 0, 0.55);

  --font-display: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 20px;
  overflow: hidden;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

body {
  background:
    radial-gradient(ellipse at top, rgba(123, 201, 80, 0.08), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(252, 191, 73, 0.05), transparent 50%),
    var(--bg-deep);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* CRT scanlines overlay */
.scanlines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.12) 3px,
    transparent 4px
  );
  pointer-events: none;
  z-index: 1000;
  mix-blend-mode: multiply;
}

/* ======== Layout ======== */

.app {
  width: min(960px, 96vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 22px 14px;
  background: var(--bg-mid);
  border: 4px solid var(--ink);
  box-shadow:
    0 0 0 4px var(--grass-mid),
    0 0 0 8px var(--ink),
    8px 8px 0 8px rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 1;
}

/* ======== HUD ======== */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  background: var(--ink);
  border: 3px solid var(--grass-light);
  padding: 12px 16px;
  align-items: center;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-block:last-child {
  align-items: flex-end;
}

.hud-block.timer {
  align-items: center;
  border-left: 2px dashed var(--grass-mid);
  border-right: 2px dashed var(--grass-mid);
  padding: 0 28px;
}

.hud-label {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--grass-light);
  text-shadow: 2px 2px 0 var(--ink);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--cream);
  text-shadow: 3px 3px 0 var(--pkmn-red-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-block.timer .hud-value {
  font-size: 28px;
  color: var(--pkmn-yellow);
  text-shadow: 3px 3px 0 var(--ink);
}

.multiplier {
  font-family: var(--font-display);
  font-size: 13px;
  padding: 4px 8px;
  background: var(--grass-mid);
  color: var(--ink);
  transition: all 0.2s ease;
}

.multiplier[data-tier="2"] { background: var(--pkmn-blue); color: var(--ink); }
.multiplier[data-tier="3"] { background: var(--pkmn-yellow); color: var(--ink); }
.multiplier[data-tier="4"] { background: #ff7b00; color: var(--ink); animation: pulse 0.6s infinite; }
.multiplier[data-tier="5"] { background: var(--pkmn-red); color: var(--cream); animation: pulse 0.4s infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* ======== Game area ======== */

.game-area {
  display: grid;
  grid-template-columns: auto 220px;
  gap: 18px;
  align-items: flex-start;
}

.canvas-frame {
  position: relative;
  width: 480px;
  height: 480px;
  border: 4px solid var(--ink);
  box-shadow:
    inset 0 0 0 3px var(--grass-light),
    inset 0 0 0 6px var(--ink),
    0 6px 0 var(--grass-dark);
  background: var(--grass-dark);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: manipulation;
}

/* ======== Canvas tint overlay (per-level mood) ======== */
.canvas-tint {
  position: absolute;
  inset: 6px; /* keep inside the chunky border */
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0;
  background: transparent;
  transition: background 0.8s ease, opacity 0.8s ease;
  z-index: 2;
}

.canvas-tint[data-tint="goldenhour"] {
  background: #ffb24a;
  opacity: 0.18;
}
.canvas-tint[data-tint="dusk"] {
  background: #5d4a8e;
  opacity: 0.32;
}
.canvas-tint[data-tint="night"] {
  background: #1c2a5a;
  opacity: 0.5;
  mix-blend-mode: multiply;
}
.canvas-tint[data-tint="aurora"] {
  background: linear-gradient(180deg, #5b1d8a 0%, #2a4a8a 60%, #0d4d3d 100%);
  opacity: 0.45;
}

/* ======== Level progress bar ======== */
.level-bar {
  background: var(--ink);
  border: 3px solid var(--pkmn-yellow);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.level-bar-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 1px;
}

.lvl-tag {
  color: var(--pkmn-yellow);
  text-shadow: 2px 2px 0 var(--pkmn-red-dark);
}

.lvl-goal {
  color: var(--cream);
}

.level-bar-track {
  height: 14px;
  background: var(--bg-frame);
  border: 2px solid var(--grass-mid);
  position: relative;
  overflow: hidden;
}

.level-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--grass-light) 0%, var(--pkmn-yellow) 100%);
  transition: width 0.25s ease;
  position: relative;
}

.level-bar-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.15) 0 4px,
    transparent 4px 8px
  );
}

/* ======== Toast stack (achievements) ======== */
.toast-stack {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
  width: max-content;
  max-width: 90%;
}

.toast {
  background: var(--ink);
  border: 3px solid var(--pkmn-yellow);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 4px 4px 0 var(--pkmn-red-dark);
  animation: toastIn 0.4s cubic-bezier(0.25, 1.5, 0.5, 1) backwards,
             toastOut 0.5s ease 2.6s forwards;
  max-width: 100%;
}

.toast-icon {
  font-size: 24px;
  filter: drop-shadow(2px 2px 0 var(--pkmn-red-dark));
}

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.toast-title {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--pkmn-yellow);
  letter-spacing: 1px;
}

.toast-msg {
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--cream);
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes toastIn {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toastOut {
  to { transform: translateY(-30px); opacity: 0; }
}

/* ======== Leaderboard sidebar ======== */

.leaderboard {
  background: var(--bg-card);
  border: 3px solid var(--grass-light);
  padding: 14px 12px;
  height: 480px;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 0 1px var(--ink), 4px 4px 0 var(--ink);
}

.leaderboard h3 {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--pkmn-yellow);
  text-shadow: 2px 2px 0 var(--ink);
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px dashed var(--grass-mid);
}

#leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

#leaderboard-list li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 6px;
  align-items: center;
  font-size: 18px;
  background: var(--ink);
  padding: 6px 8px;
  border: 2px solid var(--grass-mid);
  color: var(--cream);
}

#leaderboard-list li.empty {
  display: block;
  text-align: center;
  font-style: italic;
  color: var(--off-white);
  background: transparent;
  border: 2px dashed var(--grass-mid);
  padding: 14px 6px;
}

#leaderboard-list .rank {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--pkmn-yellow);
}

#leaderboard-list .name {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--cream);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#leaderboard-list .score {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--pkmn-yellow);
  text-shadow: 1px 1px 0 var(--pkmn-red-dark);
}

.hint-side {
  font-size: 16px;
  color: var(--off-white);
  text-align: center;
  margin-top: 12px;
  opacity: 0.7;
  font-style: italic;
}

/* ======== Overlay ======== */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 31, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-card {
  width: 100%;
  max-height: 100%;
  padding: 24px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  overflow-y: auto;
}

.title {
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1.2;
  color: var(--pkmn-yellow);
  text-shadow:
    3px 3px 0 var(--pkmn-red-dark),
    6px 6px 0 var(--ink);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.title.small {
  font-size: 18px;
}

.subtitle {
  font-size: 18px;
  color: var(--cream);
  line-height: 1.4;
}

.subtitle .danger {
  color: var(--pkmn-red);
  font-weight: bold;
}

.rules {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 17px;
  text-align: left;
  background: var(--ink);
  padding: 12px 16px;
  border: 2px solid var(--grass-mid);
  width: 100%;
}

.rules li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ink);
  box-shadow: 1px 1px 0 var(--cream);
}
.dot.common { background: var(--grass-light); }
.dot.uncommon { background: #a594d6; }
.dot.legendary { background: var(--pkmn-yellow); }
.dot.danger { background: var(--pkmn-red); }

.hint {
  font-size: 16px;
  color: var(--off-white);
  font-style: italic;
}
.hint strong {
  color: var(--pkmn-yellow);
}

.big-btn {
  font-family: var(--font-display);
  font-size: 14px;
  padding: 14px 24px;
  background: var(--pkmn-red);
  color: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 var(--pkmn-red-dark);
  transition: transform 0.1s, box-shadow 0.1s;
  margin-top: 4px;
}

.big-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ink);
}

.big-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.big-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 2px 2px 0 var(--ink);
}

.ghost-btn {
  font-family: var(--font-display);
  font-size: 10px;
  padding: 8px 16px;
  background: transparent;
  color: var(--grass-light);
  border: 2px solid var(--grass-mid);
  cursor: pointer;
  transition: all 0.15s;
}

.ghost-btn:hover {
  background: var(--grass-mid);
  color: var(--ink);
}

/* ======== Game over ======== */

.final-score {
  font-family: var(--font-display);
  font-size: 56px;
  color: var(--pkmn-yellow);
  text-shadow:
    4px 4px 0 var(--pkmn-red-dark),
    8px 8px 0 var(--ink);
  margin: 8px 0;
  animation: scoreReveal 0.6s ease-out;
}

@keyframes scoreReveal {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  background: var(--ink);
  padding: 12px;
  border: 2px solid var(--grass-mid);
}

.stats > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.stats span {
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--grass-light);
  letter-spacing: 1px;
}

.stats strong {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--cream);
  text-shadow: 2px 2px 0 var(--pkmn-red-dark);
}

.name-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: stretch;
}

.name-form label {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--grass-light);
  letter-spacing: 1px;
}

#player-name {
  font-family: var(--font-display);
  font-size: 14px;
  padding: 12px 14px;
  background: var(--ink);
  border: 3px solid var(--grass-light);
  color: var(--cream);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
  outline: none;
}

#player-name:focus {
  border-color: var(--pkmn-yellow);
  box-shadow: 0 0 0 3px rgba(252, 191, 73, 0.3);
}

.status {
  font-size: 16px;
  min-height: 22px;
}
.status.success { color: var(--pkmn-yellow); }
.status.error { color: var(--pkmn-red); }

/* ======== Leaderboard full screen ======== */

.board-full {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.board-full li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 11px;
  background: var(--ink);
  padding: 10px 12px;
  border: 2px solid var(--grass-mid);
  color: var(--cream);
  align-items: center;
}

.board-full li:first-child { border-color: var(--pkmn-yellow); }
.board-full li:nth-child(2) { border-color: var(--off-white); }
.board-full li:nth-child(3) { border-color: var(--pkmn-red); }

.board-full .rank { color: var(--pkmn-yellow); }
.board-full .score { color: var(--pkmn-yellow); }

.board-full li.empty {
  display: block;
  text-align: center;
  font-style: italic;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--off-white);
}

/* ======== Footer ======== */

.footer {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--grass-mid);
  padding-top: 8px;
  border-top: 2px dashed var(--grass-mid);
  letter-spacing: 1px;
}

/* ======== Level-up screen ======== */
.level-up-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  padding: 8px;
}

.level-up-banner {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--pkmn-yellow);
  letter-spacing: 2px;
  animation: bannerWiggle 0.6s ease infinite;
}

@keyframes bannerWiggle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.level-up-num {
  font-family: var(--font-display);
  font-size: 64px;
  color: var(--pkmn-yellow);
  text-shadow:
    4px 4px 0 var(--pkmn-red-dark),
    8px 8px 0 var(--ink);
  animation: scoreReveal 0.5s ease-out;
}

.level-up-biome {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--grass-light);
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 var(--ink);
  padding: 8px 14px;
  background: var(--ink);
  border: 2px solid var(--grass-mid);
}

.level-up-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
}

.level-up-stat {
  background: var(--ink);
  padding: 8px 10px;
  border: 2px solid var(--grass-mid);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.level-up-stat span {
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--grass-light);
  letter-spacing: 1px;
}

.level-up-stat strong {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--pkmn-yellow);
  text-shadow: 2px 2px 0 var(--pkmn-red-dark);
}

/* ======== Best score tag ======== */
.best-score {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--pkmn-yellow);
  background: var(--ink);
  padding: 6px 12px;
  border: 2px solid var(--grass-mid);
  letter-spacing: 1px;
  margin-top: -4px;
}

.best-score strong {
  color: var(--cream);
  margin-left: 6px;
}

/* ======== Pokedex grid ======== */
.pokedex {
  width: 100%;
  background: var(--ink);
  border: 2px solid var(--grass-mid);
  padding: 8px;
}

.pokedex-title {
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--pkmn-yellow);
  letter-spacing: 1px;
  text-align: center;
  margin-bottom: 6px;
}

.pokedex-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.pokedex-cell {
  aspect-ratio: 1;
  background: var(--bg-frame);
  border: 1px solid var(--grass-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--cream);
  position: relative;
}

.pokedex-cell.locked {
  opacity: 0.4;
  color: var(--grass-mid);
}

.pokedex-cell .count {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 6px;
  color: var(--pkmn-yellow);
  background: var(--ink);
  padding: 0 2px;
  border-radius: 2px;
}

/* ======== Menu buttons / mode select ======== */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.modes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  background: var(--ink);
  border: 3px solid var(--grass-mid);
  color: var(--cream);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.1s;
  box-shadow: 3px 3px 0 var(--ink);
}

.mode-card:hover {
  border-color: var(--pkmn-yellow);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}

.mode-card:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.mode-icon {
  font-size: 22px;
  filter: drop-shadow(2px 2px 0 var(--pkmn-red-dark));
}

.mode-card strong {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--pkmn-yellow);
  letter-spacing: 1px;
}

.mode-desc {
  font-size: 13px;
  color: var(--off-white);
  line-height: 1.2;
}

.mode-best {
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--grass-light);
  letter-spacing: 1px;
  margin-top: auto;
}

/* ======== Settings rows ======== */
.settings-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  background: var(--ink);
  padding: 10px;
  border: 2px solid var(--grass-mid);
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  color: var(--cream);
  cursor: pointer;
  user-select: none;
}

.setting-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--pkmn-yellow);
  cursor: pointer;
}

/* ======== Leaderboard tabs ======== */
.lb-tabs {
  display: flex;
  gap: 4px;
  width: 100%;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.lb-tab {
  flex: 1;
  min-width: 70px;
  font-family: var(--font-display);
  font-size: 8px;
  padding: 6px 4px;
  background: var(--bg-frame);
  color: var(--off-white);
  border: 2px solid var(--grass-mid);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s;
}

.lb-tab.active {
  background: var(--pkmn-yellow);
  color: var(--ink);
  border-color: var(--pkmn-red-dark);
}

.lb-tab:hover:not(.active) {
  background: var(--grass-mid);
  color: var(--ink);
}

/* ======== Reduced motion ======== */
body.reduced-motion * {
  animation: none !important;
  transition: none !important;
}

/* ======== Responsive ======== */

@media (max-width: 760px) {
  body { font-size: 18px; align-items: flex-start; padding: 10px 0; }
  .app { padding: 14px; }
  .game-area { grid-template-columns: 1fr; }
  .canvas-frame {
    width: 100%;
    max-width: 420px;
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
  }
  .leaderboard {
    height: auto;
    max-height: 220px;
  }
  .hud { grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 8px; }
  .hud-block.timer { padding: 0 6px; }
  .hud-label { font-size: 7px; }
  .hud-value { font-size: 14px; }
  .hud-block.timer .hud-value { font-size: 18px; }
  .multiplier { font-size: 9px; padding: 2px 4px; }
  .level-bar-info { font-size: 8px; }
  .title { font-size: 24px; }
  .final-score { font-size: 40px; }
  .level-up-num { font-size: 44px; }
  .pokedex-grid { grid-template-columns: repeat(4, 1fr); }
  .toast { padding: 6px 10px; }
  .toast-title { font-size: 8px; }
  .toast-msg { font-size: 7px; }
}
