:root {
    --bg-app: #f0f2f5;
    --bg-card: #ffffff;
    
    --text-primary: #1a1a1b;
    --text-secondary: #565758;
    
    --border-default: #d3d6da;
    --border-active: #878a8c;
    
    --tile-bg: #transparent;
    --radius-l: 16px;
    --radius-m: 8px;
    --radius-s: 4px;
    
    --key-bg: #d3d6da;
    --key-text: #1a1a1b;
    
    --color-correct: #6aaa64;
    --color-present: #c9b458;
    --color-absent: #787c7e;
    --color-white: #ffffff;

    --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
    
    --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* Screen Reader Only - for SEO and accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

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

body {
    font-family: var(--font-primary);
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    width: 100vw;
    margin: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

/* 
   Main Layout Wrapper 
*/
.game-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 500px; 
    height: 100%;
    padding: 1rem;
    padding-top: 2vh; /* Slight top spacing */
}

/* 
   1. Header Section 
   Now sits directly in layout, outside card.
*/
header {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 2vh;
    text-align: center;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    width: 100%;
}

/* Restart Button */
#header-restart-btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border: none;
    box-shadow: none;
}

#header-restart-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
    transform: translateY(-50%) rotate(180deg);
}

#header-restart-btn svg {
    width: 24px;
    height: 24px;
}



/* Brand Link Wrapper */
.brand-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: opacity 0.2s ease;
}

.brand-link:hover {
    opacity: 0.7;
}

/* Updated Game Header Brand Styles */
.brand-game {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    justify-content: center;
}

.brand-text-game {
    font-size: 2.5rem;
    font-weight: 900;
    color: #0F172A; /* Match Landing Page Slate 900 */
    letter-spacing: -0.05em;
    line-height: 1;
}

.badge-game {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%); /* Match Landing Page Blue */
    color: white;
    font-weight: 800;
    font-size: 1.25rem;
    width: 36px; /* Scaled down from 64px */
    height: 36px;
    display: flex; /* Flex to center content like landing badge */
    align-items: center;
    justify-content: center;
    border-radius: 10px; /* Scaled down border radius */
    box-shadow: 0 4px 8px -2px rgba(37, 99, 235, 0.4);
    transform: rotate(6deg) translateY(-2px); /* Match Landing rotation */
}

.subtitle {
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* 
   2. Game Card Section (The Board)
*/
.game-card {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    
    background-color: var(--bg-card);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
    padding: 1.5rem;
    margin-bottom: 2vh;
    position: relative;
    overflow: hidden;
}

#game-board-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(6, 1fr);
    aspect-ratio: 1 / 2;
    height: 100%; 
    max-height: 100%;
    max-width: 100%;
    gap: 1.5vmin;
}

.tile {
    width: 100%;
    height: 100%;
    border: 2px solid var(--border-default);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.5rem, 6vmin, 3rem); 
    font-weight: 700;
    text-transform: uppercase;
    border-radius: var(--radius-m);
    background-color: var(--bg-card);
    color: var(--text-primary);
    user-select: none;
}

.tile[data-state='active'] {
    border-color: var(--text-primary);
    animation: pop 0.1s;
    background-color: #f8f9fa;
}
.tile[data-state='correct'] {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
    color: var(--color-white);
}
.tile[data-state='present'] {
    background-color: var(--color-present);
    border-color: var(--color-present);
    color: var(--color-white);
}
.tile[data-state='absent'] {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
    color: var(--color-white);
}
.tile.flip { animation: flip 0.6s ease; }

/* 
   3. Keyboard Section
*/
#keyboard-container {
    flex: 0 0 auto;
    width: 100%;
    padding-bottom: env(safe-area-inset-bottom);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 0.5vh;
    gap: 1vw;
}

button {
    font-family: inherit;
    font-weight: 600;
    border: 0;
    padding: 0;
    height: clamp(35px, 6.5vh, 60px);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    background-color: var(--key-bg);
    color: var(--key-text);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    font-size: clamp(0.8rem, 2vh, 1.2rem);
    transition: background-color 0.1s;
}

button.wide-btn {
    flex: 1.5;
    font-size: clamp(0.7rem, 1.5vh, 1rem);
}

button[data-state='correct'] { background-color: var(--color-correct) !important; color: white; }
button[data-state='present'] { background-color: var(--color-present) !important; color: white; }
button[data-state='absent'] { background-color: var(--color-absent) !important; color: white; }

/* Toast */
#toast-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 100;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.toast {
    /* Better toast visibility */
    background-color: #333;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    margin-bottom: 10px; /* Space between stacked toasts if we allow them */
}
.toast.show { 
    opacity: 1; 
    transform: translateY(0);
}

.toast.error {
    background-color: #ff4d4d;
    color: white;
    box-shadow: 0 10px 30px rgba(255, 77, 77, 0.4);
}

@keyframes pop { 50% { transform: scale(1.05); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}
.shake { 
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; 
    border-color: #ff4d4d !important; /* Flash red border */
}

@keyframes dance {
    0%, 100% { transform: translateY(0); }
    20% { transform: translateY(-30px); }
    40% { transform: translateY(5px); }
    60% { transform: translateY(-15px); }
    80% { transform: translateY(2px); }
}

.tile.dance {
    animation: dance 0.6s ease-in-out;
}

/* 
   Modal 
*/
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Dimmed background */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(2px);
}

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

.modal-content {
    background-color: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-l);
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 90%;
    width: 320px;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.hidden .modal-content {
    transform: scale(0.8);
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.revealed-word {
    font-size: 3rem;
    font-weight: 800;
    color: #1DA1F2; /* Brand Blue */
    letter-spacing: 0.2rem;
    margin-bottom: 2rem;
    text-transform: uppercase;
}

#restart-btn {
    background-color: #1DA1F2;
    color: white;
    width: 100%;
    padding: 0; /* Reset generic button padding if any */
    height: 50px;
    font-size: 1.1rem;
    border-radius: var(--radius-m);
    box-shadow: 0 4px 12px rgba(29, 161, 242, 0.4);
    transition: transform 0.1s, background-color 0.2s;
}

#restart-btn:hover {
    background-color: #0c85d0;
    transform: translateY(-2px);
}

#restart-btn:active {
    transform: translateY(0);
}


/* 
   EXTREME SHORT SCREEN OPTIMIZATION 
   We keep the logic of Side-by-Side but we adapt the header.
*/
@media (max-height: 500px) {
    .game-layout {
        padding: 0.5rem;
        flex-direction: row; /* Side by side layout */
        flex-wrap: wrap;
        align-items: center;
        max-width: 750px;
    }

    /* 
       In landscape, we put the header top-left or centered above board?
       Let's try a split: Left Side = Header + Board, Right Side = Keyboard.
    */
    
    header {
        position: absolute; /* Take it out of flow to stick it somewhere? No, lets flow it. */
        /* Actually with flex-direction row, header becomes a column item. 
           We need a container for Header+Board to keep them stacked on the left.
        */
        display: none; /* User insisted on "Always on top". 
                          If I hide it, they complain. 
                          If I show it, it eats vertical space.
                          Solution: Overlay or Tiny */
        position: fixed;
        top: 5px;
        left: 50%;
        transform: translateX(-50%);
        margin: 0;
        flex-direction: row;
        gap: 10px;
        background: rgba(240, 242, 245, 0.9);
        padding: 2px 10px;
        padding-right: 5px; /* Adjust padding for button */
        border-radius: 20px;
        z-index: 200;
        width: auto; /* Override global width 100% */
    }

    #header-restart-btn {
        position: static;
        width: 30px;
        height: 30px;
        transform: none;
        margin-left: 5px;
    }

    #header-restart-btn:hover {
        transform: rotate(180deg);
    }
    
    .brand-game { gap: 0.3rem; }
    .brand-text-game { font-size: 1.2rem; }
    .badge-game { width: 20px; height: 20px; font-size: 0.7rem; border-radius: 6px; }
    .subtitle { display: none; }

    .game-card {
        margin-bottom: 0;
        margin-right: 1rem;
        height: 85%; /* Leave room for header */
        margin-top: 20px; /* Space for the fixed header */
        width: auto;
        aspect-ratio: 1/2;
        padding: 0.5rem;
    }

    #keyboard-container {
        width: 50%;
        height: 85%;
        margin-top: 20px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .keyboard-row {
        margin-bottom: 4px;
    }

    button {
        height: 14vh;
    }
}

/* TALL & NARROW (Mobile) */
@media (max-width: 480px) {
    header {
        margin-bottom: 1vh;
    }
    .brand-text-game { font-size: 1.75rem; }
    
    .game-card {
        width: 100%;
        padding: 1rem;
    }
    
    .tile { font-size: 2rem; }
}

/* 
   LANDING PAGE STYLES - REDESIGN 
*/
.landing-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    /* Override global body centering for landing */
    max-width: 100%; 
    background-color: #F8FAFC; 
    font-family: 'Inter', sans-serif;
}

.landing-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    gap: 3rem;
}

/* Header / Brand */
.landing-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.brand-large {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.brand-text {
    font-size: 4.5rem;
    font-weight: 900;
    color: #0F172A; /* Slate 900 */
    letter-spacing: -0.05em;
    line-height: 1;
}

.badge-large {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
    font-weight: 800;
    font-size: 2.5rem;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    box-shadow: 0 10px 20px -5px rgba(37, 99, 235, 0.4);
    transform: rotate(6deg) translateY(-5px);
}

/* Hero Text */
.hero-text-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 600px;
}

.overline {
    font-size: 0.85rem;
    font-weight: 700;
    color: #94A3B8; /* Slate 400 */
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.hero-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #334155; /* Slate 700 */
    line-height: 1.3;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: #64748B; /* Slate 500 */
    font-weight: 500;
    margin-top: 0.5rem;
}

/* Actions */
.actions-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
}

.start-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: #3B82F6; /* Blue 500 */
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    text-decoration: none;
    padding: 1rem 4rem;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    width: auto;
    min-width: 240px;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px -5px rgba(59, 130, 246, 0.5);
    background-color: #2563EB;
}

.start-btn svg {
    margin-left: 5px;
}

.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: white;
    color: #475569; /* Slate 600 */
    border: 1px solid #E2E8F0;
    padding: 0.8rem 2rem;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    width: auto;
    height: auto;
    text-transform: none; /* Override global button uppercase */
}

.secondary-btn:hover {
    background-color: #F8FAFC;
    color: #1E293B;
    border-color: #CBD5E1;
    transform: translateY(-1px);
}

/* Footer */
.landing-footer {
    padding: 2rem;
    padding-bottom: 3rem;
    text-align: center;
    color: #94A3B8; /* Slate 400 */
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    align-items: center;
    width: 100%;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.footer-links a {
    color: #94A3B8;
    text-decoration: none;
    transition: color 0.2s;
    font-weight: 500;
}

.footer-links a:hover {
    color: #64748B;
}

@media (min-width: 640px) {
    .hero-title {
        font-size: 2rem;
    }
}

/* LANDING MODAL STYLES */
.landing-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(4px);
    padding: 1rem;
}

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

.landing-modal-content {
    background-color: white;
    padding: 2.5rem;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: left;
    max-width: 500px;
    width: 100%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.landing-modal-content h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: #0F172A;
    margin-bottom: 1.5rem;
}

.close-modal-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: transparent;
    color: #94A3B8;
    width: auto;
    height: auto;
    padding: 0.5rem;
    border-radius: 50%;
}

.close-modal-btn:hover {
    background-color: #F1F5F9;
    color: #64748B;
}

.instruction-text p {
    color: #475569;
    margin-bottom: 1rem;
    line-height: 1.6;
    font-size: 1.05rem;
}

.instruction-text strong {
    color: #1E293B;
}

.examples-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #E2E8F0;
}

.examples-section h3 {
    font-size: 0.9rem;
    color: #0F172A;
    margin-bottom: 1rem;
    text-transform: uppercase;
    font-weight: 800;
}

.example-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.example-tiles {
    display: flex;
    gap: 0.25rem;
}

.landing-tile {
    width: 40px;
    height: 40px;
    border: 2px solid #E2E8F0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 1.2rem;
    border-radius: 4px;
    color: #0F172A;
}

.landing-tile.correct {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
    color: white;
}

.landing-tile.present {
    background-color: var(--color-present);
    border-color: var(--color-present);
    color: white;
}

.landing-tile.absent {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
    color: white;
}

.example-row p {
    font-size: 0.95rem;
    color: #475569;
    flex: 1;
}

.primary-action-btn {
    width: 100%;
    background-color: #0F172A; /* Slate 900 */
    color: white;
    font-weight: 700;
    padding: 1rem;
    border-radius: 12px;
    margin-top: 1rem;
    font-size: 1.1rem;
    transition: background-color 0.2s;
    height: auto; 
    text-transform: none;
}

.primary-action-btn:hover {
    background-color: #1E293B;
}

/* Footer Link Button */
.footer-link-btn {
    background: none;
    border: none;
    color: #94A3B8;
    font-size: inherit;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    transition: color 0.2s;
    height: auto;
    text-transform: none; /* Reset button uppercase */
    display: inline;
    width: auto;
    border-radius: 0;
}

.footer-link-btn:hover {
    color: #64748B;
    background: none;
    text-decoration: underline;
}

