/* --- Font Definitions --- */
@font-face {
    font-family: 'Kirang Haerang Local';
    src: url('../KirangHaerang-Latin.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

/* --- Design System Variables --- 
 * Defines colors, typography, and layout constants used throughout the app.
 */
:root {
    /* Base Colors: Backgrounds and global text */
    --bg-color: #1a1a1c;
    --text-color: #ffffff;

    /* Keyboard Colors: Unused state */
    --key-bg: #58585a;
    --key-text: #d1d1d3;

    /* Game State Colors: Feedback for correct/present/absent letters */
    --absent: #121213;
    --present: hsl(35, 85%, 55%);
    --correct: hsl(150, 70%, 35%);
    --border: #404042;
    --accent: #6bb1f8;

    /* Theme Overlays: Modal backgrounds for win/loss */
    --win-bg: #1a2e1c;
    --loss-bg: #2e1a1a;
    --loss-red: #e66;
    --error: #a72e2e;
    --tile-toggled: #565758;

    /* Saturated Pastels: Used for animated title letters */
    --pastel-1: hsl(4, 100%, 78%);
    --pastel-2: hsl(24, 100%, 80%);
    --pastel-3: hsl(83, 75%, 78%);
    --pastel-4: hsl(159, 83%, 75%);
    --pastel-5: hsl(231, 73%, 80%);
    --pastel-6: hsl(355, 100%, 75%);
    --pastel-0: hsl(195, 96%, 75%);
    --pastel-7: hsl(298, 88%, 82%);

    /* Fonts */
    --font-main: 'Outfit', sans-serif;
    --font-title: 'Kirang Haerang Local', 'Kirang Haerang', cursive;

    /* Global Sizing */
    --max-main-width: 500px;
    --header-height: 48px; /* Reverted to original slim thickness */
    --transition-speed: 0.2s;
}

/* --- Global Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

/* Ensure the background canvas always fills the full viewport */
#bg-canvas {
    width: 100vw;
    height: 100vh;
    display: block;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#bg-canvas.ready {
    opacity: 1;
}

/* --- Particle Effects --- */
.particle {
    position: fixed;
    pointer-events: none;
    z-index: 11000;
    width: 12px;
    height: 12px;
    background-color: var(--correct);
    border-radius: 50%;
    animation: particle-burst 1.2s cubic-bezier(0, 0, 0.2, 1) forwards;
}

.particle.sparkle {
    background-color: white;
    box-shadow: 0 0 8px white;
}

@keyframes particle-burst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* --- Splash Screen --- */
.splash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Allow scrolling from the top */
    overflow-y: auto;        /* Enable scrolling */
    transition: opacity 0.5s ease, visibility 0.5s;
}

.splash-overlay.hidden {
    display: none;
}

/* Hide game elements while splash is visible so they don't bleed through */
#splash-screen:not(.hidden) ~ header,
#splash-screen:not(.hidden) ~ #boards-nav-container,
#splash-screen:not(.hidden) ~ main#game-container {
    visibility: hidden;
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 400px;
    padding: 40px 24px 60px;
    gap: 0px;
    min-height: min-content;
}

.result-title {
    font-family: var(--font-title);
    font-size: clamp(1.8rem, 12vw, 4rem); /* Responsive size (narrower minimum) */
    margin-bottom: 8px;
    letter-spacing: 2px;
    white-space: nowrap; /* Prevent wrapping */
}

.splash-title {
    font-family: var(--font-title);
    font-size: clamp(3.5rem, 19vw, 9rem); /* Larger responsive size for mobile */
    font-weight: normal;
    letter-spacing: 2px;
    margin-bottom: -15px;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    gap: 4px;
    white-space: nowrap; /* Ensure title stays on one line */
}

.animated-letter {
    display: inline-block;
    animation: title-float 3s ease-in-out infinite;
    text-shadow:
        0 2px 6px rgba(0,0,0,0.9),
        0 0 20px rgba(0,0,0,0.7),
        0 0 40px rgba(0,0,0,0.5);
}

/* Pastel Colors */
/* Pastel Colors Mapping */
.animated-letter:nth-child(7n+1) {
    color: var(--pastel-1);
}

.animated-letter:nth-child(7n+2) {
    color: var(--pastel-2);
}

.animated-letter:nth-child(7n+3) {
    color: var(--pastel-3);
}

.animated-letter:nth-child(7n+4) {
    color: var(--pastel-4);
}

.animated-letter:nth-child(7n+5) {
    color: var(--pastel-5);
}

.animated-letter:nth-child(7n+6) {
    color: var(--pastel-6);
}

.animated-letter:nth-child(7n+0) {
    color: var(--pastel-0);
}

@keyframes title-float {

    0%,
    100% {
        transform: translateY(0) rotate(0deg) scale(1);
    }

    33% {
        transform: translateY(-3px) rotate(-1.5deg) scale(1.03);
    }

    66% {
        transform: translateY(2px) rotate(1.5deg) scale(0.97);
    }
}

.no-animation {
    animation: none !important;
    transform: none !important;
}

.splash-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, 2vw, 10px);
    margin-top: 0px;
    margin-bottom: 2px;
    width: 100%;
    flex-wrap: wrap;
    line-height: 1;
}

.splash-meta-separator {
    color: var(--pastel-4);
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    opacity: 0.7;
    user-select: none;
    line-height: 1;
    display: inline-block;
    transform: translateY(1.5px);
}

.splash-number {
    font-size: clamp(1.2rem, 4.5vw, 1.6rem) !important;
    font-family: var(--font-title);
    color: var(--text-color);
    letter-spacing: 1.5px;
    margin-bottom: 0px;
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    gap: 2px;
    line-height: 1;
}

.splash-date {
    font-size: clamp(1.1rem, 4vw, 1.45rem) !important;
    font-family: var(--font-title) !important;
    letter-spacing: 1.5px;
    color: var(--key-text) !important;
    margin-bottom: 0px !important;
    text-transform: uppercase;
    text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 0 20px rgba(0,0,0,0.7);
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    gap: 2px;
    line-height: 1;
}

/* User Welcome Message / CTA */
.splash-user-msg {
    font-family: var(--font-title) !important;
    font-size: clamp(1.1rem, 4.5vw, 1.5rem) !important;
    letter-spacing: 1px;
    color: var(--text-color);
    margin-top: 2px;
    margin-bottom: 12px;
    line-height: 1.15;
    width: 100%;
    max-width: 340px;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    font-weight: normal;
    text-transform: uppercase;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2px;
    box-sizing: border-box;
}

.splash-user-msg.cta {
    cursor: pointer;
    transition: all 0.2s ease;
}

.splash-user-msg.cta:hover {
    transform: scale(1.03);
    opacity: 0.95;
}

.play-btn {
    background-color: var(--correct);
    color: white;
    border: none;
    padding: 10px 40px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    width: 100%;
    max-width: 280px;
    position: relative;
    z-index: 1;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.7);
}

#splash-settings-btn {
    background-color: var(--pastel-5);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.7);
}

#splash-settings-btn:hover {
    background-color: #c9a9f2;
    z-index: 5;
}

.play-btn:hover {
    transform: translateY(-3px);
    z-index: 5;
    background-color: #75a877;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.7), 0 8px 16px rgba(0, 0, 0, 0.8);
}

.play-btn.disabled {
    background-color: #3a3a3e;
    color: #909092;
    cursor: default;
    pointer-events: none;
    opacity: 1;
    z-index: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 3px 6px rgba(0, 0, 0, 0.6);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--key-text);
    padding: 10px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    text-transform: uppercase;
    font-family: var(--font-main);
    letter-spacing: 1px;
    margin-top: 10px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 0 15px rgba(0,0,0,0.7);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.secondary-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
}

.play-btn:active {
    transform: translateY(-1px) scale(0.97);
    z-index: 2;
    background-color: #5a8a5b;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6), 0 3px 6px rgba(0, 0, 0, 0.7);
}

.splash-footer {
    font-size: 0.8rem;
    color: var(--key-text);
    letter-spacing: 1px;
    opacity: 0.7;
    margin-top: 10px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 0 15px rgba(0,0,0,0.7);
}

/* Disable text-shadow on sub-header individual animated letters to prevent character-to-character shadow bleeding (leaving the main HARDLE16 title shadow intact) */
#splash-screen .splash-number .animated-letter,
#splash-screen .splash-date .animated-letter,
#splash-screen .splash-user-msg .animated-letter,
#results-overlay .splash-user-msg .animated-letter,
#auth-success-title .animated-letter {
    text-shadow: none !important;
}

/* Apply drop-shadow filters on the parent word wrappers so shadows render as a single composite backing layer strictly behind all letters */
#splash-screen .splash-number > span,
#splash-screen .splash-date > span,
#splash-screen .splash-user-msg > span,
#results-overlay .splash-user-msg > span,
#auth-success-title > span {
    filter: 
        drop-shadow(0 2px 4px rgba(0, 0, 0, 0.75)) 
        drop-shadow(0 4px 10px rgba(0, 0, 0, 0.75)) 
        drop-shadow(0 0 12px rgba(0, 0, 0, 0.75)) !important;
}

/* For static elements without animated letter children, apply standard clean backing blurs directly */
#splash-screen .splash-meta-separator,
#splash-screen .next-game-timer,
#splash-screen .next-game-timer .timer-display,
#splash-screen .splash-footer {
    text-shadow: 
        0 2px 4px #000, 
        0 4px 12px #000, 
        0 0 20px #000 !important;
}

#splash-screen .next-game-timer {
    opacity: 1 !important;
}

#splash-screen .splash-footer {
    opacity: 0.95 !important;
}


#splash-logout-btn {
    background-color: rgba(167, 46, 46, 0.7);
    border: 1px solid rgba(255, 100, 100, 0.35);
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.7);
}

#splash-logout-btn:hover {
    background-color: rgba(167, 46, 46, 0.85);
    z-index: 5;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.7), 0 8px 16px rgba(0, 0, 0, 0.8);
}

#guest-login-btn {
    background-color: var(--loss-red) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.7) !important;
    transition: all 0.2s ease !important;
}

#guest-login-btn:hover {
    background-color: #ff7777 !important;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.7), 0 8px 16px rgba(0, 0, 0, 0.8) !important;
}

.help-text {
    color: var(--text-color);
    margin-bottom: 12px;
    line-height: 1.6;
    opacity: 0.9;
    font-size: 0.9rem;
    text-align: center;
    width: 100%;
    text-shadow: 0 2px 6px rgba(0,0,0,0.9);
}

.help-examples {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 280px;
    margin: 4px auto;
}

.help-example-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.help-tile {
    width: 36px;
    height: 36px;
    border: 2px solid;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: uppercase;
    color: white;
    flex-shrink: 0;
    text-shadow: none;
}

.help-tile-label {
    font-size: 0.85rem;
    color: var(--text-color);
    text-shadow: 0 2px 6px rgba(0,0,0,0.9);
    text-align: left;
}

@media (max-width: 480px) {
    #boards-nav-container {
        padding: 2px 4px 0 4px;
    }

    .splash-title {
        margin-bottom: -10px;
        line-height: 1;
    }

    .splash-content {
        padding: 24px 16px 32px !important;
    }

    .splash-meta {
        margin-top: 0px !important;
        margin-bottom: 2px !important;
        gap: 6px !important;
    }

    .splash-number {
        font-size: 1.15rem !important;
        margin-bottom: 0 !important;
    }

    .splash-meta-separator {
        transform: translateY(1px) !important;
    }

    .splash-date {
        font-size: 1.05rem !important;
        margin-bottom: 0 !important;
        transform: none !important;
    }

    .splash-user-msg {
        margin-top: 2px !important;
        margin-bottom: 8px !important;
        max-width: 290px !important;
        font-size: 1.05rem !important;
    }

    #help-overlay .splash-date {
        margin-bottom: 15px;
    }

    .help-text {
        font-size: 0.75rem;
        line-height: 1.4;
        margin-bottom: 15px;
    }
    
    #help-overlay .splash-title {
        font-size: clamp(1.5rem, 7vw, 2.5rem);
        margin-bottom: -5px;
    }
}



/* Help title should never be as large as the main game title */
#help-overlay .splash-title {
    font-size: clamp(1.8rem, 6vw, 3rem);
}

body {
    background: #000;
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overflow-x: hidden;
    transition: background-color 0.5s ease;
}

/* Dark overlay that sits between the canvas and the game UI for readability */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: -50;
    pointer-events: none;
}

/* Hide overlay when splash is showing so canvas pops at full brightness */
body:has(#splash-screen:not(.hidden))::before {
    background: transparent;
}

body.win-theme {
    background-color: var(--win-bg);
}

body.loss-theme {
    background-color: var(--loss-bg);
}

/* Force pure black background and hide the background engine canvas completely */
body.pure-black {
    background-color: #000000 !important;
    background: #000000 !important;
}

body.pure-black #bg-canvas {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* --- Header Component --- */
header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.header-content {
    width: 100%;
    max-width: 480px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
    height: 100%;
}

header .title-group h1 {
    font-family: var(--font-title);
    font-size: 34px;
    font-weight: normal;
    letter-spacing: 1px;
    white-space: nowrap;
    margin: 0;
    text-transform: uppercase;
    display: flex;
    gap: 3px;
    line-height: 1;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.9)) drop-shadow(0 0 20px rgba(0,0,0,0.7));
}

.title-group {
    display: flex;
    flex-direction: row; /* Side-by-side */
    align-items: baseline; /* Aligned along the bottom of the text */
    justify-content: flex-start;
    gap: 12px;
    line-height: 1;
}

.header-number {
    font-size: 14px;
    font-family: var(--font-title);
    letter-spacing: 1px;
    color: var(--text-color);
    opacity: 1;
    white-space: nowrap;
    text-shadow: none !important;
}

.header-number .animated-letter {
    text-shadow: none !important;
}

.header-number > span {
    filter: 
        drop-shadow(0 2px 4px #000) 
        drop-shadow(0 4px 10px #000) 
        drop-shadow(0 0 12px #000) !important;
}

.help-number {
    font-size: 1.5rem;
    font-family: var(--font-title);
    color: var(--text-color);
    letter-spacing: 1.5px;
    margin-bottom: 0px;
    display: flex;
    justify-content: center;
    gap: 2px;
}

.next-game-timer {
    font-size: 0.85rem;
    color: var(--key-text);
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    opacity: 0.9;
    text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 0 15px rgba(0,0,0,0.7);
}


.next-game-timer .timer-display {
    font-weight: 700;
    color: var(--text-color);
    font-family: monospace;
    font-size: 1.1rem;
}

#help-overlay .next-game-timer {
    margin-top: 10px;
    margin-bottom: 20px;
}

.header-right {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: 
        drop-shadow(0 2px 4px #000) 
        drop-shadow(0 4px 10px #000) 
        drop-shadow(0 0 12px #000)
        drop-shadow(0 0 20px #000)
        drop-shadow(0 0 28px #000) !important;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    display: block;
    transition: all 0.2s ease;
}

.icon-btn:hover svg {
    filter: drop-shadow(0 0 4px var(--pastel-0));
}

/* --- Navigation Component --- */
#boards-nav-container {
    position: sticky;
    top: var(--header-height);
    background: transparent;
    z-index: 10;
    border-top: none;
    border-bottom: none;
    padding: 4px 4px 0 4px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: var(--max-main-width);
    margin: 0 auto;
    margin-bottom: -1px;
}

#boards-nav {
    display: flex;
    gap: 4px;
    justify-content: space-between;
    flex: 1;
}

#guess-counter {
    background: #444446;
    color: #ffffff;
    padding: 0 12px;
    border-radius: 6px 6px 0 0;
    font-weight: 700;
    font-size: 14px;
    border: 2px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-pair {
    display: flex;
    background: #444446;
    padding: 1px;
    border-radius: 6px 6px 0 0;
    gap: 1.5px;
    border: 2px solid transparent;
    flex: 1;
    min-width: 0;
    height: 36px;
    align-items: center;
    transition: all 0.2s;
}

.nav-pair.active {
    border-color: #6bb1f8;
}

.nav-pair.active .nav-btn {
    color: white;
}

.nav-btn {
    background: transparent;
    color: var(--key-text);
    border: none;
    border-radius: 2px;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 0;
}

.nav-btn[data-solved="true"] {
    background: var(--correct);
    color: white;
}

/* --- Game Board Component --- */
main#game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    max-width: var(--max-main-width);
    margin: 0 auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: rgba(0, 0, 0, 0.5);
}

main#game-container::-webkit-scrollbar {
    display: none;
}

#boards-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 12px;
    padding: 16px 8px;
    width: 100%;
    position: relative;
}

#boards-container::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    background-color: #ffbd8e;
    opacity: 0.6;
    transform: translateX(-50%);
    pointer-events: none;
    border-radius: 1px;
}

.grid {
    display: grid;
    grid-template-rows: repeat(21, 1fr);
    grid-gap: 4px;
    width: 100%;
    min-width: 0;
    scroll-margin-top: 130px;
}

.board-label {
    text-align: center;
    font-weight: normal;
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-color);
    font-family: var(--font-title);
    display: flex;
    justify-content: center;
    gap: 2px;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.9)) drop-shadow(0 0 15px rgba(0,0,0,0.7));
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-gap: 3px;
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    border: 1.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    transition: transform 0.1s ease;
    user-select: none;
    background-color: rgba(0, 0, 0, 0.75);
}

.tile[data-state="toggled"] {
    border-color: var(--tile-toggled);
}

.tile[data-state="correct"] {
    background-color: var(--correct);
    border-color: var(--correct);
}

.tile[data-state="present"] {
    background-color: var(--present);
    border-color: var(--present);
}

.tile[data-state="absent"] {
    background-color: var(--absent);
    border-color: var(--absent);
}

.tile[data-state="invalid"] {
    background-color: var(--error);
    border-color: var(--error);
}

/* --- Keyboard Component --- */
#keyboard-container {
    position: sticky;
    bottom: 0;
    background: var(--bg-color);
    padding: 8px 4px;
    border-top: 1px solid var(--border);
    z-index: 10;
    width: 100%;
}

#keyboard {
    width: 100%;
    max-width: var(--max-main-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.key-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    touch-action: manipulation;
}

.key {
    background-color: var(--key-bg);
    color: var(--key-text);
    border: none;
    border-radius: 4px;
    height: 52px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    transition: opacity 0.1s, background 0.3s;
}

.key:active {
    opacity: 0.6;
}

.key.large {
    flex: 1.5;
    font-size: 12px;
}

.key[data-state="used"] {
    background-color: #464648;
    color: #000000;
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.5);
    border-color: rgba(0, 0, 0, 0.2);
}

/* --- Modals --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11000;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    width: 95%;
    max-width: 420px;
    padding: 30px;
    border-radius: 16px;
    border: 2px solid var(--pastel-4);
    position: relative;
    text-align: center;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: hidden; /* Lock the outer box so the top-right X button stays persistent */
    display: flex;
    flex-direction: column;
}

.close-x-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--pastel-4); /* Matches the border custom mint color! */
    font-size: 32px;
    font-weight: normal;
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s ease, color 0.2s ease;
    line-height: 0.8;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.close-x-btn:hover {
    transform: scale(1.15);
    color: var(--pastel-3); /* Light pastel green on hover for glow effect */
}

.modal-scroll-area {
    width: 100%;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
}

.modal-scroll-area::-webkit-scrollbar {
    width: 6px;
}

.modal-scroll-area::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

.modal .splash-title {
    font-size: clamp(1.8rem, 8vw, 2.8rem) !important;
    margin-top: 0 !important;
    margin-bottom: 20px !important;
    line-height: 1 !important;
    display: flex !important;
    justify-content: center !important;
    gap: 4px !important;
    font-family: var(--font-title) !important;
    font-weight: normal !important;
    letter-spacing: 2px !important;
    white-space: nowrap !important;
}

.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

.primary-btn {
    background-color: var(--correct);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.primary-btn:hover {
    background-color: #75a877;
    transform: translateY(-1px);
}

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

.debug-content {
    max-height: 80vh;
    overflow-y: auto;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.close-btn:hover {
    opacity: 1;
}

/* --- Results Overlay --- */
.results-content {
    max-width: 420px;
    width: 95%;
    padding: 15px; /* Extremely tight padding */
    text-align: center;
}

#stats-container .grid {
    gap: 1.25rem 0.5rem; /* Slightly tighter gap */
}

.result-title {
    font-size: 4rem;
    font-family: var(--font-title);
    margin-bottom: 5px;
    letter-spacing: -2px;
    display: flex;
    justify-content: center;
}

.result-subtitle {
    display: flex;
    justify-content: center;
    gap: 2px;
    font-weight: 600;
}


.win-theme .secondary-btn {
    border-color: var(--correct);
    color: var(--correct);
}

.win-theme .secondary-btn:hover {
    background: rgba(100, 152, 102, 0.1);
    border-color: var(--correct);
}

.loss-theme .result-title {
    color: var(--loss-red);
}

.loss-theme .result-subtitle,
.loss-theme .next-game-timer,
.loss-theme .next-game-timer .timer-display {
    color: var(--loss-red);
}

.loss-theme .secondary-btn {
    border-color: var(--loss-red);
    color: var(--loss-red);
}

.loss-theme .secondary-btn:hover {
    background: rgba(238, 102, 102, 0.1);
    /* Keep semi-transparent for now */
    border-color: var(--loss-red);
}

.result-subtitle {
    font-size: 1.1rem;
    color: var(--key-text);
    margin-bottom: 5px; /* Reduced from 30px */
    font-weight: 500;
}

.debug-controls {
    display: flex;
    gap: 8px;
}

.debug-btn-accent {
    background: var(--accent) !important;
    color: white !important;
    flex: 1;
    font-size: 11px !important;
}

.debug-btn-correct {
    background: var(--correct) !important;
    color: white !important;
    flex: 1;
    font-size: 11px !important;
}

.debug-btn-error {
    background: var(--error) !important;
    color: white !important;
    width: 100%;
    margin-top: 10px;
}

#back-to-title-btn {
    margin-top: 15px !important; /* Reduced from 30px */
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: #818384;
    font-size: 24px;
    cursor: pointer;
}

/* Removed .stats-container class - using #stats-container ID */

.stat-val {
    display: block;
    font-size: 28px;
    font-weight: 500;
}

.stat-label {
    font-size: 12px;
}

/* Removed typo selector .stat-labelh1 */

.footer {
    margin-top: 30px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

#timer {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 10px;
}

#toast-container {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 30000;
}

.toast {
    background: #ffffff;
    color: #000000;
    padding: 10px 16px;
    border-radius: 4px;
    font-weight: 700;
    animation: fadeInOut 2s ease-in-out forwards;
}

/* --- Animations --- */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    75% {
        transform: translateX(3px);
    }
}

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

    50% {
        transform: scale(1.05);
    }

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


@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translateY(-20px);
    }

    10% {
        opacity: 1;
        transform: translateY(0);
    }

    90% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-20px);
    }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

.reveal {
    animation: reveal 0.2s ease-in-out forwards;
}

/* --- Responsive Adjustments --- */
@media (max-width: 400px) {
    .tile {
        font-size: 1rem;
    }

    header .title-group h1 {
        font-size: 28px;
    }

    .header-number {
        font-size: 11px;
    }

    .header-number {
        font-size: 12px; /* Decreased from 14px */
    }

    .title-group {
        gap: 8px;
    }

    .key {
        height: 48px;
        font-size: 16px;
    }

    .key.large {
        font-size: 11px;
    }

    #boards-container {
        grid-gap: 8px;
        padding: 12px 6px;
    }

    #boards-nav-container {
        padding: 2px 4px 0 4px;
    }

    .nav-btn {
        font-size: 10px;
    }
}



/* Aggressive Statistics Panel Compaction for Mobile */
/* Aggressive Statistics Panel Height Fix for Mobile */
@media screen and (max-width: 600px), screen and (max-height: 800px) {
    .results-content {
        padding: 15px 15px 10px !important;
        max-height: 95vh !important;
        max-height: 95dvh !important; /* Use dvh to avoid nav bar */
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
    }
    .result-title {
        font-size: 2.2rem !important; /* Shrink a tiny bit more */
        margin-top: 0;
        margin-bottom: 2px !important;
    }
    .result-subtitle {
        font-size: 1rem !important; /* Shrink a tiny bit more */
        margin-bottom: 2px !important;
    }
    .next-game-timer {
        font-size: 0.8rem !important; /* Shrink a tiny bit more */
        margin-bottom: 5px !important;
    }
    #stats-container {
        /* Removed padding to minimize gaps, let Tailwind p-4 handle it */
        margin: 0 !important;
        border-radius: 12px !important;
        height: auto !important; /* DONT STRETCH */
        min-height: 0 !important; /* DONT STRETCH */
        flex: 0 0 auto !important; /* DON'T SHRINK OR GROW */
    }
    #stats-grid {
        gap: 0.75rem 0.5rem !important; /* Tighter gap */
    }
    #stats-grid .text-2xl {
        font-size: 1.25rem !important; /* Restoring size */
    }
    #stats-grid .text-\[10px\] {
        font-size: 9px !important; /* Restoring size */
    }
    #back-to-title-btn {
        margin-top: 10px !important;
        padding: 10px !important;
    }
}

/* --- Social & Leaderboard Styles --- */
.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

#stats-tab-bar button {
    outline: none;
}

#friends-leaderboard-body td,
#global-leaderboard-body td {
    padding-left: 2px;
    padding-right: 2px;
}

#friends-leaderboard-body tr:last-child,
#global-leaderboard-body tr:last-child {
    border-bottom: none;
}

#friends-list-container,
#global-list-container {
    mask-image: linear-gradient(to bottom, black 90%, transparent 100%);
}

#profile-section {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

#profile-section:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
}

[data-sort] {
    transition: color 0.2s;
    user-select: none;
}

[data-sort]:active {
    opacity: 0.7;
}

/* Auth Form Username Field Animation */
#username-field {
    animation: slideDown 0.3s ease-out forwards;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Premium Mobile Styling for Auth Modal */
@media screen and (max-width: 480px), screen and (max-height: 800px) {
    .modal-content.auth-content {
        padding: 18px 18px 12px 18px !important;
        max-height: 96vh !important;
        max-height: 96dvh !important;
        border-radius: 12px !important;
    }
    
    .modal-content.auth-content .close-x-btn {
        top: 10px !important;
        right: 10px !important;
        font-size: 26px !important;
        width: 24px !important;
        height: 24px !important;
    }
    
    #auth-title-container {
        margin-bottom: 8px !important;
    }
    
    .modal-content.auth-content .splash-title {
        font-size: clamp(1.4rem, 6vw, 1.8rem) !important;
        margin-bottom: 4px !important;
    }
    
    .modal-content.auth-content .modal-scroll-area {
        padding-top: 0 !important;
    }
    
    /* Compact the form and inputs */
    .modal-content.auth-content input {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
        font-size: 0.8rem !important;
        border-radius: 8px !important;
    }
    
    /* Social Buttons Side-by-Side */
    .modal-content.auth-content #auth-google-btn,
    .modal-content.auth-content #auth-facebook-btn {
        padding-top: 9px !important;
        padding-bottom: 9px !important;
        font-size: 0.7rem !important;
        letter-spacing: 0.05em !important;
        border-radius: 8px !important;
        gap: 6px !important;
    }
    
    .modal-content.auth-content #auth-google-btn svg,
    .modal-content.auth-content #auth-facebook-btn svg {
        width: 14px !important;
        height: 14px !important;
    }

    /* OR divider margins */
    .modal-content.auth-content .my-3 {
        margin-top: 6px !important;
        margin-bottom: 6px !important;
    }

    /* Form gap spacing */
    .modal-content.auth-content .space-y-3 > :not([hidden]) ~ :not([hidden]) {
        --tw-space-y-reverse: 0;
        margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse))) !important;
        margin-bottom: calc(0.5rem * var(--tw-space-y-reverse)) !important;
    }

    /* Submit Button spacing and sizing */
    #auth-submit-btn {
        padding-top: 9px !important;
        padding-bottom: 9px !important;
        margin-top: 8px !important;
        font-size: 0.75rem !important;
        border-radius: 8px !important;
    }

    /* Bottom toggle container */
    #auth-toggle-text {
        padding-top: 10px !important;
        padding-bottom: 10px !important;
        margin-top: 8px !important;
        font-size: 0.75rem !important;
        border-radius: 8px !important;
    }
    
    /* Forgot password placement */
    #forgot-password-link {
        font-size: 10px !important;
    }

    /* Mobile scaling for welcome back & signup modals */
    #auth-success-subtitle {
        font-size: clamp(0.8rem, 3.5vw, 1.05rem) !important;
        margin-top: 10px !important;
        margin-bottom: 4px !important;
    }
    
    #auth-success-title {
        font-size: clamp(1.4rem, 6.5vw, 2.2rem) !important;
        margin-bottom: 12px !important;
        gap: 2px !important;
    }
}

/* Brighter and larger welcome back title and stats styling */
#auth-success-subtitle {
    font-size: clamp(0.95rem, 4vw, 1.3rem) !important;
    line-height: 1.2 !important;
    margin-top: 15px !important;
    margin-bottom: 6px !important;
    width: 100% !important;
    max-width: none !important;
    display: flex !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    gap: 3px !important;
    letter-spacing: 2px !important;
}

#auth-success-title {
    font-size: clamp(1.8rem, 8vw, 3rem) !important;
    line-height: 1.05 !important;
    margin-top: 0 !important;
    margin-bottom: 16px !important;
    width: 100% !important;
    max-width: none !important;
    display: flex !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

/* Expanded Full Width Stats Card */
#auth-success-stats {
    max-width: none !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 16px 20px !important;
    margin-top: 15px !important;
    margin-bottom: 15px !important;
}

#auth-success-stats .flex {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: wrap !important; /* Allow wrapping to next line if needed */
    gap: 4px 12px !important; /* 4px vertical gap if wrapped, 12px horizontal */
    padding: 6px 0 !important;
}

#auth-success-stats span {
    font-size: clamp(13px, 4vw, 16px) !important;
}

#auth-success-stats .flex span:first-child {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

#auth-success-stats .flex span:last-child {
    text-align: right !important;
    white-space: nowrap !important; /* Keep value unit (name + score) unbroken */
    margin-left: auto !important; /* Pushes to the right on both single line and wrapped line */
    flex-shrink: 0 !important; /* Don't shrink the value, let it wrap instead! */
}