/* ==========================================================================
   Wordle'nt — base, variables, reset
   ========================================================================== */

* {
    box-sizing: border-box;
}

:root {
    --color-bg: #ffffff;
    --color-text: #1a1a1b;
    --color-text-secondary: #6b6f70;

    --color-border: #d3d6da;
    --color-border-filled: #878a8c;

    --color-correct: #6aaa64;
    --color-present: #c9b458;
    --color-absent: #787c7f;

    --color-key-bg: #d3d6da;
    --color-key-text: #1a1a1b;

    --color-danger: #d93025;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;

    --page-max-width: 500px;
    --board-width: min(330px, 88vw);
    --keyboard-width: min(500px, 96vw);
}

html, body {
    height: 100%;
}

body {
    margin: 0;

    font-family: var(--font-family);

    background: var(--color-bg);
    color: var(--color-text);

    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p {
    margin: 0;
}

a {
    color: inherit;
}

button {
    font-family: inherit;
}


/* ==========================================================================
   Buttons (shared)
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 100%;

    min-height: 52px;

    padding: 12px 20px;

    border: 2px solid var(--color-text);
    border-radius: 8px;

    font-size: 1.05rem;
    font-weight: 700;

    text-decoration: none;
    cursor: pointer;

    touch-action: manipulation;
    user-select: none;

    transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--color-text);
    color: #fff;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #fff;
    color: var(--color-text);
}

.btn-secondary:hover {
    background: #f5f5f5;
}


/* ==========================================================================
   Icon buttons + back buttons (shared across header/back nav)
   ========================================================================== */

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 38px;
    height: 38px;

    border-radius: 50%;

    font-size: 1.2rem;
    text-decoration: none;

    color: var(--color-text);

    touch-action: manipulation;

    transition: background 0.15s ease;
}

.icon-btn:hover {
    background: #f0f0f0;
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 38px;
    height: 38px;

    border-radius: 50%;

    font-size: 1.3rem;
    font-weight: bold;

    text-decoration: none;
    color: var(--color-text);

    touch-action: manipulation;

    transition: background 0.15s ease;
}

.back-btn:hover {
    background: #f0f0f0;
}


/* ==========================================================================
   Home page
   ========================================================================== */

.center-page {
    min-height: 100dvh;
    min-height: 100vh;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: 24px;

    text-align: center;
}

.home-title {
    font-size: 2.2rem;
    font-weight: 800;

    letter-spacing: 0.02em;

    margin-bottom: 8px;
}

.home-subtitle {
    color: var(--color-text-secondary);

    margin-bottom: 36px;

    font-size: 1rem;
}

.home-actions {
    display: flex;
    flex-direction: column;

    gap: 14px;

    width: 100%;
    max-width: 320px;
}


/* ==========================================================================
   Auth pages (login / register)
   ========================================================================== */

.auth-page {
    position: relative;

    min-height: 100dvh;
    min-height: 100vh;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 24px;
}

.auth-page .back-btn {
    position: absolute;
    top: 16px;
    left: 16px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
}

.auth-card h1 {
    font-size: 1.8rem;
    font-weight: 800;

    text-align: center;

    margin-bottom: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;

    gap: 6px;
}

.auth-form label {
    font-size: 0.9rem;
    font-weight: 700;

    margin-top: 12px;
    margin-bottom: 2px;
}

.auth-form input {
    width: 100%;

    padding: 14px 16px;

    font-size: 1.1rem;

    border: 2px solid var(--color-border);
    border-radius: 8px;

    background: #fff;
    color: var(--color-text);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--color-text);
}

.auth-form .btn {
    margin-top: 22px;
}

.auth-switch {
    text-align: center;

    margin-top: 20px;

    font-size: 0.95rem;

    color: var(--color-text-secondary);
}

.auth-switch a {
    font-weight: 700;
    color: var(--color-text);

    text-decoration: underline;
}

.flash-error {
    background: #fdecea;
    color: var(--color-danger);

    border: 1px solid #f5c6c0;
    border-radius: 8px;

    padding: 10px 14px;

    font-size: 0.9rem;
    font-weight: 600;

    margin-top: 16px;
}


/* ==========================================================================
   Game page — layout
   ========================================================================== */

.game-container {
    position: relative;

    min-height: 100dvh;
    min-height: 100vh;

    display: flex;
    flex-direction: column;
    align-items: center;

    padding-bottom: 40px;
}

.game-header {
    width: 100%;

    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;

    padding: 12px 16px;

    border-bottom: 1px solid var(--color-border);
}

.game-title {
    font-size: 1.4rem;
    font-weight: 800;

    letter-spacing: 0.02em;

    text-align: center;
}

.header-side {
    display: flex;
    align-items: center;

    gap: 8px;
}

.header-right {
    justify-content: flex-end;
}

.header-username {
    font-size: 0.8rem;
    color: var(--color-text-secondary);

    max-width: 90px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* Streak badge — fixed top-left of the screen, fire icon */


.streak-badge {
    position: fixed;
    top: 54px;
    left: 12px;

    display: none;
    align-items: center;

    gap: 4px;

    padding: 5px 12px;

    background: #fff;
    border: 2px solid var(--color-border);
    border-radius: 999px;

    font-weight: 800;
    font-size: 1rem;

    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);

    z-index: 50;
}

.streak-badge .fire {
    font-size: 1.05rem;
}


/* Home button — fixed bottom-left, deliberately small */


.home-fab {
    position: fixed;
    top: 12px;
    left: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 32px;
    height: 32px;

    border-radius: 50%;

    background: var(--color-key-bg);
    color: var(--color-text);

    font-size: 0.9rem;
    text-decoration: none;

    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);

    touch-action: manipulation;
    z-index: 50;
}


/* Toast */

.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-16px);

    background: var(--color-text);
    color: #fff;

    padding: 12px 20px;

    border-radius: 6px;

    font-weight: 700;
    font-size: 0.9rem;

    text-align: center;

    max-width: 90vw;

    opacity: 0;
    pointer-events: none;

    transition: opacity 0.2s ease, transform 0.2s ease;

    z-index: 100;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}


/* ==========================================================================
   Game board
   ========================================================================== */

#game-board {
    margin-top: 24px;

    width: var(--board-width);

    display: grid;
    grid-template-rows: repeat(6, 1fr);

    gap: 5px;
}

.game-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);

    gap: 5px;
}

.tile {
    aspect-ratio: 1 / 1;
    width: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(--color-border);

    font-size: clamp(1.3rem, 7vw, 2rem);
    font-weight: 800;

    text-transform: uppercase;

    color: var(--color-text);

    user-select: none;

    perspective: 400px;
}

.tile.filled {
    border-color: var(--color-border-filled);
}

.tile.pop {
    animation: popTile 0.1s ease;
}

.tile.correct,
.tile.present,
.tile.absent {
    color: #fff;
}

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

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

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

.tile.flip {
    animation: flipTile 0.5s ease;
}

.tile.bounce {
    animation: bounceTile 0.65s ease;
}

.game-row.shake {
    animation: shakeRow 0.5s;
}


/* ==========================================================================
   Keyboard
   ========================================================================== */

#keyboard {
    margin-top: 26px;

    width: var(--keyboard-width);

    display: flex;
    flex-direction: column;

    gap: 8px;

    transition: opacity 0.2s ease;
}

#keyboard.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.keyboard-row {
    display: flex;

    gap: 6px;

    justify-content: center;
}

.key {
    flex: 1;

    border: none;
    border-radius: 4px;

    min-width: 0;

    height: clamp(42px, 12vw, 58px);

    background: var(--color-key-bg);
    color: var(--color-key-text);

    font-weight: 700;
    font-size: clamp(0.7rem, 3.4vw, 0.95rem);

    cursor: pointer;

    touch-action: manipulation;
    user-select: none;

    transition: background 0.15s ease, color 0.15s ease;
}

.key:active {
    opacity: 0.8;
}

.key-wide {
    flex: 1.6;

    font-size: clamp(0.6rem, 2.6vw, 0.8rem);
}

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

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

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


/* ==========================================================================
   Animations
   ========================================================================== */

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

@keyframes bounceTile {
    0%, 20% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-22%);
    }
    50% {
        transform: translateY(0);
    }
    60% {
        transform: translateY(-10%);
    }
    80%, 100% {
        transform: translateY(0);
    }
}

@keyframes shakeRow {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}

@keyframes popTile {
    0% { transform: scale(0.9); }
    50% { transform: scale(1.06); }
    100% { transform: scale(1); }
}


/* ==========================================================================
   Stats page
   ========================================================================== */

.stats-page {
    max-width: var(--page-max-width);

    margin: 0 auto;

    padding: 0 20px 40px;
}

.page-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;

    padding: 14px 0;
}

.page-header h1 {
    text-align: center;

    font-size: 1.4rem;
    font-weight: 800;
}

.page-header-spacer {
    width: 38px;
}

.stats-grid {
    display: flex;

    justify-content: space-between;

    gap: 8px;

    margin-top: 20px;
    margin-bottom: 36px;
}

.stat-block {
    flex: 1;

    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: clamp(1.8rem, 8vw, 2.4rem);
    font-weight: 800;

    line-height: 1.1;
}

.stat-label {
    margin-top: 4px;

    font-size: 0.75rem;
    font-weight: 600;

    color: var(--color-text-secondary);

    text-align: center;
}

.section-title {
    font-size: 1rem;
    font-weight: 800;

    text-align: center;

    margin-bottom: 20px;
}


/* Most common guess — small tile row on the stats page */

.common-word-block {
    display: flex;
    flex-direction: column;
    align-items: center;

    gap: 10px;

    margin-bottom: 36px;
}

.common-word-tiles {
    display: flex;

    gap: 6px;
}

.common-word-tile {
    width: 42px;
    height: 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(--color-border-filled);
    border-radius: 4px;

    font-size: 1.25rem;
    font-weight: 800;

    text-transform: uppercase;

    color: var(--color-text);
}

.common-word-caption {
    font-size: 0.85rem;
    font-weight: 600;

    color: var(--color-text-secondary);

    text-align: center;
}

.distribution-chart {
    display: flex;
    align-items: flex-end;

    gap: 10px;

    height: 200px;

    padding: 0 4px;
}

.dist-column {
    flex: 1;

    height: 100%;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.dist-count {
    font-weight: 800;
    font-size: 0.9rem;

    margin-bottom: 6px;
}

.dist-bar {
    width: 100%;

    height: var(--pct, 4%);
    min-height: 4px;

    background: var(--color-absent);
    border-radius: 4px 4px 0 0;

    transition: height 0.6s ease;
}

.dist-bar.highlight {
    background: var(--color-correct);
}

.dist-label {
    margin-top: 8px;

    font-weight: 800;
    font-size: 0.85rem;

    color: var(--color-text-secondary);
}


/* ==========================================================================
   Small-screen tweaks
   ========================================================================== */

@media (max-width: 360px) {
    .stat-number {
        font-size: 1.5rem;
    }

    .home-title {
        font-size: 1.8rem;
    }
}


/* ==========================================================================
   Larger screens — a little extra breathing room
   ========================================================================== */

@media (min-width: 700px) {
    #game-board {
        margin-top: 36px;
    }

    #keyboard {
        margin-top: 34px;
    }
}


/* ==========================================================================
   Result grid (shared by history + daily leaderboard)
   ========================================================================== */

.history-grid {
    display: flex;
    flex-direction: column;

    gap: 3px;
}

.history-grid-row {
    display: flex;

    gap: 3px;
}

.history-square {
    width: 16px;
    height: 16px;

    border-radius: 3px;

    background: var(--color-border);
}

.history-square.correct {
    background: var(--color-correct);
}

.history-square.present {
    background: var(--color-present);
}

.history-square.absent {
    background: var(--color-absent);
}


.history-result {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 3px 10px;

    border-radius: 999px;

    font-size: 0.8rem;
    font-weight: 800;

    color: #fff;
}

.history-result.won {
    background: var(--color-correct);
}

.history-result.lost {
    background: var(--color-absent);
}


/* ==========================================================================
   History detail page (single day replay)
   ========================================================================== */

.detail-container {
    padding-bottom: 60px;
}

.detail-summary {
    display: flex;
    align-items: center;
    justify-content: center;

    gap: 14px;

    margin-top: 30px;
}

.detail-answer {
    font-size: 0.95rem;
    font-weight: 600;

    color: var(--color-text-secondary);
}

.detail-answer strong {
    color: var(--color-text);

    letter-spacing: 0.06em;
    text-transform: uppercase;
}


/* ==========================================================================
   History page
   ========================================================================== */

.history-page {
    max-width: var(--page-max-width);

    margin: 0 auto;

    padding: 0 20px 40px;
}

.history-filter-row {
    display: flex;
    flex-direction: column;

    gap: 6px;

    margin: 8px 0 20px;
}

.history-filter-label {
    font-size: 0.8rem;
    font-weight: 700;

    color: var(--color-text-secondary);
}

.history-filter-select {
    width: 100%;

    padding: 12px 14px;

    font-size: 1rem;
    font-weight: 600;

    border: 2px solid var(--color-border);
    border-radius: 8px;

    background: #fff;
    color: var(--color-text);
}

.history-filter-select:focus {
    outline: none;
    border-color: var(--color-text);
}

.history-list {
    display: flex;
    flex-direction: column;

    gap: 14px;
}

.history-card {
    display: block;

    border: 2px solid var(--color-border);
    border-radius: 10px;

    padding: 14px 16px;

    text-decoration: none;
    color: inherit;

    touch-action: manipulation;

    transition: transform 0.05s ease, background 0.15s ease;
}

.history-card:hover {
    background: #f5f5f5;
}

.history-card:active {
    transform: scale(0.99);
    background: #f0f0f0;
}

.history-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 12px;
}

.history-date {
    font-weight: 700;
    font-size: 0.95rem;
}

.history-empty {
    color: var(--color-text-secondary);

    text-align: center;

    padding: 30px 0;
}

.history-link-btn {
    margin-top: 28px;
}


/* ==========================================================================
   Leaderboard page
   ========================================================================== */

.leaderboard-page {
    max-width: var(--page-max-width);

    margin: 0 auto;

    padding: 0 20px 40px;
}

.leaderboard-layout {
    display: flex;
    flex-direction: column;

    gap: 32px;

    margin-top: 8px;
}

.leaderboard-overall,
.leaderboard-daily {
    min-width: 0;
}

.leaderboard-block {
    margin-bottom: 22px;
}

.leaderboard-block-title {
    font-size: 0.78rem;
    font-weight: 800;

    text-transform: uppercase;
    letter-spacing: 0.03em;

    color: var(--color-text-secondary);

    margin-bottom: 8px;
}

.leaderboard-list {
    list-style: none;

    display: flex;
    flex-direction: column;

    gap: 6px;

    margin: 0;
    padding: 0;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: center;

    gap: 8px;

    padding: 9px 12px;

    border: 2px solid var(--color-border);
    border-radius: 8px;
}

.leaderboard-row-first {
    border-color: var(--color-text);
    background: #fafafa;
}

.leaderboard-rank {
    font-weight: 800;
    font-size: 0.9rem;

    color: var(--color-text-secondary);

    text-align: center;
}

.leaderboard-row-first .leaderboard-rank {
    color: var(--color-text);
}

.leaderboard-name {
    font-weight: 600;
    font-size: 0.95rem;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-value {
    font-weight: 800;
    font-size: 0.95rem;

    white-space: nowrap;
}

.leaderboard-empty {
    color: var(--color-text-secondary);

    font-size: 0.85rem;

    padding: 4px 2px;
}

.daily-list {
    display: flex;
    flex-direction: column;

    gap: 12px;
}

.daily-entry {
    border: 2px solid var(--color-border);
    border-radius: 10px;

    padding: 10px 14px;
}

.daily-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 8px;
}

.daily-entry-name {
    font-weight: 700;
    font-size: 0.95rem;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    margin-right: 8px;
}


/* Wide screens — leaderboard splits into two side-by-side columns */

@media (min-width: 700px) {

    .leaderboard-page {
        max-width: 760px;
    }

    .leaderboard-layout {
        flex-direction: row;
        align-items: flex-start;

        gap: 36px;
    }

    .leaderboard-overall,
    .leaderboard-daily {
        flex: 1;
    }

    .leaderboard-daily {
        border-left: 1px solid var(--color-border);

        padding-left: 36px;
    }
}
