:root {
  --bg: #dce9cf;
  --text-dark: #3a2008;
  --text-mid: #6b4020;
  --accent: #c45c18;
  --accent-dark: #8a3a08;
  --card-bg: rgba(255, 255, 255, 0.6);
  --card-border: rgba(160, 110, 60, 0.22);
}

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

body {
  touch-action: none;
  background: var(--bg);
  font-family: 'Nunito', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  position: relative;
  color: var(--text-dark);
}

/* Soft bokeh */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 15% 85%, rgba(180, 220, 130, 0.55) 0%, transparent 60%),
    radial-gradient(ellipse 55% 45% at 85% 10%, rgba(210, 240, 170, 0.45) 0%, transparent 55%),
    radial-gradient(ellipse 80% 65% at 50% 45%, rgba(200, 230, 160, 0.25) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Scattered deco */
.deco {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  opacity: 0.18;
  color: var(--text-mid);
  font-size: 1.1rem;
  user-select: none;
}
.deco-1 { top: 12%; left: 7%; font-size: 0.9rem; }
.deco-2 { top: 18%; right: 8%; font-size: 1rem; }
.deco-3 { top: 45%; left: 4%; font-size: 0.75rem; }
.deco-4 { bottom: 30%; right: 5%; font-size: 0.9rem; }
.deco-5 { bottom: 18%; left: 8%; font-size: 0.8rem; }
.deco-6 { top: 60%; right: 7%; font-size: 0.75rem; }

/* =====================
   HEADER (in-game)
   ===================== */
header {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 14px 20px 4px;
  width: 100%;
}

h1 {
  font-family: 'Nunito', sans-serif;
  font-size: 1.4rem;
  font-style: normal;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0;
}

/* =====================
   STATS BAR
   ===================== */
.stats {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 5px 0 14px;
  z-index: 10;
  position: relative;
}

.stat {
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid var(--card-border);
  border-radius: 20px;
  padding: 3px 12px;
  color: var(--text-dark);
  font-weight: 700;
  font-size: 0.8rem;
}

.stat span { color: var(--accent); }

/* =====================
   GAME AREA & MAZE
   ===================== */
#game-area {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 10px;
}

#maze-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 3px rgba(160, 110, 60, 0.28),
    0 0 0 6px rgba(255, 255, 255, 0.45),
    0 8px 28px rgba(0, 0, 0, 0.12);
}

canvas {
  display: block;
  image-rendering: pixelated;
}

/* =====================
   D-PAD CONTROLS
   ===================== */
.controls {
  display: grid;
  grid-template-columns: 56px 56px 56px;
  grid-template-rows: 56px 56px;
  gap: 6px;
  position: relative;
  z-index: 10;
}

.btn {
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  color: var(--text-dark);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 3px 0 rgba(160, 110, 60, 0.18), 0 4px 10px rgba(0, 0, 0, 0.07);
  transition: transform 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active, .btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(160, 110, 60, 0.18), 0 1px 4px rgba(0, 0, 0, 0.06);
}

.btn-up    { grid-column: 2; grid-row: 1; }
.btn-left  { grid-column: 1; grid-row: 2; }
.btn-down  { grid-column: 2; grid-row: 2; }
.btn-right { grid-column: 3; grid-row: 2; }

/* =====================
   SHARED: CTA BUTTON
   ===================== */
.cta-btn, .next-btn {
  background: var(--accent);
  border: none;
  border-radius: 50px;
  padding: 14px 32px;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 4px 0 var(--accent-dark), 0 6px 18px rgba(0, 0, 0, 0.13);
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.cta-btn:active, .next-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--accent-dark);
}

/* =====================
   NAME SCREEN
   ===================== */
#name-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 28px;
  overflow-y: auto;
  text-align: center;
}

#name-screen.show { display: flex; }

/* =====================
   CONTINUE SCREEN
   ===================== */
#continue-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 28px;
  text-align: center;
  gap: 12px;
}

.secondary-btn {
  background: transparent;
  border: 1.5px solid var(--card-border);
  border-radius: 50px;
  padding: 12px 32px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-mid);
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.secondary-btn:active { background: rgba(0,0,0,0.05); }

/* =====================
   FINALE SCREEN
   ===================== */
#finale-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px 20px 32px;
  overflow-y: auto;
}

/* =====================
   BIRTHDAY SCREEN
   ===================== */
#birthday-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 28px;
  text-align: center;
}

.birthday-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 300px;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.birthday-emoji {
  font-size: 5rem;
  animation: sway 1.5s ease-in-out infinite alternate;
}

@keyframes sway {
  from { transform: rotate(-8deg) scale(1); }
  to   { transform: rotate(8deg) scale(1.1); }
}

/* also support style="display:flex" set by JS */
#name-screen[style*="flex"] { display: flex !important; }

.chapter-badge {
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text-mid);
  border: 1.5px solid var(--card-border);
  border-radius: 20px;
  padding: 4px 14px;
  margin-bottom: 14px;
  opacity: 0.75;
}

.story-title {
  font-family: 'Nunito', sans-serif;
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1.05;
  margin-bottom: 8px;
}

.story-subtitle {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-mid);
  margin-bottom: 18px;
  max-width: 280px;
  line-height: 1.55;
}

.scene-image {
  width: 200px;
  height: 200px;
  border-radius: 22px;
  overflow: hidden;
  margin-bottom: 22px;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.6),
    0 8px 28px rgba(0, 0, 0, 0.13);
}

.scene-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.name-prompt {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-mid);
  margin-bottom: 8px;
  text-align: left;
}

.name-input {
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid var(--card-border);
  border-radius: 12px;
  padding: 11px 16px;
  color: var(--text-dark);
  font-family: 'Nunito', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.name-input::placeholder { color: rgba(60, 30, 10, 0.3); }
.name-input:focus { border-color: var(--accent); }

/* =====================
   WIN SCREEN
   ===================== */
#win-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px 20px 32px;
  overflow-y: auto;
}

#win-screen.show { display: flex; }

.win-box {
  max-width: 340px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0.92) translateY(16px); opacity: 0; }
  to   { transform: scale(1) translateY(0);       opacity: 1; }
}

.win-emoji { display: none; }

.win-scene-image {
  width: 220px;
  height: 220px;
  border-radius: 22px;
  overflow: hidden;
  margin-bottom: 6px;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.6),
    0 8px 28px rgba(0, 0, 0, 0.13);
}

.win-scene-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.level-badge {
  display: inline-block;
  background: rgba(196, 92, 24, 0.1);
  border: 1.5px solid rgba(196, 92, 24, 0.3);
  border-radius: 20px;
  padding: 2px 14px;
  color: var(--accent);
  font-weight: 900;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
}

.win-title {
  font-family: 'Nunito', sans-serif;
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1.15;
}

.win-msg {
  color: var(--text-mid);
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 400;
}

.win-stars {
  font-size: 1.6rem;
  letter-spacing: 3px;
}

.win-stats-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.win-stat-item {
  background: rgba(255, 255, 255, 0.6);
  border: 1.5px solid var(--card-border);
  border-radius: 12px;
  padding: 3px 12px;
  color: var(--text-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

.leaderboard {
  background: rgba(255, 255, 255, 0.5);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 14px;
  width: 100%;
  text-align: left;
  min-height: 52px;
}

.lb-title {
  color: var(--accent);
  font-weight: 900;
  font-size: 0.8rem;
  text-align: center;
  margin-bottom: 6px;
}

.lb-entry {
  color: var(--text-dark);
  font-size: 0.83rem;
  font-weight: 700;
  padding: 2px 0;
}

.lb-time    { color: var(--text-mid); font-weight: 400; }
.lb-loading { color: var(--text-mid); font-size: 0.82rem; }
