:root {
    --primary-color: #0284c7;
    /* Blue like Vikatan header */
    --accent-color: #eab308;
    /* Gold/Yellow */
    --bg-color: #f8fafc;
    /* Very light slate */
    --grid-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --selection-color: rgba(234, 179, 8, 0.4);
    /* Translucent Yellow */
    --found-color: #86efac;
    /* Light Green */
    --found-border: #22c55e;

    --cell-size: 38px;
    --gap-size: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Baloo Thambi 2', sans-serif;
    user-select: none;
    /* Critical for drag selection */
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 1000px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* --- Header --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.timer-area {
    font-family: 'Outfit', monospace;
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-main);
}

.title-area {
    text-align: center;
}

.title-area h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    line-height: 1;
}

.progress-info {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-muted);
}

.share-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    transition: all 0.2s;
}

.share-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* --- Content Layout --- */
.game-content {
    display: flex;
    flex: 1;
    gap: 20px;
    overflow: hidden;
    /* Prevent body scroll if grid is large */
}

/* --- Grid Section --- */
.grid-container {
    flex: 2;
    background: var(--grid-bg);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
    overflow: auto;
    /* Allow scroll if grid is huge on small screen */
}

.grid {
    display: grid;
    /* Grid template columns set by JS */
    gap: var(--gap-size);
    position: relative;
    z-index: 1;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    /* border: 1px solid #f1f5f9; optional guide lines */
    transition: background 0.2s;
}

.cell.found {
    background-color: var(--found-color);
    color: #064e3b;
    animation: popIn 0.3s ease;
}

.cell.selected {
    background-color: var(--selection-color);
}

/* Canvas Overlay for drag line */
#selectionCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 2;
    width: 100%;
    height: 100%;
}

/* --- Sidebar (Word List) --- */
.sidebar {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 250px;
}

.word-list-header {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    text-align: center;
}

.word-list-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.word-list {
    list-style: none;
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.word-item {
    padding: 10px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.word-item.found {
    text-decoration: line-through;
    color: var(--text-muted);
    opacity: 0.6;
}

/* --- Modal --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
}

.modal h2 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.stats {
    margin: 20px 0;
    font-size: 1.2rem;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
        height: auto;
        min-height: 100vh;
    }

    .game-content {
        flex-direction: column-reverse;
    }

    .sidebar {
        min-width: 100%;
        flex: none;
        height: 200px;
        margin-top: 10px;
    }

    .grid-container {
        padding: 10px;
        min-height: 400px;
    }

    .cell {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}