* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --ink: #0b1a2b;
    --orange: #f28c00;
    --blue: #2667d8;
    --card: rgba(8, 18, 36, .6);
}
html, body { height: 100%; }
/* Inside the site iframe a fixed footer bar (~40px) covers the bottom; the site hides it when height <= 400px. */
html.in-frame { --frame-bottom: 44px; }
@media (max-height: 400px) { html.in-frame { --frame-bottom: 0px; } }

body {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none;
    background: radial-gradient(1200px 700px at 50% 25%, #23406e 0%, #0f1f3c 55%, #070f20 100%);
}
#app {
    position: relative; z-index: 1;
    height: calc(100vh - var(--frame-bottom));
    height: calc(100dvh - var(--frame-bottom));
    padding: 0 var(--frame-right) 0 var(--frame-left);
    display: flex; justify-content: center;
}
/* The UI column (480 px max) is transparent; the 3D view sits behind it and is wider on landscape screens
   (game.js sizes it to max(column, min(free width, height))). */
#stage { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; z-index: 2; }
#scene {
    position: absolute; top: 0; left: 0; display: block; touch-action: none; z-index: 1; background: #e7d6d0;
    box-shadow: 0 20px 70px rgba(0, 0, 0, .6);
}
.screen { display: none; position: absolute; inset: 0; flex-direction: column; z-index: 2; }
.screen.active { display: flex; }

.loading { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; z-index: 50; background: #0f1f3c; text-align: center; padding: 24px; font-size: 16px; }
.loading.hide { display: none; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
    display: block; width: 300px; max-width: 100%; border: none; padding: 12px 18px; margin: 6px auto;
    font-size: 19px; font-weight: bold; border-radius: 16px; cursor: pointer; font-family: inherit; min-height: 48px; color: #fff;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .35), 0 8px 18px rgba(0, 0, 0, .25); transition: transform .12s ease;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn small { display: block; font-size: 12px; font-weight: normal; opacity: .92; margin-top: 2px; }
.btn-orange { background: linear-gradient(#ffa23a, #e2711c); box-shadow: 0 4px 0 #9a4a08, 0 8px 18px rgba(0, 0, 0, .3); }
.btn-blue { background: linear-gradient(#4b93ff, #2667d8); box-shadow: 0 4px 0 #173f8a, 0 8px 18px rgba(0, 0, 0, .3); }
.btn-dark { background: rgba(26, 46, 74, .92); font-size: 15px; padding: 10px 6px; min-height: 44px; }
.btn-primary { background: #fff; color: var(--ink); }
.btn-secondary { background: rgba(255, 255, 255, .14); color: #fff; border: 2px solid rgba(255, 255, 255, .75); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 15px; padding: 8px 6px; min-height: 40px; }
.icon-btn {
    width: 42px; height: 42px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .12);
    color: #fff; font-size: 17px; font-weight: bold; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-family: inherit;
}
.icon-btn.dark { background: var(--card); border-color: rgba(255, 255, 255, .3); }
.icon-spacer { width: 42px; flex-shrink: 0; }
i.coin { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2a8 0 18%, #ffcb3a 40%, #d58a00 100%); box-shadow: inset 0 0 0 2px #b87400; flex-shrink: 0; }

/* ---------- Start ---------- */
/* menu shading over the whole 3D view (which can be wider than the column) */
#scene-shade { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; opacity: 0; transition: opacity .3s;
    background: linear-gradient(180deg, rgba(8, 16, 34, .45) 0%, rgba(8, 16, 34, 0) 26%, rgba(8, 16, 34, 0) 42%, rgba(8, 16, 34, .7) 64%, rgba(8, 16, 34, .92) 100%); }
#scene-shade.on { opacity: 1; }
.sound-start { position: absolute; top: 15px; left: 15px; z-index: 3; background: rgba(8, 18, 36, .5); }
.coin-chip { position: absolute; top: 18px; left: 66px; z-index: 3; display: flex; align-items: center; gap: 6px; background: rgba(8, 18, 36, .6); border: 1px solid rgba(255, 255, 255, .25); border-radius: 999px; padding: 6px 12px 6px 8px; font-weight: bold; font-size: 15px; }
.coin-chip.static { position: static; }
.title-wrap { margin-top: calc(66px + 1vh); text-align: center; padding: 0 16px; }
.kicker { font-size: 13px; font-weight: bold; letter-spacing: 4px; color: #bfe4ff; text-shadow: 0 2px 0 #0b2a5a, 0 0 10px rgba(0, 0, 0, .5); }
#start-screen h1 {
    font-size: clamp(44px, 14vw, 64px); letter-spacing: 2px; font-weight: 900; line-height: 1; margin-top: 4px;
    color: #fff; -webkit-text-stroke: 2px #0b2a5a; paint-order: stroke fill;
    text-shadow: 0 5px 0 #0b2a5a, 0 10px 24px rgba(0, 0, 0, .45);
}
.start-inner { position: relative; z-index: 2; margin-top: auto; padding: 0 18px 16px; text-align: center; }
.desc { font-size: 14px; line-height: 1.45; max-width: 340px; margin: 0 auto 8px; color: #dbe8f6; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
.gift { display: none; margin: 0 auto 8px; width: fit-content; background: linear-gradient(#fff3c4, #ffd36b); color: #4a2c00; font-weight: bold; font-size: 14px; border-radius: 12px; padding: 6px 12px; animation: pop .5s ease; }
.gift.show { display: block; }
.profile { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; min-height: 22px; }
.profile span { background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .28); border-radius: 14px; padding: 4px 10px; }
.profile b { color: #ffd166; }
.row3 { display: flex; justify-content: center; gap: 8px; width: 300px; max-width: 100%; margin: 4px auto 0; }
.row3 .btn { flex: 1; width: auto; margin: 2px 0; }

/* ---------- Garage ---------- */
.topbar {
    height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 12px; flex-shrink: 0; z-index: 5;
    background: linear-gradient(#1c3557, #132845); box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.topbar.clear { background: none; box-shadow: none; }
.topbar .title { flex: 1; text-align: center; font-weight: bold; font-size: 19px; text-shadow: 0 2px 4px rgba(0, 0, 0, .6); }
.garage-sheet { margin-top: auto; max-height: 56%; display: flex; flex-direction: column; background: linear-gradient(rgba(10, 22, 44, .86), rgba(6, 14, 30, .96)); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 24px rgba(0, 0, 0, .35); }
.cars-list { overflow-y: auto; padding: 12px 12px 18px; -webkit-overflow-scrolling: touch; }
.car-card {
    display: flex; gap: 10px; align-items: center; background: rgba(255, 255, 255, .07); border: 2px solid rgba(255, 255, 255, .12);
    border-radius: 14px; padding: 9px 10px; margin-bottom: 8px; cursor: pointer; width: 100%; color: #fff; text-align: left; font-family: inherit;
}
.car-card.view { border-color: rgba(120, 190, 255, .8); background: rgba(80, 150, 255, .12); }
.car-card.sel { border-color: #ffd166; }
.car-card .sw { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .3); }
.car-card .info { flex: 1; min-width: 0; }
.car-card b { font-size: 16px; display: block; }
.car-card p { font-size: 12px; opacity: .82; margin: 2px 0 5px; line-height: 1.3; }
.car-card .stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 6px; align-items: center; font-size: 11px; opacity: .9; }
.car-card .bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.car-card .bar i { display: block; height: 100%; background: linear-gradient(90deg, #7cc7ff, #2f7cf6); }
.car-card .act { flex-shrink: 0; min-width: 84px; text-align: center; font-size: 13px; font-weight: bold; padding: 9px 8px; border-radius: 12px; border: none; font-family: inherit; color: #fff; background: rgba(255, 255, 255, .18); cursor: pointer; }
.car-card .act.on { background: #ffd166; color: #3a2200; }
.car-card .act.buy { background: linear-gradient(#ffa23a, #e2711c); display: flex; gap: 5px; align-items: center; justify-content: center; }
.car-card .act.buy:disabled { background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .6); cursor: default; }
.car-card .need { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }

/* ---------- Stats ---------- */
.list-screen { background: linear-gradient(170deg, #12305a 0%, #0b1a2b 60%, #050d18 100%); }
.scroll { flex: 1; overflow-y: auto; padding: 10px 10px 24px; -webkit-overflow-scrolling: touch; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat { background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); border-radius: 12px; padding: 10px; }
.stat small { display: block; font-size: 12px; opacity: .75; }
.stat b { font-size: 20px; color: #ffd166; }
.section-title { font-size: 14px; font-weight: bold; opacity: .8; margin: 6px 2px 8px; text-transform: uppercase; letter-spacing: .5px; }
.ach { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, .06); margin-bottom: 6px; }
.ach .ico { font-size: 24px; width: 32px; text-align: center; filter: grayscale(1); opacity: .45; }
.ach.on .ico { filter: none; opacity: 1; }
.ach b { display: block; font-size: 14px; } .ach small { font-size: 12px; opacity: .75; }
.ach.on b { color: #ffd166; }

/* ---------- Game HUD ---------- */
#game-screen { background: transparent; }
.touch { position: absolute; inset: 0; touch-action: none; z-index: 1; cursor: pointer; }
.hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; text-shadow: 0 2px 0 rgba(11, 26, 43, .9), 0 0 10px rgba(0, 0, 0, .35); }
.hud-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: flex-start; justify-content: space-between; }
.pill {
    background: var(--card); border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 6px 13px 6px 8px; min-height: 40px;
    font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; text-shadow: none;
}
.pill i.coin { width: 22px; height: 22px; }
#btn-pause { pointer-events: auto; }
#btn-pause i { display: block; width: 4px; height: 15px; background: #fff; margin: 0 2px; border-radius: 1px; }
.score { position: absolute; top: 58px; left: 0; right: 0; text-align: center; font-size: clamp(46px, 14vw, 60px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.score small { display: block; font-size: 13px; font-weight: bold; letter-spacing: 3px; margin-top: 4px; opacity: .92; }
.daily-badge {
    position: absolute; left: 50%; top: 142px; transform: translateX(-50%); white-space: nowrap; display: none; text-shadow: none;
    font-size: 12px; font-weight: bold; background: rgba(226, 113, 28, .85); border-radius: 999px; padding: 4px 10px;
}
.daily-badge.show { display: block; }
.boosts { position: absolute; top: 172px; left: 0; right: 0; display: flex; justify-content: center; gap: 8px; text-shadow: none; }
.bst { display: none; align-items: center; gap: 6px; background: var(--card); border: 1px solid rgba(255, 255, 255, .25); border-radius: 999px; padding: 4px 10px 4px 8px; font-size: 14px; }
.bst.show { display: flex; animation: pop .35s ease; }
.bst b { font-size: 15px; } .bst.x2 b { color: #ffb020; }
.bst span { display: block; width: 46px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.bst span i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffd166, #ff8a1f); }
.bst.magnet span i { background: linear-gradient(90deg, #8fd0ff, #2f7cf6); }
.bst em { font-style: normal; font-weight: bold; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.banner {
    position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-weight: 900; font-size: clamp(30px, 10vw, 42px); letter-spacing: 2px;
    text-shadow: 0 0 18px #4bd5a0, 0 3px 0 #0b2a3f, 0 3px 10px #000; opacity: 0; transform: translateY(10px); transition: opacity .35s, transform .35s;
}
.banner small { display: block; font-size: 15px; font-weight: 700; letter-spacing: 2px; opacity: .9; margin-top: 4px; }
.banner.show { opacity: 1; transform: none; }
.toast {
    position: absolute; left: 50%; top: 40%; transform: translate(-50%, 0) scale(.8) rotate(-3deg); font-weight: 900; font-size: 34px; white-space: nowrap;
    color: #ffd84a; text-shadow: 0 3px 0 #5a2a00, 0 0 14px rgba(0, 0, 0, .5); opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.small { font-size: 24px; color: #fff; }
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-3deg); }
.countdown { position: absolute; left: 0; right: 0; top: 30%; text-align: center; display: none; }
.countdown.show { display: block; }
.countdown h3 { font-size: 26px; color: #b9ffcf; }
.countdown .n { font-size: 84px; font-weight: 900; line-height: 1.1; }
.countdown .w { display: inline-block; font-size: 18px; font-weight: bold; background: var(--card); border-radius: 12px; padding: 6px 14px; text-shadow: none; }
.hint {
    position: absolute; left: 12px; right: 12px; bottom: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    opacity: 0; transition: opacity .4s; text-shadow: none;
}
.hint.show { opacity: 1; }
.hint .h { background: var(--card); border: 2px solid rgba(255, 255, 255, .35); border-radius: 14px; padding: 8px 6px; text-align: center; font-size: 14px; line-height: 1.3; }
.hint .h b { display: block; font-size: 15px; }
.hint .h.on { border-color: #ffd166; background: rgba(226, 113, 28, .55); }
.hint small { grid-column: 1 / 3; text-align: center; font-size: 12px; opacity: .8; }
.ach-toast {
    position: absolute; left: 50%; top: 214px; transform: translate(-50%, -20px); opacity: 0; transition: opacity .3s, transform .3s; text-shadow: none;
    background: #fff; color: var(--ink); border-radius: 14px; padding: 8px 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 8px 22px rgba(0, 0, 0, .35); white-space: nowrap; z-index: 5;
}
.ach-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ach-toast .ico { font-size: 24px; } .ach-toast small { display: block; font-size: 10px; color: #6b7280; text-transform: uppercase; letter-spacing: .5px; } .ach-toast b { font-size: 14px; }

/* ---------- Modals ---------- */
.modal-overlay { position: absolute; inset: 0; background: rgba(2, 6, 16, .6); display: none; align-items: center; justify-content: center; z-index: 400; padding: 12px; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; color: #374151; border-radius: 18px; padding: 18px 16px 0; width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; text-align: center; box-shadow: 0 15px 35px rgba(0, 0, 0, .45); animation: modalIn .25s ease; }
@keyframes modalIn { from { transform: scale(.92); opacity: 0; } }
.modal h2 { font-size: 26px; margin-bottom: 6px; color: var(--ink); }
.modal p { font-size: 14px; line-height: 1.45; margin: 4px 0; }
.modal .btn { width: 100%; max-width: 280px; box-shadow: 0 3px 0 rgba(0, 0, 0, .2); }
.modal .btn-primary { background: linear-gradient(#ffa23a, #e2711c); color: #fff; }
.modal .btn-secondary { background: #fff; color: var(--ink); border-color: var(--ink); }
.modal .btn-ghost.dark { color: var(--ink); box-shadow: none; }
.modal-buttons { padding: 8px 0 14px; }
.results .modal-buttons { position: sticky; bottom: 0; background: #fff; margin-top: 8px; box-shadow: 0 -8px 12px -8px rgba(0, 0, 0, .18); }
.modal.help { text-align: left; } .modal.help h2 { text-align: center; } .modal.help p { margin: 8px 0; font-size: 14px; }
.cause { font-size: 15px; color: #4b5563; margin-bottom: 8px !important; }
.record { display: inline-block; background: linear-gradient(#ffd166, #f5a524); color: #3a2200; font-weight: 900; padding: 5px 14px; border-radius: 14px; margin: 2px 0 8px; animation: pop .5s ease; }
.res-table { width: 100%; border-collapse: collapse; font-size: 15px; color: #1f2937; margin: 4px 0 6px; }
.res-table td { padding: 6px 4px; border-bottom: 1px solid #eef0f3; text-align: left; }
.res-table td:last-child { text-align: right; font-weight: bold; }
.res-table tr.total td { border-bottom: none; font-size: 19px; color: var(--ink); padding-top: 9px; }
.res-table .pts { color: #6b7280; font-weight: normal; font-size: 12px; margin-left: 4px; }
.res-table i.coin { width: 15px; height: 15px; vertical-align: -2px; margin-right: 4px; }
.daily-info { font-size: 13px !important; background: #fff7e6; border-radius: 10px; padding: 7px 8px; color: #7a4a00; }
.big-score { font-size: 46px; font-weight: 900; color: var(--ink); line-height: 1.05; }
