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

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --ink: #0b2a3f;
    --orange: #f28c00;
    --card: rgba(8, 24, 40, .72);
}
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: linear-gradient(180deg, #1d4f82 0%, #5f9bd4 45%, #cfe3f1 75%, #eef5fa 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: #0b2a3f;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35), 0 20px 60px rgba(0, 30, 60, .45);
}
.screen { display: none; position: absolute; inset: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
    display: block; width: 290px; max-width: 100%; border: none; padding: 13px 18px; margin: 6px auto;
    font-size: 17px; font-weight: bold; border-radius: 50px; cursor: pointer; font-family: inherit;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .2); transition: transform .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: #fff; color: var(--ink); }
.btn-secondary { background: rgba(255, 255, 255, .16); color: #fff; border: 2px solid rgba(255, 255, 255, .7); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 15px; padding: 6px; }
.btn-orange { background: linear-gradient(#ffb020, #f28c00); color: #3a2200; box-shadow: 0 4px 0 #a65d00, 0 8px 18px rgba(0, 0, 0, .3); }
.icon-btn {
    width: 36px; height: 36px; 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-btn.small { width: 30px; height: 30px; font-size: 14px; }
.icon-spacer { width: 36px; flex-shrink: 0; }

/* ---------- Start ---------- */
#start-bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#start-screen::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(6, 22, 40, .55) 0%, rgba(6, 22, 40, .1) 30%, rgba(6, 22, 40, .1) 45%, rgba(6, 22, 40, .78) 75%, rgba(6, 22, 40, .9) 100%); pointer-events: none; }
.sound-start { position: absolute; top: 15px; left: 15px; z-index: 3; background: rgba(8, 24, 40, .5); }
.start-inner { position: relative; z-index: 2; margin-top: auto; padding: 0 18px 22px; text-align: center; }
#start-screen h1 { font-size: 46px; letter-spacing: 3px; text-shadow: 0 3px 0 rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .45); margin-bottom: 6px; font-style: italic; }
#start-screen .desc { font-size: 15px; line-height: 1.45; max-width: 360px; margin: 0 auto 12px; opacity: .95; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.profile { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.profile span { background: rgba(255, 255, 255, .14); 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: 18px; }
.row2 .btn { width: auto; margin: 2px 0; }

/* ---------- List screens ---------- */
.list-screen { background: linear-gradient(170deg, #12446e 0%, #0b2a3f 60%, #061a2b 100%); }
.topbar {
    height: 50px; display: flex; align-items: center; gap: 8px; padding: 0 10px; flex-shrink: 0; z-index: 5;
    background: linear-gradient(#1e3a5f, #15304f); box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
.topbar .title { flex: 1; text-align: center; font-weight: bold; font-size: 17px; text-shadow: 1px 1px 2px rgba(0, 0, 0, .4); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 6px; padding: 8px 10px 4px; flex-shrink: 0; }
.tabs button { flex: 1; border: 1px solid rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .08); color: #fff; padding: 8px; border-radius: 20px; font-weight: bold; font-family: inherit; font-size: 14px; cursor: pointer; }
.tabs button.active { background: #fff; color: var(--ink); }
.scroll { flex: 1; overflow-y: auto; padding: 8px 10px 20px; -webkit-overflow-scrolling: touch; }
.row {
    width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; color: #fff; font-family: inherit;
    background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .16); border-radius: 12px; padding: 9px 10px; margin-bottom: 7px; cursor: pointer;
}
.row.cur { border-color: #ffd166; background: rgba(255, 209, 102, .14); }
.row.locked { opacity: .45; cursor: default; }
.row .num { width: 20px; text-align: center; font-weight: bold; opacity: .8; }
.row .mid { flex: 1; min-width: 0; }
.row .mid b { display: block; font-size: 15px; }
.row .mid small { display: block; font-size: 11.5px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; min-width: 54px; }
.row .right b { display: block; font-size: 16px; }
.row .right small { font-size: 11px; opacity: .8; }
.row .tag { background: #ffd166; color: #3a2200; font-size: 11px; font-weight: bold; border-radius: 10px; padding: 2px 7px; }
.place.p1 { color: #ffd166; } .place.p2 { color: #e5e7eb; } .place.p3 { color: #f0a868; }
canvas.flag { border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); flex-shrink: 0; vertical-align: middle; }
.note { font-size: 12px; opacity: .75; text-align: center; margin: 8px 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl td, .tbl th { padding: 5px 4px; border-bottom: 1px solid rgba(255, 255, 255, .1); text-align: left; }
.tbl th { font-size: 11px; opacity: .7; font-weight: normal; }
.tbl .nm { width: 100%; }
.tbl .nm small, .tbl td small { display: block; font-size: 10.5px; opacity: .7; }
.tbl .pt { text-align: right; font-weight: bold; }
.tbl tr.me td { background: rgba(255, 209, 102, .2); color: #ffd166; font-weight: bold; }
.tbl.rec td:nth-child(2), .tbl.rec td:nth-child(3), .tbl.rec th { text-align: right; white-space: nowrap; }
.section-title { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; opacity: .75; margin: 14px 0 6px; font-weight: bold; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; font-size: 11px; }
.stats div { background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 8px 2px; }
.stats b { display: block; font-size: 20px; color: #ffd166; }
.seasons { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.seasons span { background: rgba(255, 255, 255, .1); border-radius: 12px; padding: 4px 9px; }
.ach { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ach div { background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12); border-radius: 10px; padding: 7px; opacity: .45; font-size: 12px; }
.ach div.on { opacity: 1; border-color: rgba(255, 209, 102, .6); background: rgba(255, 209, 102, .12); }
.ach span { font-size: 20px; float: left; margin-right: 6px; }
.ach b { display: block; font-size: 12.5px; }
.ach small { display: block; font-size: 10.5px; opacity: .8; }

/* ---------- Game ---------- */
#game-screen { background: #0b2a3f; touch-action: none; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud.off { visibility: hidden; }
.hud button, .hud .result-card { pointer-events: auto; }
.hud-top { position: absolute; top: 0; left: 0; right: 0; padding: 8px 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.hud-top .left { display: flex; gap: 6px; align-items: flex-start; min-width: 0; }
.hud-top .right { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
.card { background: var(--card); border: 1px solid rgba(255, 255, 255, .22); border-radius: 12px; padding: 5px 9px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.hill-name { font-weight: bold; font-size: 14px; line-height: 1.15; min-width: 0; }
.hill-name span { opacity: .85; font-weight: normal; }
.hill-name small { display: block; font-weight: normal; font-size: 10.5px; opacity: .85; margin-top: 2px; }
.bib { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.bib .num { background: #fff; color: var(--ink); font-weight: bold; border-radius: 5px; padding: 1px 6px; font-size: 14px; }
.wind { display: flex; align-items: center; gap: 7px; }
.wind svg { width: 28px; height: 28px; }
.wind b { display: block; font-size: 15px; white-space: nowrap; } .wind b.head { color: #7CFF9E; } .wind b.tail { color: #ff8a8a; }
.wind small, .speed small { display: block; font-size: 10.5px; opacity: .85; }
.speed { font-size: 12px; text-align: right; min-width: 78px; }
.speed b { font-size: 16px; }
.leader, .tobeat {
    position: absolute; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid rgba(255, 255, 255, .22); border-radius: 20px;
    padding: 4px 12px; font-size: 12.5px; white-space: nowrap; opacity: 0; transition: opacity .3s;
}
.leader, .tobeat { left: 56px; transform: none; padding: 3px 10px; font-size: 12px; }
.leader { top: 66px; } .tobeat { top: 92px; border-color: rgba(60, 255, 120, .6); }
.leader span, .tobeat span { opacity: .8; } .tobeat b { color: #6dff9a; }
.leader.show, .tobeat.show { opacity: 1; }
.flash {
    position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 26px; font-weight: bold; letter-spacing: 1px; font-style: italic;
    color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .45); opacity: 0; transform: scale(.8); transition: opacity .2s, transform .2s;
}
.flash.show { opacity: 1; transform: scale(1); }
.flash.good { color: #ffd166; font-size: 34px; } .flash.warn { color: #fff3c4; } .flash.bad { color: #ff8a8a; font-size: 32px; }
.distpop { position: absolute; left: 0; right: 0; top: 22%; text-align: center; font-size: 54px; font-weight: bold; letter-spacing: -1px; text-shadow: 0 4px 14px rgba(0, 0, 0, .5); opacity: 0; }
.distpop small { font-size: 22px; }
.distpop.show { animation: distIn 2.2s ease forwards; }
@keyframes distIn { 0% { opacity: 0; transform: scale(1.4); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }

.gatebox { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); display: none; flex-direction: column; align-items: center; gap: 6px; }
.gatebox.show { display: flex; }
.gatebox .light { position: relative; width: 64px; height: 64px; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #6dff9a 0%, #16a34a 60%, #0b5e2b 100%); box-shadow: 0 0 22px rgba(60, 255, 120, .7), 0 0 0 4px rgba(8, 24, 40, .7); }
.gatebox:not(.good) .light { background: radial-gradient(circle at 50% 40%, #ffe08a 0%, #f59e0b 60%, #8a5200 100%); box-shadow: 0 0 18px rgba(255, 200, 80, .6), 0 0 0 4px rgba(8, 24, 40, .7); }
.gatebox svg { position: absolute; inset: -6px; width: 76px; height: 76px; }
.gatebox span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: bold; color: #08311a; }
.gatebox:not(.good) span { color: #3a2200; }
.gate-tip { background: var(--card); border-radius: 14px; padding: 4px 10px; font-size: 12.5px; }

.balance { position: absolute; left: 50%; bottom: 142px; transform: translateX(-50%); width: 230px; display: none; }
.balance.show { display: block; }
.balance .lbl { display: flex; justify-content: space-between; font-size: 10px; letter-spacing: .5px; opacity: .9; margin-bottom: 3px; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.balance .bar { position: relative; height: 14px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .35);
    background: linear-gradient(90deg, rgba(239, 68, 68, .6) 0%, rgba(245, 158, 11, .45) 18%, rgba(8, 24, 40, .6) 32%, rgba(34, 197, 94, .6) 41%, rgba(34, 197, 94, .6) 59%, rgba(8, 24, 40, .6) 68%, rgba(245, 158, 11, .45) 82%, rgba(239, 68, 68, .6) 100%); }
.balance i { position: absolute; top: -5px; width: 8px; height: 24px; margin-left: -4px; border-radius: 4px; background: #fff; box-shadow: 0 0 8px rgba(0, 0, 0, .6); }
.balance i.ok { background: #6dff9a; } .balance i.warn { background: #ffd166; } .balance i.bad { background: #ff6b6b; }
.minimap { position: absolute; left: 10px; right: 10px; bottom: 76px; height: 50px; background: var(--card); border: 1px solid rgba(255, 255, 255, .22); border-radius: 10px; }
.minimap canvas { width: 100%; height: 100%; display: block; }
.hint { position: absolute; left: 0; right: 0; bottom: 20px; text-align: center; opacity: 0; transition: opacity .25s; }
.hint.show { opacity: 1; }
.hint span { display: inline-block; background: rgba(8, 24, 40, .82); border: 1px solid rgba(255, 255, 255, .25); border-radius: 40px; padding: 10px 18px; font-size: 15px; }
.hint em { color: #ffd166; font-style: normal; font-weight: bold; }

.result-card {
    position: absolute; left: 10px; right: 10px; bottom: 12px; background: rgba(8, 24, 40, .9); border: 1px solid rgba(255, 255, 255, .3); border-radius: 18px;
    padding: 12px 16px 12px; text-align: center; box-shadow: 0 14px 40px rgba(0, 0, 0, .45); display: none; max-height: calc(100% - 24px); overflow-y: auto;
}
.result-card.show { display: block; animation: cardIn .35s ease; }
@keyframes cardIn { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.result-card .badge { display: inline-block; background: linear-gradient(#ffb020, #f28c00); color: #3a2200; font-weight: bold; border-radius: 20px; padding: 3px 12px; font-size: 12px; letter-spacing: 1px; margin-bottom: 4px; }
.result-card .badge.warn { background: #e5e7eb; color: #1f2937; } .result-card .badge.bad { background: #ef4444; color: #fff; }
.result-card .dist { font-size: 50px; font-weight: bold; line-height: 1; letter-spacing: -1px; }
.result-card .dist small { font-size: 20px; }
.result-card .sub { font-size: 12px; opacity: .8; margin-top: 3px; }
.judges { display: flex; justify-content: center; gap: 5px; margin: 9px 0 6px; }
.judges span { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); border-radius: 8px; padding: 4px 0; width: 46px; font-weight: bold; font-size: 15px; animation: judgeIn .3s ease backwards; }
.judges span.drop { opacity: .4; text-decoration: line-through; }
@keyframes judgeIn { from { transform: scale(.4); opacity: 0; } }
.rows { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 13px; text-align: left; }
.rows b { text-align: right; }
.rows .total { border-top: 1px solid rgba(255, 255, 255, .25); padding-top: 5px; margin-top: 3px; font-size: 16px; }
.rows b.total { color: #ffd166; }
.result-card .fb { font-size: 12px; opacity: .8; margin-top: 6px; }
.result-card .notes span { display: inline-block; margin: 6px 3px 0; background: rgba(255, 209, 102, .2); color: #ffd166; border-radius: 12px; padding: 3px 9px; font-size: 12.5px; font-weight: bold; }
.result-card .rank { margin-top: 6px; font-size: 13px; } .result-card .rank b { color: #7CFF9E; }
.result-card .btns { display: flex; gap: 8px; margin-top: 8px; }
.result-card .btns .btn { margin: 0; flex: 1; padding: 11px 10px; font-size: 16px; }
.ach-toast {
    position: absolute; left: 50%; top: 64px; transform: translate(-50%, -20px); display: flex; align-items: center; gap: 8px; background: #fff; color: var(--ink);
    border-radius: 14px; padding: 7px 14px 7px 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); opacity: 0; transition: opacity .3s, transform .3s; z-index: 50; white-space: nowrap;
}
.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(0, 0, 0, .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: 16px; padding: 18px 16px; width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; text-align: center; box-shadow: 0 15px 35px rgba(0, 0, 0, .4); animation: modalIn .25s ease; }
@keyframes modalIn { from { transform: scale(.92); opacity: 0; } }
.modal h2 { font-size: 21px; 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; }
.modal .btn-primary { background: var(--orange); color: #3a2200; }
.modal .btn-secondary { background: #fff; color: var(--ink); border-color: var(--ink); }
.modal .btn-ghost.dark { color: var(--ink); }
.modal-buttons { margin-top: 10px; }
.modal.help { text-align: left; } .modal.help h2 { text-align: center; } .modal.help p { margin: 7px 0; font-size: 13.5px; }
.modal .tip { font-size: 12.5px; color: #6b7280; margin-top: 8px; }
.intro-head { display: flex; align-items: center; gap: 12px; text-align: left; }
.intro-head h2 { margin: 0; font-size: 24px; } .intro-head small { color: #6b7280; font-size: 12.5px; }
.tags { margin: 6px 0; text-align: left; } .tags span { display: inline-block; background: #fff1d6; color: #8a5200; border-radius: 10px; padding: 2px 8px; font-size: 11.5px; font-weight: bold; margin-right: 4px; }
.facts { width: 100%; border-collapse: collapse; font-size: 13.5px; text-align: left; margin-top: 6px; }
.facts td { padding: 5px 2px; border-bottom: 1px solid #eef0f3; } .facts td:first-child { color: #6b7280; width: 38%; }
.facts small { color: #6b7280; }
.results { padding-bottom: 0; }
.results .modal-buttons { position: sticky; bottom: 0; background: #fff; padding: 8px 0 12px; margin-top: 8px; box-shadow: 0 -8px 12px -8px rgba(0, 0, 0, .18); }
.results .modal-buttons .btn { margin: 4px auto; padding: 11px 16px; }
.modal .tbl { color: #1f2937; font-size: 13px; }
.modal .tbl td { border-bottom: 1px solid #eef0f3; padding: 4px 3px; }
.modal .tbl tr.me td { background: #fff4d6; color: #7a4a00; }
.modal .tbl tr.cut td { border-bottom: 2px dashed #ef4444; }
.modal .tbl .d { white-space: nowrap; color: #6b7280; font-size: 12px; text-align: right; }
.modal .tbl i { color: #ef4444; font-style: normal; font-weight: bold; }
.list-box { max-height: 46vh; overflow-y: auto; border: 1px solid #eef0f3; border-radius: 10px; margin-top: 8px; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 6px; margin: 10px 0 6px; }
.pod { width: 31%; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
.pod b { font-size: 12.5px; color: var(--ink); } .pod small { color: #6b7280; }
.pod .step { width: 100%; border-radius: 8px 8px 0 0; color: #fff; font-weight: bold; font-size: 20px; display: flex; align-items: center; justify-content: center; margin-top: 3px; }
.pod.p1 .step { height: 56px; background: linear-gradient(#ffd166, #e0a000); } .pod.p2 .step { height: 42px; background: linear-gradient(#e5e7eb, #9ca3af); } .pod.p3 .step { height: 32px; background: linear-gradient(#f0a868, #b8662c); }
.me-line { font-size: 14px; margin: 6px 0 2px; } .me-line b { color: var(--ink); }
.wc-gain { display: inline-block; background: #e8f9ee; color: #12753a; border-radius: 12px; padding: 4px 10px; font-weight: bold; font-size: 13.5px; margin-top: 4px; }
.modal .section-title { color: #6b7280; opacity: 1; text-align: left; }
details { text-align: left; margin-top: 8px; font-size: 13px; } details summary { cursor: pointer; color: #1f4fc4; font-weight: bold; padding: 4px 0; }
.globe { font-size: 64px; }
@media (max-height: 640px) {
    .result-card .dist { font-size: 40px; } .judges span { width: 40px; font-size: 14px; }
    .minimap { height: 42px; bottom: 70px; }
}
