:root {
    --bg-light: #f5f2eb;
    /* Warm, creamy studio wall */
    --text-primary: #3a3836;
    --text-secondary: #7a7571;
    --font-family: 'Outfit', sans-serif;

    --grid-size: 6;
    --board-padding: 0.5rem;
    --tile-gap: 4px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--bg-light);
    font-family: var(--font-family);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    /* Soft noise texture or vignette for physical vibe */
    background-image: radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.03) 100%);
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 900px;
    padding: 2rem;
    z-index: 1;
}

header {
    text-align: center;
    margin-top: 3rem;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
    text-shadow: 1px 2px 0px rgba(255, 255, 255, 0.8);
}

header h1#player-name-display {
    color: #e63946;
    min-height: 3.8rem; /* Keeps layout from shifting before name is typed */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

header p {
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin: 0 0 1.5rem 0;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
}

.stats-container {
    position: absolute;
    top: 2rem;
    left: 2rem;
    right: 2rem;
    display: flex;
    justify-content: space-between;
    z-index: 50;
    pointer-events: none;
}

.moves-display,
.score-display {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    pointer-events: auto;
}

#moves-count,
#score-count {
    color: #c97a7e;
    /* A muted terracotta */
}

button {
    background: linear-gradient(135deg, #e8e4db 0%, #dcd8cf 100%);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.6);
    padding: 0.8rem 2rem;
    border-radius: 99px;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.05),
        inset 1px 1px 2px rgba(255, 255, 255, 0.8);
}

button:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.08),
        inset 1px 1px 2px rgba(255, 255, 255, 0.9);
}

button:active {
    transform: translateY(1px);
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.1);
}

button.active {
    background: #c97a7e;
    color: white;
    border-color: transparent;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.1);
}

.game-board {
    position: relative;
    width: min(95vw, 1200px);
    height: min(95vw, 1200px);
    background: #e0dbce;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    padding: var(--board-padding);
    /* Inset shadow making the board look like a recessed tray holding the ceramic tiles */
    box-shadow:
        inset 3px 3px 8px rgba(0, 0, 0, 0.1),
        inset -3px -3px 8px rgba(255, 255, 255, 0.5),
        0 20px 40px -10px rgba(0, 0, 0, 0.1);
}

.tile {
    position: absolute;
    width: calc((100% - (var(--board-padding) * 2)) / var(--grid-size));
    height: calc((100% - (var(--board-padding) * 2)) / var(--grid-size));
    padding: var(--tile-gap);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 2;
}

.tile-inner {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    /* classic ceramic square feel */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 3.5vmin, 2rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #ffffff;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    text-align: center;
    padding: 0.15rem;

    /* Materic Ceramic Styling */
    background-color: #f0f0f0;
    /* Default fallback */
    /* Glossy glaze effect with gradients + raw ceramic texture overlay */
    background-image:
        linear-gradient(135deg, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 40%, rgba(0, 0, 0, 0.05) 100%),
        url('ceramic.png');
    background-size: cover, 150px 150px;
    background-blend-mode: normal, multiply;
    box-shadow:
        inset 1px 1px 3px rgba(255, 255, 255, 0.9),
        /* Top-left glaze highlight */
        inset -2px -2px 5px rgba(0, 0, 0, 0.15),
        /* Bottom-right rounded shadow */
        2px 3px 5px rgba(0, 0, 0, 0.2),
        /* Drop shadow for physical depth */
        0 1px 2px rgba(0, 0, 0, 0.1);
    /* Debossed/etched text effect for white text */
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), 0 -1px 1px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.05);
    text-transform: lowercase;
}

.tile:not(.empty-tile):hover .tile-inner {
    transform: translateY(-2px);
    box-shadow:
        inset 1px 1px 2px rgba(255, 255, 255, 1),
        inset -2px -2px 4px rgba(0, 0, 0, 0.08),
        2px 6px 8px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.1);
}

.game-board.has-selection .tile-inner.selected {
    border: 1px solid #0c9c67;
    box-shadow:
        inset 0 0 0 2px #ffffff,
        inset 1px 1px 3px rgba(255, 255, 255, 0.9),
        inset -2px -2px 5px rgba(0, 0, 0, 0.15),
        2px 3px 5px rgba(0, 0, 0, 0.2),
        0 0 15px rgba(255, 255, 255, 0.6);
}

.game-board.has-selection .tile:not(.empty-tile):hover .tile-inner.selected {
    transform: translateY(-2px);
    box-shadow:
        inset 0 0 0 2px #ffffff,
        inset 1px 1px 2px rgba(255, 255, 255, 1),
        inset -2px -2px 4px rgba(0, 0, 0, 0.08),
        2px 6px 8px rgba(0, 0, 0, 0.15),
        0 4px 15px rgba(255, 255, 255, 0.8);
}

.game-board.has-selection .tile:not(.empty-tile) .tile-inner:not(.selected) {
    opacity: 0.4;
}


/* Empty tile styling */
.empty-tile {
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}

/* Add a very soft success animation when solved */
@keyframes solved-burst {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

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

.solved .tile-inner {
    animation: solved-burst 0.5s ease-out;
}

/* Modal and Name Display */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #e8e4db;
    padding: 2.5rem 3rem;
    border-radius: 16px;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.15),
        inset 2px 2px 5px rgba(255, 255, 255, 0.8),
        inset -2px -2px 5px rgba(0, 0, 0, 0.05);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.6);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    max-width: 90%;
}

.modal-overlay.hidden .modal-content {
    transform: translateY(-20px);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 2rem;
    color: var(--text-primary);
    text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.8);
}

.modal-content input {
    width: 100%;
    padding: 1rem;
    margin: 1.5rem 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 1.2rem;
    font-family: var(--font-family);
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.05);
    background: #f5f2eb;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-content input:focus {
    border-color: #c97a7e;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(201, 122, 126, 0.2);
}

.game-title {
    color: var(--text-secondary);
    font-size: 1.2rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 0;
    pointer-events: auto;
}

.modal-content textarea {
    width: 100%;
    padding: 1rem;
    margin: 1.5rem 0 0.5rem 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 1.1rem;
    font-family: var(--font-family);
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.05);
    background: #f5f2eb;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    resize: vertical;
}

.modal-content textarea:focus {
    border-color: #c97a7e;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(201, 122, 126, 0.2);
}

#word-count-indicator {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: right;
    font-weight: 600;
}

#word-count-indicator.ready {
    color: #0c9c67;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #e0dbce;
    color: var(--text-secondary);
    box-shadow: none;
    transform: none;
}

.saved-comment {
    margin-top: 2rem;
    padding: 1.5rem;
    font-size: 1.6rem;
    color: var(--text-primary);
    background: #e8e4db;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 
        0 4px 6px rgba(0, 0, 0, 0.05),
        inset 1px 1px 2px rgba(255, 255, 255, 0.8);
    text-align: center;
    width: min(95vw, 1200px);
}

.saved-comment.hidden {
    display: none;
}

.image-footer {
    margin-top: 1.5rem;
    padding: 0.75rem;
    font-size: 1.2rem;
    color: var(--text-secondary);
    text-align: center;
    letter-spacing: 0.05em;
    opacity: 0.7;
}

.image-footer.hidden {
    display: none;
}