/* Physics Track Racing — flat retro-80s sunset poster UI (magenta / orange / teal / deep purple). */
:root {
  --ink: #1e0b3a; --plum: #2b1055; --violet: #5b1f8f; --pink: #ff3d8b; --orange: #ff8a3d;
  --sun: #ffd23f; --teal: #1fc8b8; --lime: #b8f25b; --cream: #fff4dc;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--plum); color: var(--cream);
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; background: var(--plum); }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; touch-action: none; display: block; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(30, 11, 58, 0.72); animation: fade .2s ease;
}
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.85) translateY(10px); opacity: 0 } to { transform: none; opacity: 1 } }

.loader { text-align: center; font-size: 24px; font-weight: 800; }
.sunload {
  width: 90px; height: 90px; margin: 0 auto 10px; border-radius: 50%;
  background: repeating-linear-gradient(180deg, var(--sun) 0 12px, var(--orange) 12px 18px, var(--pink) 18px 22px);
  animation: rise 1.2s ease-in-out infinite alternate; box-shadow: 0 0 0 6px var(--ink);
}
@keyframes rise { to { transform: translateY(-10px) } }

/* ---------------------------------------------------------------- buttons (flat poster style) */
.btn {
  font: inherit; font-weight: 800; font-size: 20px; color: var(--ink); cursor: pointer; position: relative;
  border: 3px solid var(--ink); border-radius: 14px; padding: 8px 22px 10px;
  box-shadow: 0 5px 0 var(--ink); transition: transform .07s, filter .15s; background: var(--cream);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { filter: grayscale(.9) brightness(.75); cursor: not-allowed; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.teal { background: var(--teal); }
.btn.sun { background: var(--sun); }
.btn.lime { background: var(--lime); }
.btn.orange { background: var(--orange); }
.btn.plum { background: var(--violet); color: #fff; }
.btn.icon { padding: 8px 14px 10px; }
.btn.off { opacity: .45; }
.btn.big { font-size: 24px; padding: 10px 28px 12px; }
.btn small { display: block; font-size: 14px; font-weight: 700; opacity: .85; white-space: nowrap; }
.btn .badge {
  position: absolute; top: -10px; right: -10px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  background: var(--pink); color: #fff; font-size: 15px; line-height: 21px; border: 3px solid var(--ink);
}
.continue { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { filter: brightness(1.15); transform: translateY(-2px); } }

/* ---------------------------------------------------------------- menu */
.menu {
  justify-content: flex-start; padding-top: 22px; gap: 12px;
  background: linear-gradient(180deg, rgba(30,11,58,.25), rgba(30,11,58,.35) 45%, rgba(30,11,58,.82));
}
.menu-head { width: 1200px; display: flex; justify-content: space-between; align-items: flex-start; }
.logo { display: flex; flex-direction: column; line-height: .82; transform: rotate(-4deg); transform-origin: left center; margin-left: 6px; }
.logo .l1 {
  font-size: 34px; font-weight: 800; letter-spacing: 12px; color: var(--teal);
  text-shadow: 3px 3px 0 var(--ink); padding-left: 6px;
}
.logo .l2 {
  font-size: 76px; font-weight: 800; font-style: italic; letter-spacing: 1px;
  background: repeating-linear-gradient(180deg, #fff6c2 0 18%, var(--sun) 18% 42%, var(--orange) 42% 62%, var(--pink) 62% 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 3px var(--ink); filter: drop-shadow(6px 6px 0 var(--ink));
}
.head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chips { display: flex; gap: 8px; }
.chip {
  font-size: 22px; font-weight: 800; background: var(--ink); border: 3px solid rgba(255,255,255,.18);
  padding: 3px 14px; border-radius: 30px; white-space: nowrap;
}
.chip b { color: var(--sun); }
.chip.streak b { color: var(--orange); }

.world-tabs { display: flex; gap: 10px; width: 1200px; }
.wtab {
  font: inherit; font-weight: 800; font-size: 19px; cursor: pointer; color: #fff; flex: 1;
  border: 3px solid var(--ink); border-radius: 14px; padding: 6px 14px; text-align: left; position: relative; overflow: hidden;
  background-size: cover; background-position: center 38%; box-shadow: 0 4px 0 var(--ink); text-shadow: 2px 2px 0 var(--ink);
  min-height: 62px;
}
.wtab .wname { display: block; line-height: 1.15; padding-right: 30px; }
.wtab small { display: block; font-size: 15px; color: var(--sun); }
.wtab.on { outline: 4px solid var(--sun); outline-offset: -1px; }
.wtab.locked { filter: grayscale(.85) brightness(.55); cursor: not-allowed; }
.wtab .lock { position: absolute; right: 12px; top: 14px; font-size: 26px; }

.tracks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; width: 1200px; }
.track {
  position: relative; background: rgba(30,11,58,.86); border: 3px solid var(--ink); border-radius: 16px;
  padding: 8px 14px 10px; cursor: pointer; box-shadow: 0 5px 0 var(--ink); transition: transform .12s;
  animation: pop .25s ease both; min-height: 116px; overflow: hidden;
}
.track::before {
  content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%;
  background: repeating-linear-gradient(180deg, var(--sun) 0 14px, var(--orange) 14px 22px, var(--pink) 22px 28px); opacity: .22;
}
.track:hover:not(.locked) { transform: translateY(-4px); border-color: var(--sun); }
.track.last { border-color: var(--teal); }
.track .num { font-size: 15px; font-weight: 800; color: var(--teal); }
.track .nm { font-size: 22px; font-weight: 800; line-height: 1.1; margin: 1px 0 4px; position: relative; overflow-wrap: anywhere; }
.track .st { font-size: 24px; letter-spacing: 2px; color: var(--sun); line-height: 1; }
.track .st .off { color: rgba(255,255,255,.18); }
.track .best { font-size: 15px; color: #d9c8ff; padding-right: 64px; line-height: 1.2; }
.track .goal { position: absolute; right: 12px; bottom: 10px; font-size: 13px; color: rgba(255,255,255,.55); text-align: right; line-height: 1.2; }
.track.locked { cursor: not-allowed; filter: grayscale(.8) brightness(.55); }
.track.locked .nm::after { content: ' 🔒'; }
.track .ghost { position: absolute; right: 12px; top: 8px; font-size: 13px; color: #e0d4ff; }

.menu-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 4px; max-width: 1200px; }
.menu-row.small { justify-content: center; margin-top: 12px; }

/* ---------------------------------------------------------------- modals */
.modal {
  background: var(--plum); border: 4px solid var(--ink); border-radius: 24px; padding: 22px 32px;
  min-width: 440px; max-width: 1100px; text-align: center; box-shadow: 10px 10px 0 var(--ink), 0 0 0 3px rgba(255,255,255,.08) inset;
  animation: pop .22s ease both; position: relative;
  background-image: radial-gradient(rgba(255,255,255,.05) 1.5px, transparent 1.6px); background-size: 14px 14px;
}
.modal.wide { width: 900px; }
.modal h2 { margin: 0 0 6px; font-size: 44px; line-height: 1.05; color: var(--sun); text-shadow: 4px 4px 0 var(--ink); font-style: italic; }
.modal .sub { margin: 0 0 8px; color: #d9c8ff; font-size: 18px; }
.modal .sub.small { font-size: 14px; max-width: 320px; margin: 12px auto 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }

.rows { display: grid; gap: 10px; margin-top: 10px; text-align: left; }
.row { display: grid; grid-template-columns: 50px 1fr auto; gap: 14px; align-items: center; background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.08); border-radius: 14px; padding: 8px 14px; }
.row .ic { font-size: 30px; text-align: center; }
.row .nm { font-size: 20px; font-weight: 800; }
.row .ds { color: #d9c8ff; font-size: 15px; }
.row .btn { font-size: 17px; padding: 5px 14px 7px; min-width: 124px; }
.prog { height: 10px; border-radius: 5px; background: rgba(0,0,0,.35); overflow: hidden; margin-top: 4px; }
.prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--orange)); }

/* garage */
.garage { width: 1100px; padding: 14px 26px 16px; }
.garage .actions { margin-top: 10px; }
.garage-body { display: grid; grid-template-columns: 330px 1fr; gap: 18px; margin-top: 8px; text-align: left; }
.veh-list { display: grid; gap: 8px; align-content: start; }
.veh {
  display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; cursor: pointer;
  background: rgba(255,255,255,.05); border: 3px solid rgba(255,255,255,.08); border-radius: 14px; padding: 4px 10px;
}
.veh.on { border-color: var(--sun); background: rgba(255,210,63,.1); }
.veh.sel .nm::after { content: ' ✓'; color: var(--lime); }
.veh img, .veh canvas { width: 110px; height: 55px; object-fit: contain; }
.veh .nm { font-weight: 800; font-size: 19px; }
.veh .ds { font-size: 14px; color: #d9c8ff; }
.veh.locked img { filter: brightness(0) opacity(.5); }
.veh-detail { background: rgba(0,0,0,.18); border-radius: 18px; padding: 10px 18px 14px; }
.veh-detail .hero { display: flex; gap: 16px; align-items: center; }
.veh-detail .hero > div { flex: 1; min-width: 0; }
.veh-detail .hero img { flex: none; width: 270px; height: 135px; object-fit: contain; filter: drop-shadow(5px 5px 0 var(--ink)); }
.veh-detail h3 { margin: 0; font-size: 34px; color: var(--sun); font-style: italic; text-shadow: 3px 3px 0 var(--ink); }
.veh-detail .ds { color: #d9c8ff; font-size: 16px; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 15px; margin-top: 6px; }
.bars span { white-space: nowrap; }
.bars i { display: flex; gap: 3px; align-items: center; }
.bars i b { width: 26px; height: 9px; border-radius: 3px; background: rgba(255,255,255,.12); }
.bars i b.on { background: var(--teal); }
.upg { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; margin-top: 6px; background: rgba(255,255,255,.05); border-radius: 12px; padding: 4px 10px; }
.upg .nm, .veh .nm { line-height: 1.2; }
.upg .ic { font-size: 26px; text-align: center; }
.upg .nm { font-weight: 800; font-size: 18px; }
.upg .ds { font-size: 13px; }
.pips { display: inline-flex; gap: 3px; margin-left: 8px; vertical-align: middle; }
.pips i { width: 16px; height: 9px; border-radius: 3px; background: rgba(255,255,255,.14); }
.pips i.on { background: var(--orange); }
.upg .btn { font-size: 16px; padding: 4px 12px 6px; min-width: 112px; }
.veh-cta { margin-top: 10px; display: flex; gap: 10px; align-items: center; }

/* language picker */
.lang-btn .lang-code { font-size: 15px; vertical-align: 2px; }
.lang-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.lang-grid .btn { font-size: 18px; padding: 6px 12px 8px; white-space: nowrap; }

/* daily */
.daily-info { display: grid; gap: 6px; font-size: 18px; margin: 6px 0; }
.daily-info b { color: var(--sun); }

/* how to */
.howto { text-align: left; font-size: 18px; line-height: 1.4; }
.keys-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; margin: 8px 0 10px; }
.keys-grid div { display: flex; align-items: center; gap: 6px; }
.keys-grid kbd { flex: none; white-space: nowrap; }
.keys-grid span { margin-left: 4px; }
.howto ul { margin: 8px 0; padding-left: 22px; }
.howto li { margin: 5px 0; }
kbd { background: var(--ink); border: 2px solid rgba(255,255,255,.25); border-radius: 7px; padding: 0 8px; font-family: inherit; font-weight: 800; color: #fff; min-width: 30px; text-align: center; display: inline-block; }
.touchicon { font-size: 22px; }

/* result */
.result { min-width: 560px; }
.stars { font-size: 72px; letter-spacing: 10px; line-height: 1; margin: 2px 0 6px; }
.stars span { display: inline-block; color: var(--sun); text-shadow: 4px 4px 0 var(--ink); animation: pop .4s ease both; }
.stars span.off { color: rgba(255,255,255,.15); text-shadow: none; }
.rtime { font-size: 40px; font-weight: 800; line-height: 1; }
.rtime small { display: block; font-size: 17px; color: #d9c8ff; font-weight: 700; margin-top: 4px; }
.rtime .rec { color: var(--lime); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 8px; }
.stats div { background: rgba(255,255,255,.07); border-radius: 12px; padding: 4px 8px; }
.stats b { display: block; font-size: 24px; color: var(--teal); }
.stats small { color: #d9c8ff; font-size: 14px; }
.rcoins { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; font-size: 16px; }
.rcoins span { background: rgba(0,0,0,.25); border-radius: 10px; padding: 2px 10px; }
.rcoins .tot { background: var(--sun); color: var(--ink); font-weight: 800; font-size: 20px; }
.result-extra { font-size: 16px; display: grid; gap: 3px; margin-top: 8px; }
.result-extra .q { color: var(--lime); }
.result-extra .goal { color: var(--sun); }

/* toast + tutorial */
.toast {
  position: absolute; top: 150px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--sun); color: var(--ink); font-weight: 800; font-size: 20px; border: 3px solid var(--ink);
  padding: 8px 22px; border-radius: 14px; box-shadow: 0 5px 0 var(--ink); animation: pop .25s ease both; pointer-events: none;
  width: max-content; max-width: 900px; text-align: center;
}
.tut {
  position: absolute; top: 118px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: 760px; text-align: center;
  background: rgba(30,11,58,.9); border: 3px solid var(--teal); color: #fff; font-weight: 800; font-size: 24px;
  padding: 10px 26px; border-radius: 18px; box-shadow: 0 6px 0 var(--ink); animation: pop .25s ease both;
}
.tut small { display: block; font-size: 15px; color: #d9c8ff; font-weight: 700; margin-top: 2px; }
.tut .skip { pointer-events: auto; cursor: pointer; color: var(--sun); text-decoration: underline; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) {
  #rotate {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; padding: 12px; text-align: center; z-index: 50;
    background: var(--sun); color: var(--ink); font-weight: 800; border-top: 3px solid var(--ink);
  }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .modal, .track, .toast, .tut, .continue, .stars span { animation: none !important; }
}
