*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0f0f1a;
    --surface:  #1a1a2e;
    --border:   #2e2e4a;
    --accent:   #e63946;
    --text:     #e0e0e0;
    --text-dim: #888;
    --btn-bg:   #2a2a40;
    --btn-hover:#3a3a58;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */

body { display: flex; flex-direction: column; }

#toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

#main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Left: board */
#board-wrap {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: var(--bg);
}

#board-canvas {
    display: block;
    border-radius: 4px;
    box-shadow: 0 4px 24px #0008;
    cursor: crosshair;
    max-width: 100%;
    max-height: 100%;
}

/* Resizer handle between board and sidebar */
#resizer {
    width: 5px;
    flex-shrink: 0;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
}
#resizer:hover, #resizer.active { background: var(--accent); }

/* Right: sidebar */
#sidebar {
    width: 260px;
    min-width: 180px;
    max-width: 600px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;
}

/* Tree panel */
#tree-panel {
    flex: 0 0 200px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#tree-canvas {
    flex: 1;
    display: block;
    min-height: 0;
}

#tree-slider {
    width: 100%;
    margin: 0;
    padding: 2px 4px;
    background: #111120;
    accent-color: var(--accent);
    cursor: pointer;
    box-sizing: border-box;
}

#tree-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Info panel */
#info-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
    overflow: auto;
}

#move-info {
    font-size: 12px;
    color: var(--text-dim);
    min-height: 16px;
}

#comment-box {
    flex: 1;
    min-height: 60px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    font-size: 13px;
    resize: none;
    font-family: inherit;
}

#comment-box:focus { outline: none; border-color: var(--accent); }

/* Nav row */
#nav-row {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

/* Variation controls */
#var-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* Edit mode toggle */
#edit-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

input[type=checkbox] { accent-color: var(--accent); }

/* Status bar */
#statusbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 12px;
    flex-shrink: 0;
}

#status-msg { flex: 1; }
#status-msg.status-ok  { color: #52b788; }
#status-msg.status-err { color: var(--accent); }

/* Game title */
#game-title {
    font-weight: 600;
    font-size: 15px;
    margin-right: 8px;
    min-width: 80px;
    outline: none;
    border-bottom: 1px dashed transparent;
    cursor: text;
}
#game-title:hover, #game-title:focus { border-bottom-color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────────── */

button, .btn {
    background: var(--btn-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

button:hover  { background: var(--btn-hover); }
button:active { background: #444; }
button:disabled { opacity: 0.4; cursor: default; }

button.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
button.accent:hover { background: #c1121f; }

/* ── Modals ──────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: #0009;
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 360px;
    max-width: 95vw;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-box h2 { font-size: 16px; }

.modal-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

.modal-box input, .modal-box select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 13px;
    font-family: inherit;
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Games list modal */
#modal-games .modal-box { width: 440px; }

#games-list {
    list-style: none;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}

#games-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
#games-list li:last-child { border-bottom: none; }
#games-list li:hover { background: var(--btn-hover); }
#games-list li.empty { color: var(--text-dim); cursor: default; justify-content: center; }

.game-meta { font-size: 11px; color: var(--text-dim); }

/* Game info panel */
#game-info {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    font-size: 12px;
}
#game-info:empty { display: none; }
#game-info table {
    width: 100%;
    border-collapse: collapse;
}
#game-info td {
    padding: 2px 4px;
    vertical-align: top;
}
#game-info td:first-child {
    color: var(--text-dim);
    white-space: nowrap;
    padding-right: 16px;
    width: 1%;
}
#game-info .gi-result {
    font-weight: 600;
    color: #7ec8a0;
}

/* Captures display */
#captures-display {
    display: flex;
    gap: 6px;
}

.cap-player {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    min-width: 0;
}

.cap-stone {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cap-stone-black { background: radial-gradient(circle at 35% 35%, #666, #000); border: 1px solid #444; }
.cap-stone-white { background: radial-gradient(circle at 35% 35%, #fff, #ccc); border: 1px solid #999; }

.cap-count {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    min-width: 1ch;
    text-align: right;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 700px) {
    #main { flex-direction: column; }
    #sidebar { width: 100%; flex-direction: row; border-left: none; border-top: 1px solid var(--border); }
    #tree-panel { flex: 0 0 160px; border-bottom: none; border-right: 1px solid var(--border); }
    #info-panel { flex: 1; }
}
