:root {
  --color-primary: #ff5da2;
  --color-primary-dark: #e6408a;
  --color-accent: #ffd23f;
  --color-blue: #2ec4f1;
  --color-ink: #2b2140;
  --color-card: #ffffff;
  --font-heading: 'Fredoka', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--color-ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 93, 162, 0.24), transparent 42%),
    radial-gradient(circle at 88% 12%, rgba(46, 196, 241, 0.22), transparent 40%),
    radial-gradient(circle at 18% 88%, rgba(255, 210, 63, 0.28), transparent 42%),
    radial-gradient(circle at 92% 82%, rgba(79, 184, 95, 0.2), transparent 42%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.5), transparent 60%),
    linear-gradient(160deg, #fff6ea 0%, #ffe6cf 100%);
  background-attachment: fixed;
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.screen.active {
  display: flex;
}

h1, h2 {
  font-family: var(--font-heading);
  margin: 0 0 12px;
}

/* ---------- INTRO ---------- */

#screen-intro {
  overflow-y: auto;
  justify-content: flex-start;
  padding-top: 32px;
  padding-bottom: 32px;
}

.intro-content {
  max-width: 480px;
  width: 100%;
  text-align: center;
  margin: 0 auto;
}

.intro-content h1 {
  font-size: 2.2rem;
  color: var(--color-primary-dark);
}

.hero-car {
  width: 100%;
  max-width: 380px;
  margin: 8px auto 16px;
  animation: drive-in 1s ease-out;
}

.hero-car img {
  width: 100%;
  height: auto;
  display: block;
}

.hero-car .img-fallback {
  font-size: 5rem;
  padding: 30px 0;
}

@keyframes drive-in {
  from { transform: translateX(-120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.intro-text {
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0 0 20px;
}

.instructions {
  background: var(--color-card);
  border: 3px solid var(--color-ink);
  border-radius: 18px;
  padding: 16px 18px;
  text-align: left;
  margin-bottom: 24px;
  box-shadow: 5px 5px 0 rgba(43,33,64,0.15);
}

.instructions h2 {
  font-size: 1.2rem;
  text-align: center;
  color: var(--color-primary-dark);
}

.instructions ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.instructions li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 0;
  line-height: 1.4;
}

.instructions .ico {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.btn-primary {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  color: #fff;
  background: var(--color-primary);
  border: 3px solid var(--color-ink);
  border-radius: 999px;
  padding: 14px 36px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--color-ink);
  transition: transform 0.1s ease;
}

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

.intro-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.corner-character {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 92px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.corner-character img,
.corner-character .img-fallback {
  width: 92px;
  height: 92px;
  object-fit: contain;
  animation: bob 2.4s ease-in-out infinite;
}

.corner-character .img-fallback {
  font-size: 3.4rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.corner-caption {
  position: relative;
  z-index: 2;
  margin-top: -26px;
  background: var(--color-primary);
  color: #fff;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 3px 16px;
  border-radius: 999px;
  border: 2px solid var(--color-ink);
  white-space: nowrap;
}

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

/* ---------- KINGA IN THE GAME HUD ---------- */
/* Lives between the fuel and ball counters, up top — out of the way of the
   touch controls at the bottom of the screen on mobile. */

.kinga-hud {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.kinga-hud-avatar,
.kinga-hud .img-fallback {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 4px solid var(--color-ink);
  box-shadow: 3px 3px 0 rgba(43, 33, 64, 0.15);
  animation: bob 2.4s ease-in-out infinite;
}

.kinga-hud .img-fallback {
  font-size: 2.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kinga-hud-caption {
  position: relative;
  z-index: 2;
  margin-top: -12px;
  background: var(--color-primary);
  color: #fff;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 2px 12px;
  border-radius: 999px;
  border: 2px solid var(--color-ink);
  white-space: nowrap;
}

/* ---------- GAME ---------- */

#screen-game {
  padding: 10px;
  justify-content: flex-start;
}

.hud {
  position: relative;
  z-index: 20;
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  background: var(--color-card);
  border: 3px solid var(--color-ink);
  border-radius: 999px;
  padding: 6px 14px;
}

.fuel-wrap {
  flex: 1;
}

.fuel-bar {
  flex: 1;
  height: 14px;
  background: #eee;
  border: 2px solid var(--color-ink);
  border-radius: 999px;
  overflow: hidden;
}

.fuel-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffd23f, #ff8a3d);
  transition: width 0.15s linear, background 0.3s ease;
}

.fuel-fill.low {
  background: linear-gradient(90deg, #ff5d5d, #d92626);
  animation: fuel-pulse 0.8s ease-in-out infinite;
}

@keyframes fuel-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.hud-sep {
  opacity: 0.5;
}

.ball-progress-row {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ball-progress-label {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  background: var(--color-card);
  border: 3px solid var(--color-ink);
  border-radius: 999px;
  padding: 5px 12px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 5.5rem;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 3px var(--color-ink);
  paint-order: stroke fill;
  z-index: 10;
  pointer-events: none;
}

.countdown-overlay.pop {
  animation: countdown-pop 0.8s ease-out;
}

@keyframes countdown-pop {
  0% { transform: scale(0.3); opacity: 0; }
  35% { transform: scale(1.15); opacity: 1; }
  65% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0; }
}

#game-canvas {
  background: #6bbf59;
  border: 4px solid var(--color-ink);
  border-radius: 14px;
  box-shadow: 5px 5px 0 rgba(43,33,64,0.15);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

.touch-controls {
  width: 100%;
  max-width: 420px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.btn-touch {
  flex: 1;
  font-size: 1.8rem;
  padding: 14px 0;
  background: var(--color-blue);
  color: #fff;
  border: 3px solid var(--color-ink);
  border-radius: 16px;
  box-shadow: 4px 4px 0 var(--color-ink);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

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

/* ---------- CARDS (retry / win) ---------- */

.card {
  position: relative;
  z-index: 2;
  max-width: 440px;
  width: 100%;
  background: var(--color-card);
  border: 3px solid var(--color-ink);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 6px 6px 0 rgba(43,33,64,0.15);
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0.4; }
}

#screen-retry h2 {
  color: #d92626;
}

#retry-message {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.retry-stat {
  margin: 0 0 22px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}

/* ---------- SHARED LEADERBOARD ---------- */

.score-submit {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.player-name-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 14px;
  border: 3px solid var(--color-ink);
  border-radius: 999px;
  outline: none;
}

.player-name-input:focus {
  border-color: var(--color-primary);
}

.btn-secondary {
  flex-shrink: 0;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  color: var(--color-ink);
  background: var(--color-accent);
  border: 3px solid var(--color-ink);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--color-ink);
  transition: transform 0.1s ease;
}

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

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: default;
}

.submit-status {
  min-height: 1.2em;
  margin: 0 0 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary-dark);
}

.leaderboard-title {
  font-size: 1.05rem;
  color: var(--color-primary-dark);
}

.leaderboard {
  text-align: left;
  background: rgba(255, 255, 255, 0.6);
  border: 3px solid var(--color-ink);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.leaderboard-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.leaderboard-tab {
  flex: 1;
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--color-ink);
  background: #fff;
  border: 2px solid var(--color-ink);
  border-radius: 999px;
  padding: 6px 4px;
  cursor: pointer;
  white-space: nowrap;
}

.leaderboard-tab.active {
  background: var(--color-primary);
  color: #fff;
}

.leaderboard-list {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.leaderboard-list.active {
  display: block;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  font-size: 0.9rem;
  border-bottom: 1px dashed rgba(43, 33, 64, 0.15);
}

.leaderboard-list li:last-child {
  border-bottom: none;
}

.leaderboard-rank {
  flex-shrink: 0;
  width: 20px;
  font-weight: 700;
  opacity: 0.6;
}

.leaderboard-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.leaderboard-score {
  flex-shrink: 0;
  font-family: var(--font-heading);
  color: var(--color-primary-dark);
}

.leaderboard-empty {
  opacity: 0.6;
  font-style: italic;
  text-align: center;
}

@media (max-width: 480px) {
  .intro-content h1 { font-size: 1.8rem; }
  .corner-character { width: 84px; height: 84px; }
}
