:root {
    color-scheme: dark;
    --bg: #111418;
    --panel: rgba(21, 26, 32, 0.94);
    --panel-strong: rgba(26, 33, 41, 0.98);
    --line: rgba(224, 232, 220, 0.18);
    --text: #edf4f6;
    --muted: #aab6bd;
    --wood: #d5a35f;
    --wood-dark: #8f5f2f;
    --accent: #48c7f4;
    --gold: #f2c464;
    --danger: #ef4444;
}

* { box-sizing: border-box; }
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.13), transparent 34%),
        linear-gradient(135deg, #111418, #171c22 52%, #0f1318);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(320px, 23vw, 380px);
    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, .captured-pieces-container, .status-card, .panel, .boundary-info {
    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;
}

.timer-section, .captured-pieces-container {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.player-timer, .captured-side {
    display: grid;
    gap: 3px;
    padding: 8px 10px;
    border: 1px solid rgba(224, 232, 220, 0.13);
    border-radius: 7px;
    background: rgba(10, 14, 18, 0.55);
}
.player-timer span, .captured-label, .muted { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.player-timer strong { font-size: 18px; }
.player-timer.active { border-color: rgba(242, 196, 100, 0.78); }
.capture-count { font-weight: 850; }

.board-panel {
    display: grid;
    align-items: start;
    justify-items: center;
    height: clamp(460px, calc(100vh - 130px), 92vh);
    min-height: 0;
    padding: 8px;
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(12, 15, 19, 0.58), rgba(12, 15, 19, 0.9));
    overflow: auto;
}

#goBoard {
    display: block;
    width: min(100%, 1280px);
    max-width: none;
    aspect-ratio: 1;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    touch-action: none;
}

.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, .boundary-info { padding: 10px; }
.status-line { font-size: 14px; font-weight: 760; }
.status-line + .status-line { margin-top: 5px; }

.control-group { display: grid; gap: 6px; }
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; }
button:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
.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; }
.online-controls {
    display: none;
    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.active { display: grid; }
.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; }
.chat-panel { display: grid; gap: 8px; }
.chat-messages {
    display: grid;
    align-content: start;
    gap: 6px;
    min-height: 104px;
    max-height: 170px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 8px;
    background: rgba(7, 12, 18, 0.4);
}
.chat-empty { color: var(--muted); font-size: 12px; }
.chat-message {
    max-width: 92%;
    padding: 7px 8px;
    border: 1px solid rgba(72, 199, 244, 0.24);
    border-radius: 8px;
    background: rgba(72, 199, 244, 0.08);
    font-size: 12px;
    line-height: 1.35;
}
.chat-message.mine {
    justify-self: end;
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(34, 197, 94, 0.1);
}
.chat-meta {
    margin-bottom: 3px;
    color: #a7f3d0;
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}
.chat-text { color: var(--text); overflow-wrap: anywhere; }
.chat-compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.chat-compose input { min-width: 0; }
.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;
}

@media (min-width: 981px) {
    .play-area { min-height: calc(100vh - 28px); }
}

@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, .captured-pieces-container { grid-template-columns: 1fr; display: grid; }
    .timer-section { grid-template-columns: 1fr 1fr; }
    #goBoard { width: min(96vw, 100%); }
}

.robot-panel {
    border: 1px solid rgba(125, 211, 252, 0.28);
    background: rgba(15, 23, 42, 0.48);
    border-radius: 8px;
    display: grid;
    gap: 8px;
}
.robot-panel h3,
.robot-panel h4 { margin: 0.25rem 0 0.45rem; color: #e0f7ff; }
.compact-control { margin-bottom: 0.4rem; }
.robot-controls { margin: 0.35rem 0; }
.robot-controls button:last-child { border-color: rgba(56, 189, 248, 0.7); }
.robot-controls button:disabled { cursor: wait; opacity: 0.58; }
.robot-analysis {
    max-height: 360px;
    overflow: auto;
    padding: 0.75rem;
    background: rgba(2, 6, 23, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 8px;
    font-size: 0.88rem;
    line-height: 1.45;
}
.robot-muted { color: #94a3b8; font-size: 0.82rem; }
.robot-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin-bottom: 0.6rem; }
.robot-summary-grid > div { padding: 0.5rem; border-radius: 8px; background: rgba(15, 23, 42, 0.78); border: 1px solid rgba(148, 163, 184, 0.16); }
.robot-label { display: block; color: #93c5fd; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.robot-move-list,
.robot-piece-list { padding-left: 1.15rem; margin: 0.35rem 0 0.8rem; }
.robot-move-list > li,
.robot-piece-list > li { margin-bottom: 0.6rem; }
.robot-move-list ul { margin: 0.25rem 0 0; padding-left: 1rem; }
.robot-bad-list strong { color: #fecaca; }


.robot-final-flow { display: grid; gap: 0.5rem; }
.robot-flow-chart { width: 100%; min-height: 180px; display: block; border-radius: 8px; background: rgba(15, 23, 42, 0.62); border: 1px solid rgba(148, 163, 184, 0.18); }
.robot-flow-axis { stroke: rgba(148, 163, 184, 0.34); stroke-width: 1; }
.robot-flow-black { stroke: #e5e7eb; stroke-width: 3; fill: none; }
.robot-flow-white { stroke: #f2c464; stroke-width: 3; fill: none; }
.robot-flow-label { fill: #94a3b8; font-size: 12px; font-weight: 800; }
.robot-flow-legend { display: flex; flex-wrap: wrap; gap: 0.75rem; color: #cbd5e1; font-size: 0.82rem; }
.robot-flow-swatch { display: inline-block; width: 22px; height: 3px; vertical-align: middle; margin-right: 0.35rem; border-radius: 999px; background: currentColor; }

.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; }
@media (min-width: 981px) {
    .robot-panel { margin-top: 0; }
}
