@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Nunito:wght@700;800;900&display=swap');

:root {
  --primary-color: #4f46e5;
  --primary-light: #818cf8;
  --accent-gold: #f59e0b;
  --accent-yellow: #fbbf24;
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --accent-blue: #0ea5e9;
  --accent-purple: #8b5cf6;
  --card-bg: rgba(255, 255, 255, 0.95);
  --dark-text: #1e1b4b;
  --border-radius: 16px;
  --font-main: 'Fredoka', 'Nunito', -apple-system, sans-serif;
  --font-display: 'Nunito', 'Fredoka', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
  font-family: var(--font-main);
  color: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-wrapper {
  position: relative;
  width: 100vw;
  max-width: 1024px;
  aspect-ratio: 16 / 9;
  max-height: 100vh;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  overflow: hidden;
  background-color: #87CEEB;
}

@media (max-aspect-ratio: 16/9) {
  #game-wrapper {
    width: 100vw;
    height: auto;
    border-radius: 0;
  }
}

canvas#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

/* ================= TOP HUD ================= */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* Runner Hearts Badge (3 Lives) */
.runner-hearts-badge {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 30px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hero-icon {
  width: 30px;
  height: 30px;
  display: inline-block;
  background: url('../assets/characters/lantern-runner-v1.png') center / 145% auto no-repeat;
  border-radius: 50%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

#hearts-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.heart-icon {
  font-size: 18px;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
  display: inline-block;
}

.heart-icon.lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.8);
}

/* Grade badge */
#grade-badge {
  background: rgba(79, 70, 229, 0.85);
  border-color: rgba(165, 180, 252, 0.4);
  color: #fff;
}

/* Center Wave Card */
.runner-center-card {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 5px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.distance-title {
  font-size: 13px;
  font-weight: 800;
  color: #fef08a;
  letter-spacing: 0.5px;
}

.speed-indicator {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
}

/* Score & Best Badges */
.score-badge, .best-badge {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  min-width: 60px;
}

.best-badge {
  border-color: rgba(251, 191, 36, 0.4);
}

.score-label {
  font-size: 9px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.score-num {
  font-size: 14px;
  font-weight: 900;
  color: #38bdf8;
}

.best-num {
  font-size: 14px;
  font-weight: 900;
  color: #fbbf24;
}

.stats-badge {
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #fbbf24;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

.hud-btn {
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.hud-btn:hover {
  background: rgba(99, 102, 241, 0.85);
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.6);
}

/* ================= GRADE SELECTOR CARDS ================= */
.grade-selector-intro {
  margin: 14px 0 0;
  color: #475569;
  font-size: 12px;
  line-height: 1.55;
}

.grade-selector-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
  text-align: left;
}

.grade-card {
  background: #f8fafc;
  border: 2.5px solid #e2e8f0;
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grade-card:hover {
  border-color: #818cf8;
  transform: translateY(-2px);
}

.grade-card.selected {
  border-color: #4f46e5;
  background: #eef2ff;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.2);
}

.grade-card-badge {
  font-size: 10px;
  font-weight: 800;
  background: #10b981;
  color: #fff;
  padding: 2px 7px;
  border-radius: 8px;
  display: inline-block;
  align-self: flex-start;
}

.grade-card-title {
  font-size: 16px;
  font-weight: 900;
  color: #1e1b4b;
}

.grade-card-desc {
  font-size: 11px;
  color: #64748b;
  line-height: 1.35;
}

.runner-controls-box {
  background: #f1f5f9;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 12px;
  text-align: left;
  line-height: 1.5;
  color: #334155;
}

kbd {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ================= RESULTS / GAME OVER STATS GRID ================= */
.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  padding: 14px;
  margin: 14px 0;
  text-align: left;
}

.result-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cell-label {
  font-size: 11px;
  color: #64748b;
  font-weight: 700;
}

.cell-value {
  font-size: 16px;
  font-weight: 900;
  color: #0f172a;
}

.new-record-tag {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
  display: inline-block;
  animation: pulse-dot 1s infinite alternate;
}

/* ================= OVERLAY DIALOGS & MODALS ================= */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #fff;
  color: var(--dark-text);
  border-radius: 24px;
  padding: 26px;
  width: 90%;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(255, 255, 255, 0.2);
  transform: scale(0.85);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 14px;
  color: #475569;
  margin-bottom: 14px;
  line-height: 1.45;
}

.modal-btn {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 800;
  border: none;
  padding: 11px 24px;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 24px rgba(79, 70, 229, 0.6);
}

/* Onscreen Jump Button (Mobile/Tablet) */
#touch-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  pointer-events: none;
  z-index: 15;
}

.touch-action {
  pointer-events: auto;
}

.touch-jump-btn {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #10b981, #059669);
  border: 3px solid #a7f3d0;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.5);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.touch-jump-btn:active {
  transform: scale(0.92);
}

/* Toast Banner */
.toast-banner {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(15, 23, 42, 0.92);
  color: #fef08a;
  padding: 8px 20px;
  border-radius: 30px;
  border: 2px solid rgba(254, 240, 138, 0.3);
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 50;
}

.toast-banner.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@keyframes pulse-dot {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}
