:root {
    --bg-dark: #121213;
    --bg-board: #121213;
    --color-tone-1: #ffffff;
    --color-tone-2: #818384;
    --color-tone-3: #565758;
    --color-tone-4: #3a3a3c; /* Absent */
    --color-present: #85c1e9; /* Present - Light Blue */
    --color-correct: #2979ff; /* Correct - Vivid Blue */
    --key-bg: #818384;
    
    --color-brand: #2979ff; /* Blue Brand */
    
    --font-head: 'Teko', sans-serif;
    --font-body: 'Helvetica Neue', Arial, sans-serif;
    --header-height: 65px;
}

* { box-sizing: border-box; user-select: none; }

body {
    margin: 0;
    background-color: var(--bg-dark); /* Solid color like NYT */
    color: var(--color-tone-1);
    font-family: var(--font-body);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    width: 100%;
    max-width: 500px; /* NYT constraints the game area */
    margin: 0 auto;
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    justify-content: space-between; /* Push content apart */
}

/* HEADER */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--color-tone-4);
    background-color: var(--bg-dark);
    height: var(--header-height);
}

.header-left, .header-icons {
    display: flex;
    align-items: center;
    width: 80px; /* Balance left/right */
}
.header-icons {
    justify-content: flex-end;
    gap: 10px;
}

.brand {
    font-family: var(--font-head);
    font-size: 32px;
    letter-spacing: 1px;
    text-align: center;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}
.logo-main { font-weight: 700; color: white; }
.logo-sub { color: var(--color-tone-1); font-weight: 400; } /* NYT title is all white usually, but we keep sub white/gray */

.icon-btn-simple {
    background: none;
    border: none;
    color: var(--color-tone-1);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* BOARD */
#game-board {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-height: 420px; /* Constrain board height */
}

.grid-container {
    display: grid;
    grid-template-rows: repeat(5, 1fr);
    grid-gap: 5px;
    width: 100%;
    /* max-width and aspect-ratio handled by JS for dynamic word lengths */
    /* max-width: 350px; */
    /* aspect-ratio: 5/6; */
}

.row {
    display: grid;
    /* grid-template-columns handled by JS */
    /* grid-template-columns: repeat(5, 1fr); */
    grid-gap: 5px;
}

.tile {
    width: 100%;
    height: 100%;
    border: 2px solid var(--color-tone-4);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px; /* Slightly smaller for cleaner look */
    font-weight: bold;
    text-transform: uppercase;
    color: var(--color-tone-1);
    background: transparent;
    transition: transform 0.25s, border-color 0.25s, background-color 0.25s;
}

/* KEYBOARD */
#keyboard-container {
    width: 100%;
    max-width: 500px;
    margin-bottom: 20px; /* More space at bottom */
    margin-top: auto; /* Push to bottom */
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    gap: 6px;
}

.key {
    font-family: var(--font-body);
    font-weight: bold;
    font-size: 13px;
    background: var(--key-bg);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    height: 58px;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    padding: 0;
}

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

/* STATES */
.tile[data-state='tbd'] {
    border-color: var(--color-tone-3); /* Lighter gray when filled */
    animation: pop 0.1s;
}
.tile.correct { background: var(--color-correct); border-color: var(--color-correct); }
.tile.present { background: var(--color-present); border-color: var(--color-present); color: #000000; }
.tile.absent { background: var(--color-tone-4); border-color: var(--color-tone-4); }

.key[data-state='correct'] { background: var(--color-correct); }
.key[data-state='present'] { background: var(--color-present); color: #000000; }
.key[data-state='absent'] { background: var(--color-tone-4); }

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

.flip {
    animation: flip 0.5s ease forwards;
}
@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

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

/* SETTINGS MODAL */
.settings-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--color-tone-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.settings-section:last-child {
    border-bottom: none;
}
.settings-info {
    display: flex;
    flex-direction: column;
}
.settings-title {
    font-size: 18px;
    font-weight: 500;
}
.settings-desc {
    font-size: 12px;
    color: var(--color-tone-2);
    margin-top: 4px;
}

/* MODALS */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-dark);
    border: 1px solid var(--color-tone-2);
    box-shadow: 0 4px 23px 0 rgba(0, 0, 0, 0.5);
    padding: 16px;
    width: 90%;
    max-width: 500px; /* NYT width */
    z-index: 2000;
    border-radius: 8px;
    color: var(--color-tone-1);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translate(-50%, -40%); opacity: 0; }
    to { transform: translate(-50%, -50%); opacity: 1; }
}

.modal h2 {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 16px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.modal-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.btn-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--color-tone-3);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-close:hover { color: var(--color-tone-1); }

/* STATS */
.stats-box {
    display: flex;
    justify-content: center; /* Center the stats */
    gap: 20px; /* Space between items */
    margin-bottom: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    min-width: 50px;
}

.stat span {
    font-size: 30px;
    font-weight: 400;
    line-height: 1;
    margin-bottom: 4px;
}

.stat label {
    font-size: 12px;
    text-transform: uppercase;
    text-align: center;
    color: var(--color-tone-2);
}

.divider {
    border: 0;
    border-top: 1px solid var(--color-tone-4);
    margin: 16px 0;
}

/* LEADERBOARD TABLE */
.leaderboard-container {
    max-height: 200px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    text-align: left;
    color: var(--color-tone-2);
    font-weight: normal;
    padding: 8px 4px;
    border-bottom: 1px solid var(--color-tone-4);
    text-transform: uppercase;
    font-size: 12px;
}

td {
    padding: 8px 4px;
    border-bottom: 1px solid #252526;
}

/* FORMS */
.form-group {
    margin-bottom: 15px;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    color: var(--color-tone-2);
}
.form-group input {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--color-tone-4);
    color: white;
    border-radius: 4px;
    font-size: 16px;
}
.form-group input:focus {
    outline: none;
    border-color: var(--color-correct);
}

.btn-primary {
    background: var(--color-correct);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 20px; /* NYT rounded buttons */
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    text-transform: uppercase;
}

/* TOAST */
#msg-toast {
    font-family: var(--font-body);
    font-size: 14px;
    background-color: var(--color-tone-1) !important;
    color: var(--bg-dark) !important;
    border-radius: 4px !important;
    padding: 12px 16px !important;
    font-weight: 700 !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* SOCIAL BUTTONS */
.divider-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    position: relative;
}
.divider-container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: var(--color-tone-4);
    z-index: 1;
}
.divider-text {
    background: #121213;
    padding: 0 10px;
    color: var(--color-tone-2);
    font-size: 14px;
    z-index: 2;
    position: relative;
}

.btn-social {
    background: white;
    color: black;
    border: none;
    padding: 12px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    font-family: var(--font-body);
    transition: background-color 0.2s;
}

.btn-social:hover {
    background-color: #f0f0f0;
}

.social-icon {
    display: block;
}

.login-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--color-tone-1);
}

.login-footer a {
    color: var(--color-correct);
    text-decoration: none;
    font-weight: bold;
}
.login-footer a:hover {
    text-decoration: underline;
}

/* TIMER */
#next-word-timer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
}
#next-word-timer p {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}
#timer {
    font-size: 24px;
    font-weight: 400;
}

.hidden { display: none !important; }

#modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1500;
}

