* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

/* Block low-effort asset grabs: no drag-save on images/canvas/svg, no tap-hold
   callout on iOS, no system context highlight. Real inputs keep selection. */
img, canvas, svg {
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: auto;
}

input, textarea, [contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
}

/* ── Mobile portrait blocker ────────────────────────────────────────────────
   The game is designed for a 1280×720 landscape canvas. On touch devices held
   in portrait, show a full-screen "rotate your phone" card and block clicks
   so the menu/game underneath are not driven by tap targets that are too tall
   and narrow to be usable. Desktop browsers never match (pointer: coarse). */
#rotate-prompt {
    display: none;
}

@media (pointer: coarse) and (orientation: portrait) {
    #rotate-prompt {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 99999;
        align-items: center;
        justify-content: center;
        padding: 24px;
        background: radial-gradient(ellipse at center, #102634 0%, #07111a 80%);
        color: #d6fbff;
        font-family: 'Outfit', system-ui, sans-serif;
        text-align: center;
        /* No `pointer-events: auto` override needed — fills viewport so it
           naturally catches every tap. */
    }
    .rotate-card {
        max-width: 320px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 18px;
    }
    .rotate-icon {
        color: #8be8ff;
        animation: rotate-hint 2.4s ease-in-out infinite;
        filter: drop-shadow(0 6px 18px rgba(139, 232, 255, 0.35));
    }
    .rotate-title {
        font-size: 22px;
        font-weight: 700;
        letter-spacing: 0.02em;
    }
    .rotate-sub {
        font-size: 14px;
        color: #8fb0c2;
        line-height: 1.5;
    }
    /* Hide the menu/game UI under the prompt to avoid layout thrash when the
       prompt itself is being read by screen readers. */
    body { overflow: hidden; }
}

@keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    40%      { transform: rotate(-90deg); }
    60%      { transform: rotate(-90deg); }
}

body {
    background-color: #0c0f1d;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    color: #fff;
}

body.game-active {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

#game-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 100svh;
    overflow: hidden;
    background:
        radial-gradient(circle at 74% 18%, rgba(255, 248, 216, 0.22), transparent 18rem),
        radial-gradient(circle at 24% 92%, rgba(255, 181, 107, 0.18), transparent 26rem),
        linear-gradient(180deg, #07111a 0%, #102634 54%, #06111a 100%);
    isolation: isolate;
    z-index: 20;
    transform: translateZ(0);
    contain: layout paint size;
}

#game-container::before,
#game-container::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#game-container::before {
    z-index: 1;
    opacity: 0.5;
    background:
        linear-gradient(115deg, transparent 0 42%, rgba(139, 232, 255, 0.08) 46%, transparent 52%);
    mix-blend-mode: screen;
    animation: game-light-drift 9s linear infinite;
}

#game-container::after {
    z-index: 2;
    background:
        radial-gradient(ellipse at center, transparent 48%, rgba(0, 0, 0, 0.42) 100%),
        linear-gradient(180deg, rgba(255,255,255,0.04), transparent 16%, transparent 84%, rgba(0,0,0,0.24));
}

@keyframes game-light-drift {
    from { transform: translateX(-3%); }
    to { transform: translateX(3%); }
}

#gameCanvas {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    transform: translateZ(0);
    will-change: transform;
}

/* UI Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(8, 22, 32, 0.82);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 30;
    transition: opacity 0.3s ease;
}

.hidden {
    opacity: 0;
    pointer-events: none;
}

#game-container h1 {
    font-family: "Bagel Fat One", "Outfit", system-ui;
    font-size: 80px;
    line-height: 0.88;
    color: #b6f0ff;
    text-shadow: 0 0 12px rgba(139, 232, 255, 0.55), 0 0 38px rgba(139, 232, 255, 0.35);
    margin-bottom: 20px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

#game-container p {
    font-family: "Outfit", sans-serif;
    font-size: 1.1rem;
    color: #8fb0c2;
    margin-bottom: 40px;
    text-align: center;
    line-height: 1.6;
    letter-spacing: 0.1em;
}

#game-container .highlight {
    color: #8be8ff;
    font-weight: 700;
}

#game-container .btn {
    appearance: none;
    border: 1px solid rgba(255, 181, 107, 0.35);
    background: linear-gradient(135deg, rgba(255, 181, 107, 0.22), rgba(139, 232, 255, 0.12));
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: #eaf6fb;
    font-family: "Outfit", sans-serif;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    padding: 18px 40px;
    cursor: pointer;
    border-radius: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 8px 32px -8px rgba(139, 232, 255, 0.2);
}

#game-container .btn:hover {
    background: linear-gradient(135deg, rgba(255, 181, 107, 0.36), rgba(139, 232, 255, 0.22));
    border-color: rgba(255, 181, 107, 0.6);
    box-shadow: 0 18px 50px -16px rgba(255, 181, 107, 0.6);
    transform: translateY(-2px);
}

#game-container .btn:active {
    transform: translateY(1px) scale(0.98);
}

/* Keyboard layout tips */
.controls-info {
    display: flex;
    gap: 30px;
    margin-top: 30px;
}

.key-tip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.9rem;
}

.key {
    background: #fff;
    color: #000;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: bold;
    box-shadow: 0 3px 0 #cbd5e0;
}

#game-over-title {
    color: #ff7a8a;
    text-shadow: 0 0 12px rgba(255, 122, 138, 0.55), 0 0 38px rgba(255, 122, 138, 0.35);
}

.stat-group {
    display: flex;
    gap: 40px;
    margin-bottom: 30px;
}

.stat-box {
    text-align: center;
}

.stat-label {
    font-family: "Outfit", sans-serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #8fb0c2;
    margin-bottom: 5px;
}

.stat-val {
    font-family: "Bagel Fat One", "Outfit";
    font-size: 2.5rem;
    font-weight: 400;
    color: #ffd58b;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: calc(28px + env(safe-area-inset-bottom));
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 clamp(18px, 5vw, 56px);
    z-index: 24;
    pointer-events: none; /* Let container handle touches */
}

.mobile-btn {
    background: rgba(11, 28, 39, 0.62);
    border: 1px solid rgba(139, 232, 255, 0.16);
    color: #b6f0ff;
    font-family: "Outfit", sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    padding: 15px 30px;
    border-radius: 40px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none; /* Fallthrough touch to canvas */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 12px 40px -16px rgba(139, 232, 255, 0.25);
}

@media (min-width: 1025px) {
    #mobile-controls {
        display: none;
    }
}

/* Mobile landscape (phones): the canvas is ~1.7–2.2:1 wide vs the designed
   1.78:1, so the duck lives in the bottom-right quadrant. The default SLIDE
   /JUMP pill (15×30 padding, 1.2rem) covers it. Shrink + push to the corners
   so the playfield stays visible. Also move the in-game gear button down so
   it doesn't overlap the TOTAL SCORE / DISTANCE HUD drawn at the canvas's
   top-right. */
@media (max-height: 500px) and (orientation: landscape) {
    #mobile-controls {
        bottom: calc(14px + env(safe-area-inset-bottom));
        padding: 0 calc(10px + env(safe-area-inset-left)) 0 calc(10px + env(safe-area-inset-right));
    }
    .mobile-btn {
        padding: 8px 16px;
        font-size: 0.78rem;
        letter-spacing: 0.1em;
        border-radius: 28px;
        background: rgba(11, 28, 39, 0.42);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        opacity: 0.78;
        box-shadow: 0 6px 18px -10px rgba(139, 232, 255, 0.2);
    }
}

/* Same treatment for mobile portrait phones (rotate-prompt blocker covers
   most cases, but if the prompt is dismissed or the rule misses on some
   browser, keep the buttons compact). */
@media (max-width: 600px) {
    .mobile-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

/* ===== Supabase auth + leaderboard ===== */
#cloud-panel {
    display: flex;
    gap: 24px;
    margin-top: 32px;
    width: min(820px, 92%);
    max-height: 38vh;
    overflow: auto;
}

#auth-panel,
#leaderboard-panel {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 16px;
    text-align: left;
}

#cloud-panel h3 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #ffd700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#cloud-panel input[type="email"],
#cloud-panel input[type="password"],
#cloud-panel input[type="text"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-family: inherit;
}

#cloud-panel input:focus {
    outline: none;
    border-color: #ffd700;
}

.auth-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.auth-line {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #cbd5e0;
}

.mini-btn {
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #0c0f1d;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
}

.mini-btn.alt {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.mini-btn:hover {
    filter: brightness(1.1);
}

.auth-status {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #a0aec0;
    min-height: 1em;
}

.link-btn {
    background: transparent;
    border: none;
    color: #718096;
    font-size: 0.75rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0 4px;
    margin-left: 6px;
    font-family: inherit;
}

.link-btn:hover {
    color: #ffd700;
}

.auth-warn {
    font-size: 0.75rem;
    color: #ffb86b;
    margin: 6px 0;
    line-height: 1.4;
    text-align: left;
}

#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.lb-row {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.95rem;
}

.lb-row:nth-child(odd) {
    background: rgba(255, 255, 255, 0.04);
}

.lb-rank {
    color: #ffd700;
    font-weight: bold;
}

.lb-name {
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    color: #00ffff;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}

.lb-loading,
.lb-empty {
    padding: 12px;
    text-align: center;
    color: #718096;
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    #cloud-panel {
        flex-direction: column;
        max-height: 50vh;
    }
}
