* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark theme (default) */
    --bg-primary: #121213;
    --bg-secondary: #1a1a1b;
    --text-primary: #ffffff;
    --text-secondary: #aaa;
    --border-color: #3a3a3c;
    --border-filled: #565758;

    /* Tile colors */
    --tile-bg: #121213;
    --tile-correct: #538d4e;
    --tile-present: #b59f3b;
    --tile-absent: #3a3a3c;
    --tile-locked: #8b2e2e;

    /* Lock icon colors (darker versions) */
    --lock-correct: #3a6e35;
    --lock-present: #8a7a2a;
    --lock-absent: #2a2a2c;

    /* Button colors */
    --btn-primary: #538d4e;
    --btn-primary-hover: #6aaa64;
    --btn-secondary: #818384;
    --btn-secondary-hover: #9a9a9a;
    --btn-mode: #3a3a3c;
    --btn-mode-hover: #4a4a4c;

    /* Keyboard */
    --key-bg: #818384;
    --key-hover: #9a9a9a;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #1a1a1b;
    --text-secondary: #787c7e;
    --border-color: #d3d6da;
    --border-filled: #878a8c;

    /* Tile colors */
    --tile-bg: #ffffff;
    --tile-correct: #6aaa64;
    --tile-present: #c9b458;
    --tile-absent: #787c7e;
    --tile-locked: #d85656;

    /* Lock icon colors (darker versions) */
    --lock-correct: #4a7a44;
    --lock-present: #998438;
    --lock-absent: #58595e;

    /* Button colors */
    --btn-primary: #6aaa64;
    --btn-primary-hover: #538d4e;
    --btn-secondary: #878a8c;
    --btn-secondary-hover: #787c7e;
    --btn-mode: #d3d6da;
    --btn-mode-hover: #b3b6ba;

    /* Keyboard */
    --key-bg: #d3d6da;
    --key-hover: #b3b6ba;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 500px;
    width: 100%;
    padding: 12px;
    padding-bottom: 60px; /* Space for banner ad on mobile */
}

header {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding: 8px 10px 12px 10px;
    margin-bottom: 8px;
    position: relative;
}

#settings-btn {
    position: absolute;
    top: 8px;
    right: 10px;
}

.icon-btn {
    background-color: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--btn-mode-hover);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.header-buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

h1 {
    font-size: 30px;
    font-weight: bold;
    letter-spacing: 0.5px;
    margin: 0;
}

#stats-btn,
#new-game-btn {
    background-color: var(--btn-primary);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 13px;
    font-weight: bold;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#stats-btn:hover,
#new-game-btn:hover {
    background-color: var(--btn-primary-hover);
}

#how-to-play-btn {
    background-color: var(--btn-secondary);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 13px;
    font-weight: bold;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#how-to-play-btn:hover {
    background-color: var(--btn-secondary-hover);
}

/* Settings Modal Content */
.settings-section {
    margin-bottom: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.setting-item label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    cursor: pointer;
}

.setting-label {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-primary);
}

.setting-description {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Theme Toggle Button Inside Settings */
.theme-toggle-container {
    flex-shrink: 0;
}

.theme-toggle-btn {
    background-color: var(--btn-secondary);
    border: none;
    border-radius: 20px;
    padding: 4px;
    cursor: pointer;
    display: flex;
    gap: 4px;
    position: relative;
    transition: background-color 0.2s ease;
}

.theme-toggle-btn:hover {
    background-color: var(--btn-secondary-hover);
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    transition: all 0.2s ease;
    cursor: pointer;
}

.theme-option.active {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Ensure icon colors follow text color */
.theme-option svg {
    color: inherit;
}

.theme-icon {
    width: 18px;
    height: 18px;
    display: block;
}

.mode-selector {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 12px;
}

.mode-btn {
    background-color: var(--btn-mode);
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: bold;
    padding: 10px 30px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.mode-btn:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}

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

.mode-btn:not(.active):hover {
    background-color: var(--btn-mode-hover);
}

.mode-btn.completed:not(.active) {
    background-color: var(--btn-mode-hover);
    color: var(--text-secondary);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal.open {
    display: block;
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 2% auto 5% auto;
    padding: 25px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    color: var(--text-primary);
    position: relative;
}

.modal-content h2 {
    margin-top: 0;
    font-size: 24px;
    margin-bottom: 15px;
}

.modal-content h3 {
    font-size: 16px;
    margin-top: 15px;
    margin-bottom: 10px;
}

.modal-content p {
    line-height: 1.5;
    margin-bottom: 8px;
    font-size: 14px;
}

.modal-content ul {
    margin-left: 18px;
    margin-bottom: 12px;
}

.modal-content li {
    margin-bottom: 6px;
    font-size: 14px;
}

/* Example tiles in How to Play modal */
.example-tiles {
    margin: 15px 0;
}

.example-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.example-tile {
    width: 55px;
    height: 55px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    text-transform: uppercase;
    background-color: var(--tile-bg);
    color: white;
    position: relative;
    flex-shrink: 0;
}

.example-tile .letter {
    z-index: 1;
}

.example-tile .lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: block;
    pointer-events: none;
    opacity: 1;
}

.example-tile .lock-icon svg {
    display: block;
    width: 36px;
    height: 36px;
}

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

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

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

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


.example-text {
    flex: 1;
    line-height: 1.5;
    font-size: 14px;
}

.example-text strong {
    display: block;
    margin-bottom: 3px;
    font-size: 14px;
}

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

.close:hover,
.close:focus {
    color: var(--text-primary);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
    position: relative;
}

#game-board {
    display: grid;
    grid-template-rows: repeat(8, 1fr);
    gap: 5px;
    margin-bottom: 8px;
}

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

.tile {
    width: 62px;
    height: 62px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    text-transform: uppercase;
    background-color: var(--tile-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
    position: relative;
}

.tile .lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    pointer-events: none;
    opacity: 1;
}

.tile .lock-icon svg {
    display: block;
    width: 40px;
    height: 40px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Colored lock icons for evaluated tiles */
.tile .lock-icon.lock-correct svg rect {
    fill: var(--lock-correct);
}

.tile .lock-icon.lock-correct svg path {
    stroke: var(--lock-correct);
    fill: none;
}

.tile .lock-icon.lock-present svg rect {
    fill: var(--lock-present);
}

.tile .lock-icon.lock-present svg path {
    stroke: var(--lock-present);
    fill: none;
}

.tile .lock-icon.lock-absent svg rect {
    fill: var(--lock-absent);
}

.tile .lock-icon.lock-absent svg path {
    stroke: var(--lock-absent);
    fill: none;
}

/* Gold/silver animated lock that appears in corner */
.tile .lock-icon-anim {
    position: absolute;
    top: 4px;
    right: 4px;
    display: none;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
    z-index: 10;
}

.tile .lock-icon-anim svg {
    display: block;
    width: 20px;
    height: 20px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

/* Show and animate the corner lock */
.tile.lock-revealing .lock-icon-anim {
    display: block;
    animation: lockCornerReveal 0.8s ease-out forwards;
}

@keyframes lockCornerReveal {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-20deg);
    }
    40% {
        opacity: 1;
        transform: scale(1.2) rotate(5deg);
    }
    60% {
        transform: scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: scale(0.8);
    }
}

.tile .letter {
    z-index: 1;
}

.tile.filled {
    border-color: var(--border-filled);
    animation: pop 0.1s ease-in-out;
}

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

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

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

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

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

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

/* Shake animation for invalid words */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* Bounce animation for winning */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
        animation-timing-function: ease-in;
    }
    50% {
        transform: translateY(-20px);
        animation-timing-function: ease-out;
    }
}

/* Locked letter reveal animation */
@keyframes lockedReveal {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Pulse animation for lock icons */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.8;
    }
}

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Fade out animation */
@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Fade in animation for messages */
@keyframes slideIn {
    from {
        transform: translateX(-50%) translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Fade out animation for messages */
@keyframes slideOut {
    from {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
    to {
        transform: translateX(-50%) translateY(-10px);
        opacity: 0;
    }
}

/* Success pulse for buttons */
@keyframes successPulse {
    0%, 100% {
        transform: scale(1);
    }
    25% {
        transform: scale(0.95);
    }
    50% {
        transform: scale(1.05);
    }
    75% {
        transform: scale(0.98);
    }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

#message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    min-width: 200px;
}

#message.error {
    background-color: #8b2e2e;
    color: white;
}

#message.success {
    background-color: #4CAF50;
    color: white;
}

#keyboard {
    margin-top: 10px;
}

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

.key {
    background-color: var(--key-bg);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    padding: 14px;
    min-width: 43px;
    cursor: pointer;
    text-transform: uppercase;
    transition: background-color 0.1s ease;
}

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

.key.wide {
    min-width: 65px;
    font-size: 12px;
}

/* Backspace key - center SVG icon */
#key-BACK {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
}

#key-BACK svg {
    width: 24px;
    height: 24px;
}

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

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

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

/* Statistics Modal */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
    color: var(--text-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
}

#guess-distribution {
    margin-top: 15px;
}

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

.distribution-label {
    width: 15px;
    font-size: 14px;
    font-weight: bold;
    margin-right: 5px;
}

.distribution-bar {
    background-color: var(--btn-mode);
    color: white;
    padding: 4px 8px;
    min-width: 20px;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    transition: width 0.3s ease;
}

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

#stats-modal #share-btn {
    margin-top: 20px;
    width: 100%;
    background-color: var(--btn-primary);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 16px;
    font-weight: bold;
    padding: 12px 24px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#stats-modal #share-btn:hover {
    background-color: var(--btn-primary-hover);
}

.support-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.support-section p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.kofi-btn {
    display: inline-block;
    background-color: #13C3FF;
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.kofi-btn:hover {
    background-color: #0fb9f1;
    transform: translateY(-1px);
}

.kofi-icon {
    font-size: 16px;
    margin-right: 5px;
}

/* Tablet/medium screens */
@media screen and (max-width: 800px) {
    h1 {
        font-size: 28px;
    }

    #stats-btn,
    #new-game-btn,
    #how-to-play-btn {
        font-size: 12px;
        padding: 8px 12px;
    }

    .header-buttons {
        gap: 8px;
    }
}

/* Mobile responsive styles */
@media screen and (max-width: 600px) {
    .container {
        padding: 10px;
    }

    header {
        padding-bottom: 15px;
        margin-bottom: 10px;
    }

    h1 {
        font-size: 24px;
    }

    .header-buttons {
        gap: 6px;
        margin-bottom: 12px;
    }

    #how-to-play-btn,
    #stats-btn,
    #new-game-btn {
        font-size: 11px;
        padding: 8px 10px;
    }

    /* Smaller tiles */
    .tile {
        width: 52px;
        height: 52px;
        font-size: 28px;
    }

    .tile .lock-icon svg {
        width: 32px;
        height: 32px;
    }

    /* Keyboard on mobile */
    .key {
        font-size: 13px;
        padding: 14px;
        min-width: 43px;
    }

    .key.wide {
        min-width: 65px;
        font-size: 12px;
    }

    .keyboard-row {
        gap: 6px;
        margin-bottom: 8px;
    }

    /* Smaller mode buttons */
    .mode-btn {
        font-size: 12px;
        padding: 8px 20px;
    }

    /* Modal adjustments - fit on one screen */
    .modal-content {
        margin: 2% auto;
        padding: 15px;
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content h2 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .modal-content h3 {
        font-size: 15px;
        margin-top: 12px;
        margin-bottom: 6px;
    }

    .modal-content p {
        font-size: 13px;
        line-height: 1.4;
        margin-bottom: 8px;
    }

    .modal-content ul {
        margin-left: 18px;
        margin-bottom: 10px;
    }

    .modal-content li {
        font-size: 13px;
        line-height: 1.4;
        margin-bottom: 6px;
    }

    .example-tiles {
        margin: 12px 0;
    }

    /* Smaller example tiles on mobile */
    .example-tile {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }

    .example-tile .lock-icon svg {
        width: 28px;
        height: 28px;
    }

    .example-row {
        gap: 10px;
        margin-bottom: 10px;
    }

    .example-text {
        font-size: 13px;
        line-height: 1.4;
    }

    /* Stats grid - 2x2 on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .stat-value {
        font-size: 28px;
    }

    #message {
        font-size: 16px;
        padding: 10px 20px;
    }

    #stats-modal #share-btn {
        font-size: 14px;
        padding: 10px 20px;
    }
}

/* Extra small phones */
@media screen and (max-width: 380px) {
    h1 {
        font-size: 20px;
    }

    .tile {
        width: 46px;
        height: 46px;
        font-size: 24px;
    }

    .tile .lock-icon svg {
        width: 28px;
        height: 28px;
    }

    .key {
        font-size: 13px;
        padding: 14px 0;
        min-width: 28px;
        flex: 1;
    }

    .key.wide {
        min-width: 50px;
        font-size: 11px;
        flex: 1.5;
    }

    /* Backspace icon size on small phones */
    #key-BACK svg {
        width: 24px;
        height: 24px;
    }

    .keyboard-row {
        gap: 3px;
        width: 100%;
    }

    /* Modal even smaller on tiny screens */
    .modal-content {
        padding: 12px;
        margin: 1% auto;
    }

    .modal-content h2 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .modal-content h3 {
        font-size: 14px;
        margin-top: 10px;
        margin-bottom: 5px;
    }

    .modal-content p,
    .modal-content li {
        font-size: 12px;
        line-height: 1.3;
    }

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

    .example-tile .lock-icon svg {
        width: 24px;
        height: 24px;
    }

    .example-row {
        gap: 8px;
        margin-bottom: 8px;
    }

    .example-text {
        font-size: 12px;
    }
}
