:root {
    color-scheme: dark;
    --bg: #101418;
    --panel: rgba(20, 25, 31, 0.94);
    --line: rgba(224, 232, 220, 0.18);
    --text: #edf4f6;
    --muted: #aab6bd;
    --wood: #d9aa62;
    --wood-dark: #87572d;
    --board-line: rgba(47, 28, 14, 0.72);
    --board-line-soft: rgba(71, 42, 20, 0.42);
    --accent: #48c7f4;
    --gold: #f2c464;
    --danger: #ef4444;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(72, 199, 244, 0.12), transparent 34%),
        linear-gradient(135deg, #101418, #171c22 52%, #0f1318);
}
.app-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; padding: 14px; }
.play-area, .sidebar { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.play-area { min-width: 0; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; gap: 12px; padding: 14px; }
.top-bar h1, .sidebar h2, .panel h3 { margin: 0; letter-spacing: 0; }
.top-bar h1 { font-size: 30px; }
.top-bar p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.game-info-bar, .status-card, .panel, .boundary-display { border: 1px solid rgba(224, 232, 220, 0.14); border-radius: 8px; background: rgba(13, 17, 22, 0.62); }
.game-info-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; }
.turn-pill, .boundary-display { min-height: 34px; display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid rgba(72, 199, 244, 0.38); border-radius: 999px; color: #e0f7ff; font-weight: 800; }
.captured-pieces-container { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.captured-side { display: grid; gap: 3px; padding: 10px 12px; border: 1px solid rgba(224, 232, 220, 0.13); border-radius: 8px; background: rgba(10, 14, 18, 0.55); }
.captured-side.active { border-color: rgba(242, 196, 100, 0.78); }
.captured-label, .muted { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.capture-count { font-size: 18px; font-weight: 900; }
.board-panel {
    min-height: clamp(560px, 70vh, 820px);
    padding: 16px;
    border: 1px solid rgba(72, 199, 244, 0.22);
    border-radius: 10px;
    background:
        radial-gradient(circle at 20% 10%, rgba(72, 199, 244, 0.1), transparent 34%),
        linear-gradient(180deg, rgba(11, 15, 20, 0.82), rgba(5, 8, 13, 0.96));
    overflow: auto;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 18px 42px rgba(0, 0, 0, 0.25);
}
.slice-grid { display: grid; gap: 18px; align-items: start; justify-content: center; min-width: max-content; padding: 4px; }
.slice-grid.interactive-3d-slice {
    display: block;
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: clamp(500px, 68vh, 760px);
    overflow: hidden;
    touch-action: none;
    background: linear-gradient(180deg, rgba(4, 10, 20, .94), rgba(3, 7, 14, .98));
}
.interactive-3d-edge-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.interactive-3d-edge { stroke: rgba(108, 164, 224, .34); stroke-width: 1; }
.interactive-3d-slice .vertex.projected-vertex {
    position: absolute;
    width: 24px;
    height: 24px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(220, 239, 252, .9) 0 3px, transparent 3.5px);
    transform: translate(-50%, -50%);
    overflow: visible;
}
.interactive-3d-slice .vertex.projected-vertex::before,
.interactive-3d-slice .vertex.projected-vertex::after { display: none; }
.interactive-3d-slice .vertex.projected-vertex .stone { width: 24px; height: 24px; }
.interactive-3d-slice .vertex.projected-vertex.liberty {
    background: radial-gradient(circle, rgba(74, 222, 128, 1) 0 6px, rgba(34, 197, 94, .32) 6.5px 10px, transparent 10.5px);
    box-shadow: none;
}
.interactive-3d-slice .vertex.projected-vertex.group {
    background: radial-gradient(circle, rgba(56, 189, 248, 1) 0 6px, rgba(14, 165, 233, .3) 6.5px 10px, transparent 10.5px);
    box-shadow: none;
}
.interactive-3d-slice .slice-3d-label {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10000;
    color: #d9edf4;
    font-size: 13px;
    font-weight: 900;
    pointer-events: none;
}
.view-settings { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: rgba(10,14,18,.55); }
.view-settings summary { cursor: pointer; font-weight: 850; margin-bottom: 9px; }
.slice-board {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(199, 216, 222, 0.18);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(18, 25, 31, 0.92), rgba(8, 12, 17, 0.96));
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.slice-title {
    justify-self: center;
    min-height: 22px;
    padding: 3px 9px;
    border: 1px solid rgba(72, 199, 244, 0.24);
    border-radius: 999px;
    color: #d9edf4;
    background: rgba(5, 12, 18, 0.86);
    font-size: 11px;
    font-weight: 900;
    text-align: center;
    cursor: pointer;
}
.xy-grid {
    position: relative;
    display: grid;
    gap: 0;
    aspect-ratio: 1;
    width: clamp(154px, 13vw, 188px);
    border: 1px solid rgba(69, 43, 21, 0.58);
    border-radius: 8px;
    background:
        radial-gradient(circle at 25% 22%, rgba(255, 239, 196, 0.18), transparent 30%),
        linear-gradient(135deg, var(--wood), var(--wood-dark));
    padding: 11px;
    box-shadow: inset 0 0 0 1px rgba(255, 245, 210, 0.16), inset 0 -18px 40px rgba(71, 42, 20, 0.22), 0 10px 22px rgba(0, 0, 0, 0.32);
}
.slice-board.zoomed .xy-grid { width: min(74vh, 760px); }
.vertex {
    appearance: none;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: radial-gradient(circle at center, var(--board-line) 0 3px, transparent 3.5px);
    display: grid;
    place-items: center;
    cursor: pointer;
    position: relative;
}
.vertex::before,
.vertex::after { content: ""; position: absolute; background: var(--board-line-soft); pointer-events: none; }
.vertex::before { width: 100%; height: 1px; }
.vertex::after { width: 1px; height: 100%; }
.stone {
    width: 82%;
    aspect-ratio: 1;
    border-radius: 50%;
    z-index: 2;
    box-shadow: inset -4px -5px 10px rgba(0,0,0,0.28), inset 2px 2px 5px rgba(255,255,255,0.18), 0 4px 10px rgba(0,0,0,0.42);
}
.stone.black { background: radial-gradient(circle at 30% 24%, #a8d8f0 0 7%, #365b70 18%, #101923 52%, #020407 78%); border: 2px solid rgba(99, 196, 234, 0.72); }
.stone.white { background: radial-gradient(circle at 34% 26%, #ffffff 0 18%, #edf4f7 45%, #b5c3ca 78%); border: 1px solid rgba(37, 50, 58, 0.34); }
.vertex.hover,
.vertex.group { box-shadow: inset 0 0 0 999px rgba(72, 199, 244, 0.18); }
.vertex.territory-black { box-shadow: inset 0 0 0 999px rgba(15, 23, 42, 0.58); }
.vertex.territory-white { box-shadow: inset 0 0 0 999px rgba(248, 250, 252, 0.52); }
.vertex.territory-neutral { box-shadow: inset 0 0 0 999px rgba(148, 163, 184, 0.34); }
.vertex.liberty {
    box-shadow: inset 0 0 0 999px rgba(34, 197, 94, 0.34);
    outline: 2px solid rgba(74, 222, 128, 0.92);
    outline-offset: -2px;
}
.vertex.selected { outline: 2px solid var(--gold); outline-offset: -2px; box-shadow: inset 0 0 0 999px rgba(242, 196, 100, 0.18); }
.sidebar { display: flex; flex-direction: column; gap: 12px; padding: 14px; overflow: auto; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.space-home-link { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; color: #eef5ff; text-decoration: none; border: 1px solid rgba(97, 174, 255, 0.42); border-radius: 999px; background: rgba(5, 12, 24, 0.92); padding: 8px 12px; font-weight: 900; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28); }
.status-card, .panel { padding: 10px; }
.status-line { font-size: 14px; font-weight: 760; }
.status-line + .status-line { margin-top: 5px; }
.control-group { display: grid; gap: 6px; }
.dimension-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
label { color: #dce8ec; font-size: 13px; font-weight: 850; }
select, input, button { width: 100%; min-height: 38px; border: 1px solid rgba(224, 232, 220, 0.2); border-radius: 7px; background: rgba(10, 14, 18, 0.82); color: var(--text); font: inherit; }
select, input { padding: 0 10px; }
button { cursor: pointer; font-weight: 850; }
button:hover:not(:disabled), button:focus-visible { border-color: rgba(72, 199, 244, 0.75); color: #e0f7ff; }
.danger { border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.slice-switcher { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.slice-switcher button { width: auto; min-width: 38px; padding: 6px 9px; }
.slice-switcher button[aria-pressed="true"] { border-color: var(--gold); color: #fff2bf; background: rgba(242, 196, 100, 0.14); }
.move-choice-panel { display: grid; gap: 8px; padding: 10px; border: 1px solid rgba(72,199,244,.22); border-radius: 8px; background: rgba(8,14,20,.88); }
.move-choice-heading { display: flex; justify-content: space-between; gap: 10px; color: #dcecf3; font-size: 13px; }
.move-choice-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.move-choice-buttons button { width: auto; min-height: 34px; padding: 6px 9px; font-size: 12px; }
.move-choice-buttons button.active { border-color: #4ade80; box-shadow: inset 0 0 0 2px rgba(74,222,128,.28); color: #dcfce7; }
.online-controls { display: grid; gap: 10px; padding: 12px; border: 1px solid rgba(34, 197, 94, 0.55); border-radius: 8px; background: rgba(34, 197, 94, 0.09); }
.online-controls[hidden] { display: none; }
.connection-status { padding: 9px; border-radius: 8px; font-weight: 900; text-align: center; }
.connection-status.disconnected { background: rgba(239, 68, 68, 0.16); color: #fecaca; }
.connection-status.connecting { background: rgba(245, 158, 11, 0.16); color: #fde68a; }
.connection-status.connected { background: rgba(34, 197, 94, 0.16); color: #bbf7d0; }
.online-btn.match { border-color: rgba(245, 158, 11, 0.82); }
.online-btn.create { border-color: rgba(34, 197, 94, 0.7); }
.online-btn.join { border-color: rgba(56, 189, 248, 0.7); }
.divider-text { color: var(--muted); font-size: 11px; font-weight: 900; text-align: center; }
.room-info { display: grid; gap: 8px; padding: 9px; border: 1px solid rgba(224, 232, 220, 0.14); border-radius: 7px; }
.room-info[hidden] { display: none; }
.room-id-display { font-size: 22px; font-weight: 950; letter-spacing: 0.12em; color: var(--gold); }
.share-link-box { display: grid; grid-template-columns: minmax(0, 1fr) 70px; gap: 6px; }
.online-controls, .room-info, .share-link-box { min-width: 0; max-width: 100%; box-sizing: border-box; overflow: hidden; }
.room-id-display { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0.08em; }
.share-link-input { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.move-history { min-height: 178px; max-height: 210px; overflow: auto; align-content: start; display: grid; gap: 6px; }
.move-history-item { padding: 7px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.045); font-size: 13px; }
.rules-text { color: var(--muted); font-size: 13px; line-height: 1.45; }
.score-panel {
    display: grid;
    gap: 6px;
}
.score-panel[hidden] { display: none; }
.go-score-total {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.go-score-total strong {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(72, 199, 244, 0.22);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.045);
}
.go-score-breakdown {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px;
}
.go-score-chip {
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
    border: 1px solid rgba(224, 232, 220, 0.14);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 12px;
}
.go-score-chip span:nth-child(2) { overflow-wrap: anywhere; }
.go-score-chip strong { color: #f8fbff; }
.go-score-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: #94a3b8;
}
.go-score-chip.black .go-score-swatch,
.go-score-chip.dead-black .go-score-swatch { background: #030712; }
.go-score-chip.white .go-score-swatch,
.go-score-chip.dead-white .go-score-swatch { background: #f8fafc; }
.go-score-chip.black-territory .go-score-swatch { background: #334155; }
.go-score-chip.white-territory .go-score-swatch { background: #cbd5e1; }
.go-score-chip.komi .go-score-swatch { background: #f2c464; }
.go-score-chip.neutral .go-score-swatch { background: #64748b; }
.go-score-note,
.go-score-result {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}
.go-score-result {
    color: var(--text);
    font-weight: 850;
}
.chat-panel { margin-top: auto; }
.chat-messages { min-height: 130px; max-height: 220px; overflow: auto; display: grid; align-content: start; gap: 7px; }
.chat-empty { color: var(--muted); font-size: 13px; }
.chat-message { padding: 7px 8px; border-radius: 7px; background: rgba(255, 255, 255, 0.045); }
.chat-meta { color: #e0f7ff; font-size: 11px; font-weight: 850; text-transform: uppercase; }
.chat-text { margin-top: 3px; color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.chat-input-row { display: grid; grid-template-columns: minmax(0, 1fr) 78px; gap: 8px; margin-top: 8px; }
@media (max-width: 980px) { .app-shell { grid-template-columns: 1fr; } .sidebar { max-height: none; } }
@media (max-width: 620px) {
    .app-shell { padding: 8px; }
    .game-info-bar { display: grid; }
    .timer-section { grid-template-columns: 1fr 1fr; }
    .board-panel { padding: 10px; overflow-x: hidden; }
    .slice-grid:not(.interactive-3d-slice) {
        width: 100%;
        min-width: 0 !important;
        grid-template-columns: 1fr !important;
        justify-content: stretch;
    }
    .slice-board {
        min-width: 0;
        max-width: 100%;
        justify-items: center;
        padding: 8px;
    }
    .xy-grid {
        width: min(100%, calc(100vw - 58px));
        max-width: 330px;
    }
    .slice-board.zoomed .xy-grid {
        width: min(100%, calc(100vw - 58px));
    }
}

.dynamics-settings { display: grid; gap: 10px; }
.dynamics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dynamics-grid .control-group { min-width: 0; }
.dynamics-grid input,
.dynamics-grid select { width: 100%; box-sizing: border-box; }
