:root {
  --cream: #FFF6E9;
  --sky: #BDE3FF;
  --asphalt: #454B5C;
  --asphalt-dark: #3A3F4E;
  --ink: #33323E;
  --muted: #B0A896;
  --green: #5CB85C;
  --amber: #F5A623;
  --red: #E5533C;
  --purple: #8E6FC8;
  --night: #232842;
  --card-shadow: 0 3px 0 rgba(0, 0, 0, .08);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Baloo 2', sans-serif;
  color: var(--ink);
  background: var(--cream);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.screen {
  display: none;
  min-height: 100%;
  min-height: 100dvh;
  flex-direction: column;
}
.screen.active { display: flex; }

#app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: none;
  color: inherit;
}

/* ---------- HOME ---------- */
#screen-home {
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky) 29%, var(--cream) 29.2%);
}
.skyart { position: relative; height: 196px; flex-shrink: 0; }
.sun {
  position: absolute; top: 24px; right: 28px; width: 56px; height: 56px; border-radius: 50%;
  background: #FFD34E; box-shadow: 0 0 0 11px rgba(255, 211, 78, .35);
}
.cloud { position: absolute; background: #fff; border-radius: 20px; opacity: .9; }
.cloud.c1 { width: 74px; height: 22px; top: 40px; left: 30px; }
.cloud.c1::after {
  content: ''; position: absolute; width: 34px; height: 26px;
  background: #fff; border-radius: 50%; top: -13px; left: 18px;
}
.cloud.c2 { width: 52px; height: 16px; top: 92px; left: 140px; opacity: .7; }
.homeroad { position: absolute; bottom: 0; left: 0; right: 0; height: 74px; background: var(--asphalt); }
.homeroad::before {
  content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 4px; margin-top: -2px;
  background: repeating-linear-gradient(90deg, #FFD34E 0 22px, transparent 22px 40px);
}
.homeroad .rv { position: absolute; bottom: 13px; filter: drop-shadow(0 3px 2px rgba(0,0,0,.3)); }
.homeroad .rv svg { display: block; }

.title-wrap { text-align: center; margin-top: 14px; padding: 0 20px; }
.title {
  font-family: 'Lilita One', cursive;
  font-size: clamp(32px, 9.6vw, 40px);
  line-height: .95;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .12);
}
.title .accent { color: var(--red); }
.subtitle { font-weight: 600; font-size: 15px; color: #7A7466; margin-top: 7px; }

.diffs { padding: 16px 18px 0; display: flex; flex-direction: column; gap: 10px; }
.diff {
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 18px;
  padding: 10px 14px; box-shadow: var(--card-shadow); text-align: left; width: 100%;
  transition: transform .1s;
}
.diff:active { transform: scale(.97); }
.diff .dot {
  width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center;
  justify-content: center; font-size: 23px; flex-shrink: 0;
}
.diff .info { flex: 1; }
.diff .name { font-weight: 800; font-size: 18px; line-height: 1.1; }
.bar { height: 7px; border-radius: 4px; background: #EFE7D8; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; width: 0; }
.diff .count { font-weight: 800; font-size: 13.5px; color: var(--muted); }
.d-rookie .dot { background: #E3F4DF; } .d-rookie .bar i { background: var(--green); }
.d-driver .dot { background: #FDEFD2; } .d-driver .bar i { background: var(--amber); }
.d-expert .dot { background: #FBDFDA; } .d-expert .bar i { background: var(--red); }
.d-master .dot { background: #EAE2F6; } .d-master .bar i { background: var(--purple); }
.home-foot {
  text-align: center; padding: 14px 0 20px; font-size: 13px; font-weight: 700; color: var(--muted);
  margin-top: auto;
}

/* ---------- LEVEL SELECT ---------- */
#screen-levels { background: var(--cream); }
.lv-head {
  display: flex; align-items: center; gap: 12px; padding: 22px 18px 6px;
}
.btn-round {
  width: 42px; height: 42px; border-radius: 14px; background: #fff;
  box-shadow: var(--card-shadow); display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 800; color: #8A8375; flex-shrink: 0;
  transition: transform .1s;
}
.btn-round:active { transform: scale(.92); }
.lv-head .lv-title { font-weight: 800; font-size: 23px; line-height: 1; }
.lv-head .lv-sub { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.lv-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding: 14px 18px 30px;
}
.lv-btn {
  aspect-ratio: 1; border-radius: 16px; background: #fff; box-shadow: var(--card-shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; color: var(--ink); gap: 1px;
  transition: transform .1s;
}
.lv-btn:active { transform: scale(.92); }
.lv-btn .pips { font-size: 8.5px; letter-spacing: 1px; color: #E2D9C6; }
.lv-btn.done { background: #FFF9EC; box-shadow: 0 3px 0 rgba(219, 180, 60, .35); }
.lv-btn.done .pips { color: #F5B301; }

/* ---------- PLAY ---------- */
#screen-play { background: var(--cream); }
.hud { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 8px; }
.hud .mid { text-align: center; }
.hud .mid .pz { font-weight: 800; font-size: 19px; line-height: 1; }
.hud .mid .lvl { font-size: 11.5px; font-weight: 700; letter-spacing: .14em; }
.lvl.c-rookie { color: var(--green); }
.lvl.c-driver { color: var(--amber); }
.lvl.c-expert { color: var(--red); }
.lvl.c-master { color: var(--purple); }
.moves-chip {
  text-align: center; background: #fff; border-radius: 14px; padding: 4px 12px;
  box-shadow: var(--card-shadow); min-width: 58px;
}
.moves-chip b { display: block; font-size: 20px; line-height: 1; }
.moves-chip span { font-size: 10px; font-weight: 700; letter-spacing: .1em; color: var(--muted); }

.board-zone { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 24px; }
.board-wrap { position: relative; margin: 0 auto; }
.board {
  position: relative; background: var(--asphalt); border-radius: 18px;
  box-shadow: inset 0 0 0 4px var(--asphalt-dark), 0 6px 0 rgba(0, 0, 0, .12);
  touch-action: none;
}
.cell {
  position: absolute; border-radius: 8px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .05);
}
.exit {
  position: absolute; background: var(--cream); border-radius: 0 8px 8px 0;
}
.exit .flag {
  position: absolute; right: -6px; top: 50%; transform: translateY(-50%); font-size: 20px;
}
.veh {
  position: absolute; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35));
  display: flex; align-items: center; justify-content: center;
  will-change: transform;
  touch-action: none;
}
.veh svg { display: block; flex-shrink: 0; pointer-events: none; }
.veh.vert svg { transform: rotate(90deg); }
.veh.dragging { filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .45)); z-index: 5; }
.veh.hero-exit { transition: left .55s cubic-bezier(.5, 0, .9, .6); }

.play-foot { display: flex; justify-content: center; gap: 12px; padding-bottom: 8px; }
.pill {
  background: #fff; border-radius: 16px; padding: 10px 24px; font-weight: 800; font-size: 15px;
  color: var(--ink); box-shadow: 0 3.5px 0 rgba(0, 0, 0, .1);
  display: flex; align-items: center; gap: 8px; transition: transform .1s;
}
.pill:active { transform: scale(.94); }
.best-note {
  text-align: center; padding: 12px 0 22px; font-size: 13px; font-weight: 700; color: var(--muted);
}

/* ---------- VICTORY ---------- */
#victory {
  position: fixed; inset: 0; z-index: 50; display: none;
  flex-direction: column; align-items: center; overflow: hidden;
  background: radial-gradient(140% 90% at 50% 0%, #35406B 0%, var(--night) 60%);
  opacity: 0; transition: opacity .35s;
}
#victory.show { display: flex; }
#victory.visible { opacity: 1; }
.v-inner {
  width: 100%; max-width: 440px; margin: 0 auto; flex: 1;
  display: flex; flex-direction: column; align-items: center; position: relative;
}
.bunting { position: absolute; top: 0; left: 0; right: 0; height: 54px; }
.bunting span {
  position: absolute; top: 0; width: 26px; height: 34px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.confetti-piece {
  position: absolute; border-radius: 2px; top: -20px;
  animation: confetti-fall linear infinite;
}
@keyframes confetti-fall {
  0% { transform: translateY(-20px) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(720deg); }
}
.win-title {
  font-family: 'Lilita One', cursive; font-size: clamp(38px, 12vw, 48px); color: #FFD34E;
  margin-top: 84px; text-shadow: 0 4px 0 rgba(0, 0, 0, .3); transform: rotate(-2deg);
  animation: pop-in .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
.win-sub { color: #AEB6DA; font-weight: 700; font-size: 15px; margin-top: 4px; }
.stars { display: flex; gap: 10px; margin-top: 20px; align-items: flex-start; height: 60px; }
.stars .s {
  font-size: 38px; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .3));
  animation: pop-in .4s cubic-bezier(.2, 1.6, .4, 1) both;
}
.stars .s.mid { font-size: 58px; margin-top: -12px; }
.stars .s.off { filter: grayscale(1) opacity(.28); }
.stars .s:nth-child(1) { animation-delay: .15s; }
.stars .s:nth-child(2) { animation-delay: .3s; }
.stars .s:nth-child(3) { animation-delay: .45s; }
@keyframes pop-in {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}
.win-car {
  margin-top: 16px; transform: rotate(-3deg);
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .5));
  animation: drive-in .5s cubic-bezier(.2, 1.2, .4, 1) both .2s;
}
@keyframes drive-in {
  0% { transform: translateX(-120vw) rotate(-3deg); }
  100% { transform: translateX(0) rotate(-3deg); }
}
.win-stats { display: flex; gap: 12px; margin-top: 26px; }
.stat {
  background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 16px; padding: 8px 18px; text-align: center; color: #fff; min-width: 78px;
}
.stat b { display: block; font-size: 20px; line-height: 1.05; }
.stat span { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; color: #AEB6DA; }
.win-cta {
  margin-top: 28px; background: var(--green); color: #fff; font-weight: 800; font-size: 19px;
  padding: 14px 42px; border-radius: 20px; box-shadow: 0 5px 0 #3C8C3C; transition: transform .1s;
}
.win-cta:active { transform: scale(.95); }
.win-row { display: flex; gap: 14px; margin-top: 18px; padding-bottom: 30px; }
.win-mini {
  width: 48px; height: 48px; border-radius: 16px; background: rgba(255, 255, 255, .1);
  border: 2px solid rgba(255, 255, 255, .16); display: flex; align-items: center;
  justify-content: center; font-size: 20px; color: #fff; transition: transform .1s;
}
.win-mini:active { transform: scale(.9); }
