

#stats-menu-content {
    display: flex;
    flex-direction: column;
    width: 98%;
    max-width: 1024px;
    height: 98vh;
    background-color: var(--background-frost);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--box-shadow-modal);
    border: 1px solid var(--border-color-subtle);
    color: var(--color-text-primary);
    padding: 1rem;
    position: relative;
    overflow: hidden;
}

/* --- NEW: Stats Menu Tabs --- */
.stats-menu-tabs {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color-subtle);
    margin: 0 -1rem 1rem -1rem;
    padding: 0 1rem;
    line-height: 1.3;
}

.stats-menu-tab {
    padding: 0.75rem 1.25rem;
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.stats-menu-tab:hover {
    color: var(--color-text-primary);
}

.stats-menu-tab.active {
    color: var(--color-accent-yellow);
    border-bottom-color: var(--color-accent-yellow);
}

.stats-tab-content {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0; /* Required for flex scrolling */
}

.stats-tab-content.active {
    display: flex;
}
/* --- END: Stats Menu Tabs --- */


#stats-menu-title {
    font-family: var(--font-family-display);
    color: var(--color-accent-yellow);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    text-align: center;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
    font-weight: 600;
}

#stats-list-container, #owid-list-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 0.75rem; /* Space for scrollbar */
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}

#stats-list-container::-webkit-scrollbar, #owid-list-container::-webkit-scrollbar {
    width: 14px;
}
#stats-list-container::-webkit-scrollbar-track, #owid-list-container::-webkit-scrollbar-track {
    background: var(--scrollbar-track-color);
}
#stats-list-container::-webkit-scrollbar-thumb, #owid-list-container::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb-color);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.stats-list-item {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border-radius: var(--border-radius-lg);
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
}

.stats-list-item:hover {
    background-color: var(--background-hover-strong);
    border-color: var(--color-accent-blue);
    transform: translateY(-2px);
}

.stats-item-title {
    font-size: clamp(1.6rem, 2.5vw, 2.25rem);
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
}

.stats-item-description {
    font-size: clamp(0.85rem, 2vw, 1.3rem);
    color: var(--color-text-muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* --- NEW: OWID Discover Link --- */
#owid-discover-link {
    display: flex;
    width: fit-content; /* Shrink to content width */
    margin-left: auto; /* Center the element */
    margin-right: auto; /* Center the element */
    margin-bottom: 0.75rem; /* Retain bottom margin */
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: var(--border-radius-md);
    transition: background-color 0.2s;
    text-decoration: none;
    color: var(--color-text-muted);
}

#owid-discover-link:hover {
    background-color: var(--background-hover-light);
    color: var(--color-text-primary);
}

#owid-discover-link svg {
    flex-shrink: 0;
    width: 1.5rem; /* 24px */
    height: 1.5rem; /* 24px */
    fill: currentColor;
}

/* Specific underline for the 'Our World In Data' part within the link */
#owid-discover-link u, #owid-discover-link-bottom u {
    text-decoration: underline;
    color: var(--color-text-secondary);
    font-weight: 600;
}

#owid-discover-link:hover u, #owid-discover-link-bottom:hover u {
    color: var(--color-text-primary);
}

/* --- NEW: Bottom OWID Discover Link --- */
#owid-discover-link-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.5rem; /* Space above the link */
    padding: 1rem;
    border-radius: var(--border-radius-lg);
    transition: background-color 0.2s;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: clamp(1.5rem, 4vw, 2rem); /* Title-sized */
    font-weight: 600;
    text-align: center;
}

#owid-discover-link-bottom:hover {
    background-color: var(--background-hover-light);
    color: var(--color-text-primary);
}

#owid-discover-link-bottom svg {
    flex-shrink: 0;
    width: 2.5rem; /* Larger icon */
    height: 2.5rem;
    fill: currentColor;
}


/* --- NEW: OWID URL Form Styles --- */
#owid-url-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

#owid-url-input {
    flex-grow: 1;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color-subtle);
    border-radius: var(--border-radius-md);
    color: var(--color-text-primary);
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#owid-url-input:focus {
    border-color: var(--color-accent-blue);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
}

#owid-load-button {
    flex-shrink: 0;
    background: none;
    border: none;
    color: rgba(var(--color-success-rgb), 1);
    padding: 0.5rem;
    border-radius: var(--border-radius-full);
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-green 1.5s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

#owid-load-button:hover {
    background-color: rgba(var(--color-success-rgb), 0.2);
}

#owid-load-button svg {
    width: 2rem;
    height: 2rem;
}


/* --- NEW: Worldbank Explorer Styles --- */
#wb-controls {
    flex-shrink: 0;
    margin-bottom: 1rem;
}

#wb-search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color-subtle);
    border-radius: var(--border-radius-md);
    color: var(--color-text-primary);
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#wb-search-input:focus {
    border-color: var(--color-accent-blue);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
}

#wb-list-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}
#wb-list-container .loader {
    margin: 3rem auto;
}
#wb-list-container .wb-indicator-item {
    position: relative; /* For positioning context of the child ID */
    background-color: rgba(0,0,0,0.1);
    padding: 0.75rem 1rem;
    padding-bottom: 1.75rem; /* Extra space for the ID at the bottom */
    border-radius: var(--border-radius-md);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s;
}
#wb-list-container .wb-topic-item {
    background-color: rgba(0,0,0,0.2);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s;
    border-left: 3px solid var(--color-accent-blue);
}

#wb-list-container .wb-indicator-item:hover,
#wb-list-container .wb-topic-item:hover {
    background-color: rgba(255,255,255,0.1);
}
#wb-list-container .wb-indicator-title,
#wb-list-container .wb-topic-title {
    font-weight: 600;
    color: var(--color-text-primary);
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

#wb-list-container .wb-indicator-title {
    font-size: 1.6rem;
}

#wb-list-container .wb-indicator-description,
#wb-list-container .wb-topic-description {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* NEW: Style for indicator ID */
.wb-indicator-id {
    position: absolute;
    bottom: 0.5rem;
    right: 0.75rem;
    font-family: monospace, monospace;
    font-size: 0.75rem;
    color: var(--color-text-subtle);
    opacity: 0.7;
}

#wb-back-button {
    background: none;
    border: 1px solid var(--border-color-subtle);
    color: var(--color-text-muted);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    margin-bottom: 1rem;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}
#wb-back-button:hover {
    background-color: var(--background-hover-light);
    color: var(--color-text-primary);
}
/* --- END: Worldbank Explorer Styles --- */


/* --- Stats Mode Header --- */
body.stats-mode #top-info-bar .stats {
    display: none;
}

body.stats-mode #top-info-bar #stats-title-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
}

/* Hover effect moved to the title value span to not interfere with the button */

#stats-title-value {
    font-family: var(--font-family-display);
    font-size: clamp(1.05rem, 3.2vw, 1.75rem);
    /* padding-top: 0.5rem; */
    line-height: 1;
    font-weight: 700;
    transition: opacity 0.2s;
    text-align: center;
}

#stats-title-value:hover {
    opacity: 0.8;
}

body.stats-mode #leaderboard-button,
body.stats-mode #mobile-controls-toggle,
body.stats-mode #save-game-button,
body.stats-mode #refresh-style-button,
body.stats-mode #music-toggle-button {
    display: none;
}

/* --- Stats Mode Magic Wand Button --- */
#stats-magic-wand-button,
#stats-graph-button,
#stats-play-pause-button,
#stats-info-modal-button,
#stats-story-editor-button,
#stats-yearevents-button {
    display: none;
}

body.stats-mode #stats-magic-wand-button,
body.stats-mode #stats-graph-button,
body.stats-mode #stats-play-pause-button,
body.stats-mode #stats-info-modal-button,
body.stats-mode #stats-story-editor-button,
body.stats-mode #stats-yearevents-button {
    display: flex;
}

#stats-graph-button.activemode svg,
#stats-yearevents-button.activemode svg {
    fill: var(--color-accent-yellow);
    filter: drop-shadow(0 0 6px var(--color-accent-yellow));
}

/* --- Stats Mode Tooltip --- */
#country-tooltip {
    position: fixed;
    /* REMOVED styling to make it a seamless container */
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
    
    color: var(--color-text-primary);
    font-weight: 500;
    pointer-events: none;
    transform: translate(-50%, -100%) translateY(-10px) scale(0.95); 
    z-index: 1003; 
    white-space: nowrap;
    transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
    opacity: 0;
    visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}

/* Downward-pointing triangle at the bottom */
#country-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0; 
    height: 0; 
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    /* UPDATED: White arrow to match value box */
    border-top: 8px solid rgba(255, 255, 255, 0.6); 
}

#country-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -100%) translateY(-20px) scale(1);
}

#country-tooltip strong, 
#country-tooltip .tooltip-value {
    display: block;
    width: 100%;
    text-align: left;
    text-shadow: none;
}

#country-tooltip strong {
    /* Style for country name */
    display:inline-block;
    background: var(--background-frost);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    padding: 2px 4px;
    line-height: 1;
    width: min-content;
    border-radius: 0; /* As requested */
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--color-text-primary);
}

#country-tooltip .tooltip-value {
    color: #222;
    font-weight: 500; 
    line-height: 1;
    padding: 2px 4px;
	border-radius: 0; /* As requested */
	border: 1px solid rgba(255, 255, 255,0.2);
	background-color: rgba(255, 255, 255, 0.6);
    font-size: 1.2rem;
}


/* --- NEW: Onboarding Tooltip --- */
#onboarding-tooltip {
    position: fixed;
    background: var(--background-frost);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    color: var(--color-text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color-subtle);
    box-shadow: var(--box-shadow-modal);
    font-size: 1rem;
    font-weight: 500;
    pointer-events: none;
    z-index: 1005; /* Above everything else */
    white-space: nowrap;
    
    /* Default (hidden) state */
    opacity: 0;
    visibility: hidden;
    transform: translate(-120%, -50%) scale(0.9); /* Start further left and smaller */
    
    /* Transition for disappearing (fade-out) */
    transition: opacity 0.3s ease-out, transform 0.3s ease-out, visibility 0s linear 0.3s;
}

#onboarding-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-110%, -50%) scale(1); /* Move to final position and full size */
    
    /* Transition for appearing (fade-in) - overrides the base transition */
    transition: opacity 0.4s ease-out, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}


/* Arrow pointing to the right */
#onboarding-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    margin-left: -1px; /* Overlap border slightly */
    border-width: 8px;
    border-style: solid;
    border-color: transparent transparent transparent var(--border-color-subtle);
}

/* --- NEW: Event Tooltip Styles --- */
#event-tooltips-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1004;
}

.event-tooltip {
    position: absolute;
    background: transparent;
    padding: 0;
    color: var(--color-text-primary);
    font-weight: 500;
    transform: translate(-50%, -100%) translateY(-10px) scale(0.95);
    white-space: nowrap;
    transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out, visibility 0s linear 0.15s;
    opacity: 0;
    visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}

.event-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0; 
    height: 0; 
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(255, 255, 255, 0.6); 
}

.event-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -100%) translateY(-20px) scale(1);
    transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
}

.event-tooltip strong, 
.event-tooltip .tooltip-value {
    display: block;
    width: 100%;
    text-align: left;
    text-shadow: none;
}

.event-tooltip strong {
    display:inline-block;
    background: var(--background-frost);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    padding: 2px 4px;
    line-height: 1;
    width: min-content;
    border-radius: 0;
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--color-text-primary);
}

.event-tooltip .tooltip-value {
    color: #222;
    font-weight: 500; 
    line-height: 1;
    padding: 2px 4px;
	border-radius: 0;
	border: 1px solid rgba(255, 255, 255,0.2);
	background-color: rgba(255, 255, 255, 0.6);
    font-size: 1.2rem;
}
/* --- END: Event Tooltip Styles --- */


/* --- NEW/UPDATED Stats Controls Panel --- */
#stats-controls-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to slider */
}

#stats-controls-panel > * {
    pointer-events: auto; /* Re-enable for children */
}

#stats-controls-panel.hidden {
    display: none;
}

#year-slider-container {
    position: relative;
    width: 100%;
    height: 24vh;
}

#svg-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20vh;
    padding-left: 25px;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 1;
}

#svg-container svg {
    width: 100%;
    height: 100%;
}

#year-slider {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0; /* REMOVED margin-bottom to fix gap */
    padding: 0 20px; /* ADDED padding for thumb */
    box-sizing: border-box; /* ADDED for correct padding calculation */
    background: linear-gradient(90deg, rgba(0,0,255,0.7) 0%,  rgba(255,0,0,0.7) 100%);
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.9) 100%);
    mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.9) 100%);
    outline: none;
    background-color: transparent; /* Critical for interaction */
    z-index: 2;
}

#year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 24vh;
    border: none;
    border-radius: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(255, 255, 255,0.6));
    cursor: pointer;
    border-right: solid 1px #FFF;
}

#year-slider::-moz-range-thumb {
    width: 25px;
    height: 24vh;
    border: none;
    border-radius: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(255, 255, 255,0.6));
    cursor: pointer;
    border-right: solid 1px #FFF;
}

#year-slider-container.readgraph #year-slider::-moz-range-thumb,
#year-slider-container.readgraph #year-slider::-webkit-slider-thumb {
    border-right: solid 1px #aaa;
}

#year-slider-container.readgraph #year-slider {
    background: linear-gradient(90deg, rgba(0,0,255,0.4) 0%,  rgba(255,0,0,0.4) 100%);
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.7) 100%);
    mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.7) 100%);
}

#year-slider-container.readgraph #svg-container {
    height: 30vh;
}

#year-output {
    position: absolute;
    top: 0; /* Position at the top of the container */
    left: 50%; /* JS will override this, but good for initial placement */
    background-color: transparent;
    color: var(--color-text-primary);
    opacity: 0.8;
    padding: 4px 8px;
    font-family: var(--font-family-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
    pointer-events: none;
    transform: translateX(-50%);
    white-space: nowrap;
    z-index: 3; /* Above everything */
    transition: color 0.2s ease-in-out, text-shadow 0.2s ease-in-out, transform 0.2s ease-in-out, opacity 0.3s ease-in-out;
}

#graph-country-name-output {
    position: absolute;
    top: 4rem; /* Position it below the year output, give more space for multi-line */
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-text-primary);
    font-size: clamp(1.2rem, 3.5vw, 1.6rem); 
    line-height: 1.2; 
    font-weight: 600;
    font-family: var(--font-family-display);
    text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
    pointer-events: none;
    z-index: 12; /* Ensure it is above the SVG graph and slider thumb */
    white-space: normal;
    max-width: 90%;
    text-align: center;
    transition: opacity 0.2s ease-in-out;
    opacity: 0;
}

#graph-country-name-output.visible {
    opacity: 0.9;
}

/* --- NEW: Event Text Output --- */
#event-text-output {
    position: absolute;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-text-primary);
    font-size: clamp(1.2rem, 3.5vw, 1.6rem);
    line-height: 1.3;
    font-weight: 700;
    font-family: var(--font-family-display);
    text-shadow: 1px 1px 4px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 13; /* HIGHER than graph-country-name-output */
    white-space: normal;
    max-width: 90%;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0s linear 0.3s;
    background-image: linear-gradient(to bottom, rgba(10, 15, 25, 0), rgba(10, 15, 25, 0.25));
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-md);
   /*  box-shadow: inset 0 0 10px rgba(0,0,0,0.2); Inset shadow */
}

#event-text-output.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1.05); /* Add a subtle scale effect */
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* --- Event Marker Styles --- */
#event-markers-container {
    position: absolute;
    bottom: -20px; /* Position below the main slider container */
    left: 25px; /* Align with SVG padding */
    right: 25px; /* Align with SVG padding */
    height: 20px;
    pointer-events: auto;
    z-index: 2; /* Ensure markers are above the SVG graph */
}

.event-marker {
    position: absolute;
    bottom: 5px;
    width: 2px;
    height: 10px;
    background-color: var(--color-accent-yellow);
    transform: translateX(-50%);
    opacity: 0.6;
    transition: opacity 8s, transform 0.2s, background-color 0.2s;
    font-size: clamp(1.3rem, 2.3rem, 2.5rem);
}

#year-output.event-year {
    color: var(--color-accent-yellow);
    text-shadow: 0 0 8px var(--color-accent-yellow), 2px 2px 4px rgba(0,0,0,0.7);
    transform: translateX(-50%) scale(1.05);
}

/* --- Graph Highlighting --- */
#svg-container .c-gph {
    transition: stroke 0.2s ease-in-out, stroke-width 0.2s ease-in-out, opacity 0.2s ease-in-out;
    stroke: rgba(255,255,255,0.8);
    fill: rgba(255,255,255,0.02);
    opacity: 0.45;
    stroke-opacity: 0.7;
    stroke-width: 0.6;
}

#svg-container .c-gph.highlighted {
    stroke: rgba(255,255,255,1);
    stroke-width: 2; /* unitless for SVG */
    stroke-opacity: 1;
    opacity: 1;
    filter: drop-shadow(0 0 4px var(--color-accent-yellow));
}

/* --- Game Mode Icon Menu Order --- */
body:not(.stats-mode) #language-selector-container { order: 1; }
body:not(.stats-mode) #save-game-button { order: 2; }
body:not(.stats-mode) #music-toggle-button { order: 3; }
body:not(.stats-mode) #refresh-style-button { order: 4; }
body:not(.stats-mode) #credits-link { order: 5; } /* this is the share button */
body:not(.stats-mode) #leaderboard-button { order: 6; }
body:not(.stats-mode) #info-button { order: 7; }
body:not(.stats-mode) #mobile-controls-toggle { order: 8; }

/* --- Stats Mode Icon Menu Order --- */
body.stats-mode #language-selector-container { order: 1; }
body.stats-mode #stats-play-pause-button { order: 2; }
body.stats-mode #stats-yearevents-button { order: 3; }
body.stats-mode #stats-magic-wand-button { order: 4; }
body.stats-mode #stats-graph-button { order: 5; }
body.stats-mode #stats-info-modal-button { order: 6; }
body.stats-mode #stats-story-editor-button { order: 7; }
body.stats-mode #credits-link { order: 8; }
body.stats-mode #info-button { order: 9; }
body.stats-mode #mobile-controls-toggle { order: 10; }


/* === Summary & Credits Overlay Styles === */
#summary-overlay, #credits-overlay, #leaderboard-overlay, #save-game-overlay, #story-editor-overlay, #password-prompt-overlay {
    position: fixed;
    inset: 0;
    background: var(--main-gradient);
    -webkit-backdrop-filter: var(--blur-md);
    backdrop-filter: var(--blur-md);
    z-index: 1010;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
}
#summary-overlay.active, #credits-overlay.active, #leaderboard-overlay.active, #save-game-overlay.active, #story-editor-overlay.active, #password-prompt-overlay.active { 
    display: flex;
}

#summary-modal-content, #save-game-modal-content, #password-modal-content {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 800px;
    max-height: 99vh;
    background-color: var(--background-frost);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--box-shadow-modal);
    border: 1px solid var(--border-color-subtle);
    color: var(--color-text-primary);
    padding: 1.25rem;
    position: relative;
}

#password-modal-content {
    max-width: 500px;
    padding: 2rem;
}

.password-prompt-input-group {
    display: flex;
    gap: 0.75rem;
    margin: 1.5rem 0;
    align-items: center;
}

#story-password-input {
    flex-grow: 1;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color-subtle);
    border-radius: var(--border-radius-md);
    color: var(--color-text-primary);
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#story-password-input:focus {
    border-color: var(--color-accent-blue);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
}

#submit-story-password {
    margin: 0;
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    flex-shrink: 0;
}

#password-feedback {
    min-height: 1.25rem;
    color: rgba(var(--color-danger-rgb), 1);
    font-weight: 600;
}


#credits-modal-content, #leaderboard-modal-content, #story-editor-modal-content {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 1024px;
    height: 98vh;
    height: 98svh;
    max-height: 100%;
    font-weight: normal;
    background-color: var(--background-frost);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--box-shadow-modal);
    border: 1px solid var(--border-color-subtle);
    color: var(--color-text-primary);
    position: relative;
    overflow: hidden; /* Prevent content from overflowing rounded corners */
}

 #leaderboard-modal-content {
    height: 99vh;
 }

#end-of-round-modal .modal-content {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}

.leaderboard-dynamic-container {
        overflow-y: scroll;
        scrollbar-width: large;
        scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}


#game-summary-section {
    flex: 1;
    min-height: 0; /* Critical for flex + scroll */
    display: flex;
    flex-direction: column;
}

.credits-section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
    padding-bottom: 0.75rem;
    margin: 0;
    flex-shrink: 0;
}

#game-summary-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 0.5rem; /* Space for scrollbar */
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}
#game-summary-container::-webkit-scrollbar { width: 6px; }
#game-summary-container::-webkit-scrollbar-track { background: var(--scrollbar-track-color); }
#game-summary-container::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 3px; }

.summary-line {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0.5rem 0;
    font-size: clamp(1.1rem, 2.5vw, 1.3rem);
    border-bottom: 1px solid rgba(107, 114, 128, 0.2);
    gap: 1.25rem;
}
.summary-line > span:first-child {
    font-weight: 700;
    color: var(--color-text-muted);
    word-break: break-word;
    text-align: left;
    flex-shrink: 1;
    font-size: 1.5rem;
}
.summary-line > span:last-child {
    word-break: break-word;
    text-align: left;
    flex-shrink: 1;
    font-size: 1.5rem;
}
#no-summary-message {
     text-align: center;
     color: var(--color-text-subtle);
     padding-top: 2rem;
}


#social-share-container {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 0;
}
.social-button {
    color: var(--color-text-muted);
    transition: color 0.2s ease-in-out, transform 0.2s ease-in-out;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}
.social-button:hover {
    color: #ffffff;
    transform: scale(1.1);
}
.social-button svg {
    width: 2rem;
    height: 2rem;
}

/* NEW: Feedback class for copied text */
.copied-feedback {
    color: var(--color-accent-green) !important;
    transition: color 0.2s ease-in-out;
}

/* --- NEW: Error pulse for country select in highscore submission --- */
@keyframes pulse-red-ring {
    0%   { box-shadow: 0 0 0 0 rgba(var(--color-danger-rgb), 0.7); }
    70%  { box-shadow: 0 0 0 8px rgba(var(--color-danger-rgb), 0); }
    100% { box-shadow: 0 0 0 0 rgba(var(--color-danger-rgb), 0); }
}

.custom-select-wrapper.error-pulse .custom-select-trigger,
.custom-select-trigger.error-pulse {
    border-color: rgba(var(--color-danger-rgb), 1) !important;
    animation: pulse-red-ring 0.9s ease-out 0s 2;
}

#credits-content-wrapper, #leaderboard-content-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden; 
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.close-overlay-button {
    position: absolute;
    top: 1rem; 
    right: 1rem; 
    color: var(--color-text-secondary); 
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--border-radius-full); 
    transition: background-color 0.2s, color 0.2s;
    z-index: 1003; /* Above modal content */
}
.close-overlay-button:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.15);
}
.close-overlay-button svg {
    width: 2.5rem; 
    height: 2.5rem; 
}

#leaderboard-modal-content .close-overlay-button {
    position: relative;
    display: flex;
    justify-content: flex-end;
}

#credits-text-scroller {
    position: absolute;
    text-align: center;
    color: var(--color-text-primary);
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-y: scroll;
    height: 100%;
    width: 100%; 
    padding: 2rem 50px;
    box-sizing: border-box;
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}
#credits-text-scroller strong {
    font-family: 'Orbitron';
    margin-top: 2rem;
    display: inline-block;
}

/* === REFACTORED: Story Editor Styles === */

/* Visually hide an element but keep it accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

#story-editor-modal-content {
    display: flex;
    flex-direction: column;
    height: 100%; /* Take full height of parent */
    padding: 0; /* Remove padding to manage it internally */
}

#story-editor-modal-content > .credits-section-title,
#story-editor-modal-content > #story-editor-subtitle {
    padding: 0 1.5rem;
    flex-shrink: 0;
}
#story-editor-modal-content > .credits-section-title {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
}
#story-editor-subtitle {
    font-family: var(--font-family-display);
    font-size: clamp(1.6rem, 3vmin, 2.1rem);
    text-align: center;
    color: var(--color-accent-yellow);
    margin-top: -1rem;
    margin-bottom: 1.5rem;
    font-weight: bold;
}

#story-editor-scroller {
    flex: 1 1 auto; /* Let it grow and shrink */
    overflow-y: auto;
    min-height: 0; /* Important for flex scrolling */
    padding: 1rem 1.5rem; /* Inner padding */
    scrollbar-width: large;
    scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
}
#story-editor-scroller::-webkit-scrollbar { width: 6px; }
#story-editor-scroller::-webkit-scrollbar-track { background: var(--scrollbar-track-color); }
#story-editor-scroller::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 3px; }

#story-editor-footer {
    flex-shrink: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color-subtle);
    background-color: rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 1rem;
}

#story-editor-footer .modal-buttons {
    margin-left: auto; /* Push submit button to the right */
    padding-bottom: 0; /* Reset padding from general modal styles */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#story-editor-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

#story-editor-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#story-editor-form label {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    margin-bottom: -0.25rem;
}

#story-editor-form input[type="text"],
#story-editor-form input[type="email"],
#story-editor-form input[type="url"],
#story-editor-form input[type="number"],
#story-editor-form input[type="password"],
#story-editor-form textarea,
#story-editor-form .custom-select-trigger {
    background-color: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color-subtle);
    border-radius: var(--border-radius-md);
    padding: 0.5rem 0.75rem;
    color: var(--color-text-primary);
    font-size: 1.2rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}


#story-editor-form .custom-select-trigger {
    padding: 0.25rem 0.75rem;
}

#editor-language-select-wrapper .custom-select-trigger {
    padding: 0.5rem 0.75rem;
}
#story-editor-form input:focus,
#story-editor-form textarea:focus,
#story-editor-form .custom-select-wrapper.open .custom-select-trigger {
    border-color: var(--color-accent-blue);
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.3);
}

#story-editor-form textarea.auto-resize {
    resize: none;
    min-height: 4rem;
    line-height: 1.3;
}

.editor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* NEW: Horizontal form group for Language and Title */
.form-group-horizontal {
    flex-direction: row!important;
    align-items: flex-end;
    gap: 1rem;
}

.form-group-horizontal > .form-group {
    margin-bottom: 0; /* Remove default margin from subgroups */
}

.language-select-subgroup {
    flex: 1; /* Takes 1 part of the available space */
}

.title-input-subgroup {
    flex: 4; /* Takes 4 parts, creating an ~80/20 split */
}


@media (max-width: 640px) {
    .editor-grid { grid-template-columns: 1fr; }
    .form-group-horizontal { flex-wrap: wrap; }
}

.editor-help-text {
    font-size: 0.85rem;
    color: var(--color-text-subtle);
    margin-bottom: 0.75rem;
    margin-top: -0.5rem;
}

#yearevents-editor-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.year-event-card {
    background-color: rgba(0,0,0,0.15);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color-subtle);
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    padding-left: 2.5rem; /* Space for reorder buttons */
    transition: background-color 0.2s, box-shadow 0.2s;
    position: relative; /* For arrow positioning */
}

.card-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}
.card-main-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center; /* Center items vertically for better balance */
    flex-grow: 1;
}

.card-main-inputs .form-group {
    flex: 1 1 100px;
    min-width: 80px;
}
.card-main-inputs .form-group:nth-child(2) /* Country */ { /* Zoom */
    flex: 0 0 7rem;
}

.card-main-inputs .form-group:nth-child(3) { /* Zoom */
    flex: 0 0 10rem;
}

.card-main-inputs .custom-select-trigger {
    width: 100%; /* Fill the container */
    padding: 0.5rem;
    min-width: 0; /* Allow shrinking */
}


.tooltip-section {
    border-top: 1px solid var(--border-color-subtle);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}
.tooltip-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.tooltip-section-header label {
    margin-bottom: 0; /* Override default */
}
.tooltip-items-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.tooltip-item {
    display: grid;
    grid-template-columns: 140px 1fr 32px; /* Fixed country, flexible text, fixed button */
    align-items: flex-end;
    gap: 0.5rem;
}
.tooltip-item .custom-select-trigger,
.tooltip-item input[type="text"] {
    font-size: 0.9rem;
    padding: 0.35rem 0.5rem;
}


.remove-button, .add-button {
    background: none;
    border: 1px solid var(--border-color-subtle);
    color: var(--color-text-muted);
    border-radius: var(--border-radius-full);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
.remove-card-button {
    margin-top: 1.25rem; /* Align roughly with inputs */
}
.remove-button:hover {
    background-color: rgba(var(--color-danger-rgb), 0.2);
    color: var(--color-text-primary);
    border-color: rgba(var(--color-danger-rgb), 0.5);
}
.add-button:hover {
    background-color: var(--background-hover-light);
    color: var(--color-text-primary);
    border-color: var(--color-accent-blue);
}

/* --- Reorder Buttons --- */
.reorder-button {
    position: absolute;
    left: 0.15rem;
    background: none;
    border: 1px solid var(--border-color-subtle);
    color: var(--color-accent-yellow);
    border-radius: var(--border-radius-full);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
    z-index: 5;
}
.reorder-button:hover {
    background-color: rgba(224, 187, 0, 0.2);
    color: var(--color-accent-yellow);
    border-color: var(--color-accent-yellow);
    filter: drop-shadow(0 0 4px var(--color-accent-yellow));
}
.move-up-button {
    top: 0.5rem;
}
.move-down-button {
    bottom: 0.5rem;
}

/* --- Year Event Card Input Customizations --- */

/* NEW: Inline group for Zoom label and input */
#story-editor-form .year-event-card .event-zoom-group {
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
}

.year-event-card .event-zoom-group label {
    margin-bottom: 0;
    flex-shrink: 0;
    font-size: 1.1rem;
    color: var(--color-text-muted);
    font-weight: 600;
}
.year-event-card .event-zoom-group input {
    flex-grow: 1;
    min-width: 0; /* Allow shrinking */
}

/* Make Year input's container shrink to fit */
.card-main-inputs .form-group:first-child {
    flex: 0 0 auto;
    margin-right: 0.5rem;
}

/* Special seamless style for Year input */
.year-event-card .card-main-inputs .event-year-input {
    background-color: transparent !important;
    border: 1px solid transparent !important;
    font-family: var(--font-family-display);
    font-size: clamp(1.6rem, 4vw, 2.5rem) !important; 
    padding: 0 0.25rem !important;
    line-height: 1;
    text-align: center;
    color: var(--color-text-primary)!important;
    transition: all 0.2s ease-in-out!important;
    width: 7ch!important;
    min-width: 7ch!important;
    box-sizing: border-box!important;
}



/* On focus, make it look like a regular input again */
.year-event-card .card-main-inputs .form-group:first-child input[type="number"]:focus {
    background-color: rgba(0,0,0,0.3) !important;
    border: 1px solid var(--border-color-subtle) !important;
    border-radius: var(--border-radius-md) !important;
    padding: 0.5rem 0.75rem !important; /* Restore standard padding */
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.3) !important;
}

/* Enlarge Zoom and Event Text inputs to match the height of the Country select */
.year-event-card .card-main-inputs .form-group:nth-child(3) input,
.year-event-card .card-content input[type="text"] {
    font-size: 1.2rem;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    min-height: 42px; /* Explicitly match height of select w/ flag */
    box-sizing: border-box;
}


#story-editor-feedback.feedback-message {
    text-align: center;
    font-weight: 600;
    min-height: 1.5rem;
    flex-grow: 1; /* Take up space in the footer */
}
#story-editor-feedback.success { color: var(--color-accent-green); }
#story-editor-feedback.error { color: rgba(var(--color-danger-rgb), 1); }

/* NEW: Confirmation Prompt */
#story-editor-confirmation-prompt {
    color: var(--color-text-muted);
    font-style: italic;
    font-size: 0.9rem;
    text-align: right;
    max-width: 450px;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}
#story-editor-confirmation-prompt.hidden {
    display: none;
}


/* === END: Story Editor Styles === */



/* NEW: Difficulty Modal Styles */
#difficulty-modal .modal-content {
    max-width: 768px;
    padding: 2em 0.5em;
}
#difficulty-modal .modal-content #modal-language-selector-container {
    position: absolute;
    top: 4.5rem;
    right: 3.5rem;
}
#difficulty-modal h1 {
    font-family: var(--font-family-display);
    color: var(--color-accent-yellow);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
#difficulty-modal h2 {
    font-family: var(--font-family-main);
    font-weight: 500;
}
#difficulty-modal .modal-buttons button {
    margin: 0 0.5rem;
    font-size: 1.2rem;
    padding: 0.8rem 1.5rem;
}

/* --- UPDATED Difficulty Section Styles --- */
@keyframes subtle-pan-right-zoom {
    to {
        transform: translateX(6%) translateY(-6%) scale(1.15);
    }
}

@keyframes subtle-pan-down-zoom {
    to {
        transform: translateX(-5%)  translateY(25%) scale(1.5);
    }
}

#difficulty-selection-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 2rem;
    width: 100%;
}

.difficulty-section {
    position: relative;
    padding: 2rem 1.5rem;
    border-radius: var(--border-radius-xl);
    overflow: hidden;
    border: 1px solid var(--border-color-subtle);
    box-shadow: var(--box-shadow-modal);
    transition: transform 0.3s ease-out, box-shadow 0.3s ease-out;
    -webkit-backdrop-filter: var(--blur-sm);
    backdrop-filter: var(--blur-sm);
}

.difficulty-section.stats-mode-section {
    cursor: pointer;
}

.difficulty-section:hover {
    box-shadow: 0 10px 35px rgba(0,0,0,0.4);
}

.difficulty-section::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    background-size: cover;
    opacity: 0.7;
    transition: opacity 0.3s ease-out, transform 0.8s ease;
}

.difficulty-section::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(90deg, rgba(19, 1, 70, 0.3) 0%, rgba(19, 1, 70, 0.4) 50%, rgba(19, 1, 70, 0.8) 100%);
    transition: background 0.3s ease-out;
}

.difficulty-section:hover::before {
    animation-play-state: paused;
    opacity: 0.9;
}

.difficulty-section:hover::after {
    background: linear-gradient(90deg,  rgba(19, 1, 70, 0.3) 0%, rgba(19, 1, 70, 0.4) 50%, rgba(19, 1, 70, 0.8) 100%);
    transition : 0.4s all ease-out;
}

.difficulty-section.stats-mode-section::before {
    background-image: url('https://zanasagesse.ci/wp-content/uploads/2025/09/terraguessr_stats.webp');
    background-position: left 74%;
    animation: subtle-pan-right-zoom 18s infinite alternate ease-in-out;
}

.difficulty-section.game-mode-section::before {
    background-image: url('https://zanasagesse.ci/wp-content/uploads/2025/09/terraguessr_opt.webp');
    background-position: left 70%;
    animation: subtle-pan-down-zoom 8s infinite alternate ease-in-out;
}


/* Ensure content is above the pseudo-elements */
.difficulty-section > * {
    position: relative;
    z-index: 2;
}

.difficulty-section-title {
    font-family: var(--font-family-display);
    font-size: clamp(1.6rem, 4vw, 2rem);
    color: var(--color-text-primary);
    margin-bottom: 1.5rem;
    font-weight: 600;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.7);
}

#difficulty-stats {
    width: 100%;
    max-width: 350px;
    margin-left: auto;
    margin-right: auto;
    font-size: 1.4rem;
    padding: 1rem 1.5rem;
    background-image: var(--green-gradient); /* Re-using green from before */
}
#difficulty-stats:hover {
   background-image: linear-gradient(315deg, rgba(47, 200, 48,0.7) 0%, rgba(12, 250, 19,0.8) 74%);
   box-shadow: inset 2px 2px 4px 0px rgba(150, 255, 200, .3), 8px 8px 25px 0px rgba(0, 0, 0, .15), 5px 5px 10px 0px rgba(0, 0, 0, .15);
   transition: all 0.6s ease;
}


#level-share-link-container {
    overflow:hidden;
    align-items: center;
    display: flex;
}


#leaderboard-modal-content .close-overlay-button:hover {
    background-color: rgba(255, 255, 255, 0);
}

#leaderboard-modal-content .close-overlay-button svg:hover {
    fill: #E0BB00;
    stroke-width: 3;
    stroke: #E0BB00;
    transition:all 0.4s;
}

#save-game-link-container {
    max-width:100%;
}

#mobile-controls-toggle, #mobile-controls-burger {
//    display: none;
}

#mobile-controls-burger {
    display: none;
}

#mobile-controls-burger svg {
    fill:rgba(255,255,255,0.9);
}



    .controls-container.collapsed #main-controls-group {
        opacity: 0;
        max-height: 0;
        visibility: hidden;
        margin-top: -0.75rem; /* collapse margin as well */
        transition: opacity 0.3s ease, max-height 0.3s ease, visibility 0.3s, margin-top 0.3s ease;
    }
    
    body:not(.menu-open) #mobile-controls-toggle {
        display: none;
    }
    body:not(.menu-open) #mobile-controls-burger {
        display: flex;
    }
    
    body.menu-open #mobile-controls-toggle {
        display: flex;
    }
    body.menu-open #mobile-controls-burger {
        display: none;
    }

    #stats-mobile-controls-burger {
        display: none; /* Hide by default */
    }

    /* In Stats Mode, manage visibility of the two different burger buttons */
    body.stats-mode #mobile-controls-burger {
        display: none !important; /* Hide the bottom (game) burger */
    }

    body.stats-mode:not(.menu-open) #stats-mobile-controls-burger {
        display: flex; /* Show the top (stats) burger when menu is closed */
    }
    
    body.stats-mode.menu-open #stats-mobile-controls-burger {
        display: none; /* Hide the top (stats) burger when menu is open (triangle shows instead) */
    }

/* --- Autocomplete Fullscreen Mobile Layout --- */
@media (max-height: 699px),
screen and (max-height: 799px),
screen and (max-height: 1100px) and (-webkit-min-device-pixel-ratio: 2) {
    /* When suggestions are active, make the entire bottom panel a fullscreen container */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh; /* Fallback for older browsers */
        height: 100svh; /* More robust for mobile keyboards */
        transform: none;
        display: flex;
        flex-direction: column;
        justify-content: flex-end; /* Pushes content to the bottom */
        z-index: 20; /* Ensure it's above the globe and top bar */
        padding: 0;
        background: transparent; /* The overlay will provide the background */
    }

    /* Make the overlay visible and interactive */
    #suggestions-overlay:not(.hidden) {
        pointer-events: auto;
        backdrop-filter: var(--blur-lg);
        -webkit-backdrop-filter: var(--blur-lg);
    }

    /* Make the flex containers inside fill the height */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel > .relative,
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel > .relative > .relative {
        height: 100%;
        width: 100% !important; /* Override inline styles */
        max-width: 100% !important;
        display: flex;
        flex-direction: column;
    }

    /* This is the key: reverse the order of input and dropdown */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel > .relative > .relative {
         flex-direction: column-reverse;
    }

    /* Style the dropdown to take up the remaining space */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel #country-suggestions-dropdown {
        position: relative; /* Let it be part of the flex flow */
        bottom: auto;
        flex-grow: 0; /* Don't grow to fill space */
        height: auto; /* Let flexbox control height */
        max-height: 90%; /* Set a reasonable max-height */
        padding-top: 5rem; /* Avoid top bar */
        padding-bottom: 1rem;
        box-sizing: border-box;

    }
    
    /* Add padding and background to the input area to make it look like a bottom bar */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel .relative > .relative {
         padding: 0 1rem 1rem 1rem;
         background: rgba(10, 15, 25, 0.4);
         -webkit-backdrop-filter: var(--blur-sm);
         backdrop-filter: var(--blur-sm);
    }
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel #country-autocomplete-input {
        margin: 0;
        padding: 1rem;
        background: transparent;
        border-radius: 0;
        border-bottom: 1px solid rgba(209, 213, 219, 0.8);
        position: fixed;
    }

    /* The hint button and other elements in that bar need adjustment too */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel #show-hint-button {
        left: 0.75rem;
    }
     #suggestions-overlay:not(.hidden) ~ #bottom-control-panel #mobile-controls-burger {
        right: 0.75rem;
    }

    /* Hide the feedback message when in this fullscreen mode */
    #suggestions-overlay:not(.hidden) ~ #bottom-control-panel #feedback-message {
        display: none;
    }

}

/* Desktop layout for OWID tab */
@media (min-width: 1025px) {
    #owid-url-form {
        width: 70%;
        margin-left: auto;
        margin-right: auto;
    }

    #owid-discover-link-bottom {
        width: 50%;
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 1024px) {
    .custom-select-options {
        left:20px!important;
    }
    #top-info-bar {
        justify-content: flex-end; /* Align stats to the right */
        padding-right: 0.5rem;    /* Set space on the right */
    }
    #top-info-bar h1 {
        font-size: 1.25rem;
    }
    #top-info-bar .stats {
        gap: 0.75rem;
        margin-right: 0; /* This is now controlled by parent padding */
    }
     #top-info-bar .stats .stat-item {
        font-size: 0.875rem;
     }
    #level-value, #score-value, #attempts-value {
        font-size: 1.5rem;
    }
    #music-toggle-button svg,
    #quality-toggle-button svg, 
    .credits-link svg {
        width: 1.5rem;
        height: 1.5rem;
    }
    #current-language-flag, #modal-current-language-flag {
        font-size: 1.5rem;
    }
    #language-grid-container {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); 
        gap: 1rem;
        padding: 1.5rem;
    }
    .language-option-grid-item {
        font-size: 2.8rem; 
    }
    .language-option-grid-item .lang-name {
         font-size: 0.75rem; 
    }



    /* Mobile layout improvements */
    #bottom-control-panel {
        width: 100%;
        max-width: 100%;
        left: 0;
        transform: none;
        bottom: 0;
        padding: 1rem 0.25rem 2rem 0.25rem;
        box-sizing: border-box;
    }
    #stats-controls-panel {
        padding: 0; /* Remove padding that interferes with new slider design */
    }
    #bottom-control-panel .relative[style] {
        width: 100% !important;
        max-width: 100% !important;
    }
    #top-info-bar .controls-container {
        position: absolute;
        top: 4.5rem;
        right: 0.5rem;
        flex-direction: column;
        align-items: center;
        gap: 0; /* Gap is now on the inner group */
        flex-shrink: 0;
        /* Overrides for desktop centering */
        bottom: auto;
        margin: 0;
        height: auto;
        transform: none; /* Reset transform for mobile layout */
    }

    .modal-content {
        padding: 0.5rem;
        width: 100%;
        max-width: none;
    }

    .modal-button-custom {
        padding: 2.5vw 3vw;
        font-size: 1.6em;
    }

    #credits-modal-content, #leaderboard-modal-content, #story-editor-modal-content {
        width: 98%;
        height: 98vh;
        height: 98svh;
    }
    #leaderboard-content-wrapper {
         padding: 1rem 0.25rem;
    }

    .leaderboard-row {
        grid-template-columns: 30px 60px 1fr 1.5fr 40px;
        gap: 0;
        font-size: 0.9rem;
    }
    .leaderboard-row .score {
        font-size: 1rem;
    }
    .leaderboard-row .pseudo {
    font-size: 1rem;
    }
    .ad-wrapper{
        max-height: 200px;
        overflow: hidden;
    }
    .ad-wrapper.waiting {
        max-height: 20px;
        overflow: hidden;
    }

    /* --- Stats Mode Mobile Header Adjustments --- */
    body.stats-mode #top-info-bar {
        /* This will align the #stats-title-container to the right */
        justify-content: flex-end;
    }
    
    /* Replace the "TerraGuessr" text title with the site's favicon icon */
    body.stats-mode #top-info-bar h1 {
        display: block; /* Ensure it's not hidden by other rules */
        width: 32px;
        height: 32px;
        text-indent: -9999px; /* Hide text */
        overflow: hidden;
        background: url('/favicon.ico') no-repeat center;
        background-size: contain;
        position: absolute;
        left: 1rem;
        top: 50%;
        padding-top: 0; /* Override default padding */
        transform: translateY(-50%);
        opacity: 0.8; /* A bit of transparency like other icons */
    }

    /* Hide the "previous statistic" navigation arrow */
    body.stats-mode #stats-prev-button {
        display: none;
    }

    /* Increase size of next statistic button on mobile */
    body.stats-mode #stats-next-button svg {
        width: 2.25rem;
        height: 2.25rem;
    }

    #event-text-output {
        width: 100%;
        bottom: 0;
    }

    /* --- Stats Menu Mobile Layout --- */
    #stats-menu-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100svh;
        border-radius: 0;
        padding: 1rem 0.75rem;
        border: none;
        box-sizing: border-box;
    }

    #stats-menu-title {
        margin-bottom: 1rem;
        padding-top: 2rem; /* Add some space from the top of the screen */
    }

    #stats-list-container, #owid-list-container {
        padding-right: 0.25rem; /* Tighter scrollbar */
    }

    .stats-list-item {
        padding: 0.75rem 1rem;
        margin-bottom: 0.75rem;
    }

    #stats-info-description {
        max-width: 100%;
    }

    #stats-title-value {
        text-align: right;
    }


}

/* --- Mobile Landscape Opening Modal --- */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1024px) {
    #difficulty-modal.modal-overlay {
        align-items: flex-start;
        overflow-y: auto;
        padding: 2rem 1rem;
    }
}

@media (max-width: 767px) {
    #difficulty-modal .modal-buttons, .modal-buttons {
        flex-direction: column;
        gap: 0.75rem;
        padding-bottom: 1.5rem;
        align-items: center;
    }
    #difficulty-modal .modal-buttons button {
        width: 100%;
        margin: 0;
        font-size: 1.5rem;
        padding: 1rem 1.5rem;
    }
    .modal-buttons button {
        padding: 1rem 0.5rem;
    }
    #difficulty-selection-container {
        margin-top: 0.25rem;
        gap: 0.5rem;
    }
    .difficulty-section {
        padding: 1.5rem 0.5rem;
    }
    .difficulty-section.stats-mode-section {
        cursor: default;
    }

    #country-tooltip strong {
    font-size: 1rem;
    }

    #country-tooltip .tooltip-value {
        font-size: 0.9rem;
    }

    .event-tooltip {
        height: auto;
        max-height: fit-content;
    }

    .event-tooltip strong {
        font-size: 1rem;
    }
    .event-tooltip .tooltip-value {
        font-size: 0.9rem;
        display: block!important;
        word-break: break-word;
        white-space: pre-wrap;
        max-width: 190px;
        height: auto;
        line-height: 1.2;
    }


    #difficulty-modal .modal-content #modal-language-selector-container {
        right: 0.5rem;
    }
}

/* --- Stats Loading Modal Styles --- */
#stats-loading-overlay {
    z-index: 1004; /* Higher than stats menu */
    background: rgba(10, 15, 25, 0.3);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0s linear 0.3s;
}

#stats-loading-overlay.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease-in-out;
}

#stats-loading-modal-content {
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 1024px;
    padding: clamp(0.5rem, 2vh, 0.5rem); /* Responsive Padding */
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius-xl);
    box-shadow: 5px 5px 10px #0006, -1px -1px 2px rgba(255, 255, 255, 0.3), 1px 1px 2px rgba(0, 0, 0, 0.8);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-height: 98svh; /* Use small viewport height */
}



#stats-loading-overlay.visible #stats-loading-modal-content {
    transform: scale(1);
}

body.stats-loading-active #year-output {
    opacity: 0;
    visibility: hidden;
}

/* Container for the spinner and loading text */
#stats-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Container for the detailed info */
#stats-loading-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-height: 100%;
    overflow: hidden; /* Prevent scrolling */
}

/* Style for individual info elements */
#stats-info-title {
    font-family: var(--font-family-display);
    color: var(--color-accent-yellow);
    font-size: clamp(1.6rem, 5vmin, 2.8rem); 
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    margin-bottom: 0.25rem;
    line-height: 1.1;
    font-weight: bold;
}

#stats-info-years {
    font-family: var(--font-family-display);
    font-size: clamp(1.1rem, 3.5vmin, 1.8rem);
    color: var(--color-text-muted);
    font-weight: 500;
    min-height: 1.8rem; /* Match font-size to prevent layout shift */
    margin-bottom: 0.75rem;
    opacity: 0.8;
    transition: opacity 0.3s ease-in-out;
}

#stats-info-years .loader {
    display: inline-block;
    vertical-align: middle;
    width: 1.5rem;
    height: 1.5rem;
    border-width: 3px;
    margin: 0 0.5rem;
}

#stats-info-unit {
    font-size: clamp(0.9rem, 3vmin, 1.4rem); /* Responsive font size */
    color: var(--color-text-muted);
    margin-bottom: clamp(1rem, 2vh, 1.5rem); /* Responsive margin */
    font-style: italic;
}

#stats-info-description {
    font-size: clamp(1.2rem, 3.5vmin, 1.6rem); /* Responsive font size */
    color: var(--color-text-primary);
    text-align: left;
    margin-bottom: clamp(1rem, 2vh, 1.5rem); /* Responsive margin */
    line-height: 1.3; /* Slightly tighter line height */
    max-width: 90%;
    max-height: 100%;
    overflow-y: auto;
}

.stats-info-meta {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: clamp(0.5rem, 2vw, 1.5rem); /* Responsive gap */
    font-size: clamp(0.9rem, 3vmin, 1.4rem); /* Responsive font size */
    color: var(--color-text-primary);
    margin-bottom: clamp(1rem, 2vh, 1.5rem); /* Responsive margin */
    padding: 0.75rem;
    border-top: 1px solid var(--border-color-subtle);
    border-bottom: 1px solid var(--border-color-subtle);
    width: 90%;
    text-align: left;
}

.stats-info-meta .meta-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.stats-info-meta strong {
    color: var(--color-text-muted);
    font-weight: 600;
    white-space: nowrap;
}


.stats-info-links {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.stats-info-links a {
    text-decoration: none;
    color: var(--color-text-secondary);
    background-color: rgba(255, 255, 255, 0.1);
    padding: clamp(0.5rem, 1.5vh, 0.8rem) clamp(1rem, 4vw, 2rem); /* Responsive padding */
    border-radius: 1.8rem;
    border: 1px solid var(--border-color-subtle);
    font-weight: 600;
    transition: background-color 0.2s, border-color 0.2s;
    font-size: clamp(1.1rem, 3.5vmin, 1.6rem); /* Responsive font size */
    margin: clamp(0.5rem, 1vh, 1rem); /* Responsive margin */
    box-shadow: 2px 2px 8px 0 #000, -2px -2px 8px 0 #fff7;
}

.stats-info-links a:hover {
    background-color: var(--background-hover-strong);
    border-color: var(--color-accent-blue);
    color: #fff;
}


#quality-toggle-button { display:none; }

@keyframes glow-attention {
    0%, 100% {
        filter: drop-shadow(0 0 3px var(--color-accent-yellow));
    }
    50% {
        filter: drop-shadow(0 0 10px var(--color-accent-yellow));
    }
}

@keyframes pulse-attention {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

.onboarding-focus-animation svg {
    animation: glow-attention 1.5s ease-in-out infinite, pulse-attention 1.5s ease-in-out infinite;
}

#stats-play-pause-button.attention-animation svg {
    animation: glow-attention 2s ease-in-out infinite, pulse-attention 2s ease-in-out infinite;
}

/* NEW: Styles for updated stats modal */
#stats-info-source-container a {
    text-decoration: underline;
    color: var(--color-text-muted);
    transition: color 0.2s ease-in-out;
}
#stats-info-source-container a:hover {
    color: var(--color-accent-blue);
}
#stats-info-source-container .source-description {
    font-size: 0.9em;
    font-style: italic;
    opacity: 0.8;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color-subtle);
    padding-top: 0.5rem;
    display: block; /* Ensure it takes its own line */
    width: 100%;
}


#stats-info-watch-button {
    cursor: pointer;
}

/* --- Pre-Game State (Difficulty Modal) --- */
body.pre-game #top-info-bar {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: 1001; /* Ensure it's above the modal overlay (z-index: 1000) */
}

/* Hide stats and title during pre-game */
body.pre-game #top-info-bar .stats,
body.pre-game #top-info-bar h1,
body.pre-game #top-info-bar #stats-title-container {
    display: none;
}

/* In the controls group, hide everything */
body.pre-game #top-info-bar #main-controls-group {
    display: none;
}

#country-suggestions-dropdown {
    display: flex;
    flex-direction: column-reverse;
    max-height: 90vh;
    margin-bottom: 5rem;
    text-align:center;
    overflow-y: auto;
    background-color: transparent; /* Parent overlay will have the gradient */
    border: none;
    box-shadow: none;
    scrollbar-width: large; /* For Firefox */
    scrollbar-color: rgba(75, 85, 99, 0.7) var(--scrollbar-track-color); /* For Firefox */
}

/* --- NEW: Embed Mode Styles --- */
body.embed-mode.stats-mode #stats-prev-button,
body.embed-mode.stats-mode #stats-next-button {
    display: none !important;
}

body.embed-mode.stats-mode #stats-title-value {
    cursor: default;
}