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

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --ink: #1b2217;
    --green: #2e7d32;
    --orange: #f28c00;
    --card: rgba(10, 20, 14, .62);
}
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: Arial, Helvetica, sans-serif; color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none;
    background: radial-gradient(1200px 700px at 50% 25%, #2f6b37 0%, #173a1e 55%, #0b1d0f 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;
}
#stage {
    position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; background: #1a2a1c;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .18), 0 20px 70px rgba(0, 0, 0, .6);
}
#scene { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
.screen { display: none; position: absolute; inset: 0; flex-direction: column; z-index: 2; }
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
    display: block; width: 290px; max-width: 100%; border: none; padding: 12px 18px; margin: 6px auto;
    font-size: 18px; font-weight: bold; border-radius: 50px; cursor: pointer; font-family: inherit; min-height: 46px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .25); transition: transform .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn small { display: block; font-size: 12px; font-weight: normal; opacity: .85; margin-top: 2px; }
.btn-primary { background: #fff; color: var(--ink); }
.btn-secondary { background: rgba(10, 30, 14, .45); color: #fff; border: 2px solid rgba(255, 255, 255, .8); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 15px; padding: 8px 6px; min-height: 40px; }
.btn-orange { background: linear-gradient(#ffb020, #f28c00); color: #3a2200; box-shadow: 0 4px 0 #a65d00, 0 8px 18px rgba(0, 0, 0, .35); font-size: 21px; letter-spacing: .5px; }
.btn-orange small { color: #5a3500; }
.btn.small { font-size: 16px; min-height: 42px; padding: 9px 12px; }
.icon-btn {
    width: 40px; height: 40px; 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, .25); }
.icon-spacer { width: 40px; flex-shrink: 0; }

/* ---------- Start ---------- */
#start-screen { background: linear-gradient(180deg, rgba(4, 18, 40, .45) 0%, rgba(4, 18, 40, 0) 30%, rgba(10, 20, 10, 0) 45%, rgba(10, 20, 10, .55) 66%, rgba(8, 16, 8, .88) 100%); }
.sound-start { position: absolute; top: 15px; left: 15px; z-index: 3; background: rgba(10, 20, 14, .45); }
.title-wrap { margin-top: calc(62px + 1vh); text-align: center; padding: 0 18px; }
#start-screen h1 {
    font-size: clamp(36px, 11vw, 52px); letter-spacing: 2px; font-weight: 900; line-height: 1;
    color: #fff; -webkit-text-stroke: 1.5px #1b2217; paint-order: stroke fill;
    text-shadow: 0 0 18px rgba(255, 200, 80, .55), 0 4px 0 #1b2217, 0 8px 20px rgba(0, 0, 0, .45);
}
#start-screen .desc { font-size: 15px; line-height: 1.45; max-width: 360px; margin: 10px auto 0; text-shadow: 0 1px 3px rgba(0, 0, 0, .9), 0 0 10px rgba(0, 0, 0, .5); }
.start-inner { position: relative; z-index: 2; margin-top: auto; padding: 0 18px 14px; text-align: center; }
.profile { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; min-height: 22px; }
.profile span { background: rgba(0, 0, 0, .35); border: 1px solid rgba(255, 255, 255, .3); border-radius: 14px; padding: 4px 10px; }
.profile b { color: #ffd166; }
.row2 { display: flex; justify-content: center; gap: 10px; width: 290px; max-width: 100%; margin: 0 auto; }
.row2 .btn { flex: 1; width: auto; margin: 4px 0; }
.row3 { display: flex; justify-content: center; gap: 10px; }
.row3 .btn { width: auto; margin: 2px 0; }

/* ---------- List screens ---------- */
.list-screen { background: linear-gradient(170deg, #24502c 0%, #16301b 60%, #0c1a0f 100%); }
.topbar {
    height: 54px; display: flex; align-items: center; gap: 8px; padding: 0 10px; flex-shrink: 0; z-index: 5;
    background: linear-gradient(#2f6236, #214a27); box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.topbar .title { flex: 1; text-align: center; font-weight: bold; font-size: 18px; }
.scroll { flex: 1; overflow-y: auto; padding: 10px 10px 24px; -webkit-overflow-scrolling: touch; }
.section-title { font-size: 14px; font-weight: bold; opacity: .85; margin: 10px 2px 8px; text-transform: uppercase; letter-spacing: .5px; }
.info-line { font-size: 13px; opacity: .85; line-height: 1.4; margin: 2px 2px 10px; }
.card {
    display: flex; gap: 12px; align-items: center; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .14);
    border-radius: 14px; padding: 10px; margin-bottom: 9px; cursor: pointer; width: 100%; color: #fff; text-align: left; font-family: inherit;
}
.card.sel { border-color: #ffd166; background: rgba(255, 209, 102, .12); }
.card.locked { cursor: default; opacity: .65; }
.card canvas { width: 76px; height: 76px; flex-shrink: 0; border-radius: 10px; background: radial-gradient(circle at 50% 75%, #e6d1a3, #9fc5e6); }
.card .info { flex: 1; min-width: 0; }
.card b { font-size: 16px; display: block; }
.card p { font-size: 13px; opacity: .85; margin: 3px 0 5px; line-height: 1.35; }
.card .tag { display: inline-block; font-size: 12px; font-weight: bold; padding: 3px 9px; border-radius: 10px; background: #ffd166; color: #3a2200; }
.card .tag.choose { background: rgba(255, 255, 255, .2); color: #fff; }
.card .tag.lock { background: rgba(0, 0, 0, .3); color: #fff; font-weight: normal; }
.card .medal { font-size: 34px; width: 56px; text-align: center; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: 1 1 40%; min-height: 44px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, .18); background: rgba(255, 255, 255, .08); color: #fff; font: inherit; font-size: 14px; font-weight: bold; padding: 6px 8px; cursor: pointer; }
.chip.sel { border-color: #ffd166; background: rgba(255, 209, 102, .14); }
.chip.locked { opacity: .55; cursor: default; font-weight: normal; }
.chip small { display: block; font-size: 11px; font-weight: normal; opacity: .8; }
.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; }
.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; }

/* ---------- Race ---------- */
#game-screen { background: transparent; }
.race-top { position: relative; flex: 1 1 auto; min-height: 0; pointer-events: none; }
.hud-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.hud-top .left { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.hud-top .right { display: flex; gap: 8px; align-items: center; }
.pill {
    background: var(--card); border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 5px 12px; min-height: 36px;
    font-weight: 800; font-size: 19px; letter-spacing: .3px; text-shadow: 0 1px 2px #000; display: flex; align-items: center; gap: 3px;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pill small { font-weight: 600; font-size: 12px; opacity: .85; margin-left: 3px; }
.pill.clock { font-size: 23px; min-width: 104px; justify-content: center; }
.pill.gap { font-size: 13px; min-height: 26px; padding: 3px 10px; color: #c9ffd2; }
.pill.gap.behind { color: #ffd0d0; }
.pill.gap:empty { display: none; }
#btn-pause { pointer-events: auto; width: 40px; height: 40px; }
#btn-pause i { display: block; width: 4px; height: 14px; background: #fff; margin: 0 2px; border-radius: 1px; }
.hud-tag { position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); white-space: nowrap; font-size: 11px; font-weight: bold; letter-spacing: .5px; background: rgba(255, 200, 80, .22); border: 1px solid rgba(255, 200, 80, .6); border-radius: 999px; padding: 3px 9px; color: #ffe8b0; text-shadow: 0 1px 2px #000; }
.hud-tag:empty { display: none; }
.strip { position: absolute; left: 10px; right: 10px; bottom: 8px; height: 26px; width: calc(100% - 20px); }
.banner {
    position: absolute; left: 0; right: 0; top: 26%; text-align: center; font-weight: 900; font-size: clamp(28px, 9vw, 40px); letter-spacing: 1px;
    color: #fff; text-shadow: 0 2px 0 #1b3a1f, 0 3px 12px rgba(0, 0, 0, .85); opacity: 0; transform: translateY(10px); transition: opacity .3s, transform .3s;
}
.banner small { display: block; font-size: 14px; font-weight: 800; letter-spacing: 2px; margin-top: 4px; }
.banner.show { opacity: 1; transform: none; }
.banner.big { font-size: clamp(36px, 12vw, 56px); }
.toast {
    position: absolute; left: 50%; top: 44%; transform: translate(-50%, 0) scale(.85); font-weight: 900; font-size: 20px; white-space: nowrap;
    color: #fff3c4; text-shadow: 0 2px 0 #3a2a00, 0 0 12px rgba(0, 0, 0, .7); opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.bad { color: #ffd0d0; }
.toast.good { color: #c9ffc2; }
.ach-toast {
    position: absolute; left: 50%; top: 96px; transform: translate(-50%, -20px); opacity: 0; transition: opacity .3s, transform .3s;
    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; }

.ctrl {
    position: relative; flex: 0 0 40%; min-height: 180px; max-height: 340px; display: flex; flex-direction: column; gap: 8px; padding: 9px 11px 10px;
    background: linear-gradient(#1b2f1e, #0f1b11); border-top: 1px solid rgba(255, 255, 255, .12); touch-action: none;
}
.meters { display: flex; gap: 9px; flex: 0 0 auto; }
.meter { flex: 1; min-width: 0; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14); border-radius: 12px; padding: 5px 9px 6px; color: #dfe9df; }
.meter b { display: block; font-size: 10px; letter-spacing: 1.5px; opacity: .8; margin-bottom: 3px; }
.meter canvas { display: block; width: 100%; height: 22px; }
.pads { position: relative; flex: 1 1 auto; display: flex; gap: 10px; min-height: 0; }
.pad {
    flex: 1; position: relative; border-radius: 22px; background: linear-gradient(#3f6b43, #2a4a2d); border: 2px solid rgba(255, 255, 255, .18);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2), 0 6px 14px rgba(0, 0, 0, .4); display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #eaf5ea; font: inherit; font-weight: 800; letter-spacing: 2px; font-size: 13px; cursor: pointer; touch-action: none; transition: background .06s;
}
.pad.on { background: linear-gradient(#8bd37b, #4f9f4b); color: #0e2410; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .4), 0 0 22px rgba(140, 230, 120, .45); }
.pad.next { border-color: rgba(190, 255, 170, .75); }
.pad svg { width: clamp(34px, 9vh, 64px); height: clamp(34px, 9vh, 64px); margin-bottom: 4px; pointer-events: none; }
.pad span { pointer-events: none; }
.jump-cue {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6); width: 92px; height: 92px; border-radius: 50%;
    border: 3px solid #fff; background: radial-gradient(circle at 50% 35%, #ffcf5a, #f28c00); color: #3a2200; font: inherit; font-weight: 900; font-size: 15px; letter-spacing: .5px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; touch-action: none; z-index: 3;
}
.jump-cue.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; animation: cue .5s ease-in-out infinite alternate; }
.jump-cue.go { background: radial-gradient(circle at 50% 35%, #b8ff9a, #3fae3a); color: #0e2410; }
@keyframes cue { to { box-shadow: 0 0 0 8px rgba(255, 210, 90, .35), 0 6px 18px rgba(0, 0, 0, .45); } }
.pad-hint { flex: 0 0 auto; text-align: center; color: #b7cbb7; font-size: 11px; line-height: 1.3; }
@media (max-height: 560px) { .pad-hint { display: none; } }

/* ---------- Modals ---------- */
.modal-overlay { position: absolute; inset: 0; background: rgba(4, 10, 6, .6); display: none; align-items: center; justify-content: center; z-index: 400; padding: 12px; }
.modal-overlay.show { display: flex; }
.modal { background: #f7f4ea; color: #34403a; border-radius: 18px; padding: 16px 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: 22px; 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; margin: 5px auto; }
.modal .btn-primary { background: var(--green); color: #fff; }
.modal .btn-secondary { background: #fff; color: var(--ink); border-color: var(--ink); }
.modal .btn-ghost.dark { color: var(--ink); }
.modal-buttons { padding: 8px 0 12px; }
.results .modal-buttons { position: sticky; bottom: 0; background: #f7f4ea; 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; }
.res-title { font-size: 13px; letter-spacing: 2.5px; color: #5b6e5c; font-weight: bold; text-transform: uppercase; margin-bottom: 2px; }
.res-head { font-size: 22px; font-weight: 900; color: var(--ink); margin: 2px 0; }
.res-time { font-size: 46px; font-weight: 900; color: var(--ink); line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.res-pts { font-size: 15px; font-weight: bold; color: var(--green); margin: 2px 0 6px; }
.record { display: inline-block; background: linear-gradient(#ffd166, #f5a524); color: #3a2200; font-weight: 900; padding: 5px 14px; border-radius: 14px; margin: 2px 0 6px; animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.res-note { font-size: 14px !important; font-weight: bold; border-radius: 10px; padding: 6px 8px; margin: 6px 0 !important; }
.res-note.good { background: #e3f4dc; color: #1e5a20; }
.res-note.bad { background: #fde8e4; color: #8a2b1a; }
.res-note.info { background: #fff3d6; color: #7a4a00; }
.standings { width: 100%; border-collapse: collapse; font-size: 14px; color: #1f2a22; margin: 6px 0; }
.standings td { padding: 5px 4px; border-bottom: 1px solid #e3dccb; text-align: left; white-space: nowrap; }
.standings td.nm { white-space: normal; width: 100%; }
.standings td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: bold; }
.standings tr.me td { background: #e3f1dc; font-weight: 800; }
.standings tr.cut td { border-bottom: 2px dashed #9aa79a; }
.standings img { width: 20px; height: 14px; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0, 0, 0, .25); border-radius: 2px; }
.res-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 13px; color: #5b6e5c; margin: 4px 0; }
.res-stats b { color: var(--ink); }
@media (max-height: 620px) { #start-screen .desc { display: none; } .title-wrap { margin-top: 64px; } }
