/* ============================================
   BUFFALO WORD SEARCH — Pure CSS Styles
   ============================================ */

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1a73e8;
    --primary-dark: #1558b0;
    --accent: #00c9a7;
    --bg: #fdf8f0;
    --surface: #ffffff;
    --paper: #fffef7;
    --text: #1e293b;
    --text-muted: #64748b;
    --cell-size: 48px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.10);
    --radius: 1rem;

    /* Crayon ink colors */
    --ink-blue: #1976D2;
    --ink-green: #388E3C;
    --ink-red: #D32F2F;
    --ink-purple: #7B1FA2;
}

html, body {
    min-height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ============ GAME CONTAINER ============ */
#game-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.2rem 1.5rem 0.5rem;
}

/* ============ HEADER ============ */
.game-header {
    text-align: center;
    margin-bottom: 1rem;
}

.header-emoji {
    font-size: 2.8rem;
    line-height: 1;
    margin-bottom: 0.2rem;
    animation: bob 2.5s ease-in-out infinite;
}

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.game-header h1 {
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ============ PUZZLE SELECTOR ============ */
#puzzle-selector {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.puzzle-tab {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.35rem 0.8rem;
    border: 2px solid #e2e8f0;
    border-radius: 2rem;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.puzzle-tab.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.puzzle-tab:hover {
    border-color: var(--primary);
}

.puzzle-tab.completed {
    border-color: var(--accent);
    color: #065f46;
    background: #ecfdf5;
}

/* ============ CRAYON PALETTE ============ */
#crayon-palette {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border-radius: 2rem;
    box-shadow: var(--shadow-sm);
}

.palette-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}

.crayon-options {
    display: flex;
    gap: 0.3rem;
}

.crayon-btn {
    width: 44px;
    height: 44px;
    border: 3px solid transparent;
    border-radius: 50%;
    background: var(--paper);
    cursor: pointer;
    padding: 4px;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crayon-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.crayon-btn:hover {
    transform: scale(1.1);
}

.crayon-btn.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.15);
    transform: scale(1.1);
}

/* ============ GAME AREA ============ */
#game-area {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    justify-content: center;
}

#grid-panel {
    flex-shrink: 0;
}

/* ============ GRID WRAPPER ============ */
#grid-wrapper {
    position: relative;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    background: var(--paper);
}

/* ============ WORD SEARCH GRID ============ */
#ws-grid {
    display: grid;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    position: relative;
    z-index: 1;
}

.ws-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    cursor: inherit;
    transition: background 0.08s;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.ws-cell:hover {
    background: rgba(0,0,0,0.04);
}

/* Selecting state (during drag) — color set dynamically via inline style */
.ws-cell.ws-selecting {
    border-radius: 2px;
}

/* ============ SVG FOUND LINES OVERLAY ============ */
#found-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* ============ WORD PANEL ============ */
#word-panel {
    min-width: 200px;
    max-width: 280px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow-sm);
}

.word-panel-title {
    font-size: 0.95rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
    margin-bottom: 0.8rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid #e2e8f0;
}

#word-list {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 0.8rem;
    margin-bottom: 0.8rem;
}

#word-list li {
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0.25rem 0.4rem;
    border-radius: 0.3rem;
    letter-spacing: 0.04em;
    transition: all 0.3s;
    white-space: nowrap;
}

#word-list li.ws-found {
    text-decoration: line-through;
    text-decoration-thickness: 2.5px;
    opacity: 0.7;
}

.found-count {
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    padding-top: 0.5rem;
    border-top: 1px solid #e2e8f0;
}

/* ============ SOLVED MESSAGE ============ */
#solved-msg {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 800;
    padding: 0.7rem 1rem;
    margin-top: 1rem;
    border-radius: 2rem;
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
    animation: pop-in 0.5s ease;
}

@keyframes pop-in {
    0% { transform: scale(0.7); opacity: 0; }
    60% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

/* ============ GRID HINT ============ */
.grid-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.6rem;
    font-style: italic;
    opacity: 0.85;
    transition: opacity 0.4s;
}

.grid-hint.faded {
    opacity: 0;
}

/* ============ CONTROLS ============ */
#controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.6rem;
}

.ctrl-btn {
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0.4rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 2rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
}

.ctrl-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.ctrl-btn:active {
    transform: scale(0.97);
}

/* ============ BMC ============ */
.bmc-game-prompt {
    text-align: center;
    margin-top: 0.8rem;
}

.bmc-text-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.bmc-text-link:hover {
    opacity: 1;
    color: #7a6835;
}

/* ============ BACK NAV ============ */
.back-nav {
    text-align: center;
    padding: 0.8rem 1rem 1.5rem;
}

.back-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.2s;
}

.back-nav a:hover {
    color: var(--primary);
}

.bmc-nav-link {
    color: var(--primary) !important;
    font-weight: 700;
}

.bmc-nav-link:hover {
    color: var(--primary-dark) !important;
}

.back-nav-sep {
    color: #cbd5e1;
    margin: 0 0.4rem;
}

/* ============ UTILITY ============ */
.hidden {
    display: none !important;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    :root {
        --cell-size: 40px;
    }

    #game-area {
        flex-direction: column;
        align-items: center;
    }

    #word-panel {
        max-width: none;
        width: 100%;
    }

    #word-list {
        grid-template-columns: repeat(3, 1fr);
    }

    .game-header h1 {
        font-size: 1.3rem;
    }

    .header-emoji {
        font-size: 2.2rem;
    }

    #puzzle-selector {
        gap: 0.3rem;
    }

    .puzzle-tab {
        font-size: 0.65rem;
        padding: 0.25rem 0.6rem;
    }
}

@media (max-width: 600px) {
    :root {
        --cell-size: 34px;
    }

    .ws-cell {
        font-size: 1rem;
    }

    #word-list {
        grid-template-columns: 1fr 1fr;
    }

    #word-list li {
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    :root {
        --cell-size: 28px;
    }

    .ws-cell {
        font-size: 0.82rem;
    }

    #word-list li {
        font-size: 0.72rem;
    }

    .word-panel-title {
        font-size: 0.8rem;
    }
}
