:root {
    --ink: #fff8e7;
    --muted: #cfe0ea;
    --panel: rgba(16, 30, 44, 0.97);
    --panel-edge: rgba(255, 255, 255, 0.14);
    --accent: #ffcc33;
    --green: #3a8420;        /* white text 4.7:1 */
    --green-dark: #24560f;
    --blue: #2a6fae;         /* white text 5.3:1 */
    --blue-dark: #1a4c7c;
    --pixel: 'Press Start 2P', ui-monospace, monospace;
    --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #1b2b3a;
    color: var(--ink);
    font-family: var(--body);
    -webkit-tap-highlight-color: transparent;
}

#stage {
    position: fixed;
    inset: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hidden { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------------- HUD ---------------- */
#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 5;
}

.hud-left { display: flex; flex-direction: column; gap: 6px; }

.hud-score {
    font-family: var(--pixel);
    font-size: clamp(28px, 6vw, 44px);
    color: #fff;
    text-shadow: 3px 3px 0 #10202c, -1px -1px 0 #10202c;
    line-height: 1;
}

#score-display, #coin-display {
    display: inline-block;
    font-variant-numeric: tabular-nums;
    transform-origin: left center;
    transition: transform 0.1s;
}

#score-display.bump, #coin-display.bump { transform: scale(1.15); }

.hud-best {
    align-self: flex-start;
    font-family: var(--pixel);
    font-size: 11px;
    color: #fff;
    text-shadow: 2px 2px 0 #10202c;
    background: rgba(16, 30, 44, 0.55);
    padding: 5px 8px;
    border-radius: 8px;
}

.combo {
    font-family: var(--pixel);
    font-size: 12px;
    color: var(--accent);
    text-shadow: 2px 2px 0 #4a2a00;
    min-height: 14px;
    transform-origin: left center;
    transition: transform 0.12s;
}

.combo.pop { transform: scale(1.3); }

.hud-right { display: flex; align-items: center; gap: 8px; }

.hud-coins {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--pixel);
    font-size: 16px;
    color: #fff;
    text-shadow: 2px 2px 0 #10202c;
    background: rgba(16, 30, 44, 0.55);
    padding: 8px 10px;
    border-radius: 10px;
}

.coin-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff6b0 0 20%, #ffd23f 21% 60%, #d99a00 61%);
    box-shadow: 0 0 0 2px #8a5a00;
    vertical-align: middle;
}

.icon-btn {
    pointer-events: auto;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: rgba(16, 30, 44, 0.7);
    color: #fff;
    font-size: 16px;
    font-family: var(--body);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.08s, filter 0.15s, background-color 0.15s;
}

.icon-btn:active { transform: translateY(2px); }

.icon-btn[aria-pressed="true"] { background: rgba(160, 40, 40, 0.8); }

.icon-btn svg { display: block; }
#mute-icon.is-muted .ico-on, #mute-icon:not(.is-muted) .ico-off { display: none; }

.powerups {
    position: absolute;
    left: max(14px, env(safe-area-inset-left));
    top: calc(max(12px, env(safe-area-inset-top)) + 96px);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pu-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(16, 30, 44, 0.75);
    font-size: 13px;
    font-weight: 700;
    min-width: 120px;
    position: relative;
    overflow: hidden;
}

.pu-chip .pu-bar {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    background: currentColor;
}

.pu-schild { color: #7fd3ff; }
.pu-magnet { color: #ff8a80; }
.pu-zeitlupe { color: #d1a6ff; }

/* ---------------- Banner ---------------- */
.banner {
    position: fixed;
    left: 50%;
    top: 22%;
    transform: translate(-50%, -20px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    z-index: 6;
    font-family: var(--pixel);
    font-size: clamp(14px, 3.6vw, 24px);
    text-align: center;
    color: #fff;
    background: rgba(16, 30, 44, 0.82);
    border: 2px solid var(--accent);
    padding: 14px 20px;
    border-radius: 14px;
    line-height: 1.5;
    transition: opacity 0.25s, transform 0.25s;
    max-width: 90vw;
}

.banner small {
    display: block;
    font-family: var(--body);
    font-size: 14px;
    color: var(--muted);
    font-weight: 600;
}

.banner.show {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

/* ---------------- Screens ---------------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(10, 20, 32, 0.25), rgba(10, 20, 32, 0.6));
}

.screen:not(.hidden) { animation: rr-fade 0.25s cubic-bezier(0.22, 1, 0.36, 1); }
.screen:not(.hidden) .panel { animation: rr-pop 0.3s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes rr-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rr-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.95); }
    to { opacity: 1; transform: none; }
}
@keyframes rr-best-pop {
    0% { transform: scale(0.9); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.panel {
    margin: auto 0;
    flex-shrink: 0;
    width: min(440px, 100%);
    background: var(--panel);
    border: 2px solid var(--panel-edge);
    border-radius: 20px;
    padding: 20px 20px 18px;
    text-align: center;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.panel-small { width: min(380px, 100%); }

.logo {
    font-family: var(--pixel);
    font-size: clamp(30px, 9vw, 42px);
    line-height: 1.15;
    margin: 6px 0 0;
    color: var(--accent);
    text-shadow: 4px 4px 0 #1a6fb0, 7px 7px 0 #0e3a5c;
    letter-spacing: 2px;
}

.tagline {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.45;
}

h2 {
    font-family: var(--pixel);
    font-size: 12px;
    margin: 0 0 8px;
    color: var(--accent);
    letter-spacing: 1px;
}

.screen-title {
    font-size: clamp(16px, 5vw, 22px);
    color: #fff;
    margin: 4px 0;
    line-height: 1.4;
}

.stat-row {
    display: flex;
    justify-content: center;
    gap: 22px;
    font-size: 15px;
    color: var(--muted);
}

.stat-row b {
    font-family: var(--pixel);
    font-size: 14px;
    color: #fff;
}

.chars {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    padding: 12px;
}

.char-select {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

#char-preview {
    width: 120px;
    height: 120px;
    border-radius: 16px;
    background: radial-gradient(circle at 50% 60%, #8bd35a, #4f9a2c);
}

.char-name {
    font-family: var(--pixel);
    font-size: 13px;
    margin: 10px 0 8px;
    min-height: 16px;
}

.char-name small {
    display: block;
    margin-top: 6px;
    font-family: var(--body);
    font-size: 13px;
    color: var(--muted);
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 12px 22px;
    font-family: var(--pixel);
    font-size: 15px;
    color: #fff;
    background: var(--green);
    border: 3px solid var(--green-dark);
    border-radius: 12px;
    box-shadow: 0 5px 0 var(--green-dark);
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}

.btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--green-dark);
}

.btn:disabled {
    filter: grayscale(0.8) brightness(0.8);
    cursor: not-allowed;
}

.btn-play { font-size: 18px; min-height: 58px; }

.btn-small {
    font-size: 13px;
    min-height: 44px;
    background: #3d5a73;
    border-color: #263c50;
    box-shadow: 0 4px 0 #263c50;
}

.btn-small.buy {
    background: #c98a00;
    border-color: #7d5500;
    box-shadow: 0 4px 0 #7d5500;
}

.btn-home {
    font-size: 13px;
    min-height: 44px;
    background: var(--blue);
    border-color: var(--blue-dark);
    box-shadow: 0 4px 0 var(--blue-dark);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
    box-shadow: 0 0 0 6px #1a6fb0;
}

/* Keep the 3D ledge of the buttons and add the focus ring on top. */
.btn:focus-visible { box-shadow: 0 5px 0 var(--green-dark), 0 0 0 6px #1a6fb0; }
.btn-small:focus-visible { box-shadow: 0 4px 0 #263c50, 0 0 0 6px #1a6fb0; }
.btn-small.buy:focus-visible { box-shadow: 0 4px 0 #7d5500, 0 0 0 6px #1a6fb0; }
.btn-home:focus-visible { box-shadow: 0 4px 0 var(--blue-dark), 0 0 0 6px #1a6fb0; }
.btn:active:not(:disabled):focus-visible { box-shadow: 0 1px 0 var(--green-dark), 0 0 0 6px #1a6fb0; }

@media (hover: hover) {
    .btn:hover:not(:disabled), .icon-btn:hover { filter: brightness(1.1); }
}

.missions { text-align: left; }

.mission-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mission-list li {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1.35;
}

.mission-list li.done { color: #9be37a; }

.mission-reward {
    flex-shrink: 0;
    font-family: var(--pixel);
    font-size: 12px;
    color: var(--accent);
    white-space: nowrap;
}

.howto {
    text-align: left;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.45;
}

.howto summary {
    cursor: pointer;
    font-weight: 700;
    min-height: 28px;
    display: flex;
    align-items: center;
}

.howto ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.howto li { margin-bottom: 6px; }
.howto b { color: #fff; }

.final { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.final-score {
    font-family: var(--pixel);
    font-size: 44px;
    color: var(--accent);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.final-score small { font-size: 11px; color: var(--muted); }

#final-score {
    font-variant-numeric: tabular-nums;
    transition: transform 0.12s;
}

#final-score.bump { transform: scale(1.15); }

.final-best { font-size: 15px; color: var(--muted); font-weight: 600; }
.final-best.new {
    color: #9be37a;
    font-family: var(--pixel);
    font-size: 13px;
    animation: rr-best-pop 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.over-details {
    list-style: none;
    margin: 0;
    padding: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 14px;
}

.over-details li {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 9px;
    padding: 7px 10px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.over-details li.good { color: #9be37a; }
.over-details li.gold { color: var(--accent); }

.hint { margin: 0; font-size: 13px; color: var(--muted); }

@media (hover: none) {
    .hint { display: none; }
}

@media (max-height: 640px) {
    .logo { font-size: 26px; }
    .panel { gap: 9px; padding: 14px; }
    #char-preview { width: 92px; height: 92px; }
}

/* Site-wide achievement toasts (shared progression.js): keep them compact on
   phones so they do not cover the lower play area. Styling only, game-local. */
@media (max-width: 700px) {
    body .prog-toast-container {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: max(10px, env(safe-area-inset-bottom, 0px));
        width: min(340px, calc(100vw - 24px));
        max-width: none;
    }
    body .prog-toast { padding: 8px 12px; gap: 10px; }
    body .prog-toast__icon { display: none; }
    body .prog-toast__sub { display: none; }
    body .prog-toast__title { white-space: normal; overflow: visible; }
}

/* During a run the toast is purely informative: touches pass through to the game. */
body.rr-playing .prog-toast-container,
body.rr-playing .prog-toast { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
    .banner, .combo, .btn, .icon-btn, #score-display, #coin-display, #final-score { transition: none; }
    .screen:not(.hidden) .panel { animation-name: rr-fade; }
    .final-best.new { animation: none; }
}
