@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700&display=swap');

:root {
    /* Canadian Theme Colors */
    --color-red: #D52B1E; /* Official Canadian Flag Red */
    --color-white: #ffffff;
    
    /* State Colors */
    --color-correct: var(--color-red);
    --color-present: #f59e0b; /* Amber */
    --color-absent: #787c7e; /* Gray */
    
    /* UI Colors */
    --color-bg: #fcfcfc;
    --color-text: #111111;
    --color-tile-border: #d3d6da;
    --color-tile-fill: #ffffff;
    
    --keyboard-bg: #e2e8f0;
    --keyboard-hover: #cbd5e1;
    --keyboard-active: #94a3b8;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    background-color: var(--color-bg);
    background-image: 
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 480'%3E%3Cdefs%3E%3ClinearGradient id='grad' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' stop-color='%23D52B1E'/%3E%3Cstop offset='100%25' stop-color='%23ffffff'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath fill='url(%23grad)' d='M201 232l-13.3 4.4 61.4 54c4.7 13.7-1.6 17.8-5.6 25l66.6-8.4-1.6 67 13.9-.3-3.1-66.6 66.7 8c-4.1-8.7-7.8-13.3-4-27.2l61.3-51-10.7-4c-8.8-6.8 3.8-32.6 5.6-48.9 0 0-35.7 12.3-38 5.8l-9.2-17.5-32.6 35.8c-3.5.9-5-.5-5.9-3.5l15-74.8-23.8 13.4q-3.2 1.3-5.2-2.2l-23-46-23.6 47.8q-2.8 2.5-5 .7L264 130.8l13.7 74.1c-1.1 3-3.7 3.8-6.7 2.2l-31.2-35.3c-4 6.5-6.8 17.1-12.2 19.5s-23.5-4.5-35.6-7c4.2 14.8 17 39.6 9 47.7' opacity='0.25'/%3E%3C/svg%3E"),
        radial-gradient(circle at 100% 0%, rgba(213, 43, 30, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 0% 100%, rgba(213, 43, 30, 0.05) 0%, transparent 40%);
    background-repeat: no-repeat, no-repeat, no-repeat;
    background-position: center center, top right, bottom left;
    background-size: 85vmin auto, 100% 100%, 100% 100%;
    background-attachment: fixed;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    color: var(--color-text);
    overflow-x: hidden;
    overflow-y: auto;
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    height: 65px;
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 3px solid var(--color-red);
    box-shadow: 0 2px 10px rgba(255, 0, 0, 0.1);
    z-index: 10;
}

.header-logo {
    height: 62px;
    width: auto;
    filter: drop-shadow(0 2px 4px rgba(213, 43, 30, 0.3));
}

h1 {
    margin: 0;
    font-size: 2.2rem;
    letter-spacing: 0.2rem;
    font-weight: 700;
    color: var(--color-red);
    text-transform: uppercase;
}

/* Wrapper to perfectly center the board */
.game-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
    align-items: center;
    justify-content: center;
}

.welcome-text {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-red);
    margin-bottom: 20px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    text-shadow: 0 2px 4px rgba(255, 255, 255, 0.8);
}

#game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 10px;
    box-sizing: border-box;
    width: 100%;
    max-width: 350px;
    max-height: 420px;
}

.tile {
    border: 2px solid var(--color-tile-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    font-weight: 700;
    text-transform: uppercase;
    background-color: var(--color-tile-fill);
    user-select: none;
    box-sizing: border-box;
    border-radius: 4px;
    color: var(--color-text);
    transition: transform 0.1s, border-color 0.2s;
    aspect-ratio: 1;
    width: 100%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.tile.filled {
    border-color: #878a8c;
}

.pop {
    animation: pop 150ms ease-in-out;
}

/* Keyboard Styles */
#keyboard {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 10px;
    padding: 0 8px;
    user-select: none;
    padding-bottom: env(safe-area-inset-bottom, 10px);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 8px;
    touch-action: manipulation;
}

.key {
    font-family: inherit;
    font-weight: 600;
    border: none;
    padding: 0;
    margin: 0 2px;
    height: 58px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    background-color: var(--keyboard-bg);
    color: var(--color-text);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    font-size: 1.1rem;
    transition: background-color 0.2s, transform 0.1s;
}

.key:hover {
    background-color: var(--keyboard-hover);
}

.key:active {
    background-color: var(--keyboard-active);
    transform: translateY(2px);
}

.key.large {
    flex: 1.5;
    font-size: 0.9rem;
}

/* History Info Box */
.game-history-info {
    margin-top: 20px;
    padding: 15px 20px;
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px dashed var(--color-tile-border);
    border-radius: 8px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
}

.game-history-info h4 {
    margin: 0 0 8px 0;
    color: var(--color-red);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.game-history-info p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--color-text);
    line-height: 1.5;
}

/* Toast Notifications */
#toast-container {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 1000;
}

.toast {
    background: var(--color-text);
    color: var(--color-white);
    padding: 12px 24px;
    border-radius: 4px;
    font-weight: 600;
    margin-bottom: 10px;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

/* Modal Styles */
#modal-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.hidden {
    display: none !important;
}

.modal-content {
    background: var(--color-white);
    border: 3px solid var(--color-red);
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    max-width: 85%;
    width: 350px;
    box-shadow: 0 10px 30px rgba(255, 0, 0, 0.15);
    animation: scaleIn 0.3s ease-out;
    color: var(--color-text);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 2.5rem;
    color: var(--color-red);
}

#modal-word {
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: 0.2rem;
    color: var(--color-text);
    margin: 10px 0;
}

#modal-fact {
    color: #475569;
    line-height: 1.6;
    margin-bottom: 25px;
}

.modal-content button {
    background: var(--color-red);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1.2rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.modal-content button:hover {
    background-color: #cc0000;
    transform: translateY(-2px);
}

.modal-content button:active {
    transform: translateY(1px);
}

/* State Colors */
.tile.correct, .key.correct {
    background-color: var(--color-correct) !important;
    color: white !important;
    border-color: var(--color-correct) !important;
}

.tile.present, .key.present {
    background-color: var(--color-present) !important;
    color: white !important;
    border-color: var(--color-present) !important;
}

.tile.absent, .key.absent {
    background-color: var(--color-absent) !important;
    color: white !important;
    border-color: var(--color-absent) !important;
}

/* Animations */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes shake {
    10%, 90% { transform: translateX(-5px); }
    20%, 80% { transform: translateX(5px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}

.shake {
    animation: shake 400ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

.flip {
    animation: flip 600ms ease-in-out;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Footer Styles */
footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 0, 0, 0.1);
    width: 100%;
    margin-top: auto;
    z-index: 10;
}

.sponsors-title {
    font-size: 0.8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.sponsors-logos {
    display: flex;
    gap: 24px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.sponsor {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 9px;
    opacity: 0.82;
    transition: opacity 0.2s, color 0.2s, transform 0.2s;
}

.sponsor:hover {
    opacity: 1;
    color: var(--color-red);
    transform: translateY(-2px);
}

.sponsor-icon {
    display: block;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
}

.footer-copy {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Layout for Sidebar */
.main-layout {
    display: flex;
    flex-grow: 1;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    gap: 30px;
    padding: 20px;
    box-sizing: border-box;
    align-items: flex-start;
}

.live-leaderboard {
    flex: 1;
    min-width: 280px;
    max-width: 350px;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(213, 43, 30, 0.2);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    max-height: 550px;
}

/* Join Section */
#join-section {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

#nickname-input {
    flex-grow: 1;
    padding: 10px;
    border: 2px solid var(--color-tile-border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
    box-sizing: border-box;
}

#nickname-input:focus {
    border-color: var(--color-red);
}

#join-btn {
    background-color: var(--color-text);
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 6px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

#join-btn:hover {
    background-color: #333;
    transform: translateY(-1px);
}

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

#player-status-message {
    margin-bottom: 15px;
    font-size: 0.95rem;
    color: var(--color-text);
    font-weight: 600;
    text-align: center;
    background-color: rgba(213, 43, 30, 0.1);
    padding: 10px 15px;
    border-radius: 6px;
    border: 1px dashed var(--color-red);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#current-nickname {
    color: var(--color-red);
    font-weight: 700;
}

#logout-btn {
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
    padding: 0 5px;
}

#logout-btn:hover {
    opacity: 1;
    color: var(--color-red);
}

.live-leaderboard h3 {
    margin-top: 0;
    font-size: 1.1rem;
    color: var(--color-text);
    border-bottom: 2px solid var(--color-red);
    padding-bottom: 12px;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

/* Rules Button */
.rules-btn {
    margin-top: 15px;
    background-color: var(--color-white);
    color: var(--color-text);
    border: 2px solid var(--color-tile-border);
    padding: 10px;
    border-radius: 8px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.rules-btn:hover {
    background-color: #f8fafc;
    border-color: var(--color-red);
    color: var(--color-red);
}

/* Rules Modal */
.rules-modal {
    max-width: 400px;
    text-align: left;
    position: relative;
}

.rules-modal h2 {
    margin-top: 0;
    text-align: center;
}

.rules-modal p, .rules-modal ul {
    font-size: 0.95rem;
    color: var(--color-text);
    line-height: 1.5;
}

.rules-examples {
    margin-top: 20px;
    border-top: 1px solid var(--color-tile-border);
    padding-top: 15px;
}

.example-row {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    transform: scale(0.8);
    transform-origin: left center;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--color-text);
    opacity: 0.6;
}

.close-btn:hover {
    opacity: 1;
    color: var(--color-red);
}

#rules-modal-wrapper {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 5px;
}

#leaderboard-list::-webkit-scrollbar {
    width: 6px;
}
#leaderboard-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    border-left: 4px solid var(--color-red);
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.4s;
    animation: fadeIn 0.5s ease-out;
}

.player-card:hover {
    transform: translateX(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.player-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-text);
}

.player-stats {
    font-size: 0.85rem;
    color: #64748b;
}

.player-status {
    width: 12px;
    height: 12px;
    background-color: #22c55e;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@media (max-width: 850px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
    }
    .live-leaderboard {
        max-width: 100%;
        width: 100%;
        max-height: 400px;
    }
    .sponsors-logos {
        gap: 14px 20px;
        padding: 0 16px;
    }
    .sponsor {
        font-size: 1rem;
    }
}
