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

:root {
    --bg-color: #121213;
    --bg-secondary: #1a1a1b;
    --text-color: #ffffff;
    --border-color: #3a3a3c;
    --tile-default: #3a3a3c;
    --tile-correct: #6aaa64;
    --tile-correct-hover: #5a9a54;
    --tile-present: #c9b458;
    --tile-present-hover: #b9a448;
    --tile-absent: #787c7e;
    --key-default: #818384;
    --key-hover: #9ca3a6;
    --key-absent: #3a3a3c; /* Darker color for absent keys on dark theme */
    --modal-bg: rgba(0, 0, 0, 0.8);
    --error-color: #ff6b6b;
    --error-color-light: #d32f2f;
    --tile-filled-bg: #6b46c1;
    --transition-speed: 0.2s;
}

/* Light theme */
body.light-theme {
    --bg-color: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-color: #121213;
    --border-color: #d3d6da;
    --tile-default: #d3d6da;
    --tile-correct: #6aaa64;
    --tile-correct-hover: #5a9a54;
    --tile-present: #c9b458;
    --tile-present-hover: #b9a448;
    --tile-absent: #787c7e;
    --key-default: #d3d6da;
    --key-hover: #b8bcc0;
    --key-absent: #787c7e; /* Same as tile-absent for light theme */
    --modal-bg: rgba(255, 255, 255, 0.9);
    --error-color: #d32f2f;
    --tile-filled-bg: #7c3aed;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.embedded {
    min-height: auto;
    padding: 5px;
}

.game-container {
    width: 100%;
    max-width: 480px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.game-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text-color);
}

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

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-primary {
    background-color: var(--tile-correct);
    color: var(--text-color);
}

.btn-primary:hover {
    background-color: var(--tile-correct-hover);
}

.btn-secondary {
    background-color: var(--tile-present);
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: var(--tile-present-hover);
}

.btn-icon {
    background-color: var(--bg-secondary);
    color: var(--text-color);
    padding: 8px 12px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

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

/* Common button hover/active states */
.btn:not(:disabled):hover {
    transform: translateY(-1px);
}

.btn:not(:disabled):active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Game Board */
.game-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.game-board {
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 0;
}

.board-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.board-row.inactive {
    opacity: 0.5;
}

.board-row.invalid {
    /* Visual indicator for invalid words (not in dictionary) */
    animation: shake 0.5s ease;
}

.board-row.invalid .tile {
    /* Red border for invalid word tiles */
    border-color: #ff6b6b !important;
    border-width: 2px;
}

.tile {
    width: 60px;
    height: 60px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-color);
    transition: all 0.3s ease;
    animation: tilePop 0.1s ease;
}

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

.tile.filled {
    border-color: var(--key-default);
    animation: tileFlip 0.4s ease;
}

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

/* Tile status styles */
.tile.correct,
.tile.present,
.tile.absent {
    animation: tileReveal 0.5s ease;
}

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

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

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

/* Color tiles in previous filled row (active row) based on their status */
/* IMPORTANT: Disable base tile styles for active row first */
/* This ensures base styles don't interfere with active row coloring */

/* Disable base tile status styles for active row */
.board-row.active .tile.correct,
.board-row.active .tile.present,
.board-row.active .tile.absent {
    /* Reset to default - will be overridden by specific rules below */
    background-color: var(--tile-absent) !important;
    border-color: var(--tile-absent) !important;
    color: var(--text-color) !important;
}

/* Now apply correct colors based on status classes */
/* Yellow for letters present in target word but wrong position */
.board-row.active .tile.present {
    background-color: var(--tile-present) !important;
    border-color: var(--tile-present) !important;
    color: var(--text-color) !important;
}

/* Green for letters in correct position */
.board-row.active .tile.correct {
    background-color: var(--tile-correct) !important;
    border-color: var(--tile-correct) !important;
    color: var(--text-color) !important;
}

/* Gray for letters not in target word */
.board-row.active .tile.absent {
    background-color: var(--tile-absent) !important;
    border-color: var(--tile-absent) !important;
    color: var(--text-color) !important;
}

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

.tile.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-10px);
    }
    75% {
        transform: translateX(10px);
    }
}

/* Keyboard */
.keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 0;
}

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

.key {
    min-width: 40px;
    height: 50px;
    padding: 0 12px;
    border: none;
    border-radius: 4px;
    background-color: var(--key-default);
    color: var(--text-color);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key:not(:disabled):hover {
    background-color: var(--key-hover);
    transform: translateY(-2px);
}

.key:not(:disabled):active {
    transform: translateY(0);
    background-color: var(--tile-default);
}

.key.wide {
    min-width: 60px;
    font-size: 0.75rem;
}

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

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

.key.absent {
    background-color: var(--key-absent);
    opacity: 0.5; /* Make absent keys more subtle */
}

.key:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.key:disabled:hover {
    background-color: var(--key-default);
    transform: none;
}

/* Message */
.message {
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    min-height: 24px;
    padding: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message.show {
    opacity: 1;
}

.message.error {
    color: var(--error-color);
}

.message.success {
    color: var(--tile-correct);
}

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

.modal[hidden] {
    display: none;
}

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

.modal-content {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 30px;
    max-width: 90%;
    width: 400px;
    text-align: center;
    animation: slideUp 0.3s ease;
    border: 2px solid var(--border-color);
}

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

.modal-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 15px;
    color: var(--text-color);
}

.modal-message {
    font-size: 1rem;
    margin-bottom: 25px;
    color: var(--text-color);
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-container {
        padding: 5px;
        gap: 15px;
    }

    .game-title {
        font-size: 1.5rem;
    }

    .btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .tile {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }

    .key {
        min-width: 32px;
        height: 45px;
        padding: 0 8px;
        font-size: 0.75rem;
    }

    .key.wide {
        min-width: 50px;
        font-size: 0.7rem;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
    }

    .modal-title {
        font-size: 1.5rem;
    }
}

@media (max-height: 600px) {
    .game-main {
        gap: 10px;
    }

    .game-board {
        gap: 4px;
    }

    .board-row {
        gap: 4px;
    }

    .tile {
        width: 45px;
        height: 45px;
        font-size: 1.25rem;
    }

    .keyboard {
        gap: 4px;
        padding: 5px 0;
    }

    .keyboard-row {
        gap: 4px;
    }

    .key {
        min-width: 28px;
        height: 40px;
        padding: 0 6px;
        font-size: 0.7rem;
    }

    .key.wide {
        min-width: 45px;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .btn {
        padding: 10px 18px;
    }

    .key {
        min-width: 36px;
        height: 48px;
    }

    .key.wide {
        min-width: 55px;
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles */
.btn:focus-visible,
.key:focus-visible {
    outline: 2px solid var(--tile-correct);
    outline-offset: 2px;
}

