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

:root {
    --bg: #cfe8f6;
    --surface: #ffffff;
    --border: rgba(0, 0, 0, 0.08);
    --accent: #1f6fb2;
    --text: #1a1f2e;
    --dim: rgba(26, 31, 46, 0.55);
    --good: #2a9d5c;
    --bad: #d0453a;
    --warn: #f0a020;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

button { touch-action: manipulation; font-family: inherit; }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 12px; }

/* ── Screens and cards ── */
.screen {
    position: fixed; inset: 0;
    display: flex; justify-content: center; align-items: center;
    z-index: 50;
    background: linear-gradient(#9fd3f0, #e6f3fa);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.overlay { background: rgba(20, 40, 60, 0.35); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 26px;
    width: 360px;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

.logo { font-size: 34px; font-weight: 800; letter-spacing: -1px; color: var(--accent); margin-bottom: 16px; }
.daily-label { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .1em; }
.daily-date { font-size: 18px; font-weight: 700; margin: 2px 0 12px; }
.daily-best { margin: 8px 0 14px; }
.final-title { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.sb-round { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .1em; }

.btn-primary, .btn-secondary {
    display: block; width: 100%;
    padding: 13px;
    font-size: 16px; font-weight: 700;
    border: none; border-radius: 10px;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: rgba(31, 111, 178, 0.1); color: var(--accent); }
.btn-pair { display: flex; gap: 10px; margin-top: 16px; }
.btn-pair > * { flex: 1; }

.settings { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); text-align: left; }
.set-label { font-size: 11px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin: 8px 0 4px; }
.seg { display: flex; background: #eef3f7; border-radius: 9px; padding: 3px; }
.seg button { flex: 1; padding: 8px 4px; border: none; background: none; border-radius: 7px; font-size: 14px; color: var(--text); cursor: pointer; }
.seg button.on { background: #fff; color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
#tiltNote { margin-top: 6px; }
.how { margin-top: 14px; }
.mouse-only { display: inline; }
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
    .mouse-only { display: none; }
    .touch-only { display: inline; }
}

/* ── Level list ── */
.lvl {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 11px 12px; margin-bottom: 6px;
    background: #eef3f7; border: none; border-radius: 9px;
    font-size: 15px; color: var(--text); text-align: left; cursor: pointer;
}
.lvl .n { width: 22px; font-weight: 800; color: var(--accent); }
.lvl .nm { flex: 1; }
.lvl .st { color: #e0a000; letter-spacing: 1px; }
.lvl .sc { width: 30px; text-align: right; font-weight: 700; color: var(--dim); font-variant-numeric: tabular-nums; }
.lvl:disabled { opacity: .45; cursor: default; }

/* ── Briefing and result ── */
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.facts div { background: #eef3f7; border-radius: 8px; padding: 7px; font-size: 13px; }
.facts b { display: block; font-size: 15px; }
.tip { font-size: 14px; line-height: 1.4; margin: 6px 0 16px; text-align: left; }
.stars { font-size: 34px; color: #e0a000; letter-spacing: 4px; margin: 6px 0 0; min-height: 10px; }
.score { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.res-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 8px; }
.res-table td { padding: 5px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.res-table td:nth-child(2) { font-weight: 600; }
.res-table td:last-child { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ── Game ── */
#gameContainer { position: fixed; inset: 0; }
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#touchArea { position: absolute; inset: 0; touch-action: none; }
#stickCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#hudTop {
    position: absolute; left: 0; right: 0; top: 0;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 0 calc(env(safe-area-inset-left) + 10px);
    pointer-events: none;
}
.hud-btn {
    pointer-events: auto;
    width: 40px; height: 40px; border-radius: 50%;
    border: none; background: rgba(0, 0, 0, 0.35); color: #fff;
    font-size: 18px; cursor: pointer; flex: none;
}
.readouts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.ro {
    background: rgba(10, 20, 35, 0.55); color: #fff;
    border-radius: 8px; padding: 4px 8px;
    font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px;
    min-width: 76px; text-align: center;
}
.ro-l { font-size: 9px; opacity: .65; margin-right: 4px; letter-spacing: .05em; }
.ro-u { font-size: 9px; opacity: .65; margin-left: 2px; }
.ro.amber { color: #ffcf5a; }
.ro.red { color: #ff7a6e; }

#hudGuide {
    position: absolute; left: 50%; transform: translateX(-50%);
    top: calc(env(safe-area-inset-top) + 58px);
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    pointer-events: none;
}
#papi { display: flex; gap: 6px; background: rgba(10, 20, 35, 0.45); padding: 5px 8px; border-radius: 12px; }
#papi i { width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 6px rgba(255,255,255,.7); }
#papi i.r { background: #ff3b30; box-shadow: 0 0 6px rgba(255,59,48,.8); }
#locArrow { color: #fff; font-weight: 800; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.6); min-height: 16px; }

#warn {
    position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
    color: #ff3b30; font-size: 28px; font-weight: 900; letter-spacing: .08em;
    text-shadow: 0 0 8px rgba(0,0,0,.5);
    pointer-events: none;
    animation: blink .6s steps(2) infinite;
}
#warn.msg { color: #fff; animation: none; font-size: 24px; }
@keyframes blink { 50% { opacity: .25; } }
#hudLevel {
    position: absolute; left: calc(env(safe-area-inset-left) + 12px); bottom: calc(env(safe-area-inset-bottom) + 8px);
    color: rgba(255,255,255,.8); text-shadow: 0 1px 2px rgba(0,0,0,.5); pointer-events: none;
}

#throttle {
    position: absolute;
    right: calc(env(safe-area-inset-right) + 14px);
    top: 50%; transform: translateY(-50%);
    width: 26px; height: 38vh; max-height: 240px; min-height: 120px;
    background: rgba(10, 20, 35, 0.45); border: 2px solid rgba(255,255,255,.6);
    border-radius: 13px; overflow: hidden; pointer-events: none;
}
#thrFill { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(#ffd24a, #f08a20); }
#thrLabel {
    position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%);
    font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000;
}

.ctl-btn {
    position: absolute;
    border: 2px solid rgba(255,255,255,.7); border-radius: 12px;
    background: rgba(10, 20, 35, 0.5); color: #fff;
    font-weight: 800; font-size: 14px; cursor: pointer;
}
#gearBtn {
    right: calc(env(safe-area-inset-right) + 54px);
    bottom: calc(env(safe-area-inset-bottom) + 16px);
    width: 86px; height: 52px; line-height: 1.1;
}
#gearBtn.down { border-color: #5be08a; color: #5be08a; }
#gearBtn.up { border-color: #ff7a6e; color: #ff7a6e; }
#gearBtn.alert { animation: blink .6s steps(2) infinite; background: rgba(200, 40, 30, .6); color: #fff; }
.small-btn { width: 44px; height: 44px; font-size: 18px; border-radius: 50%; }
#viewBtn { right: calc(env(safe-area-inset-right) + 150px); bottom: calc(env(safe-area-inset-bottom) + 20px); }
#recenterBtn { right: calc(env(safe-area-inset-right) + 202px); bottom: calc(env(safe-area-inset-bottom) + 20px); }

@media (max-width: 520px) {
    .ro { min-width: 64px; font-size: 14px; padding: 3px 5px; }
    #warn { font-size: 22px; }
}
