html {
    background-color: #050815;
    /* Same as --bg-color to avoid white flashes/gaps */
    height: 100%;
    height: 100vh;
    height: 100svh;
}

:root {
    --bg-color: #050815;
    --board-bg: #0c0f26;
    --cell-empty: #141a33;
    --text-color: #e5e7ff;
    --accent-color: #5fc9df;
    --danger-color: #f472b6;
    /* Use 0px as default for env fallback to ensure valid CSS */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --custom-cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%237ee0f4' stroke='white' stroke-width='1.5' d='M5.5 3.21V20.8c0 .45.54.67.85.35l4.86-4.86a.5.5 0 0 1 .35-.15h6.87a.5.5 0 0 0 .35-.85L6.35 2.85a.5.5 0 0 0-.85.35Z'/%3E%3C/svg%3E") 6 3, auto;
    --custom-cursor-hover: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Cpath fill='%237ee0f4' stroke='white' stroke-width='1.5' stroke-linejoin='round' d='M10 11V8.99c0-.88.59-1.64 1.44-1.86h.05A1.99 1.99 0 0 1 14 9.05V12v-2c0-.88.6-1.65 1.46-1.87h.05A1.98 1.98 0 0 1 18 10.06V13v-1.94a2 2 0 0 1 1.51-1.94h0A2 2 0 0 1 22 11.06V14c0 .6-.08 1.27-.21 1.97a7.96 7.96 0 0 1-7.55 6.48 54.98 54.98 0 0 1-4.48 0 7.96 7.96 0 0 1-7.55-6.48C2.08 15.27 2 14.59 2 14v-1.49c0-1.11.9-2.01 2.01-2.01h0a2 2 0 0 1 2.01 2.03l-.01.97v-10c0-1.1.9-2 2-2h0a2 2 0 0 1 2 2V11Z'/%3E%3C/svg%3E") 8 1, pointer;
    --custom-cursor-not-allowed: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23050815' d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Z'/%3E%3Cpath fill='%237ee0f4' stroke='white' stroke-width='0.5' d='M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm0 14a6 6 0 0 1-4.88-9.47l8.36 8.36A5.95 5.95 0 0 1 12.01 18Zm4.88-2.53L8.53 7.11a6 6 0 0 1 8.35 8.36Z'/%3E%3C/svg%3E") 12 12, not-allowed;
}


* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: var(--custom-cursor);
}

body,
canvas {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-text-size-adjust: none;
    touch-action: none;
    cursor: var(--custom-cursor);
}

button,
.primary-btn,
.secondary-btn,
input[type=range] {
    touch-action: manipulation;
}

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #050815 0%, #0a0f2c 50%, #0f132f 100%);
    background-attachment: fixed;
    /* Ensures background covers the whole screen on mobile */
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    height: 100%;
    height: 100vh;
    height: 100svh;
    width: 100%;
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Allow flex children to shrink properly */
    max-width: 600px;
    /* Limit width on desktop */
    margin: 0 auto;
    width: 100%;
}

header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    /* Padding handles safe areas explicitly to avoid cutting off on resume.
       On mobile, we enforce a minimum of 24px to ensure the status bar is cleared even if env() fails momentarily. */
    padding: 16px;
    padding-top: max(16px, var(--safe-area-top));
    min-height: 80px;
    height: auto;
}

@media (max-width: 600px) {
    header {
        padding-top: max(24px, var(--safe-area-top));
    }

    .scenario-mode .tutorial-box {
        padding-top: max(24px, var(--safe-area-top));
    }
}

.score-board {
    display: flex;
    gap: 30px;
    align-items: center;
    justify-self: center;
}

.score-label {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    color: #8aa2c8;
    font-weight: bold;
    width: 70px;
    align-items: center;
}

.score-label span {
    font-size: 1.5rem;
    color: #fff;
    margin-top: 4px;
}

#status-face {
    width: 96px;
    height: 96px;
    background-image: url('assets/faces.jpg');
    background-repeat: no-repeat;
    /* Horizontal sprite strip with 6 faces.
       600% width = show 1/6 of the width (one face).
       100% height = fill the entire height. */
    background-size: 600% 100%;
    image-rendering: pixelated;
    border-radius: 4px;
    background-color: #0b1027;
    box-shadow: 0 0 8px rgba(126, 224, 244, 0.35);
    border: 2px solid #1d2b4d;
}

/* Horizontal positions for each of the 6 faces */
.face-normal {
    background-position: 0% 0%;
}

.face-concerned {
    background-position: 20% 0%;
}

.face-worried {
    background-position: 40% 0%;
}

.face-panic {
    background-position: 60% 0%;
}

.face-relief {
    background-position: 80% 0%;
}

.face-dead {
    background-position: 100% 0%;
}

#settings-btn,
#pause-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #8aa2c8;
    cursor: var(--custom-cursor-hover);
}

#settings-btn {
    justify-self: start;
}

#pause-btn {
    justify-self: end;
    font-size: 1.4em;
    border-radius: .5em;
    border: none;
    background: linear-gradient(145deg, #0f172e, #0a1026);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), 0 0 0 2px rgba(126, 224, 244, 0.25);
    color: #9edbff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .25em .5em;
    height: 40px;
    width: 40px;
}

#pause-btn:active {
    transform: translateY(1px);
}

#game-container {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: stretch;
    /* Canvas stretches to fill */
    overflow: hidden;
    min-height: 0;
    /* Allow flex children to shrink properly */
}

.hand-timer-bar {
    z-index: 1;
    position: absolute;
    height: 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(126, 224, 244, 0.25);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.hand-timer-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #7ee0f4, #5ed1c9);
    box-shadow: 0 0 12px rgba(94, 209, 201, 0.45);
    transition: width 0.1s linear, background 0.2s ease;
}

canvas {
    position: relative;
    z-index: 3;
    touch-action: none;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    width: 100%;
    height: 100%;
}

.overlay {
    position: absolute;
    top: 0;
    /* Changed from -10vh to 0 as safe area is handled by header now */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 8, 21, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.hidden {
    display: none !important;
}

#game-over-overlay h1,
.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

#game-over-overlay {
    font-size: 1rem;
}

#game-over-quote-container {
    min-height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
    width: 80%;
}

#game-over-quote {
    text-align: center;
    font-style: italic;
    opacity: 0.8;
    margin: 0;
}

#mini-leaderboard-container {
    width: 85%;
    background: rgba(12, 15, 38, 0.6);
    border: 1px solid rgba(126, 224, 244, 0.2);
    border-radius: 12px;
    padding: 15px;
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#mini-leaderboard-status {
    font-size: 0.9rem;
    color: var(--accent-color);
    text-align: center;
    margin-bottom: 5px;
}

#mini-leaderboard-list {
    width: 100%;
    max-height: none;
    overflow: visible;
}

#show-full-leaderboard-btn {
    margin-top: 5px;
}

#leaderboard-status-container {
    background: rgba(126, 224, 244, 0.1);
    border: 1px solid rgba(126, 224, 244, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    margin: 10px 0;
    max-width: 85%;
    text-align: center;
}

#leaderboard-status-text {
    margin: 0;
    font-size: 0.95rem;
    color: var(--accent-color);
    line-height: 1.4;
}

#see-leaderboard-link {
    color: var(--accent-color);
    text-decoration: underline;
    cursor: var(--custom-cursor-hover);
}

#player-name-missing-container {
    max-width: 85%;
    text-align: center;
    color: #cbd5ff;
    font-size: 0.9rem;
    margin: 10px 0;
}

#player-suggestions-container {
    background: rgba(126, 224, 244, 0.05);
    border: 1px solid rgba(126, 224, 244, 0.15);
    border-radius: 12px;
    padding: 15px;
    margin: 10px 0;
    width: 85%;
    text-align: center;
}

#player-suggestions-container p {
    margin: 0;
    font-size: 0.9rem;
    color: #8aa2c8;
}

#player-suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
    max-height: 180px;
    overflow-y: auto;
    padding: 4px;
    /* Custom Scrollbar for sleek look */
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
}

#player-suggestions-list::-webkit-scrollbar {
    width: 4px;
}

#player-suggestions-list::-webkit-scrollbar-track {
    background: transparent;
}

#player-suggestions-list::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 10px;
}

.suggestion-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(126, 224, 244, 0.1);
    border: 1px solid rgba(126, 224, 244, 0.4);
    color: var(--accent-color);
    padding: 6px 14px;
    border-radius: 15px;
    font-size: 0.9rem;
    cursor: var(--custom-cursor-hover);
    transition: all 0.2s;
    font-weight: 500;
    min-width: 64px;
    min-height: 32px;
}

.suggestion-btn.btn-submitting {
    padding: 0;
    /* Center spinner perfectly */
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.spinner {
    flex-shrink: 0;
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    border-top: 3px solid #ffffff;
    animation: spin 0.75s linear infinite;
}

.suggestion-btn:hover {
    background: rgba(126, 224, 244, 0.2);
    color: var(--accent-color);
    border-color: var(--accent-color);
    transform: translateY(-1px);
}

.suggestion-btn:active {
    transform: translateY(0);
}

#player-name-submission-container {
    margin: 15px 0;
    width: 85%;
    display: flex;
    gap: 10px;
    align-items: stretch;
}

#submission-status-message {
    padding: 12px 20px;
    margin: 10px auto;
    max-width: 85%;
    text-align: center;
    font-size: 0.95rem;
    color: var(--accent-color);
    line-height: 1.4;
    background: rgba(126, 224, 244, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(126, 224, 244, 0.15);
}

#player-name-input {
    flex: 1;
    padding: 12px 15px;
    border-radius: 8px;
    border: 1px solid rgba(126, 224, 244, 0.3);
    background: rgba(12, 15, 38, 0.8);
    color: white;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

#player-name-input:focus {
    border-color: var(--accent-color);
}

#submit-name-btn {
    padding: 0 20px;
    border-radius: 8px;
    white-space: nowrap;
}

.game-over-actions {
    text-align: center;
}

.submit-score-btn {

    color: var(--text-color);
    font-size: 1rem;
}

#restart-btn,
#close-settings-btn {
    margin-top: 30px;
    padding: 12px 30px;
    font-size: 1rem;
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    cursor: var(--custom-cursor-hover);
}

/* Settings Modal Specifics */
.modal-content {
    background: var(--board-bg);
    padding: 30px;
    border-radius: 12px;
    width: 80%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.setting-item {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.setting-item.horizontal {
    flex-direction: row;
    justify-content: center;
    gap: 15px;
}

.setting-item label {
    font-size: 1.1rem;
    color: #ccc;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: var(--custom-cursor-hover);
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #141a33;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 24px;
    border: 1px solid rgba(126, 224, 244, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #4e5b85;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
}

input:checked+.slider {
    background: rgba(126, 224, 244, 0.1);
    border-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
    background: var(--accent-color);
    box-shadow: 0 0 10px rgba(126, 224, 244, 0.5);
}

/* Custom Range Slider Styling */
input[type=range] {
    -webkit-appearance: none;
    /* Override default CSS styles */
    appearance: none;
    width: 100%;
    max-width: 280px;
    height: 40px;
    /* Increase container height for easier touch */
    background: transparent;
    cursor: var(--custom-cursor-hover);
    border-radius: 10px;
}

/* Slider Track */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: #333;
    border-radius: 4px;
    border: none;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: #333;
    border-radius: 4px;
    border: none;
}

/* Slider Thumb (Handle) */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 28px;
    width: 28px;
    border-radius: 50%;
    background: var(--accent-color);
    margin-top: -10px;
    /* Center thumb on track: (trackHeight/2) - (thumbHeight/2) = 4 - 14 = -10 */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    border: 2px solid #fff;
}

input[type=range]::-moz-range-thumb {
    height: 28px;
    width: 28px;
    border-radius: 50%;
    background: var(--accent-color);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

input[type=range]:focus {
    outline: none;
}

input[type=range]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(100, 108, 255, 0.3);
}

input[type=range]:active::-webkit-slider-thumb {
    transform: scale(1.1);
}

footer {
    text-align: center;
    padding: 10px;
    padding-bottom: 0;
    /* Remove safe-area-bottom here to let content fill the space */
    font-size: 0.8rem;
    color: #666;
    display: none;
    /* Hide footer if it's causing issues, it was commented out anyway */
}

/* Tutorial Styles */
.pointer-events-none {
    pointer-events: none;
}

.pointer-events-auto {
    pointer-events: auto;
}

#tutorial-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    /* Default centered for full overlay */
    flex-direction: column;
    justify-content: center;
    /* Center vertically for Intro/End */
    background: transparent !important;
    backdrop-filter: none !important;
    pointer-events: none;
    z-index: 20;
    padding-top: 0;
    /* Let flex handle centering */
    transition: all 0.3s ease;
}

#tutorial-overlay.scenario-mode {
    position: relative;
    /* Takes up space in the main column layout */
    top: 0;
    left: auto;
    right: auto;
    bottom: auto;
    height: auto;
    margin: 0;
    background: transparent !important;
    display: block;
    /* Normal block flow to fill width */
    padding: 0;
    min-height: 128px;
    /* Force height reservation to push grid down */
}

.tutorial-box {
    background: rgba(30, 30, 36, 0.95);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    width: 450px;
    max-width: 90%;
    margin: 0 auto;
    border: 1px solid var(--accent-color);
    backdrop-filter: blur(10px);
    transition: all 0.3s;
    /* Default Flex Column for Intro/End */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* Scenario Mode (Header Replacement) */
.scenario-mode .tutorial-box {
    width: 100%;
    max-width: 600px;
    /* Match app width constraint */
    border-radius: 0 0 12px 12px;
    padding: 10px 20px;
    padding-top: max(16px, var(--safe-area-top));
    min-height: 80px;

    /* Layout: Keep main content left, button right */
    display: flex;
    /* flex-direction: row; */
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;

    background: var(--board-bg);
    border: none;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

/* Wrapper for Title + Paragraph to keep them stacked */
.tutorial-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Left align text */
    text-align: left;
    gap: 2px;
    /* Small gap between title and text */
}

.scenario-mode .tutorial-box h2 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--accent-color);
}

.scenario-mode .tutorial-box p {
    font-size: 1rem;
    margin: 0;
    color: #ccc;
    line-height: 1.2;
}

/* Default H2/P styles (Intro/End) */
.tutorial-box h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--accent-color);
}

.tutorial-box p {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.4;
    color: #eee;
    white-space: pre-wrap;
}

.tutorial-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.scenario-mode .tutorial-actions {
    margin: 0;
}

.primary-btn {
    background: var(--accent-color);
    border: none;
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: var(--custom-cursor-hover);
    font-weight: bold;
    font-size: 0.9rem;
}

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

.scenario-mode .tutorial-box .secondary-btn,
.scenario-mode .tutorial-box .primary-btn {
    margin: 0;
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.secondary-btn {
    background: transparent;
    border: 1px solid #666;
    color: #aaa;
    /* padding: 8px 16px; */
    padding: 8px 20px;
    border-radius: 20px;
    /* margin-top: 15px; */
    cursor: var(--custom-cursor-hover);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: #fff;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

#highscore-notification {
    position: absolute;
    top: 100px;
    /* Adjust based on header height */
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #1a1a1a;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.5);
    z-index: 50;
    pointer-events: none;
    animation: slideDownFadeOut 3s forwards;
    white-space: nowrap;
}

@keyframes slideDownFadeOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -20px);
    }

    10% {
        opacity: 1;
        transform: translate(-50%, 0);
    }

    80% {
        opacity: 1;
        transform: translate(-50%, 0);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
}

#game-over-highscore-label {
    color: #FFD700;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 5px 0;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.header-right-buttons {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

/* Leaderboard Modal */
.leaderboard-content {
    background: var(--board-bg);
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 540px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.leaderboard-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.leaderboard-message {
    font-size: 0.9rem;
    margin-bottom: 8px;
    text-align: center;
    color: #cbd5ff;
}

.leaderboard-message.error {
    color: var(--danger-color);
}

.leaderboard-sections {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

#leaderboard-header-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: var(--custom-cursor-hover);
    font-size: 1.2rem;
    padding: 0;
    margin: 0;
}

/* @media (min-width: 520px) {
    .leaderboard-sections {
        grid-template-columns: 1fr 1fr;
    }
} */

/* .leaderboard-section h3 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    color: #9ca3ff;
    text-transform: uppercase;
    letter-spacing: 0.04em;
} */

.leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 260px;
    overflow-y: auto;
}

.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.9rem;
    padding: 4px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.leaderboard-list li:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    min-width: 1.6em;
    margin-right: 4px;
    color: #9ca3ff;
}

.leaderboard-name {
    flex: 1;
    margin-right: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    font-variant-numeric: tabular-nums;
    color: #e5e7ff;
}

.leaderboard-self {
    background: rgba(126, 224, 244, 0.08);
    border-radius: 6px;
    padding: 4px 6px;
}

.leaderboard-self .leaderboard-rank,
.leaderboard-self .leaderboard-score {
    color: var(--accent-color);
}

.leaderboard-ellipsis {
    color: #4a5568;
    font-size: 0.8rem;
    padding: 2px 0 !important;
    border: none !important;
}

.secondary-btn.small {
    padding: 4px 12px;
    font-size: 0.8rem;
}

/* Small phones (380px–424px) */
@media (min-width: 380px) and (max-width: 424px) {
    header {
        padding: 12px;
        /* slightly tighter than 16px */
    }

    .score-board {
        gap: 18px;
        /* down from 30px */
    }

    .score-label {
        width: 64px;
        /* down from 70px */
    }

    /* Keep face prominent, just a bit smaller */
    #status-face {
        scale: .9;
    }

    /* Avoid overlay cards pushing wider than screen */
    .tutorial-box {
        width: auto;
        /* overrides width: 450px when not in scenario-mode */
        max-width: 92vw;
    }

    .modal-content,
    .leaderboard-content {
        width: 88vw;
        /* modestly tighter than the base 80%/90% rules */
    }
}

/* Small phones (down to ~360px) */
@media (max-width: 380px) {
    header {
        padding: 10px;
        /* was 16px */
        min-height: 64px;
    }

    .score-board {
        gap: 1vw;
        /* was 30px */
    }

    .score-label {
        width: 58px;
        /* was 70px */
        font-size: 0.72rem;
    }

    .score-label span {
        font-size: 1.2rem;
        /* was 1.5rem */
    }

    #status-face {
        scale: .8;
    }

    #pause-btn,
    #settings-btn {
        width: 48px;
        /* was 56px on pause */
        height: 48px;
        font-size: 1.6rem;
        /* was 2rem */
    }

    #pause-btn {
        height: 28px;
        width: 28px;
        font-size: 1.2rem;
    }

    /* Modals / tutorial boxes should not force wider-than-screen layouts */
    .tutorial-box {
        width: auto;
        /* overrides width: 450px */
        max-width: 92vw;
        /* keep margins */
        padding: 16px;
        /* slightly tighter */
    }

    .modal-content {
        width: 92vw;
        /* was 80% with max-width 400px */
        padding: 20px;
        /* was 30px */
    }

    .leaderboard-content {
        width: 92vw;
        /* avoid edge clipping */
    }
}

#submit-name-btn.btn-submitting {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    height: 100%;
    /* Match the height of the container/input */
    padding: 0;
    pointer-events: none;
    opacity: 0.8;
}

/* Dev Mode Styling */
body.dev-mode {
    background: linear-gradient(135deg, #1a0505 0%, #3d0a0a 50%, #1a0505 100%);
}

#dev-indicator {
    position: fixed;
    top: 50%;
    left: -40px;
    transform: translateY(-50%) rotate(-90deg);
    font-size: 8rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.05);
    pointer-events: none;
    z-index: 0;
    text-transform: uppercase;
    letter-spacing: 1.5rem;
}

#dev-controls-help {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(45, 10, 10, 0.8);
    padding: 15px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #ffaaaa;
    border: 1px solid rgba(255, 68, 68, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    pointer-events: none;
    line-height: 1.6;
    backdrop-filter: blur(8px);
}

#dev-controls-help h4 {
    margin: 0 0 8px 0;
    color: #ff4444;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(255, 68, 68, 0.3);
    padding-bottom: 4px;
}

@media (max-width: 1000px) {
    #dev-indicator {
        font-size: 4rem;
        left: -20px;
        letter-spacing: 0.5rem;
    }

    #dev-controls-help {
        bottom: auto;
        top: max(80px, var(--safe-area-top));
        right: 10px;
        padding: 10px;
        font-size: 0.7rem;
        background: rgba(45, 10, 10, 0.9);
    }
}

/* Short Viewport Responsiveness (Dev Tools / Split Screen) */
@media (max-height: 700px) {
    header {
        padding: 8px 16px;
        min-height: 60px;
    }

    #status-face {
        width: 72px;
        height: 72px;
    }

    .score-label span {
        font-size: 1.2rem;
    }

    .score-label {
        width: 60px;
    }

    #dev-indicator {
        font-size: 4rem;
        left: -20px;
        letter-spacing: 0.5rem;
    }
}

@media (max-height: 550px) {
    header {
        padding: 4px 12px;
        min-height: 50px;
    }

    #status-face {
        width: 56px;
        height: 56px;
    }

    .score-label span {
        font-size: 1rem;
    }

    .score-label {
        font-size: 0.7rem;
    }

    #pause-btn,
    #settings-btn,
    #leaderboard-header-btn {
        height: 32px;
        width: 32px;
        font-size: 1.1rem;
    }

    #dev-controls-help {
        padding: 6px;
        font-size: 0.65rem;
        top: 60px;
    }

    #dev-indicator {
        font-size: 2.5rem;
        left: -15px;
        letter-spacing: 0.2rem;
    }
}