/* css/style.css */
:root {
    --color-unknown: #ffffff;
    --color-void: #e0e0e0;
    --color-body: #81c784;
    --color-head: #e57373;
    --color-border: #424242;
    --color-text-ai: #1976d2;
    --color-highlight: #fff176;
    --grid-gap: 1px;
    --sidebar-width: 320px;
    --bg-color: #fafafa;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent global scroll */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: #333;
}

/* Main Layout Container - CSS Grid */
.container {
    display: grid;
    height: 100%;
    width: 100%;
    
    /* Default: Mobile / Portrait */
    grid-template-columns: 100%;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "header"
        "board"
        "controls";
}

/* 1. Header Area */
.layout-header {
    grid-area: header;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 16px 8px;
    background: white;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

h1 {
    margin: 0 0 8px 0;
    font-size: 1.2rem;
    color: #2c3e50;
    font-weight: 600;
}

/* Algorithm Selector */
.algorithm-selector {
    display: flex;
    justify-content: center;
    width: 100%;
}

.algo-buttons {
    display: flex;
    background: #f1f2f6;
    padding: 4px;
    border-radius: 8px;
    gap: 4px;
}

.btn-algo {
    background: transparent;
    border: none;
    padding: 6px 16px;
    font-size: 0.9rem;
    color: #7f8c8d;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-algo.active {
    background: white;
    color: #2980b9;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* 2. Board Area */
.layout-board {
    grid-area: board;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
    min-height: 0; /* Important for grid overflow */
    min-width: 0;
    position: relative;
    background-color: var(--bg-color);
}

/* Status Text */
.status-text {
    margin-bottom: 12px;
    color: #546e7a;
    font-size: 1rem;
    font-weight: 500;
    height: 1.5em;
    line-height: 1.5em;
    text-align: center;
    flex: 0 0 auto;
}

/* The Board Wrapper */
.board-wrapper {
    position: relative;
    /* Dimensions set by JS */
    width: 300px; 
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border-radius: 4px;
    overflow: hidden;
    background-color: var(--color-border);
}

/* The Grid */
.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: var(--grid-gap);
    background-color: var(--color-border);
    border: var(--grid-gap) solid var(--color-border);
    width: 100%;
    height: 100%;
    user-select: none;
    touch-action: manipulation;
}

/* Board Overlay */
.board-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: var(--grid-gap);
    padding: var(--grid-gap);
    z-index: 5;
}

/* Cells */
.cell, .overlay-cell {
    position: relative;
    background-color: var(--color-unknown);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-weight: bold;
    font-size: clamp(12px, 2.5vw, 18px); 
    transition: background-color 0.15s ease;
}

.overlay-cell {
    background-color: transparent; /* Fix: Overlay should not hide underlying board */
}

.cell:hover {
    filter: brightness(0.95);
}

.cell.void { background-color: var(--color-void); }
.cell.body { background-color: var(--color-body); }
.cell.head { background-color: var(--color-head); }

/* Game Won State (ID3) */
.cell.body.won-dim {
    background-color: var(--color-unknown);
    background-image: linear-gradient(rgba(102, 187, 106, 0.35), rgba(102, 187, 106, 0.35));
    cursor: default;
}

.cell.highlight {
    position: relative;
    z-index: 2;
}
.cell.highlight::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 3px solid #2980b9;
    box-shadow: inset 0 0 15px rgba(41, 128, 185, 0.4);
}

.cell .ai-hint {
    color: var(--color-text-ai);
    font-weight: 900;
    z-index: 3;
    background: transparent;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
}

.overlay-cell.head-hint { background-color: rgba(239, 83, 80, 0.5); }
.overlay-cell.body-hint { background-color: rgba(102, 187, 106, 0.35); }

/* 3. Footer / Controls Area */
.layout-controls {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 24px 24px;
    background: white;
    border-top: 1px solid #eee;
    z-index: 10;
}

/* Controls Toolbar */
.toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 400px;
}

.instruction-text {
    font-size: 0.95rem;
    color: #555;
    text-align: center;
    line-height: 1.4;
    min-height: 1.4em;
}

.btn-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

/* Buttons */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s;
    min-width: 90px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

button:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
button:active { transform: scale(0.98); box-shadow: none; }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

button.primary { background-color: #2980b9; color: white; }
button.primary:hover { background-color: #3498db; }

button.secondary { background-color: #f5f6fa; color: #555; border: 1px solid #dcdde1; }
button.secondary:hover { background-color: #e6e8ed; }

.btn-feedback {
    padding: 10px 16px;
    min-width: 70px;
    color: white;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.f-void { background-color: var(--color-void); color: #666; }
.f-body { background-color: var(--color-body); }
.f-head { background-color: var(--color-head); }

/* Explore Palette */
.palette {
    display: flex;
    gap: 16px;
    padding: 12px;
    background: #f1f2f6;
    border-radius: 12px;
    margin-bottom: 8px;
}

.palette-item {
    width: 40px;
    height: 40px;
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}
.palette-item:hover { transform: scale(1.05); }
.palette-item.active { border-color: #2c3e50; transform: scale(1.1); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.p-void { background-color: var(--color-void); }
.p-body { background-color: var(--color-body); }
.p-head { background-color: var(--color-head); }

/* Mode Switch */
.mode-switch { margin-top: 8px; }
.mode-switch a {
    font-size: 0.9rem;
    color: #7f8c8d;
    text-decoration: none;
    border-bottom: 1px dashed #b0bec5;
    padding-bottom: 2px;
}
.mode-switch a:hover { color: #2980b9; border-bottom-style: solid; }

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    flex-direction: column;
    backdrop-filter: blur(5px);
}

/* Github Corner */
.github-corner {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 100;
}
.github-corner svg {
    fill: #2c3e50;
    color: #fff;
    width: 60px;
    height: 60px;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.github-corner:hover svg { opacity: 1; }


/* --- Responsive Layouts --- */

/* Desktop / Landscape: Sidebar Layout */
@media (min-width: 800px) {
    .container {
        grid-template-columns: 1fr var(--sidebar-width);
        grid-template-rows: auto 1fr;
        grid-template-areas: 
            "board header"
            "board controls";
    }

    .layout-header {
        border-bottom: 1px solid #eee;
        padding-top: 40px; /* Space for github corner if needed, or just breathing room */
        align-items: stretch;
        background: white;
    }

    .layout-controls {
        border-top: none;
        justify-content: flex-start;
        background: white;
        padding-top: 0;
    }

    .toolbar {
        max-width: none;
    }
    
    .btn-group {
        flex-direction: column; /* Stack buttons on sidebar */
        width: 100%;
    }
    
    .btn-group button {
        width: 100%;
    }

    /* Keep feedback buttons in a row though */
    .feedback-group {
        flex-direction: row;
    }
    
    .feedback-group button {
        width: auto;
        flex: 1;
    }
}

/* Small Mobile Adjustments */
@media (max-width: 400px) {
    h1 { font-size: 1.1rem; }
    .layout-board { padding: 8px; }
    .btn-algo { padding: 4px 10px; }
    button { padding: 8px 12px; font-size: 0.85rem; min-width: 60px; }
    .github-corner svg { width: 40px; height: 40px; }
    .status-text { font-size: 0.9rem; margin-bottom: 8px; }
}
