/* Gravity Goose: Visual & Audio Overhaul Styles */
:root {
    --bg-dark: #090d16;
    --arcade-frame: #1e1b4b;
    --neon-blue: #06b6d4;
    --neon-pink: #f43f5e;
    --neon-yellow: #facc15;
    --text-light: #f8fafc;
    --glass-bg: rgba(15, 23, 42, 0.85);
    --glass-border: rgba(56, 189, 248, 0.3);
}

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

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 50% 30%, #1e1b4b 0%, #090d16 80%);
    color: var(--text-light);
    font-family: 'Press Start 2P', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
    /* Custom pixel cursor */
    cursor: url('assets/cursor.png') 0 0, auto;
}

/* Pointer variant over clickable UI */
button,
.level-btn,
input[type="range"],
input[type="checkbox"],
select,
a {
    cursor: url('assets/cursor-pointer.png') 7 7, pointer;
}

/* Arcade Cabinet Bezel Wrapper */
#arcade-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #0f172a;
    padding: 16px;
    border-radius: 16px;
    border: 4px solid var(--neon-blue);
    box-shadow: 
        0 0 30px rgba(6, 182, 212, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
    /* Responsive: cap by viewport width, absolute size, or remaining height
       while preserving the 4:3 canvas aspect ratio. */
    width: min(96vw, 840px, calc((100dvh - 150px) * 4 / 3));
    max-height: 100dvh;
    box-sizing: border-box;
}

/* Arcade Top Header & HUD */
#arcade-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    row-gap: 10px;
    padding: 12px 20px;
    background: rgba(30, 27, 75, 0.8);
    border-bottom: 2px solid var(--glass-border);
    box-shadow: inset 0 0 10px rgba(6, 182, 212, 0.2);
}

.arcade-title {
    font-size: 14px;
    color: var(--neon-pink);
    text-shadow: 2px 2px 0px #000, 0 0 8px var(--neon-pink);
    letter-spacing: 2px;
}

/* Minimalist icon-based HUD (top bar) */
#hud {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-light);
    text-shadow: 1px 1px 0 #000;
}

#hud.hidden {
    display: none;
}

.hud-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.hud-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.hud-ico {
    font-size: 13px;
    line-height: 1;
}

#hud-lives {
    color: #fb7185;
    letter-spacing: 2px;
}

.hud-level-badge {
    color: var(--neon-yellow);
    font-size: 10px;
    letter-spacing: 1px;
}

/* Twin ability cooldown bars anchored under the icon row */
.hud-bars {
    display: flex;
    gap: 8px;
    align-items: center;
}

.hud-bar {
    width: 90px;
    height: 6px;
    border-radius: 3px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.35);
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.hud-bar.hidden {
    display: none;
}

.hud-bar-fill {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: 2px;
    transition: width 0.12s ease;
}

.hud-bar-fill.flip {
    background: linear-gradient(90deg, #a855f7, #e879f9);
    box-shadow: 0 0 6px rgba(168, 85, 247, 0.8);
}

.hud-bar-fill.blink {
    background: linear-gradient(90deg, #06b6d4, #22d3ee);
    box-shadow: 0 0 6px rgba(6, 182, 212, 0.8);
}

.hud-bar-fill.empty {
    width: 0% !important;
    background: #334155;
    box-shadow: none;
}

/* Boss-switch tracker (Level 20 only) */
.hud-boss-item {
    color: #f43f5e;
    font-size: 11px;
    letter-spacing: 2px;
}

.hud-boss-item.hidden {
    display: none;
}

#hud-boss {
    color: #f43f5e;
    letter-spacing: 2px;
}

/* Ghost-run delta vs best time (hidden entirely on mobile) */
.hud-delta {
    font-size: 9px;
    color: #94a3b8;
}

/* Canvas Box */
#game-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    height: auto;
    background-color: #0f172a;
    border: 4px solid #334155;
    border-radius: 8px;
    image-rendering: pixelated;
    overflow: hidden;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.9);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill; /* Reset object-fit since aspect ratio is enforced by container */
    image-rendering: pixelated;
}

/* Instant-respawn death effect: a subtle red vignette that fades out.
   (No bright white flash — eye-strain-free.) The quick screen shake is
   triggered by Game.screenShake() alongside this overlay. */
#flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(127, 29, 29, 0) 52%, rgba(127, 29, 29, 0.85) 100%);
    box-shadow: inset 0 0 60px 12px rgba(220, 38, 38, 0.55);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

#flash-overlay.reset {
    animation: deathVignette 0.55s ease-out forwards;
}

@keyframes deathVignette {
    0%   { opacity: 1; }
    60%  { opacity: 0.5; }
    100% { opacity: 0; }
}

/* Gravity-flip stamina bar lives inside #hud (see .hud-bar above) */
/* Boss-overload switch tracker (Level 20 only) */

/* New Best Time pulse */
@keyframes bestPulse {
    0%, 100% { opacity: 1; text-shadow: 2px 2px 0px #000, 0 0 8px var(--neon-yellow); }
    50% { opacity: 0.55; text-shadow: 2px 2px 0px #000, 0 0 20px #ffffff; }
}

.best-flash {
    color: var(--neon-yellow);
    animation: bestPulse 0.8s infinite;
}

/* Screen Shake Effect */
@keyframes shake {
    0% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 6px); }
    40% { transform: translate(6px, -6px); }
    60% { transform: translate(-6px, -6px); }
    80% { transform: translate(6px, 6px); }
    100% { transform: translate(0, 0); }
}

.shake {
    animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

/* Massive shake for the boss death sequence */
@keyframes shakeBig {
    0% { transform: translate(0, 0) rotate(0deg); }
    15% { transform: translate(-12px, 10px) rotate(-0.6deg); }
    30% { transform: translate(10px, -12px) rotate(0.5deg); }
    45% { transform: translate(-10px, -8px) rotate(-0.4deg); }
    60% { transform: translate(12px, 10px) rotate(0.6deg); }
    75% { transform: translate(-8px, 8px) rotate(-0.3deg); }
    90% { transform: translate(6px, -6px) rotate(0.2deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

.shake-big {
    animation: shakeBig 0.6s cubic-bezier(.36,.07,.19,.97) both;
}

/* Floating text layer (crumb pickups, best-run popups) */
.touch-controls {
    display: none;
    position: absolute;
    bottom: max(15px, env(safe-area-inset-bottom));
    left: max(15px, env(safe-area-inset-left));
    right: max(15px, env(safe-area-inset-right));
    width: calc(100% - max(30px, env(safe-area-inset-left) + env(safe-area-inset-right)));
    justify-content: space-between;
    pointer-events: none;
    z-index: 100;
}

#float-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 2;
}

.float-text {
    position: absolute;
    transform: translate(-50%, -50%);
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: var(--neon-yellow);
    text-shadow: 2px 2px 0 #000, 0 0 10px var(--neon-yellow);
    white-space: nowrap;
    animation: floatUp 0.9s ease-out forwards;
}

.float-text.perfect {
    font-size: 18px;
    color: var(--neon-pink);
    text-shadow: 2px 2px 0 #000, 0 0 14px var(--neon-pink);
}

/* Level Devil troll alerts ("FAKE!", "TRAP!") */
.float-text.trap {
    font-size: 16px;
    color: #f87171;
    text-shadow: 2px 2px 0 #000, 0 0 14px #ef4444;
}

@keyframes floatUp {
    0%   { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, -170%); }
}

/* UI Glassmorphism Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    pointer-events: none;
    touch-action: manipulation;
}

/* Glassmorphism Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 2px solid var(--glass-border);
    text-align: center;
    pointer-events: auto;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    scroll-behavior: smooth;
    touch-action: pan-y;
    overscroll-behavior: contain;
    padding: 40px 16px 0px 16px; /* Removed bottom padding, handled by ::after */
}

/* Keep the menu column readable on very wide screens */
.screen > * {
    max-width: 780px;
    margin-inline: auto;
}

.screen::before {
    content: '';
    display: block;
    flex-shrink: 0;
    width: 100%;
    margin: auto;
}

/* Fix flexbox scroll padding ignoring the bottom padding */
.screen::after {
    content: '';
    display: block;
    flex: 1 0 auto;
    min-height: 60px;
    flex-shrink: 0;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none !important;
    display: none !important;
}

.screen.active {
    opacity: 1;
    z-index: 60;
    pointer-events: auto;
}

/* Mechanic Toast Banner */
#mechanic-toast {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    padding: 10px 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 2px solid var(--neon-pink);
    border-radius: 8px;
    color: var(--neon-pink);
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    text-align: center;
    box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

#mechanic-toast.hidden {
    display: none !important;
}

#mechanic-toast.toast-in {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#mechanic-toast.toast-out {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
}

/* Contextual Control Hint Popup */
#control-hint {
    position: fixed;
    transform: translate(-50%, -100%);
    z-index: 85;
    padding: 6px 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 2px solid var(--neon-yellow);
    border-radius: 6px;
    color: var(--neon-yellow);
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.4);
    pointer-events: none;
    transition: opacity 0.15s ease;
}

#control-hint.hidden {
    display: none !important;
}

.screen.active {
    opacity: 1;
}

/* Typography & Titles */
.title {
    font-size: clamp(18px, 4.5vw, 30px);
    color: var(--neon-blue);
    margin-bottom: clamp(4px, 1.5vw, 8px);
    text-shadow: 3px 3px 0px #000, 0 0 12px var(--neon-blue);
}

.title-sub {
    font-size: clamp(11px, 2.5vw, 18px);
    color: var(--neon-yellow);
    margin-bottom: clamp(10px, 2.5vw, 20px);
    text-shadow: 2px 2px 0px #000;
}

.title.game-over { 
    color: var(--neon-pink); 
    text-shadow: 3px 3px 0px #000, 0 0 15px var(--neon-pink);
}

.title.win { 
    color: var(--neon-yellow); 
    text-shadow: 3px 3px 0px #000, 0 0 15px var(--neon-yellow);
}

.subtitle {
    font-size: clamp(9px, 1.8vw, 12px);
    color: #94a3b8;
    margin-bottom: clamp(12px, 3vw, 28px);
    line-height: 1.6;
}

.highlight {
    color: var(--neon-yellow);
}

/* Endgame victory cinematic: pixel-art goose eats the recovered sandwich */
#victory-canvas {
    display: block;
    width: 260px;
    height: 180px;
    margin: 0 auto 14px;
    image-rendering: pixelated;
    background: rgba(2, 6, 23, 0.55);
    border: 2px solid rgba(250, 204, 21, 0.35);
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(250, 204, 21, 0.15);
}

/* Controls Info Card */
.controls-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--glass-border);
    padding: clamp(8px, 2vw, 14px) clamp(12px, 3vw, 24px);
    border-radius: 8px;
    margin-bottom: clamp(12px, 3vw, 28px);
    font-size: clamp(8px, 1.5vw, 10px);
    color: #cbd5e1;
    line-height: 2;
}

.mobile-only {
    display: none;
}

.key {
    background: #0f172a;
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    padding: 2px 6px;
    border-radius: 4px;
}

/* 3D Retro Arcade Buttons */
.btn {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2vw, 14px);
    padding: clamp(10px, 2vw, 14px) clamp(18px, 3vw, 28px);
    background: #06b6d4;
    color: #090d16;
    border: 3px solid #0f172a;
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
    outline: none;
    box-shadow: 0 6px 0 #005f73;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto !important;
    z-index: 70;
}

.btn:hover {
    background-color: #22d3ee;
    color: #090d16;
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #005f73;
}

.btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 transparent;
}

.btn:focus-visible,
.btn-ghost:focus-visible,
.btn-danger:focus-visible,
.touch-btn:focus-visible,
.level-btn:focus-visible {
    outline: 3px solid var(--neon-yellow);
    outline-offset: 3px;
}

/* Ghost buttons (secondary actions) */
.btn-ghost {
    background: #f43f5e;
    color: #090d16;
    border: 3px solid #0f172a;
    box-shadow: 0 6px 0 #9f1239;
    margin-top: 12px;
}
.btn-ghost:last-child {
    margin-bottom: 60px; /* Force spacing at the bottom of the container */
}

.btn-ghost:hover {
    background-color: #fb7185;
    color: #090d16;
    box-shadow: 0 8px 0 #9f1239;
}

.btn-ghost:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 transparent;
}

.btn-danger {
    background: #e11d48;
    color: #ffffff;
    border: 3px solid #0f172a;
    box-shadow: 0 6px 0 #881337;
}

.btn-danger:hover {
    background-color: #f43f5e;
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #881337;
}

.btn-danger:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 transparent;
}

/* Level Select Grid */
#level-select-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    width: 100%;
    max-width: 780px;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 40px;
}

.world-header {
    flex-basis: 100%;
    width: 100%;
    text-align: center;
    color: #f8fafc;
    font-size: 14px;
    margin-top: 24px;
    margin-bottom: 8px;
    text-shadow: 2px 2px 0px #090d16;
    letter-spacing: 1px;
    border-bottom: 2px solid #334155;
    padding-bottom: 8px;
}

.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 76px;
    height: 76px;
    flex: 0 0 auto;
    position: relative;
    font-family: 'Press Start 2P', monospace;
    background: var(--neon-blue);
    color: #090d16;
    border: none;
    border-bottom: 4px solid #0891b2;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
}

.level-btn:hover:not(:disabled) {
    background-color: #ffffff;
    transform: translateY(-3px);
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.6);
}

/* Levels 6-10 preview the sunset palette */
.level-btn.sunset:not(.locked) {
    background: linear-gradient(180deg, #f97316, #b45309);
    border-bottom-color: #7c2d12;
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.4);
}

.level-btn.sunset:hover:not(:disabled) {
    background-color: #fbbf24;
}

/* Levels 11-15 preview the cyberpunk palette */
.level-btn.cyberpunk:not(.locked) {
    background: linear-gradient(180deg, #e11d48, #86198f);
    border-bottom-color: #4a044e;
    box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}

.level-btn.cyberpunk:hover:not(:disabled) {
    background-color: #f43f5e;
}

/* Levels 16-20 preview the mothership palette */
.level-btn.mothership:not(.locked) {
    background: linear-gradient(180deg, #10b981, #065f46);
    border-bottom-color: #134e3a;
    box-shadow: 0 0 15px rgba(52, 211, 153, 0.4);
}

.level-btn.mothership:hover:not(:disabled) {
    background-color: #34d399;
}

/* Levels 21-30 preview the kitchen palette */
.level-btn.kitchen:not(.locked) {
    background: linear-gradient(180deg, #fef3c7, #f59e0b);
    border-bottom-color: #f97316;
    color: #78350f;
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.4);
}

.level-btn.kitchen:hover:not(:disabled) {
    background-color: #fef3c7;
}


/* Practice-Mode chip on unlocked level buttons: secondary, stakes-free action */
.level-practice {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    line-height: 16px;
    font-size: 10px;
    text-align: center;
    color: #090d16;
    background: #facc15;
    border: 1px solid #a16207;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1;
    transition: transform 0.1s ease;
}

.level-practice:hover {
    transform: scale(1.15);
}

/* Persistent HUD badge shown while a Practice run is active */
.hud-practice-badge {
    color: #090d16;
    background: #facc15;
    border: 2px solid #a16207;
    border-radius: 4px;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 4px 6px;
    box-shadow: 0 0 10px rgba(250, 204, 21, 0.5);
    animation: practicePulse 1.2s ease-in-out infinite;
}

@keyframes practicePulse {
    0%, 100% { box-shadow: 0 0 6px rgba(250, 204, 21, 0.4); }
    50% { box-shadow: 0 0 14px rgba(250, 204, 21, 0.9); }
}

.level-btn.locked {
    background: #334155;
    color: #64748b;
    border-bottom-color: #1e293b;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.7;
}

.level-num {
    font-size: 20px;
}

.level-medal {
    font-size: 14px;
    line-height: 1;
}

.level-best {
    font-size: 9px;
    color: #090d16;
}

.level-btn.locked .level-best {
    color: #64748b;
}

.stats-line {
    font-size: 11px;
    color: var(--neon-yellow);
}

/* Settings Menu */
.settings-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin-bottom: 24px;
    width: 100%;
    max-width: 560px;
    justify-content: center;
}

.settings-label {
    font-size: 12px;
    color: var(--neon-blue);
    min-width: 110px;
    text-align: right;
}

.settings-value {
    font-size: 12px;
    color: var(--neon-yellow);
    min-width: 44px;
    text-align: left;
}

.settings-hint {
    font-size: 8px;
    color: #94a3b8;
}

/* Achievements Screen */
#achievements-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 480px;
    margin-bottom: 20px;
    max-height: 50dvh;
    overflow-y: auto;
    padding: 8px;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--glass-bg);
    border: 2px solid var(--glass-border);
    border-radius: 8px;
    backdrop-filter: blur(8px);
}

.achievement-card.unlocked {
    border-color: var(--neon-yellow);
    box-shadow: 0 0 10px rgba(250, 204, 21, 0.3);
}

.achievement-card.locked {
    opacity: 0.6;
}

.ach-icon {
    font-size: 24px;
}

.ach-info {
    flex-grow: 1;
    text-align: left;
}

.ach-title {
    font-size: 11px;
    color: var(--neon-yellow);
    margin-bottom: 4px;
}

.ach-desc {
    font-size: 8px;
    color: var(--text-light);
}

.ach-status {
    font-size: 8px;
    color: var(--neon-blue);
}

input[type="range"] {
    width: 180px;
    accent-color: var(--neon-blue);
    cursor: pointer;
}

input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--neon-blue);
    cursor: pointer;
}

/* Small-screen polish & Mobile UI responsiveness */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    .mobile-only {
        display: block !important;
    }
    #arcade-wrapper {
        padding: 8px;
        width: 98vw;
        max-height: 100dvh;
    }
    .title { font-size: clamp(16px, 5vw, 22px); margin-bottom: 4px; }
    .title-sub { font-size: clamp(10px, 3.5vw, 14px); margin-bottom: 10px; }
    .subtitle { font-size: clamp(8px, 2.5vw, 11px); margin-bottom: 12px; }
    .controls-card { font-size: 9px; padding: 8px 12px; margin-bottom: 12px; }
    .btn { font-size: clamp(9px, 2.8vw, 12px); padding: 10px 18px; }
}

/* ============================================================
   Neo-Retro Touch Controls (Glassmorphism buttons + pixel icons)
   ============================================================ */

/* Prevent pinch-zoom / scroll / double-tap zoom anywhere in the game */
html,
body {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}

#game-canvas {
    touch-action: none;
}

.touch-hint {
    opacity: 0.75;
    font-size: 9px;
}

/* Only meaningful on touch devices */
@media (hover: hover) and (pointer: fine) {
    .touch-hint {
        display: none;
    }
}

/* Root layer: a pointer-transparent overlay pinned to the viewport. The two
   zones inside re-enable pointer events so the buttons are tappable. Hidden
   by default; only revealed on touch-primary devices while a level is active. */
#touch-controls {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    padding-top: max(10px, env(safe-area-inset-top));
}

@media (pointer: coarse) {
    body.touch-device #touch-controls {
        display: block;
    }
}

#touch-controls.hidden,
body.touch-device #touch-controls.hidden {
    display: none !important;
    pointer-events: none !important;
}

/* Glassmorphism button base */
.touch-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 75px;
    min-height: 75px;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: rgba(148, 163, 184, 0.16);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), inset 0 0 16px rgba(255, 255, 255, 0.05);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
    cursor: pointer;
    outline: none;
    opacity: 0.3;
    transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease, opacity 0.1s ease;
}

.touch-btn.pressed {
    opacity: 1;
    transform: translateY(4px) scale(0.95);
    background: rgba(56, 189, 248, 0.4);
    box-shadow: 0 2px 10px rgba(56, 189, 248, 0.6);
}

@keyframes haptic-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.6); }
    100% { box-shadow: 0 0 0 14px rgba(250, 204, 21, 0); }
}

.touch-btn.haptic-pulse::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    animation: haptic-pulse 0.35s ease-out;
    pointer-events: none;
}

/* Decorative D-pad limbs (up/down) — rendered but not wired to gameplay */
.touch-btn-inert {
    pointer-events: none;
}

.touch-icon {
    display: block;
    pointer-events: none;
}

.dpad {
    display: flex;
    gap: 16px;
}

/* Action cluster — classic console layout:
   [ FLIP ]
   [BLINK][JUMP]
   Jump sits bottom-right (the big button), Blink directly to its left and
   Flip directly above Jump. */
.touch-zone-right {
    display: grid;
    grid-template-areas:
        "jump jump"
        "blink flip";
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    align-items: end;
    justify-items: center;
    gap: 12px;
}

#btn-touch-flip { grid-area: flip; }
#btn-touch-blink { grid-area: blink; }
#btn-touch-jump { grid-area: jump; }

.touch-jump {
    width: 92px;
    height: 92px;
    min-width: 92px;
    min-height: 92px;
}

.touch-pause {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    width: 52px;
    height: 52px;
}

/* Overlaid Touch Controls */
.touch-zone-left {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 100;
}

.touch-zone-right {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 100;
}

/* Edge-to-Edge Immersive Mobile Layout */
@media (max-width: 840px), (pointer: coarse) and (max-height: 500px) {
    #arcade-wrapper {
        position: relative;
        width: 100vw;
        height: 100dvh;
        max-width: none;
        padding: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        justify-content: flex-start;
    }
    #arcade-header {
        position: static;
        z-index: auto;
        flex-shrink: 0;
        margin-bottom: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        background: #0f172a;
        padding: 4px 12px;
        padding-top: max(4px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    #game-container {
        flex: 1 1 auto;
        width: 100%;
        height: auto;
        min-height: 0;
        aspect-ratio: auto;
        border: none;
        border-radius: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    #game-canvas {
        object-fit: contain;
        width: 100%;
        height: 100%;
        transform: none;
        transform-origin: center center;
    }
    body.boss-level #game-canvas {
        transform: none;
    }
    .hud-delta {
        display: none !important;
    }
    .screen {
        padding: 8px 12px;
    }
    .screen::after {
        min-height: 24px;
    }
    .controls-card {
        display: none !important;
    }
    .title {
        font-size: 16px !important;
        margin-bottom: 2px !important;
    }
    .title-sub {
        font-size: 10px !important;
        margin-bottom: 6px !important;
    }
    .subtitle {
        font-size: 9px !important;
        margin-bottom: 8px !important;
    }
    .menu-box {
        gap: 6px !important;
        margin-top: 4px !important;
    }
    .btn {
        padding: 12px 20px !important;
        font-size: 11px !important;
        border-radius: 12px !important;
    }
    #level-select-grid {
        max-width: calc(100vw - 24px);
        gap: 8px !important;
        padding-bottom: 16px;
        margin-bottom: 12px;
    }
    .level-btn {
        width: 64px;
        height: 64px;
        gap: 3px !important;
        border-radius: 8px !important;
        border-bottom-width: 3px;
    }
    .world-header {
        font-size: 10px !important;
        margin-top: 14px !important;
        margin-bottom: 4px !important;
    }
    .level-num {
        font-size: 12px;
    }
    .level-medal {
        font-size: 10px;
    }
    .level-best {
        font-size: 8px;
    }
    .level-practice {
        width: 22px;
        height: 22px;
        line-height: 20px;
        font-size: 11px;
    }
    .touch-zone-left {
        left: max(8px, env(safe-area-inset-left));
        bottom: max(8px, env(safe-area-inset-bottom));
        transform: scale(0.8);
        transform-origin: bottom left;
    }
    .touch-zone-right {
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        transform: scale(0.8);
        transform-origin: bottom right;
    }
}

/* Orientation Warning Overlay */
#orientation-warning {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-dark);
    color: var(--text-light);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

@media (orientation: portrait) {
    #orientation-warning {
        display: flex;
    }
}

/* Accessibility: Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .touch-btn.haptic-pulse::after {
        animation: none !important;
    }
    #mechanic-toast {
        transition: none !important;
    }
}
