@font-face {
    font-family: 'Petitinho';
    src: url('Fonts/Petitinho.ttf?v=petitinho-real-1') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: block;
}

/* Basic Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: #05070c;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    --app-width: 100vw;
    --app-height: 100vh;
    --app-left: 0px;
    --app-top: 0px;
    --move-stick-size: 144px;
    --move-knob-size: 68px;
    --jump-button-size: 72px;
    --move-control-opacity: 0.5;
    --jump-control-opacity: 0.5;
    --game-font: 'Petitinho', system-ui, sans-serif;
}

body {
    background:
        radial-gradient(circle at 18% 18%, rgba(77, 155, 230, 0.14), transparent 26%),
        radial-gradient(circle at 82% 10%, rgba(249, 194, 43, 0.11), transparent 24%),
        linear-gradient(145deg, #0a0b10 0%, #241b2b 52%, #05070c 100%);
    color: #e0e0e0; /* Light text */
    font-family: var(--game-font);
    font-synthesis: none;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: none;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* Prevent scrollbars initially */
    overflow-x: hidden;
    position: relative;
    overscroll-behavior: none;
    width: var(--app-width);
    min-height: var(--app-height);
    max-width: var(--app-width);
}

button,
input,
textarea,
select,
label,
a {
    font-family: var(--game-font);
    font-synthesis: none;
}

#loginStarCanvas {
    position: fixed;
    left: var(--app-left);
    top: var(--app-top);
    width: var(--app-width);
    height: var(--app-height);
    z-index: 0;
    pointer-events: none;
    border: none;
    background: transparent;
}

canvas {
    border: 1px solid #444; /* Subtle border */
    background-color: #000; /* Black canvas background */
    display: block; /* Default for canvas, ensures no extra space */
}

#gameCanvas {
    position: fixed;
    left: var(--app-left);
    top: var(--app-top);
    width: var(--app-width);
    height: var(--app-height);
    border: none;
    touch-action: none;
    z-index: 1;
}

body.game-screen-active {
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
    background: #000;
}

#mobileControls,
#landscapeBlocker,
#controllerToast {
    display: none;
}

#mobileControls {
    position: fixed;
    left: var(--app-left);
    top: var(--app-top);
    width: var(--app-width);
    height: var(--app-height);
    z-index: 18;
    pointer-events: none;
    touch-action: none;
}

.touch-stick {
    position: absolute;
    left: max(18px, env(safe-area-inset-left));
    bottom: 0;
    width: 128px;
    height: 128px;
    border: 2px solid rgba(199, 220, 208, 0.42);
    border-radius: 50%;
    background: rgba(17, 17, 24, 0.52);
    box-shadow: inset 0 0 24px rgba(143, 211, 255, 0.12), 0 10px 28px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
}

.touch-stick::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 2px;
    height: 54px;
    background: rgba(199, 220, 208, 0.22);
    transform: translate(-50%, -50%);
}

.touch-stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.56);
    background: linear-gradient(180deg, rgba(143, 211, 255, 0.86), rgba(77, 155, 230, 0.72));
    transform: translate(-50%, -50%);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

.touch-jump-button {
    position: absolute;
    right: max(20px, env(safe-area-inset-right));
    bottom: 8px;
    width: 116px;
    height: 116px;
    border: 3px solid rgba(255, 255, 255, 0.62);
    border-radius: 50%;
    background: linear-gradient(180deg, rgba(249, 194, 43, 0.96), rgba(245, 125, 74, 0.88));
    color: #2e222f;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.22rem;
    letter-spacing: 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-jump-button:active,
.touch-jump-button.is-pressed {
    transform: translateY(3px) scale(0.96);
    filter: brightness(1.08);
}

.touch-pause-button {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    top: max(76px, calc(env(safe-area-inset-top) + 12px));
    width: 58px;
    height: 34px;
    border: 1px solid rgba(199, 220, 208, 0.42);
    border-radius: 6px;
    background: rgba(17, 17, 24, 0.58);
    color: #c7dcd0;
    font-family: 'Petitinho', sans-serif;
    font-size: 0.78rem;
    line-height: 1;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-pause-button:active {
    transform: translateY(1px) scale(0.96);
    filter: brightness(1.18);
}

.controller-toast {
    position: fixed;
    left: calc(var(--app-left) + (var(--app-width) / 2));
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 18px);
    z-index: 70;
    max-width: min(86vw, 520px);
    padding: 10px 16px;
    border: 2px solid rgba(143, 211, 255, 0.72);
    border-radius: 8px;
    background: rgba(17, 17, 24, 0.92);
    color: #c7dcd0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.38), inset 0 0 18px rgba(143, 211, 255, 0.08);
    font-family: 'Petitinho', sans-serif;
    font-size: clamp(0.88rem, 2.4vw, 1.15rem);
    line-height: 1.1;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.controller-toast.visible {
    display: block;
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Login Screen Styles - Mimic Old Look */
#loginScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(180deg, rgba(62, 53, 70, 0.90), rgba(46, 34, 47, 0.92));
    padding: 26px 40px 24px;
    border-radius: 10px; /* Old border radius */
    max-width: 1060px;
    width: min(94vw, 1060px);
    /* Add side borders */
    border-left: 15px solid #4d9be6; /* Blue border */
    border-right: 15px solid #4d9be6; /* Blue border */
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55);
    z-index: 10; /* Ensure login is behind pause */
    position: relative;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

#loginScreen h1 {
    font-size: clamp(2.8rem, 6vw, 4.6rem);
    color: #ffffff; /* White */
    margin-bottom: 14px;
    letter-spacing: 3px;
    text-align: center;
    text-shadow: none; /* Remove previous shadow */
    /* font-family: Petitinho inherited */
}

.tagline {
    max-width: 720px;
    margin: -2px auto 18px;
    color: #c7dcd0;
    font-size: 1.15em;
    line-height: 1.35;
    text-align: center;
}

#authForm {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.login-lanes {
    display: grid;
    grid-template-columns: minmax(270px, 0.9fr) minmax(420px, 1.35fr);
    gap: 18px;
    align-items: stretch;
}

.login-panel {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    min-width: 0;
    padding: 16px;
    border: 1px solid rgba(199, 220, 208, 0.18);
    border-radius: 8px;
    background: rgba(17, 17, 24, 0.28);
    box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.02);
}

.section-label {
    color: #f9c22b;
    text-align: center;
    font-size: 1em;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.online-auth-block {
    padding: 12px;
    border: 1px solid rgba(199, 220, 208, 0.16);
    border-radius: 8px;
    background: rgba(42, 33, 48, 0.32);
}

.google-auth-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.email-auth-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.local-panel .input-group {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
}

.local-panel .input-group label {
    width: auto;
    text-align: left;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #f9c22b;
    font-size: 0.9em;
    text-align: center;
    white-space: nowrap;
    text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(199, 220, 208, 0.22);
}

.input-group {
    display: flex;
    flex-direction: row; /* Align label and input side-by-side */
    align-items: center; /* Vertically center label and input */
    width: 100%;
    gap: 10px; /* Space between label and input */
    min-width: 0;
}

.input-group label {
    font-size: 1.1em; /* Adjust size as needed */
    color: #ffffff; /* White label */
    width: 105px; /* Increased fixed width for labels */
    text-align: right;
    flex-shrink: 0; /* Prevent label from shrinking */
    /* font-family: Petitinho inherited */
}

#loginScreen input[type="text"],
#loginScreen input[type="email"],
#loginScreen input[type="password"] {
    flex-grow: 1; /* Allow input to take remaining space */
    min-width: 0;
    padding: 13px; /* Old padding */
    border: none;
    border-radius: 8px;
    background-color: #3e3546; /* Darker input background */
    color: #c7dcd0; /* Light text color */
    font-size: 1.1em; /* Old font size */
    /* font-family: Petitinho inherited */
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2); /* Old shadow */
}

#loginScreen input::placeholder {
    color: #7f708a; /* Old placeholder color */
    opacity: 0.8;
}

#loginScreen input[type="password"] {
    font-family: var(--game-font);
    font-size: 1.35em;
    line-height: 1;
}

/* Specific alignment for Display Name field (register only) */
.input-group.register-only {
    /* Keeps row layout from .input-group */
}

/* Remember me checkbox alignment */
.remember-me {
    justify-content: center; /* Center checkbox group */
    gap: 5px !important; /* Reduce gap */
}

.remember-me label {
    width: auto !important; /* Override fixed label width */
    text-align: left !important;
    font-size: 1em !important; /* Smaller font */
    color: #ccc !important; /* Lighter color */
}

.remember-me input[type="checkbox"] {
    margin-right: 5px;
    width: auto;
    vertical-align: middle;
    flex-grow: 0 !important; /* Don't let checkbox grow */
}

.button-group {
    display: flex;
    justify-content: center; /* Center buttons */
    gap: 20px; /* Old gap */
    width: 100%;
    margin-top: 6px; /* Increased top margin */
}

#loginScreen button {
    padding: 12px 30px; /* Old padding */
    border: none;
    border-radius: 5px; /* Old radius */
    background-color: #c7dcd0; /* Light button background */
    color: #3e3546; /* Dark text color */
    font-size: 1.1em; /* Old font size */
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2); /* Old shadow */
    text-shadow: none; /* Remove previous shadow */
    min-width: auto; /* Remove min-width */
}

#loginScreen .primary-action {
    width: 100%;
    padding: 15px 30px;
    background: #f9c22b;
    color: #2e222f;
    font-size: 1.45em;
    letter-spacing: 1px;
    box-shadow: 0 10px 30px rgba(249, 194, 43, 0.22);
}

#loginScreen .primary-action:hover:not(:disabled) {
    background: #ffe28a;
}

.google-signin-button,
.apple-signin-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 12px;
    border: 1px solid rgba(199, 220, 208, 0.38) !important;
}

.google-signin-button {
    background: #ffffff !important;
    color: #2e222f !important;
}

.apple-signin-button {
    background: #000000 !important;
    color: #ffffff !important;
}

.google-alias-panel {
    padding: 10px;
    border: 1px solid rgba(249, 194, 43, 0.32);
    border-radius: 8px;
    background: rgba(249, 194, 43, 0.08);
}

.google-alias-panel label {
    display: block;
    margin-bottom: 7px;
    color: #f9c22b;
    font-size: 0.86rem;
    text-align: center;
    text-transform: uppercase;
}

.google-alias-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

#googleAliasSaveButton {
    padding-inline: 16px;
    white-space: nowrap;
}

.google-mark {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: conic-gradient(from -45deg, #4285f4 0 25%, #34a853 0 50%, #fbbc05 0 75%, #ea4335 0);
    color: #ffffff;
    font: 700 15px var(--game-font);
}

.apple-mark {
    display: inline-grid;
    place-items: center;
    width: 54px;
    height: 54px;
    overflow: hidden;
    background: transparent;
    margin: -12px -6px;
}

.apple-mark img {
    display: block;
    width: 54px;
    height: 54px;
    object-fit: contain;
}

.menu-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    width: 100%;
}

.main-menu-version {
    position: absolute;
    right: 16px;
    bottom: 10px;
    color: rgba(199, 220, 208, 0.64);
    font-family: 'Petitinho', sans-serif;
    font-size: 0.78rem;
    line-height: 1;
    text-align: right;
    pointer-events: none;
}

#loginScreen button:hover:not(:disabled) {
    background-color: #ffffff; /* White hover */
    transform: scale(1.02); /* Slight grow */
}

#loginScreen .google-signin-button:hover:not(:disabled) {
    background: #ffffff !important;
    color: #2e222f !important;
}

#loginScreen .apple-signin-button:hover:not(:disabled) {
    background: #000000 !important;
    color: #ffffff !important;
}

#loginScreen button:active:not(:disabled) {
    transform: scale(0.98); /* Slight shrink */
}

#loginScreen button:disabled {
    background-color: #555;
    cursor: not-allowed;
    color: #999;
    transform: none;
    box-shadow: none;
}

#infoText {
    min-height: 1.2em;
    margin-top: 2px; /* Old margin */
    font-size: 1em; /* Old font size */
    color: #f9c22b; /* Yellow info color */
    text-align: center;
    /* font-family: Petitinho inherited */
}

.toggle-auth {
    margin-top: 0; /* More space */
    text-align: center;
}

.auth-links {
    display: flex;
    justify-content: center;
    gap: 34px;
    flex-wrap: wrap;
}

.toggle-auth a {
    color: #8fd3ff; /* Lighter blue */
    text-decoration: underline;
    font-size: 1em;
    cursor: pointer;
    /* font-family: Petitinho inherited */
}

.toggle-auth a:hover {
    color: #c7dcd0;
}

.menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.55);
}

.menu-card {
    width: min(92vw, 760px);
    max-height: min(86vh, 720px);
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 24px;
    border-radius: 8px;
    border-left: 12px solid #4d9be6;
    border-right: 12px solid #4d9be6;
    background: linear-gradient(180deg, rgba(62, 53, 70, 0.96), rgba(46, 34, 47, 0.98));
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.62);
}

.menu-card h2 {
    margin: 0 0 16px;
    color: #ffffff;
    text-align: center;
    font-size: 2.2rem;
}

.menu-status {
    min-height: 24px;
    margin-bottom: 12px;
    color: #f9c22b;
    text-align: center;
}

.leaderboard-source-toggle {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 0 auto 14px;
}

.source-toggle-button {
    min-width: 118px;
    padding: 10px 22px;
    border: none;
    border-radius: 5px;
    background-color: #c7dcd0;
    color: #3e3546;
    cursor: pointer;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.05rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.1s ease;
}

.source-toggle-button:hover {
    background-color: #ffffff;
    transform: scale(1.02);
}

.source-toggle-button:active {
    transform: scale(0.98);
}

.source-toggle-button.active {
    background-color: #ffffff;
    color: #3e3546;
    outline: 3px solid #f9c22b;
    box-shadow: 0 0 10px #f9c22b;
}

.menu-leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

.menu-leaderboard-row {
    display: grid;
    grid-template-columns: 54px minmax(110px, 1fr) 86px 90px 84px 42px;
    gap: 10px;
    align-items: center;
    padding: 9px 10px;
    border: 1px solid rgba(199, 220, 208, 0.16);
    border-radius: 6px;
    background: rgba(17, 17, 24, 0.35);
    color: #ffffff;
    font-size: 1rem;
}

.menu-leaderboard-row.current-player {
    border-color: rgba(249, 194, 43, 0.7);
    background: rgba(249, 194, 43, 0.12);
    box-shadow: inset 0 0 18px rgba(249, 194, 43, 0.08);
}

.menu-leaderboard-row.separator {
    display: block;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: #9babb2;
    text-align: center;
    letter-spacing: 0;
}

.menu-leaderboard-row.header {
    color: #9babb2;
    background: transparent;
    border-color: transparent;
    font-size: 0.9rem;
}

.menu-leaderboard-row .number {
    color: #f9c22b;
}

.menu-leaderboard-row .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-leaderboard-row .metric,
.menu-leaderboard-row .time {
    text-align: right;
}

.replay-icon-button {
    width: 34px;
    min-width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid rgba(143, 211, 255, 0.4);
    border-radius: 5px;
    background: rgba(143, 211, 255, 0.12);
    color: #8fd3ff;
    cursor: pointer;
}

.replay-icon-button:disabled {
    border-color: rgba(155, 171, 178, 0.2);
    background: rgba(155, 171, 178, 0.08);
    color: rgba(155, 171, 178, 0.45);
    cursor: default;
}

/* Helper to hide canvas initially if login is shown */
body:has(#loginScreen[style*="display: flex"]) #gameCanvas {
    display: none !important;
}

/* Helper to center body content when login is shown */
body:has(#loginScreen[style*="display: flex"]) {
    align-items: center;
    justify-content: center;
}

/* Login Screen - Ensure elements inherit Petitinho */
#loginScreen label,
#loginScreen input,
#loginScreen button,
#infoText,
.toggle-auth a,
.remember-me label {
    font-family: 'Petitinho', sans-serif; /* Explicitly set font */
}

/* Styles for Game Over Buttons */
#gameOverControls {
    /* Positioned via inline style in HTML */
}

.game-over-leaderboard-panel {
    position: fixed;
    left: 50%;
    top: clamp(118px, 23vh, 180px);
    transform: translateX(-50%);
    z-index: 12;
    width: min(82vw, 760px);
    max-height: min(48vh, 430px);
    display: flex;
    flex-direction: column;
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 14px 18px;
    border: 1px solid rgba(199, 220, 208, 0.22);
    border-radius: 7px;
    background: rgba(46, 34, 47, 0.86);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.48);
}

.game-over-leaderboard-panel h2 {
    margin: 0 0 10px;
    color: #ffffff;
    text-align: center;
    font-size: clamp(1.35rem, 4vw, 2rem);
    line-height: 1;
}

.game-over-leaderboard-panel .compact-action {
    align-self: center;
    min-width: 150px;
    padding: 9px 18px;
    font-size: 0.95rem;
}

#replayControls {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(960px, calc(100vw - 28px));
    padding: 10px 12px;
    border: 2px solid rgba(199, 220, 208, 0.45);
    border-radius: 8px;
    background: rgba(17, 17, 24, 0.82);
}

.replay-button {
    padding: 8px 14px;
    min-width: 64px;
    font-size: 1em;
}

#replayTimeline {
    flex: 1;
    min-width: 140px;
}

#replayTimeLabel {
    min-width: 130px;
    color: #c7dcd0;
    font-size: 1em;
    text-align: right;
}

.game-button {
    padding: 12px 30px;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.2em;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    background-color: #c7dcd0; /* Match login button style */
    color: #3e3546;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.game-button:hover {
    background-color: #ffffff;
    transform: scale(1.02);
}

.game-button:active {
    transform: scale(0.98);
}

/* Style for controller-focused button */
.game-button.focused-button {
    outline: 3px solid #f9c22b; /* Yellow outline */
    box-shadow: 0 0 10px #f9c22b; /* Yellow glow */
    transform: scale(1.05); /* Slightly larger */
}

/* Pause Menu Styles */
#pauseMenu {
    /* Uses .centered-container for base */
    display: flex; /* Ensure flex is explicitly set */
    flex-direction: column; /* Stack title and buttons vertically */
    align-items: center; /* Center items horizontally */
    background-color: rgba(46, 34, 47, 0.9); /* Dark Purple, slightly more opaque */
    padding: 30px 50px;
    border: 2px solid #c7dcd0; /* Use light button color for border */
    border-radius: 10px;
    min-width: 300px;
}

#pauseMenu h1 {
    font-size: 2.5em;
    color: #ffffff;
    margin-bottom: 30px;
    text-align: center;
    width: 100%; /* Ensure H1 takes full width for centering */
}

#pauseMenu .button-group {
    /* Uses existing .button-group styles (centered, gap) */
}

#pauseMenu .game-button {
    /* Uses existing .game-button styles */
}

/* Styles for Game Over Buttons */
#gameOverControls {
    /* Positioned via inline style in HTML */
}

.game-button {
    padding: 12px 30px;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.2em;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    background-color: #c7dcd0; /* Match login button style */
    color: #3e3546;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.game-button:hover {
    background-color: #ffffff;
    transform: scale(1.02);
}

.game-button:active {
    transform: scale(0.98);
}

/* REMOVED OLD LOGIN SCREEN STYLES THAT WERE HERE */

.pause-button.focused,
.game-over-button.focused { /* Apply focus style to both */
    outline: 3px solid yellow; /* Example focus style */
    box-shadow: 0 0 10px yellow;
}

/* Options Menu Styles */
#optionsMenu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(46, 34, 47, 0.95); /* Match pause menu background */
    padding: 22px 32px 26px; /* Match pause menu padding */
    border-radius: 10px; /* Match pause menu radius */
    border: 2px solid #c7dcd0; /* Match pause menu border */
    color: white;
    text-align: center;
    width: 90%; /* Increase width slightly */
    max-width: 640px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
    z-index: 30;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable both-edges;
}

#optionsMenu h2 {
    margin-bottom: 18px; /* More space */
    font-family: 'Petitinho', sans-serif; /* CORRECT FONT */
    font-size: clamp(2rem, 5vh, 2.8em); /* Match pause menu h1 */
    color: #ffffff; /* Match pause menu h1 color */
    text-shadow: 2px 2px 3px rgba(0,0,0,0.5); /* Add slight shadow */
}

.options-category-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.options-category-button {
    width: 100%;
    min-width: 0;
    font-size: 1.02rem;
    line-height: 1.1;
    white-space: nowrap;
}

.options-category-button.active {
    background-color: #f9c22b;
    color: #2e222f;
    box-shadow: 0 0 14px rgba(249, 194, 43, 0.24);
}

.options-section {
    display: none;
    border-top: 1px solid rgba(199, 220, 208, 0.14);
    padding-top: 4px;
}

.options-section.is-active {
    display: block;
}

.options-item {
    display: grid;
    grid-template-columns: minmax(160px, 0.9fr) minmax(180px, 1fr) 64px;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px; /* More spacing */
    padding: 7px 10px; /* More padding */
    border-radius: 5px; /* Match button radius */
    transition: background-color 0.2s;
}

.options-section-title {
    margin: 14px 0 8px;
    padding: 6px 10px;
    border-top: 1px solid rgba(199, 220, 208, 0.18);
    border-bottom: 1px solid rgba(199, 220, 208, 0.18);
    color: #f9c22b;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.05em;
    text-align: left;
    letter-spacing: 0;
}

.options-section-title:first-of-type {
    margin-top: 0;
}

/* Style for focused option item */
.options-item.focused {
    background-color: transparent;
    outline: none;
}

.options-item label {
    text-align: right;
    font-family: 'Petitinho', sans-serif; /* CORRECT FONT */
    font-size: clamp(1.05rem, 2.8vh, 1.35em); /* Larger font */
    line-height: 1.1;
    color: #e0e0e0; /* Match body text */
}

.options-item input[type="range"] {
    width: 100%;
    min-width: 0;
    cursor: pointer;
    /* Add styles to make slider thumb more visible if needed */
}

.options-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 15px;
    accent-color: #f9c22b;
    cursor: pointer;
}

.toggle-option {
    grid-template-columns: minmax(160px, 1fr) 34px 64px;
    justify-content: center;
}

.options-item span {
    min-width: 60px; /* More width for XXX% */
    text-align: left;
    font-family: 'Petitinho', sans-serif; /* CORRECT FONT */
    font-size: clamp(1.05rem, 2.8vh, 1.35em); /* Match label */
    color: #e0e0e0; /* Match body text */
}

#optionsBackButton {
    margin-top: 14px;
    width: min(100%, 260px);
}

.about-panel {
    margin: 0 auto;
    padding: 18px;
    border: 1px solid rgba(199, 220, 208, 0.35);
    border-radius: 8px;
    background: rgba(17, 17, 24, 0.46);
    text-align: left;
    max-width: 560px;
}

.about-panel h3 {
    margin: 0 0 12px;
    color: #f9c22b;
    font-family: 'Petitinho', sans-serif;
    font-size: 1.55em;
    text-align: center;
}

.about-summary {
    margin: 0 auto 16px;
    color: #c7dcd0;
    font-size: clamp(0.95rem, 2.2vh, 1.05rem);
    line-height: 1.35;
    max-width: 38ch;
    text-align: center;
}

.about-meta-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin: 0 0 14px;
}

.options-help-text {
    margin: -4px 10px 10px;
    color: rgba(199, 220, 208, 0.72);
    font-size: 0.92rem;
    line-height: 1.25;
    text-align: center;
}

.about-meta-card,
.about-support {
    border: 1px solid rgba(199, 220, 208, 0.24);
    border-radius: 8px;
    background: rgba(42, 33, 48, 0.58);
}

.about-meta-card {
    padding: 12px;
    text-align: center;
}

.about-meta-label {
    display: block;
    margin-bottom: 7px;
    color: #f9c22b;
    font-size: 0.72rem;
    text-transform: uppercase;
}

.about-meta-value {
    display: block;
    color: #ffffff;
    font-size: clamp(0.95rem, 2.4vh, 1.12rem);
}

.about-support {
    padding: 12px;
}

.about-support-title {
    margin-bottom: 9px;
    color: #f9c22b;
    font-size: 0.78rem;
    text-align: center;
    text-transform: uppercase;
}

.about-support-grid {
    display: grid;
    grid-template-columns: minmax(78px, auto) minmax(0, 1fr);
    gap: 8px 12px;
    align-items: center;
    color: #c7dcd0;
    font-size: clamp(0.86rem, 2vh, 0.98rem);
    line-height: 1.2;
}

.about-support-grid span:nth-child(odd) {
    color: #ffffff;
    text-align: right;
}

#aboutCloseButton {
    display: block;
    margin: 16px auto 0;
    width: min(100%, 220px);
}

/* Make sure focused button style uses Petitinho */
.game-button.focused-button {
    outline: 3px solid #f9c22b;
    box-shadow: 0 0 10px #f9c22b;
    transform: scale(1.05);
    font-family: 'Petitinho', sans-serif; /* Explicitly set */
}

/* Adjust slider appearance (example, might need browser prefixes) */
input[type=range] {
  height: 20px;
  -webkit-appearance: none; /* Override default look */
  margin: 10px 0;
  width: 100%;
  background: transparent; /* Remove default background */
}
input[type=range]:focus {
  outline: none; /* Remove focus outline */
}
/* Thumb */
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: #c7dcd0; /* Match button color */
  cursor: pointer;
  margin-top: -7px; /* Center thumb vertically */
  box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}
input[type=range]::-moz-range-thumb {
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: #c7dcd0;
  cursor: pointer;
  box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
  border: none;
}
/* Track */
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 5px;
  cursor: pointer;
  background: #555;
  border-radius: 3px;
  border: 1px solid #333;
}
input[type=range]::-moz-range-track {
  width: 100%;
  height: 5px;
  cursor: pointer;
  background: #555;
  border-radius: 3px;
  border: 1px solid #333;
}

/* Ensure menu buttons have consistent styling */
.menu-button {
    /* Remove visual styles that conflict with .game-button */
    cursor: pointer;
    /* background-color: #4CAF50; */ /* REMOVED */
    /* color: white; */ /* REMOVED */
    /* border: none; */ /* REMOVED */
    /* padding: 10px 15px; */ /* REMOVED */
    /* border-radius: 5px; */ /* REMOVED */
    /* font-size: 1em; */ /* REMOVED */
    /* transition: background-color 0.2s; */ /* REMOVED */
}

.menu-button:hover {
    /* background-color: #45a049; */ /* REMOVED */
}

@media (max-width: 720px) {
    body {
        overflow-y: auto;
        align-items: flex-start;
    }

    #loginScreen {
        padding: 18px 16px;
        border-left-width: 8px;
        border-right-width: 8px;
        width: 100vw;
        max-width: none;
        margin: 0;
        border-radius: 0;
    }

    #loginScreen h1 {
        font-size: clamp(2.15rem, 14vw, 3.3rem);
        line-height: 1.03;
        margin-bottom: 16px;
        max-width: 100%;
    }

    .tagline {
        max-width: 320px;
        font-size: 0.82em;
        line-height: 1.28;
    }

    .login-lanes {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .auth-divider {
        white-space: normal;
    }

    .login-panel {
        padding: 14px;
    }

    #loginScreen .primary-action {
        padding: 13px 16px;
        font-size: 1.18em;
    }

    #loginScreen button {
        padding: 11px 18px;
        font-size: 1em;
    }

    .menu-card {
        padding: 18px;
    }

    .menu-leaderboard-row {
        grid-template-columns: 42px minmax(80px, 1fr) 62px 70px 34px;
        gap: 7px;
        font-size: 0.82rem;
    }

    .menu-leaderboard-row .time {
        display: none;
    }

    .input-group {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .input-group label {
        width: auto;
        text-align: left;
    }

    .button-group {
        flex-direction: column;
        gap: 10px;
    }
}

@media (pointer: coarse), (max-width: 820px) {
    body.touch-controls-active #mobileControls {
        display: block;
    }

    body.touch-controls-active #gameCanvas {
        cursor: none;
    }
}

body.mobile-viewport {
    display: block;
    width: var(--app-width);
    min-width: var(--app-width);
    max-width: var(--app-width);
    min-height: var(--app-height);
    overflow: hidden;
}

body.mobile-viewport:not(.game-screen-active) {
    overflow: hidden;
    touch-action: pan-y;
}

body.mobile-viewport #loginScreen {
    width: var(--app-width);
    max-width: var(--app-width);
    height: var(--app-height);
    min-height: var(--app-height);
    max-height: var(--app-height);
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 20px 16px max(24px, env(safe-area-inset-bottom));
    border-left-width: 8px;
    border-right-width: 8px;
    border-radius: 0;
    transform: none;
}

body.mobile-viewport #loginScreen h1 {
    font-size: clamp(2.35rem, 15vw, 4.25rem);
    line-height: 0.95;
    margin: 10px auto 18px;
    max-width: calc(var(--app-width) - 36px);
    letter-spacing: 0;
}

body.mobile-viewport .tagline {
    max-width: calc(var(--app-width) - 52px);
    margin: 0 auto 18px;
    font-size: clamp(0.78rem, 3.9vw, 1.02rem);
    line-height: 1.22;
}

body.mobile-viewport .login-lanes {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

body.mobile-viewport .login-panel {
    padding: 14px;
}

body.mobile-viewport .online-auth-block {
    padding: 10px;
}

body.mobile-viewport .google-alias-row {
    grid-template-columns: minmax(0, 1fr);
}

body.mobile-viewport #googleAliasSaveButton {
    width: 100%;
}

body.mobile-viewport .input-group {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
}

body.mobile-viewport .input-group label {
    width: auto;
    text-align: left;
    font-size: clamp(0.95rem, 4vw, 1.1rem);
}

body.mobile-viewport #loginScreen input[type="text"],
body.mobile-viewport #loginScreen input[type="email"],
body.mobile-viewport #loginScreen input[type="password"] {
    width: 100%;
    font-size: 16px;
    padding: 13px;
}

body.mobile-viewport #loginScreen input[type="password"] {
    font-size: 20px;
}

body.mobile-viewport #loginScreen .primary-action,
body.mobile-viewport #loginScreen button {
    width: 100%;
    max-width: 100%;
    padding: 13px 14px;
    font-size: clamp(1rem, 5.1vw, 1.28rem);
}

body.mobile-viewport .button-group {
    flex-direction: column;
    gap: 10px;
}

body.mobile-viewport .menu-card {
    width: calc(var(--app-width) - 28px);
    max-height: calc(var(--app-height) - 36px);
    overflow-y: scroll;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 16px 14px;
    border-left-width: 7px;
    border-right-width: 7px;
}

body.mobile-viewport .leaderboard-card {
    width: calc(var(--app-width) - 32px);
    overflow-x: hidden;
}

body.mobile-viewport .menu-card.leaderboard-card h2 {
    max-width: 100%;
    font-size: clamp(1.35rem, 7.2vw, 1.8rem);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
}

body.mobile-viewport .menu-card h2 {
    margin-bottom: 12px;
    font-size: clamp(1.65rem, 10.5vw, 2.35rem);
    line-height: 0.95;
    letter-spacing: 0;
}

body.mobile-viewport .leaderboard-source-toggle {
    gap: 8px;
    margin-bottom: 12px;
}

body.mobile-viewport .source-toggle-button {
    min-width: 0;
    flex: 1;
    padding: 9px 10px;
    font-size: 0.88rem;
}

body.mobile-viewport .menu-status {
    margin-bottom: 10px;
    font-size: clamp(0.9rem, 4.5vw, 1.1rem);
}

body.mobile-viewport .menu-leaderboard-list {
    gap: 8px;
}

body.mobile-viewport .menu-leaderboard-row.header {
    display: none;
}

body.mobile-viewport .menu-leaderboard-row {
    grid-template-columns: 48px minmax(0, 1fr) 38px;
    grid-template-areas:
        "rank name replay"
        "rank score replay"
        "rank height replay"
        "rank time replay";
    gap: 3px 9px;
    padding: 10px;
    font-size: 0.9rem;
}

body.mobile-viewport .menu-leaderboard-row.separator {
    display: block;
    padding: 2px 0;
}

body.mobile-viewport .menu-leaderboard-row .number {
    grid-area: rank;
    align-self: center;
    font-size: 1rem;
}

body.mobile-viewport .menu-leaderboard-row .name {
    grid-area: name;
    font-size: 0.95rem;
}

body.mobile-viewport .menu-leaderboard-row .score {
    grid-area: score;
}

body.mobile-viewport .menu-leaderboard-row .height {
    grid-area: height;
}

body.mobile-viewport .menu-leaderboard-row .time {
    grid-area: time;
    display: block;
}

body.mobile-viewport .menu-leaderboard-row .metric,
body.mobile-viewport .menu-leaderboard-row .time {
    text-align: left;
    color: #c7dcd0;
    font-size: 0.78rem;
}

body.mobile-viewport .menu-leaderboard-row .score::before {
    content: "Score ";
    color: #9babb2;
}

body.mobile-viewport .menu-leaderboard-row .height::before {
    content: "Height ";
    color: #9babb2;
}

body.mobile-viewport .menu-leaderboard-row .time::before {
    content: "Time ";
    color: #9babb2;
}

body.mobile-viewport .menu-leaderboard-row .replay-icon-button {
    grid-area: replay;
    align-self: center;
    width: 34px;
    min-width: 34px;
    height: 42px;
}

body.mobile-viewport .leaderboard-card .menu-actions {
    gap: 10px;
}

body.mobile-viewport .leaderboard-card .menu-button {
    width: min(46%, 150px);
    padding: 10px 12px;
    font-size: 0.98rem;
}

body.mobile-viewport .game-over-leaderboard-panel {
    left: var(--app-left);
    top: calc(var(--app-top) + max(126px, env(safe-area-inset-top) + 72px));
    transform: none;
    width: var(--app-width);
    max-height: calc(var(--app-height) - 264px - env(safe-area-inset-bottom));
    padding: 10px 12px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
}

body.mobile-viewport .game-over-leaderboard-panel h2 {
    font-size: clamp(1.28rem, 7.4vw, 1.9rem);
    margin-bottom: 8px;
}

body.mobile-viewport .game-over-leaderboard-panel .leaderboard-source-toggle {
    margin-bottom: 8px;
}

body.mobile-viewport .game-over-leaderboard-panel .menu-status {
    margin-bottom: 8px;
    font-size: clamp(0.78rem, 3.6vw, 0.95rem);
}

body.mobile-viewport .game-over-leaderboard-panel .menu-leaderboard-list {
    margin-bottom: 10px;
}

body.mobile-viewport .game-over-leaderboard-panel .compact-action {
    width: min(54%, 170px);
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.86rem;
}

body.mobile-viewport #optionsMenu {
    width: calc(var(--app-width) - 28px);
    max-height: calc(var(--app-height) - 44px);
    overflow-y: scroll;
    padding: 18px 16px 34px;
    touch-action: auto;
}

body.mobile-viewport #optionsMenu h2 {
    margin-bottom: 16px;
    font-size: clamp(1.8rem, 10vw, 2.4rem);
}

body.mobile-viewport .main-menu-version {
    position: static;
    align-self: flex-end;
    margin-top: -2px;
    padding-right: 4px;
    font-size: 0.68rem;
}

body.mobile-viewport .options-category-grid {
    grid-template-columns: 1fr;
    gap: 9px;
    margin-bottom: 12px;
}

body.mobile-viewport .options-category-button {
    padding: 11px 12px;
    font-size: clamp(0.95rem, 4.8vw, 1.16rem);
    touch-action: manipulation;
}

body.mobile-viewport .options-section {
    padding-top: 2px;
}

body.mobile-viewport .options-section-title {
    margin: 14px 0 8px;
    font-size: 0.95rem;
    touch-action: pan-y;
}

body.mobile-viewport .options-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 56px;
    gap: 6px 10px;
    margin-bottom: 12px;
    padding: 7px;
    touch-action: pan-y;
}

body.mobile-viewport .options-item input[type="range"] {
    touch-action: pan-y;
}

body.mobile-viewport .options-item label {
    grid-column: 1 / -1;
    width: auto;
    margin-right: 0;
    text-align: left;
    font-size: 0.98rem;
}

body.mobile-viewport .options-item input[type="range"] {
    margin: 6px 0;
}

body.mobile-viewport .options-item span {
    min-width: 0;
    font-size: 0.95rem;
    text-align: right;
}

body.mobile-viewport .toggle-option {
    grid-template-columns: minmax(0, 1fr) 56px;
}

body.mobile-viewport .about-panel {
    margin-top: 12px;
    padding: 14px;
}

body.mobile-viewport .about-panel h3 {
    font-size: 1.35rem;
}

body.mobile-viewport .about-meta-grid {
    gap: 8px;
}

body.mobile-viewport .about-meta-card,
body.mobile-viewport .about-support {
    padding: 10px;
}

body.mobile-viewport .about-support-grid {
    grid-template-columns: minmax(58px, auto) minmax(0, 1fr);
    gap: 7px 9px;
    font-size: 0.82rem;
}

body.mobile-viewport.game-screen-active.landscape-blocked #landscapeBlocker {
    position: fixed;
    left: var(--app-left);
    top: var(--app-top);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--app-width);
    height: var(--app-height);
    padding: 24px;
    background: rgba(5, 7, 12, 0.94);
    color: #ffffff;
    text-align: center;
}

body.mobile-viewport.touch-controls-active #mobileControls {
    display: block;
}

body.mobile-viewport .touch-stick {
    left: max(18px, env(safe-area-inset-left));
    width: var(--move-stick-size);
    height: var(--move-stick-size);
    border-width: 2px;
    opacity: var(--move-control-opacity);
}

body.mobile-viewport .touch-stick::before {
    height: calc(var(--move-stick-size) * 0.44);
}

body.mobile-viewport .touch-stick-knob {
    width: var(--move-knob-size);
    height: var(--move-knob-size);
}

body.mobile-viewport .touch-jump-button {
    right: max(18px, env(safe-area-inset-right));
    bottom: 4px;
    width: var(--jump-button-size);
    height: var(--jump-button-size);
    border-width: 2px;
    font-size: 0.8rem;
    opacity: var(--jump-control-opacity);
}

body.mobile-viewport .touch-pause-button {
    top: max(76px, calc(env(safe-area-inset-top) + 12px));
    width: 58px;
    height: 32px;
    font-size: 0.72rem;
}

body.mobile-viewport #gameOverControls {
    position: fixed !important;
    left: var(--app-left) !important;
    right: auto !important;
    bottom: max(18px, env(safe-area-inset-bottom)) !important;
    transform: none !important;
    width: var(--app-width) !important;
    justify-content: center;
    gap: 12px !important;
    padding: 0 18px;
    z-index: 25 !important;
}

body.mobile-viewport #gameOverControls .game-button {
    width: min(42vw, 158px);
    min-width: 0;
    min-height: 58px;
    padding: 10px 12px;
    font-size: clamp(0.86rem, 4.2vw, 1.08rem);
    line-height: 1.05;
}

body.mobile-viewport #replayControls {
    left: calc(var(--app-left) + 10px);
    right: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: none;
    width: calc(var(--app-width) - 20px);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    border-width: 1px;
}

body.mobile-viewport #replayControls .replay-button {
    min-width: 0;
    width: 100%;
    height: 42px;
    padding: 6px 4px;
    font-size: clamp(0.7rem, 3.2vw, 0.9rem);
    line-height: 1;
}

body.mobile-viewport #replayTimeline {
    grid-column: 1 / -2;
    min-width: 0;
    height: 18px;
    margin: 0;
}

body.mobile-viewport #replayTimeLabel {
    min-width: 0;
    width: auto;
    font-size: 0.72rem;
    text-align: right;
}

.landscape-message {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: min(420px, calc(var(--app-width) - 48px));
    line-height: 1.25;
}

.landscape-message strong {
    color: #f9c22b;
    font-size: clamp(1.6rem, 7vw, 2.5rem);
    letter-spacing: 0;
}

.landscape-message span {
    color: #c7dcd0;
    font-size: clamp(1rem, 3.5vw, 1.4rem);
}
