/* ============================================
   BUFFALO CROSSWORD — Pure CSS Styles
   ============================================ */

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1a73e8;
    --primary-dark: #1558b0;
    --accent: #00c9a7;
    --purple: #7c3aed;
    --bg: #fdf8f0;
    --surface: #ffffff;
    --paper: #fffef7;
    --text: #1e293b;
    --text-muted: #64748b;
    --cell-size: 64px;
    --grid-gap: 2px;
    --blocked: #2d3436;
    --highlight: #fff9c4;
    --highlight-strong: #fff176;
    --correct: #c8e6c9;
    --wrong: #ffcdd2;
    --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;
}

#grid-panel {
    flex-shrink: 0;
}

/* ============ CROSSWORD GRID ============ */
#crossword-grid {
    display: grid;
    gap: var(--grid-gap);
    background: var(--blocked);
    border: 3px solid var(--blocked);
    border-radius: 4px;
    padding: var(--grid-gap);
    box-shadow: var(--shadow-md);
    user-select: none;
    position: relative;
}

.xw-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--paper);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: inherit;
    transition: background 0.12s, box-shadow 0.12s;
}

/* Empty cell affordance — subtle inner dotted border to invite typing */
.xw-cell.xw-empty::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1.5px dashed #c8c0b0;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0.6;
}

.xw-cell:hover {
    box-shadow: inset 0 0 0 2px var(--primary);
    background: #f5f0e3;
}

.xw-cell.xw-selected.xw-empty::after,
.xw-cell.xw-word-highlight.xw-empty::after {
    border-color: #a09070;
    opacity: 0.4;
}

.xw-blocked {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--blocked);
}

.xw-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #555;
    line-height: 1;
    pointer-events: none;
}

.xw-letter {
    font-size: 1.85rem;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
    text-transform: uppercase;
    /* Color is set dynamically per cell */
}

/* Highlight states */
.xw-word-highlight {
    background: var(--highlight) !important;
}

.xw-selected {
    background: var(--highlight-strong) !important;
    box-shadow: inset 0 0 0 2.5px var(--primary) !important;
}

/* Blinking cursor in selected empty cell */
.xw-selected.xw-empty::before {
    content: '|';
    position: absolute;
    font-size: 1.4rem;
    font-weight: 300;
    color: var(--primary);
    opacity: 0;
    animation: blink-cursor 1s step-end infinite;
    pointer-events: none;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 0; }
    50% { opacity: 0.7; }
}

.xw-correct {
    background: var(--correct) !important;
}

.xw-wrong {
    background: var(--wrong) !important;
}

/* ============ CONTROLS ============ */
#controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.8rem;
}

.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);
}

/* ============ SOLVED MESSAGE ============ */
#solved-msg {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 800;
    padding: 0.7rem 1rem;
    margin-top: 0.8rem;
    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; }
}

/* ============ CLUES PANEL ============ */
#clues-panel {
    flex: 1;
    min-width: 0;
    max-height: calc(var(--cell-size) * 7 + 140px);
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.clue-group {
    margin-bottom: 1rem;
}

.clue-group:last-child {
    margin-bottom: 0;
}

.clue-group h3 {
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 2px solid #e2e8f0;
}

.clue-group ul {
    list-style: none;
}

.clue-group li {
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
    border-radius: 0.4rem;
    cursor: pointer;
    transition: background 0.12s;
    line-height: 1.4;
}

.clue-group li:hover {
    background: #f1f5f9;
}

.clue-group li.clue-active {
    background: var(--highlight);
    font-weight: 600;
}

.clue-group li strong {
    color: var(--primary);
}

/* ============ 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;
}

/* ============ HIDDEN INPUT ============ */
#xw-input {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* ============ UTILITY ============ */
.hidden {
    display: none !important;
}

/* ============ RESPONSIVE ============ */
/* ============ INSTRUCTION HINT ============ */
.grid-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-style: italic;
    opacity: 0.85;
    transition: opacity 0.4s;
}

.grid-hint.faded {
    opacity: 0;
}

@media (max-width: 900px) {
    :root {
        --cell-size: 48px;
    }

    #game-area {
        flex-direction: column;
    }

    #clues-panel {
        max-height: none;
        overflow-y: visible;
    }

    .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: 40px;
    }

    .xw-letter {
        font-size: 1.3rem;
    }

    .xw-number {
        font-size: 0.55rem;
    }
}

@media (max-width: 400px) {
    :root {
        --cell-size: 34px;
    }

    .xw-letter {
        font-size: 1.1rem;
    }

    .xw-number {
        font-size: 0.5rem;
    }
}
