:root {
    --background-color: #f0f2f5;
    --puzzle-background: #ffffff;
    --cell-border: transparent;
    --cell-text: #111827;
    --highlight-color: #e0f2fe;
    --active-cell-color: #bae6fd;
    --clue-text: #4b5563;
    --clue-hover: #f3f4f6;
    --font-sans: 'Inter', sans-serif;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
    --correct-word-color: #a7f3d0;
    --incorrect-word-color: #fca5a5;
}


/* ─── Base ──────────────────────────────────────────────────────────────────── */

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--cell-text);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
}

/* ─── Mobile clue bar — hidden on desktop ───────────────────────────────────── */

.mobile-clue-bar {
    display: none;
}


/* ─── Desktop layout ────────────────────────────────────────────────────────── */

.crossword-container {
    display: flex;
    gap: 40px;
    padding: 20px;
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - 40px);
    box-sizing: border-box;
}

.puzzle {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px;
    min-width: 0;
}

#puzzle-title {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--cell-text);
}

#puzzle-grid {
    display: grid;
    width: min(calc(100vh - 200px), calc(100vw - 400px));
    aspect-ratio: 1 / 1;
    gap: 3px;
}


/* ─── Cells ─────────────────────────────────────────────────────────────────── */

.cell {
    position: relative;
    /* aspect-ratio: 1/1 makes each cell square independent of row height */
    aspect-ratio: 1 / 1;
    background-color: var(--puzzle-background);
    box-sizing: border-box;
    box-shadow: var(--box-shadow);
    border-radius: 4px;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    cursor: pointer;
}

/* Empty cells (not part of any word) */
.cell:not(:has(.cell-letter)) {
    background-color: transparent;
    box-shadow: none;
    pointer-events: none;
    cursor: default;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: clamp(7px, 1vw, 11px);
    font-weight: 600;
    color: var(--clue-text);
    line-height: 1;
    pointer-events: none;
}

/* Letter display — absolutely positioned to fill cell */
.cell-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 2.2vw, 20px);
    font-weight: 600;
    color: var(--cell-text);
    user-select: none;
    pointer-events: none;
}


/* ─── Highlight states ──────────────────────────────────────────────────────── */

.cell.highlight {
    background-color: var(--highlight-color);
}

.cell.active {
    background-color: var(--active-cell-color);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}


/* ─── Clue sidebar ───────────────────────────────────────────────────────────── */

.clues {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 280px;
    max-width: 350px;
    background-color: var(--puzzle-background);
    border-radius: 8px;
    box-shadow: var(--box-shadow);
    padding: 20px;
    box-sizing: border-box;
    height: 100%;
    overflow: hidden;
}

.clue-list-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.clue-list-container h2 {
    margin-top: 0;
    border-bottom: 2px solid var(--background-color);
    padding-bottom: 5px;
    color: var(--cell-text);
}

.clue-list {
    flex-grow: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    margin: 0;
    padding: 5px;
}

.clue-list li {
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    color: var(--clue-text);
    margin-bottom: 2px;
    list-style: none;
    font-size: 14px;
}

.clue-list li:hover {
    background-color: var(--clue-hover);
}

.clue-list li.active {
    font-weight: bold;
    color: var(--cell-text);
    background-color: var(--highlight-color);
    box-shadow: inset 3px 0 0 0 var(--cell-text);
}


/* ─── Word completion animations ────────────────────────────────────────────── */

@keyframes correct-hop {
    0%   { transform: scale(1);                   background-color: var(--correct-word-color); }
    30%  { transform: scale(1.2) translateY(-8px); }
    60%  { transform: scale(0.95) translateY(2px); }
    100% { transform: scale(1);                   background-color: var(--correct-word-color); }
}

@keyframes incorrect-shake {
    0%   { transform: translateX(0);   background-color: var(--incorrect-word-color); }
    20%  { transform: translateX(-5px); }
    40%  { transform: translateX(5px); }
    60%  { transform: translateX(-3px); }
    80%  { transform: translateX(3px); }
    100% { transform: translateX(0);   background-color: var(--puzzle-background); }
}

.cell.correct-word   { animation: correct-hop    0.8s ease-in-out; }
.cell.incorrect-word { animation: incorrect-shake 0.5s ease-in-out; }


/* ─── Mobile (≤ 640px) ──────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    body {
        justify-content: flex-start;
        align-items: stretch;
        overflow-y: auto;
    }

    /* Sticky clue bar at top */
    .mobile-clue-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 100;
        width: 100%;
        padding: 10px 14px;
        box-sizing: border-box;
        background-color: var(--active-cell-color);
        border-bottom: 2px solid #7dd3fc;
        min-height: 50px;
    }

    .mobile-clue-text {
        flex: 1;
        font-size: 13px;
        font-weight: 500;
        color: var(--cell-text);
        line-height: 1.4;
    }

    .mobile-next-btn {
        flex-shrink: 0;
        background: var(--cell-text);
        color: #fff;
        border: none;
        border-radius: 20px;
        padding: 6px 14px;
        font-size: 13px;
        font-weight: 600;
        font-family: var(--font-sans);
        cursor: pointer;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-next-btn:active {
        opacity: 0.7;
    }

    /* Stack layout vertically */
    .crossword-container {
        flex-direction: column;
        height: auto;
        gap: 0;
        padding: 12px;
    }

    .puzzle {
        padding: 0;
        width: 100%;
    }

    #puzzle-title {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }

    /* Grid fills full available width */
    #puzzle-grid {
        width: 100%;
        max-width: calc(100vw - 24px);
    }

    .cell-letter {
        font-size: clamp(11px, 4.5vw, 18px);
    }

    .cell-number {
        font-size: clamp(6px, 1.8vw, 9px);
    }

    /* Keep clues visible on mobile and allow scrolling for long lists */
    .clues {
        display: block;
        width: 100%;
        box-sizing: border-box;
        height: auto;
        max-height: calc(100vh - 220px);
        overflow-y: auto;
        margin-top: 18px;
        padding: 14px;
    }

    .clue-list-container {
        flex-grow: 0;
        margin-bottom: 12px;
    }

    .clue-list {
        max-height: none;
    }
}
