@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --green:    #4CAF50;
  --green-d:  #2e7d32;
  --green-l:  #66BB6A;
  --sky:      #87CEEB;
  --dirt:     #8B5E3C;
  --stone:    #9E9E9E;
  --cream:    #FFF9E6;
  --gold:     #F9A825;
  --gold-d:   #E65100;
  --red:      #e53935;
  --blue-d:   #263238;
  --pixel:    'Press Start 2P', monospace;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--pixel);
  image-rendering: pixelated;
}

/* ── SCREENS ─────────────────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ── LANDING ─────────────────────────────────────────────────────────────── */
#screen-landing {
  background: linear-gradient(180deg,
    #2a6bbf 0%,
    #4A90D9 30%,
    #87CEEB 56%,
    #87CEEB 60%,
    #5D9C2A 60%,
    #3d6b1a 100%
  );
  justify-content: flex-start;
  overflow-y: auto;
}

#landing-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

.landing-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 28px;
  max-width: 420px;
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  /* push content towards vertical center but not too high */
  margin-top: auto;
  margin-bottom: auto;
}

/* ── HERO PORTRAIT ───────────────────────────────────────────────────────── */
.hero-portrait {
  position: relative;
}

.hero-portrait-frame {
  position: relative;
  width: 120px;
  height: 120px;
  background: #1a1a2e;
  border: 3px solid var(--green);
  box-shadow:
    0 0 0 3px #1a1a1a,
    0 0 0 6px var(--green-d),
    0 0 24px rgba(76, 175, 80, 0.6);
  image-rendering: pixelated;
  flex-shrink: 0;
}

#hero-pixel-canvas {
  display: block;
  width: 120px;
  height: 120px;
  image-rendering: pixelated;
}

/* Grass-block corner ornaments */
.portrait-corner {
  position: absolute;
  width: 14px; height: 14px;
  background: var(--green);
  border: 2px solid var(--green-d);
}
.portrait-corner.tl { top: -5px; left: -5px; }
.portrait-corner.tr { top: -5px; right: -5px; }
.portrait-corner.bl { bottom: -5px; left: -5px; }
.portrait-corner.br { bottom: -5px; right: -5px; }

/* ── TITLE BLOCK ─────────────────────────────────────────────────────────── */
.title-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.age-transition {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.age-arrow {
  font-family: var(--pixel);
  font-size: 48px;
  color: #fff;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.4);
}

.pixel-badge.old {
  background: linear-gradient(135deg, #888 0%, #555 100%);
  border-color: #333;
  text-shadow: 3px 3px 0 #333;
}

.pixel-badge {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #F9A825 0%, #FF8F00 100%);
  border: 4px solid var(--gold-d);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--pixel);
  font-size: 30px;
  color: #fff;
  text-shadow: 3px 3px 0 var(--gold-d);
  box-shadow:
    4px 4px 0 #BF360C,
    0 0 20px rgba(249,168,37,0.6);
  animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { box-shadow: 4px 4px 0 #BF360C, 0 0 20px rgba(249,168,37,0.6); }
  50%       { box-shadow: 4px 4px 0 #BF360C, 0 0 35px rgba(249,168,37,0.9); }
}

.title-main {
  font-family: var(--pixel);
  font-size: clamp(22px, 6.5vw, 34px);
  color: #fff;
  text-align: center;
  text-shadow:
    3px 3px 0 var(--green-d),
    6px 6px 0 #1a4720,
    -1px -1px 0 rgba(0,0,0,0.5);
  line-height: 1.5;
  animation: title-flicker 4s step-end infinite;
}

@keyframes title-flicker {
  0%, 95%, 100% { opacity: 1; }
  96% { opacity: 0.85; }
  97% { opacity: 1; }
  98% { opacity: 0.9; }
}

.title-word {
  display: inline-block;
}

.subtitle {
  font-family: var(--pixel);
  font-size: 8px;
  color: rgba(255,255,255,0.85);
  text-shadow: 1px 1px 0 #000, -1px -1px 0 rgba(0,0,0,0.5);
  text-align: center;
  letter-spacing: 1px;
}

/* ── PARTY DETAILS ───────────────────────────────────────────────────────── */
.party-details {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.detail-block {
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.55) 100%);
  border: 2px solid rgba(255,255,255,0.2);
  border-top: 2px solid rgba(255,255,255,0.35);
  border-bottom: 2px solid rgba(0,0,0,0.5);
  border-radius: 2px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 88px;
  transition: border-color 0.2s, background 0.2s;
}

.detail-block:hover {
  border-color: rgba(249,168,37,0.6);
  background: linear-gradient(180deg, rgba(30,10,0,0.8) 0%, rgba(20,8,0,0.7) 100%);
}

.detail-full {
  width: 100%;
  flex-direction: row;
  gap: 10px;
  justify-content: center;
}

.detail-label {
  font-family: var(--pixel);
  font-size: 6px;
  color: var(--gold);
  letter-spacing: 2px;
}

.detail-value {
  font-family: var(--pixel);
  font-size: 7px;
  color: #fff;
  text-align: center;
  line-height: 1.5;
}

.detail-link {
  color: #64DD17;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── RSVP BLOCK ──────────────────────────────────────────────────────────── */
.rsvp-block {
  width: 100%;
  background: linear-gradient(180deg, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0.5) 100%);
  border: 2px solid rgba(255,255,255,0.15);
  border-top: 2px solid rgba(255,255,255,0.3);
  border-bottom: 2px solid rgba(0,0,0,0.5);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.rsvp-header {
  font-family: var(--pixel);
  font-size: 7px;
  color: var(--gold);
  letter-spacing: 1px;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
}

.rsvp-name-input {
  width: 100%;
  max-width: 100%;
}

.rsvp-counters {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.counter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.counter-label {
  font-family: var(--pixel);
  font-size: 7px;
  color: #ccc;
  min-width: 36px;
}

.btn-counter {
  font-family: var(--pixel);
  font-size: 14px;
  font-weight: bold;
  width: 28px; height: 28px;
  background: #333;
  border: 2px solid #555;
  border-bottom: 2px solid #222;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, transform 0.08s;
}
.btn-counter:active {
  background: #555;
  transform: scale(0.9);
}

.counter-val {
  font-family: var(--pixel);
  font-size: 12px;
  color: #fff;
  min-width: 18px;
  text-align: center;
  transition: color 0.2s;
}

.rsvp-msg {
  font-family: var(--pixel);
  font-size: 6px;
  color: #FF5252;
  text-align: center;
  min-height: 10px;
  letter-spacing: 0.5px;
}

.btn-rsvp {
  background: linear-gradient(180deg, #FF8F00 0%, #E65100 100%);
  border-color: #BF360C;
  border-top-color: #FFA726;
  border-left-color: #FFA726;
  min-width: 160px;
  letter-spacing: 2px;
}
.btn-rsvp:active {
  border-bottom: 2px solid #BF360C;
  border-right: 2px solid #BF360C;
}
.btn-cancel-rsvp {
  background: linear-gradient(180deg, #555 0%, #333 100%);
  border-color: #222;
  border-top-color: #666;
  font-size: 8px;
  margin-top: 4px;
  opacity: 0.75;
}
.btn-cancel-rsvp:hover { opacity: 1; }
.pixel-input.disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── LANDING BUTTONS ─────────────────────────────────────────────────────── */
.landing-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn-pixel {
  font-family: var(--pixel);
  font-size: 11px;
  color: #fff;
  background: var(--green);
  border: none;
  border-bottom: 4px solid var(--green-d);
  border-right: 4px solid var(--green-d);
  border-top: 2px solid var(--green-l);
  border-left: 2px solid var(--green-l);
  padding: 12px 20px;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.06s, box-shadow 0.06s;
  min-width: 180px;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
}

.btn-pixel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.15s;
}

.btn-pixel:active::after {
  background: rgba(255,255,255,0.18);
}

/* Click ripple */
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  width: 10px; height: 10px;
  background: rgba(255,255,255,0.5);
  transform: scale(0);
  animation: ripple-expand 0.4s ease-out forwards;
  pointer-events: none;
}

@keyframes ripple-expand {
  to { transform: scale(20); opacity: 0; }
}

.btn-pixel:active {
  transform: translate(2px, 2px);
  border-bottom: 2px solid var(--green-d);
  border-right: 2px solid var(--green-d);
  border-top: 1px solid var(--green-l);
  border-left: 1px solid var(--green-l);
}

.btn-pixel.btn-secondary {
  background: #455A64;
  border-color: var(--blue-d);
  border-top-color: #607D8B;
  border-left-color: #607D8B;
}
.btn-pixel.btn-secondary:active {
  border-bottom: 2px solid var(--blue-d);
  border-right: 2px solid var(--blue-d);
}

.btn-play-big {
  font-size: 12px;
  padding: 14px 28px;
  background: linear-gradient(180deg, #66BB6A 0%, #43A047 100%);
  min-width: 220px;
  box-shadow: 0 4px 0 var(--green-d), 0 0 20px rgba(76,175,80,0.4);
  letter-spacing: 2px;
}
.btn-play-big:active {
  box-shadow: 0 0 0 var(--green-d), 0 0 8px rgba(76,175,80,0.3);
}

.btn-icon {
  margin-right: 6px;
}

.btn-small {
  font-size: 8px;
  padding: 8px 14px;
  min-width: 80px;
}

/* HUD home button */
.btn-hud-home {
  font-size: 18px;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  width: 34px; height: 34px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border-radius: 2px;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.btn-hud-home:active {
  background: rgba(255,255,255,0.25);
  transform: scale(0.9);
}

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.game-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: rgba(0,0,0,0.75);
  border-bottom: 2px solid rgba(255,255,255,0.1);
  z-index: 10;
  height: 44px;
}

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hud-label {
  font-family: var(--pixel);
  font-size: 6px;
  color: #888;
}

.hud-sep {
  font-family: var(--pixel);
  font-size: 8px;
  color: #555;
}

.hud-value {
  font-family: var(--pixel);
  font-size: 10px;
  color: #fff;
}

.heart {
  font-size: 13px;
  color: var(--red);
  line-height: 1;
  transition: opacity 0.3s, transform 0.2s;
}
.heart.lost { opacity: 0.2; }
.heart.hit-flash {
  animation: heart-shake 0.3s ease;
}

@keyframes heart-shake {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.5); color: #ff8a80; }
}

/* ── GAME CANVAS ─────────────────────────────────────────────────────────── */
#screen-game {
  background: #87CEEB;
  justify-content: flex-start;
}

#game-canvas {
  width: 100%;
  flex: 1;
  margin-top: 44px;
  display: block;
  image-rendering: pixelated;
}

.touch-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--pixel);
  font-size: 7px;
  color: rgba(255,255,255,0.65);
  text-shadow: 1px 1px 0 #000;
  white-space: nowrap;
  pointer-events: none;
  animation: hint-fade 3s ease 2s forwards;
}

@keyframes hint-fade {
  to { opacity: 0; }
}

/* ── LEVEL BANNER ────────────────────────────────────────────────────────── */
.level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  border: 3px solid var(--gold);
  border-top: 3px solid #FFD54F;
  padding: 16px 28px;
  font-family: var(--pixel);
  font-size: 18px;
  color: var(--gold);
  text-align: center;
  z-index: 20;
  pointer-events: none;
  text-shadow: 2px 2px 0 #000;
  box-shadow: 0 0 30px rgba(249,168,37,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  animation: banner-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.level-banner.hidden { display: none; }

@keyframes banner-pop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ── OVERLAY SCREENS ─────────────────────────────────────────────────────── */
#screen-gameover {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(229,57,53,0.25) 0%, transparent 60%),
    #0a0a0a;
}

#screen-win {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(249,168,37,0.3) 0%, transparent 60%),
    linear-gradient(135deg, #1a237e 0%, #311b92 50%, #1b5e20 100%);
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 24px;
  max-width: 380px;
  width: 100%;
}

.pixel-title {
  font-family: var(--pixel);
  font-size: clamp(18px, 5.5vw, 26px);
  color: #fff;
  text-shadow: 3px 3px 0 var(--red);
  text-align: center;
  line-height: 1.5;
}

.go-title {
  animation: go-flash 0.8s step-end infinite;
}

@keyframes go-flash {
  0%, 49% { color: #fff; }
  50%, 100% { color: #ff5252; }
}

.win-title {
  text-shadow: 3px 3px 0 #FF8F00;
  color: #FFD54F;
  animation: win-glow 1.5s ease-in-out infinite;
}

@keyframes win-glow {
  0%, 100% { text-shadow: 3px 3px 0 #FF8F00, 0 0 20px rgba(255,213,79,0.4); }
  50%       { text-shadow: 3px 3px 0 #FF8F00, 0 0 40px rgba(255,213,79,0.8); }
}

.lb-title {
  text-shadow: 3px 3px 0 #1565C0;
  color: #90CAF9;
}

/* ── STATS ROW ───────────────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.stat-box {
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(255,255,255,0.15);
  border-bottom: 2px solid rgba(0,0,0,0.4);
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 90px;
}

.stat-box.stat-gold {
  border-color: rgba(249,168,37,0.5);
  background: rgba(249,168,37,0.08);
}

.stat-label {
  font-family: var(--pixel);
  font-size: 6px;
  color: #888;
  letter-spacing: 2px;
}

.stat-val {
  font-family: var(--pixel);
  font-size: 20px;
  color: var(--gold);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
}

.go-score, .go-level, .win-sub {
  font-family: var(--pixel);
  font-size: 9px;
  color: #ddd;
  text-align: center;
}

.go-score span, .go-level span {
  color: var(--gold);
}

.cake-emoji {
  font-size: 52px;
  line-height: 1;
  animation: cake-bounce 1s ease-in-out infinite;
}

@keyframes cake-bounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%       { transform: translateY(-8px) rotate(3deg); }
}

.win-content { gap: 12px; }

/* ── NAME ENTRY ──────────────────────────────────────────────────────────── */
.name-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.name-prompt {
  font-family: var(--pixel);
  font-size: 7px;
  color: #999;
}

.pixel-input {
  font-family: var(--pixel);
  font-size: 11px;
  color: #fff;
  background: #111;
  border: 2px solid #333;
  border-bottom: 2px solid #555;
  padding: 10px 14px;
  width: 100%;
  max-width: 260px;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pixel-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(76,175,80,0.3);
}

.saved-msg {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--green);
  animation: saved-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.saved-msg.hidden { display: none; }

@keyframes saved-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ── GO ACTIONS ──────────────────────────────────────────────────────────── */
.go-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── LEADERBOARD ─────────────────────────────────────────────────────────── */
#screen-leaderboard {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(100,181,246,0.2) 0%, transparent 60%),
    #060d1a;
}

.lb-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 20px;
  width: 100%;
  max-width: 420px;
  max-height: 100vh;
  overflow-y: auto;
}

.lb-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb-loading {
  font-family: var(--pixel);
  font-size: 8px;
  color: #444;
  text-align: center;
  padding: 24px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-left: 3px solid rgba(255,255,255,0.1);
  padding: 10px 12px;
  transition: background 0.15s;
}
.lb-row:hover {
  background: rgba(255,255,255,0.08);
}

.lb-row.rank-1 { border-left-color: #FFD700; background: rgba(255,215,0,0.06); }
.lb-row.rank-2 { border-left-color: #C0C0C0; background: rgba(192,192,192,0.04); }
.lb-row.rank-3 { border-left-color: #CD7F32; background: rgba(205,127,50,0.04); }

.lb-rank {
  font-family: var(--pixel);
  font-size: 8px;
  color: #444;
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}
.lb-row.rank-1 .lb-rank { color: #FFD700; }
.lb-row.rank-2 .lb-rank { color: #C0C0C0; }
.lb-row.rank-3 .lb-rank { color: #CD7F32; }

.lb-mob {
  width: 24px; height: 24px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.lb-name {
  font-family: var(--pixel);
  font-size: 8px;
  color: #fff;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--gold);
  flex-shrink: 0;
}

.lb-level {
  font-family: var(--pixel);
  font-size: 6px;
  color: var(--green);
  flex-shrink: 0;
}
