/* Core styles and theme variables */
*, *::after, *::before {
    box-sizing: border-box;
    font-family: Arial;
}

:root {
    /* Dark theme variables */
    --background: hsl(240, 3%, 7%);
    --text: white;
    --tile-border: hsl(240, 2%, 23%);
    --key-bg: hsl(200, 1%, 50%);
    --modal-bg: hsl(240, 3%, 7%);
    --share-text-bg: hsl(240, 2%, 23%);
    --alert-bg: hsl(0, 0%, 20%);
    --color-correct: hsl(115, 29%, 43%);
    --color-wrong: hsl(240, 2%, 23%);
    --color-wrong-location: hsl(49, 51%, 47%);
    --tile-text: white;
}

[data-theme="light"] {
    /* Light theme variables */
    --background: hsl(0, 0%, 95%);
    --text: black;
    --tile-border: hsl(240, 2%, 83%);
    --key-bg: hsl(200, 1%, 70%);
    --modal-bg: white;
    --share-text-bg: hsl(0, 0%, 90%);
    --alert-bg: hsl(0, 0%, 80%);
    --color-correct: hsl(115, 29%, 43%);
    --color-wrong: hsl(240, 2%, 60%);
    --color-wrong-location: hsl(49, 51%, 65%);
    --tile-text: white;
}

/* Base styles */
body {
    background-color: var(--background);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    padding-top: 100px;
    font-size: clamp(0.5rem, 2vmin, 1.2rem);
    position: relative;
}

/* Game layout */
.game-container {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0 auto;
    padding: 2.5rem 0 0 0;
    padding-bottom: 1rem;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1em;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.keyboard .row {
    display: flex;
    gap: 0.5rem;
    height: min(12vh, 4.5em);
    width: 100%;
    justify-content: center;
}

.key {
    font-size: min(4vh, 1.5em);
    font-weight: bold;
    padding: 0.5em;
    border: none;
    border-radius: 0.25em;
    background-color: var(--key-bg);
    color: var(--text);
    cursor: pointer;
    user-select: none;
    text-transform: uppercase;
    min-width: min(12vw, 3em);
    height: 100%;
}

.key.large {
    min-width: min(18vw, 5em);
    padding-left: 0.5em;
    padding-right: 0.5em;
}

.key:hover {
    --lightness-offset: 10%;
}

.backspace-icon {
    width: min(5vw, 1.5em);
    height: min(5vw, 1.5em);
    display: block;
    margin: auto;
}

/* Update stroke color to match text */
.key .backspace-icon {
    color: var(--text);  /* This works with stroke="currentColor" */
}

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

.key.wrong-location {
    background-color: var(--color-wrong-location);
    color: var(--tile-text);
}

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

.guess-grid {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0 auto;
}

.row {
    display: grid;
    grid-template-columns: 40px repeat(5, 3em) 40px;
    gap: 5px;
    margin: 0;
    justify-content: center;
    align-items: center;
}

.padding-cell, .dictionary-cell {
    width: 40px;
    height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile {
    width: 3em;
    height: 3em;
    font-size: 2em;
    color: var(--text);
    border: 0.08em solid var(--tile-border);
    text-transform: uppercase;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    transition: transform 100ms ease;
    aspect-ratio: 1;
}

/* Update the active tile state */
.tile[data-state="active"] {
    border: 0.12em solid var(--key-bg);
    outline: none;  /* Remove default outline */
    -webkit-tap-highlight-color: transparent;  /* Remove iOS tap highlight */
}

/* Optional: Add a subtle animation when typing */
.tile {
    width: 3em;
    height: 3em;
    font-size: 2em;
    color: var(--text);
    border: 0.08em solid var(--tile-border);
    text-transform: uppercase;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    transition: transform 100ms ease;  /* Add transition for smooth scaling */
}

/* Optional: Add a subtle pop animation when letter is entered */
.tile[data-state="active"] {
    animation: pop 100ms ease-in-out;
}

@keyframes pop {
    from {
        transform: scale(0.8);
    }
    40% {
        transform: scale(1.1);
    }
    to {
        transform: scale(1);
    }
}

/* Optional tile states */
.tile[data-state="wrong"] {
    border: none;
    background-color: var(--color-wrong);
    color: var(--tile-text);
}

.tile[data-state="wrong-location"] {
    border: none;
    background-color: var(--color-wrong-location);
    color: var(--tile-text);
}

.tile[data-state="correct"] {
    border: none;
    background-color: var(--color-correct);
    color: var(--tile-text);
}

/* Add shake animation */
@keyframes shake {
    20% {
        transform: translateX(-6px);    /* Reduced from -12px */
    }
    40% {
        transform: translateX(6px);     /* Reduced from 12px */
    }
    60% {
        transform: translateX(-6px);    /* Reduced from -12px */
    }
    80% {
        transform: translateX(6px);     /* Reduced from 12px */
    }
}

.tile.shake {
    animation: shake 0.3s cubic-bezier(.36,.07,.19,.97);
}

/* Alert styling */
.alert {
    position: fixed;
    top: 10vh;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75em 1.5em;
    border-radius: 4px;
    color: var(--text);
    background-color: var(--alert-bg);
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
    text-align: center;
    max-width: 90%;
    white-space: nowrap;
    font-size: 1.1em;
    z-index: 1000;
}

.alert.visible {
    opacity: 1;
}

.tile.flip {
    transform-style: preserve-3d;
    animation: flip 0.5s ease;
}

@keyframes flip {
    0% {
        transform: rotateX(0deg);
    }
    45% {
        transform: rotateX(90deg);
        background-color: transparent;
        border: 0.08em solid hsl(240, 2%, 23%);
    }
    55% {
        transform: rotateX(90deg);
        background-color: var(--background-color);
        border: none;
    }
    100% {
        transform: rotateX(0deg);
    }
}

/* Add celebration animations */
@keyframes celebrate {
    0% {
        transform: translateY(0) rotate(0);
    }
    25% {
        transform: translateY(-20px) rotate(-5deg);
    }
    50% {
        transform: translateY(5px) rotate(5deg);
    }
    75% {
        transform: translateY(-10px) rotate(-3deg);
    }
    100% {
        transform: translateY(0) rotate(0);
    }
}

.tile.celebrate {
    animation: celebrate 0.8s ease-in-out infinite;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.button-container {
    position: fixed;
    top: 1em;
    right: 1em;
    display: flex;
    gap: 0.5em;
}

.reset-button {
    padding: 0.5em 1em;
    font-size: 1em;
    font-weight: bold;
    color: var(--text);
    background-color: hsl(115, 29%, 43%);
    border: none;
    border-radius: 0.25em;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.reset-button:hover {
    opacity: 0.8;
}

.theme-toggle {
    padding: 0.5em 1em;
    font-size: 1em;
    background-color: transparent;
    border: none;
    cursor: pointer;
    color: var(--text);
    transition: opacity 0.2s ease;
}

.theme-toggle:hover {
    opacity: 0.8;
}

.share-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1001;
    display: none;
    justify-content: center;
    align-items: center;
}

.share-modal.visible {
    display: flex;
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 2em;
    border-radius: 8px;
    text-align: center;
    max-width: 90%;
    width: 400px;
}

.modal-content h2 {
    color: var(--text);
    margin-top: 0;
    font-family: Arial;
}

#share-text {
    background-color: var(--share-text-bg);
    padding: 1em;
    border-radius: 4px;
    color: var(--text);
    font-family: Arial;
    font-size: 1.2em;
    white-space: pre-wrap;
    margin: 1em 0;
    text-align: left;
}

.share-button, .close-button {
    padding: 0.5em 1em;
    font-size: 1em;
    font-weight: semibold;
    color: white;
    border: none;
    border-radius: 0.25em;
    cursor: pointer;
    transition: opacity 0.2s ease;
    margin: 0.5em;
}

.share-button {
    background-color: hsl(115, 29%, 43%);
    font-size: 1.5em;
    padding: 0.75em 1.25em;
}

.close-button {
    background-color: hsl(200, 1%, 50%);
}

.share-button:hover, .close-button:hover {
    opacity: 0.8;
}

/* Update dictionary cell styling to match padding cell */
.dictionary-cell {
    position: relative;
    right: 0;
    top: auto;
    transform: none;
}

.dictionary-button-wrapper {
    width: 2.5em;
    height: 2.5em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-info {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: var(--text);
    opacity: 0.7;
    transition: opacity 0.2s ease;
    height: 2em;
    width: 2em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-info:hover {
    opacity: 1;
}

.row-info svg {
    width: 24px;
    height: 24px;
}

/* Add styles for the padding cell to match dictionary-cell */
.padding-cell {
    width: 40px;  /* Match the width of dictionary-cell */
    height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Update the row styling if needed */
.row {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Dictionary Definition Styles */
.definition-list {
    padding-left: 1.5em;
}

.definition-entry {
    margin-bottom: 0.6em;
}

/* Typography styles */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    line-height: 1.2;
    border-bottom: 1px solid var(--tile-border);
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 2rem;
    font-weight: 600;
}

.modal-buttons {
    display: flex;
    gap: 1em;
    justify-content: center;
    margin-top: 1em;
}

.share-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.75em 1em;
}

.share-button svg {
    flex-shrink: 0;
}

/* Prevent double-tap zoom on touch devices */
* {
    touch-action: manipulation;
}

/* Optional: For specific elements like buttons */
.key, .share-button, .tile {
    touch-action: manipulation;
}

/* Mobile and Small Screen Styles */
@media (max-width: 480px) {
    .keyboard {
        margin-top: 40px;
        width: 100%;
        gap: 0.25rem;
    }
    
    .keyboard .row {
        gap: 0.25rem;
        height: 4em;
        margin-bottom: .5rem;
        margin-top: .5rem;
    }
    
    .key {
        padding: 0.25em;
        min-width: 9vw;
        font-size: 1.4em;
        height: 4em;
    }
    
    .key.large {
        min-width: 14vw;
        font-size: 1.3em;
    }

    h1 {
        font-size: 2.75rem;
        letter-spacing: -0.03em;
        margin-bottom: 1rem;
    }

    h2 {
        font-size: 1.5rem;
        letter-spacing: -0.01em;
    }

    .share-modal .modal-content {
        font-size: 1.2em;
    }

    .share-modal .share-button {
        font-size: 1.6em;
        padding: 0.75em 1.5em;
    }

    #share-text {
        font-size: 1.3em;
    }
}

@media (max-width: 360px) {
    .keyboard {
        margin-top: 70px;
        gap: 0.2rem;
    }
    
    .keyboard .row {
        gap: 0.2rem;
        height: 3.5em;
        margin-bottom: .5rem;
        margin-top: .5rem;
    }
    
    .key {
        min-width: 8.5vw;
        font-size: 1.3em;
        height: 3.5em;
        margin-bottom: 0.5rem;
    }
    
    .key.large {
        min-width: 13vw;
    }

    h1 {
        font-size: 2.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .share-modal .modal-content {
        font-size: 1.3em;
    }

    .share-modal .share-button {
        font-size: 1.7em;
        padding: 0.75em 1.75em;
    }

    #share-text {
        font-size: 1.4em;
    }
}
