/* CSS Variables for colors */
:root {
    --color-green: #28a745;
    --color-green-dark: #236b23;
    --color-yellow: #ffc107;
    --color-gray: #ccc;
    --color-gray-dark: #333;
    --color-key-background: #d3d6da;
    --color-key-text: #3a3a3c;
    --color-key-hover: #c9c9c9;
    --color-key-pressed: #9e9e9e;
    --color-key-absent: #818384;
    --color-key-absent-text: #d3d6da;
    --color-popup-bg: #fff;
    --color-popup-border: #333;
    --color-popup-shadow: rgba(0, 0, 0, 0.3);
    --color-notification-bg: #28a745;
    --color-notification-text: white;
    --color-firework-shadow: rgba(0, 0, 0, 0.2);
    --color-pause-bg: rgba(0, 0, 0, 0.7);
    --color-pause-message-bg: white;
    --color-stats-icon: #2c8a2c;
    --color-link: #2c8a2c;
    --color-link-hover: #236b23;
    --color-home-icon: #2c8a2c;
    --color-chart-bg: #f0f0f0;
    --color-chart-text: #333;

    --color-cell-green-background: #28a745;
    --color-cell-yellow-background: #ffc107;
    --color-cell-text: black;
    --color-cell-yellow-text: black;
    --color-cell-green-text: white;
    --color-cell-border: #ccc;
    --color-cell-active-border: #333;
    --color-cell-absent-bg: #818384;
    --color-cell-absent-text: #d3d6da;
    --color-blur: 5px;
}

/* @media (prefers-color-scheme: dark) {
    :root {
        --color-popup-bg: #222;
        --color-popup-border: #eee;
        --color-popup-shadow: rgba(0, 0, 0, 0.7);
        --color-key-background: #444;
        --color-key-text: #eee;
        --color-key-hover: #555;
        --color-key-pressed: #222;
        --color-key-absent: #333;
        --color-key-absent-text: #bbb;
        --color-chart-bg: #222;
        --color-chart-text: #eee;
        --color-cell-border: #444;
        --color-cell-active-border: #eee;
        --color-cell-absent-bg: #333;
        --color-cell-absent-text: #bbb;
        --color-pause-bg: rgba(0, 0, 0, 0.85);
        --color-pause-message-bg: #222;
        --color-link: #90ee90;
        --color-link-hover: #28a745;
        --color-home-icon: #90ee90;
        --color-stats-icon: #90ee90;
        --color-firework-shadow: rgba(0, 0, 0, 0.7);
        --color-notification-bg: #236b23;
        --color-notification-text: #fff;
        --color-cell-green-background: #28a745;
        --color-cell-yellow-background: #ffc107;
        --color-cell-text: #fff;
        --color-cell-yellow-text: #222;
        --background-color: #2b2b2b;
        --color: #eee;
    }
} */

* {
    box-sizing: border-box;
    font-weight: 400;
    line-height: 1.25rem;
    letter-spacing: .03333em;
}

html {
    height: 100%;
}

html,
body {
    min-height: 100vh;
    margin: 0;
    background-color: var(--background-color, #f0f0f0);
    color: var(--color, #333);
}

body {
    font-family: Arial, sans-serif;
    text-align: center;
    display: flex;
    flex-direction: column;
}

#game {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    text-align: center;
    flex-grow: 1;
    margin-bottom: 12em;
}

.row {
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
}

#word-row {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cell {
    border: 2px solid var(--color-cell-border);
    color: var(--color-cell-text);
    width: 1.85em;
    height: 1.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 0 2px;
    position: relative;
    overflow: visible;
    border-radius: .25em;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s, border 0.3s;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    touch-action: manipulation;
    user-select: none;
}

@media (max-width: 500px) {
    .cell {
        width: 2.25em;
        height: 2.25em;
        font-size: 18px;
    }
}

.active-cell {
    border: 2px solid var(--color-cell-active-border);
}

#instructions {
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--color);
    padding: 1em;
}

#virtual-keyboard {
    max-width: 100%;
    /* min-width: 100%; */
    width: 400px;
    margin: 20px auto 0;
    position: fixed;
    bottom: 0;
}

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

.key {
    background-color: var(--color-key-background);
    color: var(--color-key-text);
    border-radius: 4px;
    margin: 0 2px;
    padding: 0;
    flex-grow: 1;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    user-select: none;
    font-weight: bold;
    font-size: 14px;
    text-transform: uppercase;
    transition: transform 0.1s ease, background-color 0.1s ease, box-shadow 0.1s ease;
}

@media (max-width: 400px) {
    .key {
        height: 40px;
        font-size: 12px;
        margin: 0 1px;
    }
}

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

.key-pressed {
    transform: scale(0.95);
    background-color: var(--color-key-pressed) !important;
    box-shadow: 0 1px 1px var(--color-firework-shadow) !important;
    transition: all 0.1s ease;
}

.key-enter {
    font-size: 1.5em;
}

.key-enter,
.key-backspace {
    flex-grow: 1.5;
}

#result-popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--color-popup-bg);
    border: 2px solid var(--color-popup-border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px var(--color-popup-shadow);
    z-index: 100;
    text-align: center;
    max-width: 90%;
    width: 300px;
}

#result-popup h2 {
    color: var(--color-stats-icon);
    margin-top: 0;
}

#result-leaderboard {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--color-popup-bg);
    border: 2px solid var(--color-popup-border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px var(--color-popup-shadow);
    z-index: 100;
    text-align: center;
    max-width: 90%;
    width: 300px;
    max-height: 75vh;
}

#results-leaderboard h2 {
    margin-top: 0;
}

#result-leaderboard > div {
    display: flex;
    flex-direction: column;
    border: solid 1px #ccc;
    border-radius: 1em;
}

#result-leaderboard > div > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
}

#result-leaderboard > div > div {
    border-bottom: solid 1px #ccc;
    padding: .5em 1em;
}

#result-leaderboard > div > div:last-child {
    border-bottom: none;
}

#result-leaderboard > div:nth-of-type(1) > div > div:nth-of-type(2) {
    font-weight: bold;
}

#result-leaderboard > div:nth-of-type(2) {
    margin-top: 2.5em;
}

#result-leaderboard table td {
    text-align: right;;
}

.button {
    background-color: var(--color-green);
    color: var(--color-cell-green-text);
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 15px;
}

.button:hover {
    background-color: var(--color-green-dark);
}

#next-word-countdown {
    margin-top: 15px;
    padding: 10px;
    background-color: #f0f0f0;
    border-radius: 5px;
    font-size: 16px;
    color: #333;
    font-variant-numeric: tabular-nums;
}

h1 {
    text-align: left;
    align-self: start;
    border-bottom: 2px solid #ccc;
    width: 100%;
    padding-left: .5em;
    display: flex;
    justify-content: space-between;
    font-size: 1.5em;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    max-width: 100%;
    width: 400px;
    padding: 0em .5em;
    margin: 0 auto;
    /* padding-bottom: 10em; */
}

#rules-popup {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--background-color, #fff);
    border: 2px solid #333;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
    text-align: left;
    max-width: 90%;
    width: 400px;
}

#rules-popup h2 {
    color: var(--color);
    margin-top: 0;
    margin-bottom: .25em;
    text-align: center;
}

#rules-popup ul {
    margin: 0;
    list-style-type: none;
    padding: 0;
}

#rules-popup li {
    margin-bottom: 10px;
}

#rules-popup .example {
    background-color: var(--color-popup-bg);
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 1em;
}

#rules-popup .example p {
    margin: 0 0 1em 0;
}

#rules-popup .example p:last-child {
    margin: 0;
}

#rules-popup .number {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    background-color: #28a745;
    color: white;
    border-radius: 50%;
    margin-right: 5px;
}

#rules-popup .green-box, #rules-popup .yellow-box{
    padding: 2px 6px;
    border-radius: 3px;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    70% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    75% {
        transform: translateX(3px);
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.letter-animation {
    animation: popIn 0.2s ease-in-out forwards;
}

.error-animation {
    animation: shake .3s ease-in-out;
}

.correct-animation {
    animation: bounce 0.5s ease-in-out;
}

.row-fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

.popup-fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

.emoji-firework {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    font-size: 24px;
    will-change: transform;
    opacity: .5;
}

@keyframes firework {
    0% {
        transform: translate(0, 0) scale(0.1);
        opacity: 0;
    }

    10% {
        opacity: .5;
    }

    35% {
        transform: translate(var(--dx), var(--dy)) scale(1);
        opacity: .5;
    }

    70% {
        opacity: 0.25;
    }

    100% {
        transform: translate(var(--dx), var(--dy)) scale(0.1);
        opacity: 0;
    }
}

.green-box {
    color: var(--color-cell-green-text);
    background-color: var(--color-cell-green-background);
    /* padding: 2px 6px; */
    /* border-radius: 3px; */
}

.yellow-box {
    color: var(--color-cell-yellow-text);
    background-color: var(--color-cell-yellow-background);
    /* padding: 2px 6px; */
    /* border-radius: 3px; */
}

.gray-box {
    background-color: #6c757d;
    color: white;
}

a {
    text-decoration: none;
    color: var(--color-link);
    font-size: 16px;
}

a:hover:not(.button) {
    color: var(--color-link-hover);
}

.temp-notification {
    transition: opacity 0.5s ease;
    background-color: var(--color-notification-bg);
    color: var(--color-notification-text);
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

.fade-out {
    opacity: 0;
}


#result-share svg {
    display: inline-block;
    vertical-align: middle;
}

.stats-header {
    width: 100%;
    display: flex;
    align-items: center;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    margin-bottom: .5em;
    padding-bottom: .25em;
}

.stats-item {
    width: 100%;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding: .5em 0;
}

.stats-item:last-child {
    border-bottom: none;
}

.stats-item span,
.stats-header span {
    flex-grow: 1;
    text-align: left;
    width: 25%;
}

.stats-item span:last-child,
.stats-header span:last-child {
    text-align: right;
}

.stats-container {
    text-align: left;
    margin-bottom: 1em;
}

.chart-container {
    text-align: left;
    margin-bottom: 1em;
    height: 5em;
    width: 100%;
    background-color: var(--color-chart-bg);
    color: var(--color-chart-text);
}

.stats-container div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1em 0;
    border-bottom: 1px solid #eee;
}

.stats-container div span:last-child {
    font-weight: 600;
}

.stats-icon {
    margin-right: 0;
    color: var(--color-stats-icon);
    transition: transform 0.2s ease;
}

h1 a:hover .stats-icon {
    transform: scale(1.2);
}

.home-icon {
    color: var(--color-home-icon);
    transition: transform 0.2s ease;
}

h1 a:hover .home-icon {
    transform: scale(1.2);
}

.no-stats {
    display: none;
}

.key-pressed {
    transform: scale(0.95);
    background-color: var(--color-key-pressed) !important;
    box-shadow: 0 1px 1px var(--color-firework-shadow) !important;
    transition: all 0.1s ease;
}

.key {
    transition: transform 0.1s ease, background-color 0.1s ease, box-shadow 0.1s ease;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.pulse-animation {
    animation: pulse 1.5s infinite;
}

.cell.active-cell {
    border: 2px solid var(--color-cell-active-border);
    animation: pulse 1.5s infinite;
}

.row.error-shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes reveal {
    0% {
        transform: rotateX(90deg);
        opacity: 0;
    }

    100% {
        transform: rotateX(0deg);
        opacity: 1;
    }
}

.cell.reveal {
    backface-visibility: hidden;
    transform-style: preserve-3d;
    animation: reveal 0.6s ease forwards;
}

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

.pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-pause-bg);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

.pause-message {
    background-color: var(--color-pause-message-bg);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 12px var(--color-firework-shadow);
}

.blurred {
    filter: blur(var(--color-blur));
    transition: filter 0.3s ease;
    pointer-events: none;
}

.cell:active {
    transform: scale(0.95);
    /* Slight press effect */
    transition: transform 0.1s;
}

#actions-row {
    display: flex;
    justify-content: space-around;
    gap: 10px;
    margin-top: 20px;
}

#stats, #home {
    margin-right: .5em;
}

#rank {
    text-decoration: underline;
    cursor: pointer;
}

.your-row {
    background-color: aliceblue;
}