:root {
    --bg: #07080c;
    --panel: #0f1117;
    --border: #1a1d26;
    --text: #e8eaf0;
    --muted: #a0a6b4;
    --accent: #3ef3a8;
    --accent-2: #60a5fa;
    --danger: #ef4444;
    --chocolate: #f59e0b;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    background: radial-gradient(circle at 15% 20%, #0d1018, var(--bg) 55%, #05060a 100%);
    color: var(--text);
    font-family: var(--mono);
    margin: 0;
    min-height: 100vh;
}

header {
    background: rgba(10, 12, 18, 0.9);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: var(--shadow);
}

nav {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 20px;
}

nav a {
    color: var(--text);
    margin: 0 18px;
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.2px;
}

nav a:hover {
    color: var(--accent);
}

a {
    color: var(--accent);
}

a:hover {
    color: var(--accent-2);
}

.brand {
    font-weight: 800;
    letter-spacing: 0.8px;
    color: var(--text);
    text-transform: uppercase;
    font-size: 14px;
}

.dropdown {
    display: inline-block;
    position: relative;
}

.dropbtn {
    background: linear-gradient(135deg, #111722, #0c131d);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 10px;
    font-family: var(--mono);
    cursor: pointer;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #0c1017;
    min-width: 180px;
    z-index: 10;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.dropdown-content a {
    color: var(--text);
    padding: 10px 15px;
    text-decoration: none;
    display: block;
    background: #0d1119;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content a:hover {
    background: #111724;
    color: var(--accent);
}

main {
    max-width: 1400px;
    margin: 40px auto 60px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    grid-template-areas:
        "title aside"
        "settings aside"
        "controls aside"
        "board aside";
    gap: 22px;
    align-items: start;
}

.top-controls {
    max-width: 1400px;
    margin: 24px auto 0;
    padding: 0 20px;
    display: flex;
    justify-content: flex-end;
}

main.analysis-collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "title"
        "settings"
        "controls"
        "board";
}

main.analysis-collapsed #child-grids-card {
    display: none;
}

h1, h2 {
    margin: 0 0 14px;
    letter-spacing: 0.4px;
}

main > h1 { grid-area: title; }
#game-settings { grid-area: settings; }
#computer-controls { grid-area: controls; }
#game-board { grid-area: board; }
#child-grids-card { grid-area: aside; }

p, label {
    color: var(--muted);
}

section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

main section {
    margin-bottom: 0;
}

button {
    background: linear-gradient(135deg, #111722, #0c131d);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 10px;
    font-family: var(--mono);
    cursor: pointer;
    transition: transform 0.08s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(62, 243, 168, 0.1);
}

input, select {
    background: #0c1017;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: 8px;
    font-family: var(--mono);
}

#game-board {
    text-align: center;
    --cell-size: 44px;
    --cell-gap: 6px;
}

#game-board table {
    border-collapse: separate;
    border-spacing: var(--cell-gap);
    margin: 12px auto 0;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
}

#game-board td {
    width: var(--cell-size);
    height: var(--cell-size);
    border: none;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.06s ease;
    border-radius: 8px;
}

#game-board td:hover {
    transform: translateY(-1px);
}

.cell.chocolate {
    background: #e8eaf0;
    border: 1px solid #cbd0dc;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}

.cell.poison {
    background: #3ef3a8;
    border: 1px solid #2acb89;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}

.cell.empty {
    background: transparent;
    border: none;
}

#child-grids-card {
    position: sticky;
    top: 92px;
    width: min(420px, 100%);
    max-height: calc(100vh - 120px);
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px 18px;
    box-shadow: var(--shadow);
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#child-grids-card > p {
    margin: 0;
}

.child-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

#toggle-child-grids-btn {
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 13px;
}

.child-grid-summary {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

#child-grids {
    margin-top: 2px;
    flex: 1;
    overflow: auto;
    padding-right: 4px;
    min-height: 0;
}

#child-grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}

.child-grid {
    background: #0c1017;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.child-grid.is-p {
    border-color: rgba(96, 165, 250, 0.45);
}

.child-grid.is-n {
    border-color: rgba(62, 243, 168, 0.35);
}

.child-grid p {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.25;
}

.mini-grid {
    border-collapse: separate;
    border-spacing: 2px;
    margin: 0;
}

.mini-grid td {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    cursor: default;
    transform: none !important;
}

@media (max-width: 980px) {
    main {
        max-width: 1200px;
        grid-template-columns: 1fr;
        grid-template-areas:
            "title"
            "settings"
            "controls"
            "board"
            "aside";
    }

    #child-grids-card {
        position: static;
        max-height: none;
        overflow: visible;
    }

    #child-grids {
        max-height: 60vh;
    }
}

.child-grid table {
    border-collapse: collapse;
}

.child-grid td {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
}

.child-grid .chocolate {
    background: #e8eaf0;
}

.child-grid .poison {
    background: #3ef3a8;
}

.child-grid .empty {
    background-color: #0c1017;
}

#computer-controls {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
