:root {
    --color-bg-body: hsla(200, 15%, 40%, 1);
    --color-bg-game: hsla(210, 20%, 35%, 1);
    --color-bg-cell-empty: transparent;
    --color-bg-cell-filled: hsla(200, 20%, 40%, 0.9);
    --color-bg-key-default: hsla(0, 0%, 60%, 0.9);
    --color-bg-correct: hsla(90, 75%, 60%, 0.9);
    --color-bg-present: hsla(50, 75%, 60%, 0.9);
    --color-bg-absent: transparent;
    --color-bg-button: hsl(200, 30%, 50%, 0.9);

    --color-text: hsla(0, 0%, 90%, 0.9);
    --color-text-grey: hsla(0, 0%, 75%, 0.9);
    --color-text-dark: hsla(0, 0%, 100%, 0.9);
    --color-text-message-success: hsla(90, 75%, 60%, 0.9);
    --color-text-message-error: hsla(50, 75%, 60%, 0.9);

    --color-border-grid: hsla(200, 20%, 40%, 0.9);
  
    /* Animation related, can be overridden by JS if needed */
    --cell-animation-duration: 0.3s; /* Corresponds to CELL_ANIMATION_DURATION in JS (300ms) */
    --cell-animation-delay-step: 0.1s; /* Corresponds to CELL_ANIMATION_DELAY_STEP in JS (100ms) */
    --shake-animation-duration: 0.5s;
    --dance-animation-duration: 0.6s;
    --dance-animation-iterations: 2;
}

* {
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-width: 100vw;
    margin: 0;
    padding: 0;
    background-color: var(--color-bg-body);
    color: var(--color-text);
    font-size: 2vmin;
}

a {
    color: var(--color-text);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

#game-container {
    width: 100vw;
    height: 100vh;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    
    background-color: var(--color-bg-game);
    padding-left: 0.25em;
    padding-right: 0.25em;
}

header {
    height: 2em;
    display: grid;
    grid-template-columns: 1fr auto 1fr; 
    align-items: center;
    width: 100%;
    margin: 0.25em 0.25em;
    gap: 0.5em;
}

button {
    outline: none;
}
button:hover, button:focus {
    filter: brightness(1.25);
    outline: 0.1em solid var(--color-text);
}

a:focus {
    filter: brightness(1.25);
}

.header-controls-right {
    display: flex;
    align-items: center;
    grid-column: 3;
    justify-self: end;
}

#title {
    font-size: 1.8em;
    color: var(--color-text);
    display: flex; 
    align-items: center;
    justify-content: center;
    grid-column: 2;
    justify-self: center;
}

#key-info {
    display: flex;
    align-items: center;
    grid-column: 1;
    justify-self: start;
}

#word-length-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
    margin-right: 0.5em;
}

.word-length-option {
    font-size: 0.9em;
    padding: 0.4em 0.6em;
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: 0.05em solid var(--color-border-grid);
    border-radius: 0.2em;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s, filter 0.2s;
}

.word-length-option.active {
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: 0.1em solid var(--color-text);
    font-weight: bold;
    opacity: 1;
    padding: 0.35em 0.55em;
}

.word-length-option.disabled {
    background-color: var(--color-text-grey);
    color: var(--color-text);
    cursor: not-allowed;
    opacity: 0.6;
}

.word-length-option.disabled:hover {
    background-color: inherit;
}

#message-container {
    width: 100%;
    height: 1.8em; 
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.25em;
    margin-bottom: 0.25em;
}

#message-text {
    font-size: 1.5em;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
}

#message-text a {
    display: inline;
}

.message-success {
    color: var(--color-text-message-success);
}
.message-error {
    color: var(--color-text-message-error);
}
.message-info {
    color: var(--color-text);
}

#reset-button {
    display: inline-block;
    font-size: 0.9em;
    padding: 0.4em 0.8em;
    vertical-align: middle;
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: none;
    border-radius: 0.2em;
    cursor: pointer;
    transition: background-color 0.2s, filter 0.2s;
}

#reveal-button {
    display: inline-block;
    font-size: 0.9em;
    padding: 0.4em 0.8em;
    vertical-align: middle;
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: none;
    border-radius: 0.2em;
    cursor: pointer;
    transition: background-color 0.2s, filter 0.2s;
}

#stats-button {
    display: inline-block;
    font-size: 0.9em;
    padding: 0.4em 0.8em;
    vertical-align: middle;
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: none;
    border-radius: 0.2em;
    cursor: pointer;
    transition: background-color 0.2s, filter 0.2s;
    margin-left: 0.5em;
}

#grid-container {
    outline: none;
    display: grid;
    gap: 0.25em;
}

.grid-row-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
}

.grid-row {
    display: grid;
    grid-template-columns: repeat(var(--current-word-length, 6), 1fr); 
    gap: 0.25em;
}

.lookup-icon {
    font-size: 1.2em;
    color: var(--color-text-grey);
    cursor: pointer;
}

.lookup-icon:hover {
    filter: brightness(1.25);
}

.grid-cell {
    position: relative;
    height: 1.15em;
    width: 1.35em;
    border: 0.05em solid var(--color-border-grid);
    text-align: center;
    font-weight: bold;
    background-color: var(--color-bg-cell-empty);
    transition: background-color var(--cell-animation-duration), border-color var(--cell-animation-duration), color var(--cell-animation-duration), transform calc(var(--cell-animation-duration) * 2);
    transform-style: preserve-3d;
    font-size: 4em;
    color: var(--color-text);
}

.grid-cell.filled {
    background-color: var(--color-bg-cell-filled);
    border-color: var(--color-border-grid);
}

.grid-cell.correct,
.grid-cell.present,
.grid-cell.absent {
    color: var(--color-text);
    transform: rotateX(360deg);
    transition-delay: calc(var(--cell-index) * var(--cell-animation-delay-step));
}

.grid-cell.correct {
    background-color: var(--color-bg-correct);
    border-color: var(--color-bg-correct);
    background-image: linear-gradient(45deg, rgba(0,0,0,0.1) 25%, transparent 25%, transparent 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1) 75%, transparent 75%, transparent);
    background-size: 1em 1em;
    color: var(--color-text-dark)
}

.grid-cell.present {
    background-color: var(--color-bg-cell-filled);
    border-color: var(--color-border-grid);
    background-image: radial-gradient(circle, rgba(0,0,0,0.1) 25%, transparent 25%);
    background-size: 0.26em 0.26em;
}

.grid-cell.absent {
    background-color: var(--color-bg-absent);
    border-color: var(--color-bg-absent);
    background-image: none;
    color: var(--color-text-grey)
}

#keyboard-container {
    width: 98%;
    display: flex;
    flex-direction: column;
    gap: 0.35em;
    font-size: 0.8em;
    padding-top: 0.5em;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 0.35em;
}

.key {
    position: relative;
    font-size: 2em;
    font-weight: bold;
    border: none;
    border-radius: 0.3em;
    background-color: var(--color-bg-key-default);
    color: var(--color-text);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, filter 0.2s;
    width: 3.2em;
    height: 2em;
    justify-content: center;
    align-items: center;
    flex-grow: 0;
}

.key-letter-count {
    position: absolute;
    top: 0.1em;
    right: 0.2em;
    font-size: 0.6em;
    font-weight: bold;
    background-color: hsla(0, 0%, 0%, 0.3);
    color: var(--color-text);
    border-radius: 0.5em;
    padding: 0.1em 0.3em;
    line-height: 1;
    min-width: 1em;
    text-align: center;
    pointer-events: none; /* So it doesn't interfere with key clicks */
}


.key[data-key="backspace"],
.key[data-key="enter"] {
    width: 4em;
    background-color: var(--color-bg-cell-empty);
}


.key-info.correct {
    background-color: var(--color-bg-correct);
    color: var(--color-text);
    background-image: linear-gradient(45deg, rgba(0,0,0,0.1) 25%, transparent 25%, transparent 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1) 75%, transparent 75%, transparent);
    background-size: 1em 1em;
    color: var(--color-text-dark)
}

.key.correct {
    background-color: var(--color-bg-present);
    color: var(--color-text);
    background-image: radial-gradient(circle, rgba(0,0,0,0.1) 25%, transparent 25%);
    background-size: 0.52em 0.52em;
}

.key.present, .key-info.present {
    background-color: var(--color-bg-present);
    color: var(--color-text);
    background-image: radial-gradient(circle, rgba(0,0,0,0.1) 25%, transparent 25%);
    background-size: 0.52em 0.52em;
}

.key.absent, .key-info.absent {
    background-color: var(--color-bg-absent);
    color: var(--color-text);
    background-image: none;
    color: var(--color-text-grey);
}

.key-info {
    border: none;
    border-radius: 0.2em;
    color: var(--color-text);
    cursor: default;
    text-align: center;
    width: 1.5em;
}
.key-info.key.absent, .key-info.present, .key-info.correct {
    margin-left: 0.25em;
    margin-right: 0.25em;
}

#game-info {
    font-size: 0.6em;
    color: var(--color-text);
    opacity: 0.5;
    margin-top: 0.25em;
}
#game-info a {
    color: var(--color-text);
    text-decoration: none;
}
#game-info a:hover {
    text-decoration: underline;
}

.shake {
    animation: shake-effect var(--shake-animation-duration) cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes shake-effect {
    10%, 90% { transform: translateX(-0.05em); }
    20%, 80% { transform: translateX(0.05em); }
    30%, 50%, 70% { transform: translateX(-0.1em); }
    40%, 60% { transform: translateX(0.1em); }
}

.grid-cell.dance-animation {
    animation: dance-effect var(--dance-animation-duration) ease-in-out var(--dance-animation-iterations);
}
@keyframes dance-effect {
    0%, 100% { transform: translateY(0) rotateX(360deg); }
    25% { transform: translateY(-0.3em) rotateX(360deg); }
    50% { transform: translateY(0) rotateX(360deg); }
    75% { transform: translateY(0.3em) rotateX(360deg); }
}

/* Modal styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 100; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
}

.modal-content {
    background-color: var(--color-bg-game);
    margin: 10% auto; /* 10% from the top and centered */
    padding: 1.5em;
    border: 0.1em solid var(--color-border-grid);
    width: 80%;
    border-radius: 0.5em;
    position: relative;
}

.close-button {
    color: var(--color-text-grey);
    position: absolute;
    top: 0.5em;
    right: 0.8em;
    font-size: 2em;
    font-weight: bold;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: var(--color-text);
    text-decoration: none;
}

#stats-content {
    overflow-x: auto;
}

#stats-content table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1em;
}

#stats-content th, #stats-content td {
    border: 1px solid var(--color-border-grid);
    padding: 0.5em;
    text-align: center;
}

#stats-content th {
    background-color: var(--color-bg-button);
}

#reset-stats-button {
    display: block;
    font-size: 0.9em;
    padding: 0.5em 1em;
    margin: 1.5em auto 0;
    background-color: var(--color-bg-button);
    color: var(--color-text);
    border: none;
    border-radius: 0.2em;
    cursor: pointer;
    transition: background-color 0.2s, filter 0.2s;
}
