/* ============================================================
   DOODLE ROAD BUILDER — Premium Chalk/Neon Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;700&family=Fredoka+One&display=swap');

/* ---- RESET / BASE ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --board: #0d1b12;
  --board2: #111f16;
  --chalk: #e8f5e3;
  --chalk-dim: #8aab84;
  --neon-green: #39ff14;
  --neon-teal: #00ffd0;
  --neon-yellow: #ffe135;
  --neon-orange: #ff8c00;
  --neon-red: #ff3838;
  --neon-blue: #4fc3f7;
  --neon-pink: #ff6ef7;
  --gold: #ffd700;
  --star-on: #ffe135;
  --star-off: #3a4a3a;
  --font-main: 'Caveat', cursive;
  --font-ui: 'Fredoka One', cursive;
  --radius: 12px;
  --shadow-neon: 0 0 8px rgba(57,255,20,0.6), 0 0 20px rgba(57,255,20,0.3);
  --shadow-teal: 0 0 8px rgba(0,255,208,0.6), 0 0 20px rgba(0,255,208,0.3);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--board);
  color: var(--chalk);
  font-family: var(--font-main);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---- GAME WRAPPER ---------------------------------------- */
#game-wrapper {
  position: relative;
  width: 100vw; height: 100vh;
  overflow: hidden;
}

/* ---- SCREENS --------------------------------------------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--board);
}
.screen.active { display: flex; }

/* Chalkboard texture via SVG pattern embedded */
.screen::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.012) 3px,
      rgba(255,255,255,0.012) 4px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.008) 3px,
      rgba(255,255,255,0.008) 4px
    );
  pointer-events: none;
  z-index: 0;
}

/* ---- START SCREEN ---------------------------------------- */
#screen-start {
  overflow: hidden;
}

#title-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
}

#title-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}

#title-top {
  font-family: var(--font-ui);
  font-size: clamp(52px, 10vw, 100px);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal), 0 0 60px rgba(0,255,208,0.4);
  letter-spacing: 4px;
  line-height: 1;
  animation: titlePulse 3s ease-in-out infinite;
}

#title-bottom {
  font-family: var(--font-ui);
  font-size: clamp(28px, 5vw, 56px);
  color: var(--neon-green);
  text-shadow: var(--shadow-neon);
  letter-spacing: 2px;
  line-height: 1;
  animation: titlePulse 3s ease-in-out infinite 0.5s;
}

#title-sub {
  font-family: var(--font-main);
  font-size: clamp(16px, 2.5vw, 24px);
  color: var(--chalk-dim);
  margin: 8px 0 20px;
  letter-spacing: 1px;
}

@keyframes titlePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* ---- BUTTONS --------------------------------------------- */
.btn-chalk {
  font-family: var(--font-ui);
  font-size: clamp(16px, 2.5vw, 22px);
  padding: 12px 36px;
  border: 3px solid var(--neon-green);
  border-radius: var(--radius);
  background: transparent;
  color: var(--neon-green);
  text-shadow: var(--shadow-neon);
  box-shadow: var(--shadow-neon);
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.18s ease;
  position: relative;
  overflow: hidden;
  min-width: 140px;
}

.btn-chalk::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--neon-green);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.btn-chalk:hover::before, .btn-chalk:active::before { opacity: 0.12; }
.btn-chalk:hover { transform: scale(1.05); }
.btn-chalk:active { transform: scale(0.97); }

.btn-play {
  font-size: clamp(18px, 3vw, 26px);
  padding: 14px 50px;
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal);
  box-shadow: var(--shadow-teal);
  margin-top: 10px;
}

.btn-play::before { background: var(--neon-teal); }

.btn-secondary {
  border-color: var(--chalk-dim);
  color: var(--chalk-dim);
  text-shadow: none;
  box-shadow: 0 0 6px rgba(138,171,132,0.3);
  font-size: clamp(13px, 2vw, 17px);
  padding: 8px 22px;
}
.btn-secondary::before { background: var(--chalk-dim); }

.btn-back {
  font-size: 16px;
  padding: 8px 20px;
  border-color: var(--chalk-dim);
  color: var(--chalk-dim);
  text-shadow: none;
  box-shadow: none;
}

/* ---- LEVEL SELECT ---------------------------------------- */
#screen-levels {
  overflow-y: auto;
  padding: 20px;
  align-items: stretch;
}

#level-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 10px 16px;
  border-bottom: 2px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

#level-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 20px 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  overflow-y: auto;
}

.level-tile {
  background: var(--board2);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
  overflow: hidden;
}

.level-tile:hover {
  border-color: var(--neon-teal);
  box-shadow: var(--shadow-teal);
  transform: translateY(-3px);
}

.level-tile.locked {
  opacity: 0.4;
  cursor: not-allowed;
}
.level-tile.locked:hover { transform: none; box-shadow: none; border-color: rgba(255,255,255,0.15); }

.tile-num {
  font-family: var(--font-ui);
  font-size: 28px;
  color: var(--chalk);
  line-height: 1;
}

.tile-name {
  font-family: var(--font-main);
  font-size: 13px;
  color: var(--chalk-dim);
  text-align: center;
  line-height: 1.3;
}

.tile-stars {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.tile-star {
  font-size: 16px;
  color: var(--star-off);
  transition: color 0.2s;
}
.tile-star.on { color: var(--star-on); text-shadow: 0 0 6px rgba(255,225,53,0.8); }

.lock-icon {
  font-size: 24px;
  color: var(--chalk-dim);
}

/* ---- GAME SCREEN ----------------------------------------- */
#screen-game {
  padding: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ---- HUD ------------------------------------------------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: none;
}

#hud > * { pointer-events: all; }

#hud-left, #hud-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#hud-right { align-items: flex-end; }

#hud-level {
  font-family: var(--font-ui);
  font-size: clamp(11px, 2vw, 15px);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal);
  letter-spacing: 1px;
}

#hud-level-name {
  font-family: var(--font-main);
  font-size: clamp(14px, 2.5vw, 20px);
  color: var(--chalk);
  letter-spacing: 0.5px;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#hud-phase {
  font-family: var(--font-ui);
  font-size: clamp(12px, 2vw, 17px);
  color: var(--neon-yellow);
  text-shadow: 0 0 8px rgba(255,225,53,0.7);
  letter-spacing: 1px;
  animation: phasePulse 1.2s ease-in-out infinite;
}

@keyframes phasePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#hud-efficiency {
  display: flex;
  gap: 6px;
  align-items: center;
}

.lbl {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--chalk-dim);
  letter-spacing: 1px;
}

#eff-val {
  font-family: var(--font-ui);
  font-size: clamp(13px, 2vw, 17px);
  color: var(--neon-green);
  text-shadow: var(--shadow-neon);
}

#star-progress {
  display: flex;
  gap: 6px;
}

.star-slot {
  font-size: clamp(16px, 3vw, 22px);
  color: var(--star-off);
  transition: all 0.3s ease;
}
.star-slot.lit {
  color: var(--star-on);
  text-shadow: 0 0 10px rgba(255,225,53,0.9);
  animation: starPop 0.4s ease;
}
@keyframes starPop {
  0% { transform: scale(0.5); }
  60% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

#hud-coins {
  font-family: var(--font-ui);
  font-size: clamp(14px, 2.5vw, 19px);
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255,215,0,0.7);
}

#hud-timer {
  font-family: var(--font-ui);
  font-size: clamp(12px, 2vw, 16px);
  color: var(--chalk-dim);
}

#hud-btns {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.btn-hud {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.5);
  color: var(--chalk);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.btn-hud:hover {
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  box-shadow: var(--shadow-teal);
}

/* ---- OVERLAYS -------------------------------------------- */
.overlay-box {
  background: rgba(10,22,14,0.97);
  border: 2px solid var(--neon-teal);
  border-radius: 20px;
  box-shadow: var(--shadow-teal), inset 0 0 40px rgba(0,0,0,0.5);
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 20;
}

.chalk-title {
  font-family: var(--font-ui);
  font-size: clamp(22px, 4vw, 36px);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal);
  letter-spacing: 2px;
  text-align: center;
}

#tutorial-overlay, #pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  backdrop-filter: blur(3px);
}

#tutorial-box {
  background: rgba(10,22,14,0.97);
  border: 3px solid var(--neon-teal);
  border-radius: 18px;
  box-shadow: var(--shadow-teal);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  text-align: center;
}

.tut-title {
  font-family: var(--font-ui);
  font-size: 24px;
  color: var(--neon-green);
  text-shadow: var(--shadow-neon);
  letter-spacing: 2px;
}

.tut-step {
  font-family: var(--font-main);
  font-size: 18px;
  color: var(--chalk);
  line-height: 1.5;
}

/* ---- COMPLETE SCREEN ------------------------------------- */
#screen-complete {
  overflow: hidden;
}

#complete-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
  pointer-events: none;
}

#complete-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
}

#complete-title {
  font-family: var(--font-ui);
  font-size: clamp(28px, 5vw, 48px);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal), 0 0 60px rgba(0,255,208,0.4);
  letter-spacing: 3px;
  animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#complete-stars {
  display: flex;
  gap: 16px;
}

.big-star {
  font-size: clamp(40px, 7vw, 64px);
  color: var(--star-off);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-block;
  filter: drop-shadow(0 0 0 transparent);
}

.big-star.on {
  color: var(--star-on);
  filter: drop-shadow(0 0 12px rgba(255,225,53,0.9));
  transform: scale(1.2);
}

#complete-stats {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 280px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 40px;
}

.stat-lbl {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--chalk-dim);
  letter-spacing: 1px;
}

.stat-val {
  font-family: var(--font-ui);
  font-size: 20px;
  color: var(--chalk);
}

.best-row .stat-val {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255,215,0,0.5);
}

#complete-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-next {
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  text-shadow: var(--shadow-teal);
  box-shadow: var(--shadow-teal);
  font-size: clamp(16px, 2.5vw, 22px);
  padding: 12px 40px;
}
.btn-next::before { background: var(--neon-teal); }

/* ---- GAME OVER ------------------------------------------- */
#screen-gameover {
  overflow: hidden;
}

.go-box {
  border-color: var(--neon-red);
  box-shadow: 0 0 8px rgba(255,56,56,0.6), 0 0 20px rgba(255,56,56,0.3);
}

.go-title {
  color: var(--neon-red) !important;
  text-shadow: 0 0 8px rgba(255,56,56,0.6), 0 0 20px rgba(255,56,56,0.3) !important;
}

#go-msg {
  font-family: var(--font-main);
  font-size: 20px;
  color: var(--chalk-dim);
  text-align: center;
}

/* ---- MISC ------------------------------------------------ */
.chalk-title {
  font-family: var(--font-ui);
  font-size: clamp(20px, 3vw, 30px);
  color: var(--chalk);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--board); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* ---- RESPONSIVE ------------------------------------------ */
@media (max-width: 600px) {
  #level-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
  .overlay-box { padding: 24px 20px; }
  #tutorial-box { padding: 20px 18px; }
  #complete-stats { padding: 12px 20px; min-width: 240px; }
  #complete-btns { gap: 8px; }
  #hud { padding: 6px 10px; }
}
