/* Font optimization */
@font-face {
    font-family: 'Poppins';
    font-style: normal;
    font-weight: 400;
    font-display: swap; /* Improves font loading performance */
    src: url(https://fonts.gstatic.com/s/poppins/v20/pxiEyp8kv8JHgFVrJJfecg.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Poppins';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLEj6Z1xlFQ.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --correct-color: #6aaa64;
    --present-color: #c9b458;
    --absent-color: #787c7e; 
    --key-bg: #d3d6da;
    --key-text: #1a1a1b;
    --border-color: #d3d6da;
    --background-color: #ffffff;
    --accent-color: #4a90e2;
    --error-color: #d32f2f;
    --success-color: #388e3c;
    --header-color: #1a1a1b;
    --text-color: #1a1a1b;
    --secondary-text: #666666;
    --modal-background: rgba(0, 0, 0, 0.5);
    --font-family: 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --cell-size: 62px;
    --keyboard-height: 200px;
    --shadow-color: rgba(0, 0, 0, 0.15);
    --gradient-start: #4a90e2;
    --gradient-end: #357abd;
}

/* CSS Reset and Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    height: 100%;
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

button {
    font-family: var(--font-family);
    border: none;
    background: none;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s ease, background-color 0.3s ease;
}

button:hover {
    background-color: rgba(0, 0, 0, 0.06);
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
}

/* Header styles */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    padding: 0 15px;
    position: relative;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--header-color);
    text-align: center;
    margin: 0;
    position: relative;
    overflow: hidden;
}

h1::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
    transform: translateX(-100%);
    animation: gradientLineIn 1s forwards;
}

.menu-icons {
    display: flex;
    gap: 10px;
}

.menu-icons button {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--header-color);
    transition: background-color 0.3s, transform 0.1s;
}

.menu-icons button:hover {
    background-color: rgba(0, 0, 0, 0.08);
    transform: scale(1.05);
}

.menu-icons button:active {
    transform: scale(0.95);
}

/* Game container styles */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    flex-grow: 1;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    position: relative;
    perspective: 1000px; /* For 3D animations */
}

/* Game grid styles */
.grid {
    display: grid;
    grid-template-rows: repeat(6, var(--cell-size));
    grid-template-columns: repeat(5, var(--cell-size));
    gap: 5px;
    margin-bottom: 20px;
    width: fit-content;
}

.row {
    display: contents;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 2px solid var(--border-color);
    font-size: calc(var(--cell-size) * 0.5);
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    transition: transform 0.1s, border 0.3s;
    background-color: var(--background-color);
    position: relative;
    transform-style: preserve-3d;
    will-change: transform, background-color;
}

.cell.filled {
    border-color: #878a8c;
    animation: pop 0.1s;
}

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

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

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

.cell.active {
    border-color: #333;
    border-width: 3px;
}

.cell.shake {
    animation: shake 0.6s;
}

.cell.dance {
    animation: dance 0.5s ease;
}

/* Message display */
#message {
    height: 40px;
    margin: 10px 0;
    padding: 0 10px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    width: 100%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    position: absolute;
    bottom: calc(var(--keyboard-height) + 20px);
    left: 0;
    right: 0;
    margin: auto;
    visibility: hidden;
}

#message.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    animation: fadeIn 0.3s;
}

/* Virtual keyboard styles */
#keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: var(--keyboard-height);
    margin-top: auto;
    padding-bottom: 10px;
    gap: 5px;
}

.keyboard-row {
    display: flex;
    gap: 4px;
    width: 100%;
    justify-content: center;
}

.key {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 58px;
    min-width: 40px;
    padding: 0 10px;
    border-radius: 4px;
    background-color: var(--key-bg);
    color: var(--key-text);
    font-size: 14px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    flex: 1;
    max-width: 65px;
    font-weight: bold;
    transition: transform 0.1s ease-in-out, background-color 0.2s;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
    transform: translateY(-3px);
}

.key:hover {
    background-color: #c4c7cb;
    transform: translateY(-1px);
}

.key:active {
    transform: translateY(0);
    box-shadow: none;
}

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

.key.correct {
    background-color: var(--correct-color);
    color: white;
}

.key.present {
    background-color: var(--present-color);
    color: white;
}

.key.absent {
    background-color: var(--absent-color);
    color: white;
}

.spacer {
    flex: 0.5;
}

.spacer.half {
    flex: 0.25;
}

/* Multiplayer and game mode styles */
.theme-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 15px;
    padding: 10px;
    gap: 10px;
    background-color: #f8f8f8;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.game-mode {
    display: flex;
    gap: 5px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 8px 15px;
    background-color: #f0f0f0;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s, color 0.3s, transform 0.1s;
}

.mode-btn:hover {
    background-color: #e6e6e6;
}

.mode-btn.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.theme-badge {
    font-size: 14px;
    padding: 5px 10px;
    background-color: white;
    border-radius: 15px;
    color: var(--secondary-text);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    animation: themeChange 0.5s ease-in-out;
}

.theme-badge span {
    font-weight: 600;
    color: var(--accent-color);
}

/* Multiplayer tools */
.multiplayer-tools {
    display: none; /* Hidden by default */
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    margin: 15px auto;
    padding: 15px;
    background-color: #f0f0f0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    gap: 15px;
}

.multiplayer-tools.show {
    display: flex !important; /* Force display when show class is applied */
    animation: slideUp 0.3s ease-out;
}

.multiplayer-status {
    text-align: center;
    margin-bottom: 10px;
}

.connection-status {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 14px;
    background-color: #f8d7da;
    color: #721c24;
}

.connection-status.connected {
    background-color: #d4edda;
    color: #155724;
}

.multiplayer-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.room-join {
    display: flex;
    gap: 5px;
}

.primary-btn, .secondary-btn {
    padding: 10px 15px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
}

.primary-btn {
    background-color: var(--accent-color);
    color: white;
}

.primary-btn:hover {
    background-color: var(--gradient-end);
}

.secondary-btn {
    background-color: var(--key-bg);
    color: var(--text-color);
}

.secondary-btn:hover {
    background-color: #c4c7cb;
}

#room-id-input {
    width: 160px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 14px;
}

.room-display {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.room-display.show {
    display: flex;
}

#room-id-display {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    background-color: white;
    padding: 8px 15px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 0 10px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 10px;
    background-color: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.player-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-color);
}

.player-status {
    font-size: 12px;
    color: var(--secondary-text);
    margin-left: auto;
}

/* Opponent grid styles */
.opponent-container {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    gap: 5px;
    width: 100%;
}

.opponent-container.show {
    display: flex;
    animation: fadeIn 0.3s;
}

.opponent-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary-text);
    margin-bottom: 5px;
}

.opponent-grid {
    display: grid;
    grid-template-rows: repeat(6, calc(var(--cell-size) * 0.7));
    grid-template-columns: repeat(5, calc(var(--cell-size) * 0.7));
    gap: 3px;
    border: 1px dashed var(--border-color);
    padding: 5px;
    border-radius: 8px;
    background-color: #f9f9f9;
}

.opponent-grid .cell {
    width: 100%;
    height: 100%;
    font-size: calc(var(--cell-size) * 0.3);
    border-width: 1px;
}

.opponent-grid .hidden-guess {
    background-color: #e6e6e6;
    border: 1px dashed #bbb;
    position: relative;
}

.opponent-grid .hidden-guess::before {
    content: "?";
    color: #888;
    font-size: calc(var(--cell-size) * 0.4);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.opponent-grid .hidden-guess:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
}

/* Footer styles */
footer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    margin-top: 20px;
    padding: 10px;
    background-color: #333333;
    color: white;
    font-size: 12px;
    border-radius: 0 0 8px 8px;
    gap: 20px;
}

.text-link {
    color: var(--accent-color);
    text-decoration: underline;
    background: none;
    border: none;
    font-size: 12px;
    padding: 0;
    cursor: pointer;
}

.text-link:hover {
    color: var(--gradient-end);
    text-decoration: none;
    background: none;
    transform: none;
}

/* Leaderboard styles */
.leaderboard-tabs {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    gap: 5px;
}

.leaderboard-tab {
    padding: 8px 15px;
    border-radius: 15px;
    background-color: #f0f0f0;
    color: var(--secondary-text);
    font-size: 14px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s, color 0.3s;
}

.leaderboard-tab.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.leaderboard-table {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.leaderboard-header {
    display: flex;
    background-color: #f0f0f0;
    padding: 10px 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-rank {
    width: 40px;
    text-align: center;
}

.leaderboard-name {
    flex-grow: 1;
    padding: 0 10px;
}

.leaderboard-score {
    width: 80px;
    text-align: right;
}

.leaderboard-row {
    display: flex;
    padding: 8px 15px;
    background-color: white;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    align-items: center;
    transition: background-color 0.2s;
}

.leaderboard-row:hover {
    background-color: #f8f8f8;
}

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

.leaderboard-row.empty-row {
    justify-content: center;
    color: var(--secondary-text);
    font-style: italic;
    padding: 15px;
}

.leaderboard-row.current-user {
    background-color: rgba(74, 144, 226, 0.1);
    font-weight: 600;
}

.personal-records {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f8f8;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.personal-records h4 {
    font-size: 16px;
    margin-bottom: 10px;
    color: var(--text-color);
    text-align: center;
}

.record-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.record-item:last-child {
    margin-bottom: 0;
}

.record-label {
    color: var(--secondary-text);
}

.record-value {
    font-weight: 600;
    color: var(--accent-color);
}

/* Animation keyframes */
@keyframes gradientLineIn {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(0);
    }
}

@keyframes themeChange {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.theme-change {
    animation: themeChange 0.5s ease-in-out;
}

.countdown-timer {
    font-size: 14px;
    color: var(--secondary-text);
    margin-top: 5px;
    text-align: center;
}

@keyframes pop {
    0% {
        transform: scale(0.8);
    }
    40% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes shake {
    0% { transform: translateX(0); }
    10% { transform: translateX(-6px); }
    30% { transform: translateX(6px); }
    50% { transform: translateX(-6px); }
    70% { transform: translateX(6px); }
    90% { transform: translateX(-6px); }
    100% { transform: translateX(0); }
}

@keyframes dance {
    0% { transform: translateY(0); }
    20% { transform: translateY(-20px) rotate(-5deg); }
    40% { transform: translateY(0) rotate(5deg); }
    60% { transform: translateY(-10px) rotate(-3deg); }
    80% { transform: translateY(0) rotate(3deg); }
    100% { transform: translateY(0); }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes keyHighlight {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        background-color: rgba(0, 0, 0, 0.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes keyFade {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0.5;
    }
}

@keyframes shimmer {
    0% { background-position: -100% 0; }
    100% { background-position: 200% 0; }
}

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

/* Apply flip animation to cells when they get a state */
.cell.correct, .cell.present, .cell.absent {
    animation: flip3D 0.5s;
}

/* Disable animation for already revealed cells */
.cell.already-revealed {
    animation: none !important;
}

/* Responsive design */
@media (min-width: 900px) {
    .container {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    header, .theme-container, footer {
        width: 100%;
    }
    
    #game-container {
        flex: 0 0 600px;
        margin-right: 20px;
    }
    
    .multiplayer-tools {
        flex: 0 0 600px;
    }
    
    #stats-modal .modal-content {
        max-width: 600px;
    }
    
    #daily-leaderboard-container {
        flex: 0 0 300px;
        margin-left: 20px;
    }
    
    .opponent-container {
        position: absolute;
        right: -330px;
        top: 0;
        width: 300px;
    }
}

@media (max-width: 500px) {
    :root {
        --cell-size: 45px;
        --keyboard-height: 180px;
    }
    
    .cell {
        font-size: calc(var(--cell-size) * 0.5);
    }
    
    h1 {
        font-size: 22px;
    }
    
    .key {
        height: 50px;
        font-size: 12px;
    }
    
    .theme-container {
        padding: 8px;
    }
    
    .mode-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .theme-badge {
        font-size: 12px;
    }
    
    .leaderboard-row {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .primary-btn, .secondary-btn, #room-id-input {
        font-size: 12px;
        padding: 8px 12px;
    }
}

@media (max-width: 350px) {
    :root {
        --cell-size: 40px;
        --keyboard-height: 160px;
    }
    
    .cell {
        font-size: calc(var(--cell-size) * 0.5);
    }
    
    .key {
        height: 45px;
        min-width: 28px;
        padding: 0 5px;
        font-size: 10px;
    }
    
    .multiplayer-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .room-join {
        width: 100%;
    }
    
    #room-id-input {
        flex-grow: 1;
    }
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-background);
    overflow: auto;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
}

.modal-content {
    background-color: var(--background-color);
    max-width: 90%;
    width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transform: translateY(50px);
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    position: relative;
}

.modal.show .modal-content {
    transform: translateY(0);
    opacity: 1;
    animation: modalSlideUp 0.3s forwards;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    font-weight: bold;
    color: var(--secondary-text);
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--accent-color);
}

.modal h2 {
    margin-bottom: 15px;
    color: var(--text-color);
    text-align: center;
    font-size: 24px;
}

.modal h3 {
    margin: 20px 0 10px;
    color: var(--text-color);
    font-size: 18px;
}

.modal p {
    margin-bottom: 10px;
    line-height: 1.5;
    color: var(--secondary-text);
}

.modal ul {
    margin-left: 20px;
    line-height: 1.5;
    color: var(--secondary-text);
}

/* Example cells in help modal */
.examples {
    margin: 20px 0;
}

.example {
    margin-bottom: 15px;
}

.example-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    justify-content: flex-start;
}

.example-row .cell {
    width: 40px;
    height: 40px;
    font-size: 20px;
}

/* Stats container */
.stats-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.stat-number {
    font-size: 24px;
    font-weight: bold;
    color: var(--text-color);
}

.stat-label {
    font-size: 12px;
    color: var(--secondary-text);
    text-align: center;
}

/* Guess distribution */
.guess-distribution {
    margin-top: 10px;
}

.guess-row {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.guess-label {
    width: 20px;
    font-weight: bold;
    color: var(--text-color);
}

.guess-bar-container {
    flex-grow: 1;
    margin-left: 10px;
    height: 20px;
    display: flex;
    align-items: center;
}

.guess-bar {
    height: 100%;
    min-width: 30px;
    background-color: var(--absent-color);
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: white;
    font-weight: bold;
    font-size: 12px;
    border-radius: 4px;
    transition: width 1s ease-in-out;
}

.guess-bar.win {
    background-color: var(--correct-color);
    background-image: linear-gradient(90deg, 
        var(--correct-color) 0%, 
        var(--correct-color) 70%, 
        rgba(255,255,255,0.3) 70%, 
        rgba(255,255,255,0.3) 72%, 
        var(--correct-color) 72%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear;
}

.guess-count {
    min-width: 20px;
    text-align: right;
    margin-left: 5px;
    font-weight: bold;
    color: var(--secondary-text);
} 