:root {
    color-scheme: dark;
    --bg: #0e1217;
    --panel: rgba(19, 24, 31, 0.94);
    --line: rgba(222, 234, 226, 0.18);
    --text: #edf4f6;
    --muted: #a8b4bc;
    --accent: #38bdf8;
    --gold: #f5bf5b;
    --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 16% 10%, rgba(56, 189, 248, 0.16), transparent 30%),
        radial-gradient(circle at 80% 30%, rgba(245, 191, 91, 0.12), transparent 32%),
        linear-gradient(140deg, #0e1217, #151b22 56%, #0d1015);
}
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 350px;
    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;
    min-height: calc(100vh - 28px);
}
.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(222, 234, 226, 0.14);
    border-radius: 8px;
    background: rgba(11, 15, 20, 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(56, 189, 248, 0.42);
    border-radius: 999px;
    color: #e0f7ff;
    font-weight: 850;
}
.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(222, 234, 226, 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: 850; text-transform: uppercase; }
.player-timer strong { font-size: 18px; }
.player-timer.active { border-color: rgba(245, 191, 91, 0.78); }
.capture-count { font-weight: 850; }
.board-frame {
    height: 100%;
    min-height: clamp(620px, calc(100vh - 172px), 980px);
    max-height: none;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: radial-gradient(circle at center, rgba(39, 50, 61, 0.55), rgba(8, 11, 15, 0.96));
}
#goCanvas { width: 100%; height: 100%; display: block; touch-action: none; }
.board-camera-pad {
    position: absolute;
    right: 12px;
    top: 12px;
    z-index: 8;
    display: grid;
    grid-template-columns: repeat(4, 34px);
    gap: 6px;
    padding: 6px;
    border: 1px solid rgba(125, 211, 252, 0.35);
    border-radius: 12px;
    background: rgba(5, 10, 18, 0.72);
    backdrop-filter: blur(6px);
}
.board-camera-pad button {
    width: 34px;
    min-height: 32px;
    padding: 0;
    border-radius: 9px;
    background: rgba(15, 23, 42, 0.88);
    font-size: 13px;
    line-height: 1;
}
.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; }
.sidebar-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.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; }
#sphereViewGroup[hidden] { display: none; }
label { color: #dce8ec; font-size: 13px; font-weight: 850; }
select, input, button {
    width: 100%;
    min-height: 38px;
    border: 1px solid rgba(222, 234, 226, 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(56, 189, 248, 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(222, 234, 226, 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 { height: 210px; 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;
}
@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .play-area { min-height: auto; }
    .board-frame { height: min(62vh, 620px); min-height: 420px; }
}
@media (max-width: 620px) {
    .app-shell { padding: 8px; }
    .board-frame { height: min(56vh, 480px); min-height: 340px; }
    .board-camera-pad { right: 8px; top: 8px; grid-template-columns: repeat(4, 30px); gap: 4px; padding: 5px; }
    .board-camera-pad button { width: 30px; min-height: 28px; font-size: 12px; }
    .game-info-bar, .captured-pieces-container { grid-template-columns: 1fr; display: grid; }
    .timer-section { grid-template-columns: 1fr 1fr; }
}
.language-switch {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    width: auto;
    max-width: max-content;
    padding: 4px 7px;
    border: 1px solid rgba(56, 189, 248, 0.42);
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.95);
    color: #cbd5e1;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.26);
}
.language-switch .lang-option {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 0;
    height: 22px;
    min-height: 0;
    padding: 0 3px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 850;
    line-height: 1;
}
.language-switch .lang-option:hover,
.language-switch .lang-option:focus-visible {
    background: transparent;
    color: #f8fafc;
    outline: none;
}
.language-switch .lang-option.active {
    color: #38bdf8;
    text-decoration: underline;
    text-underline-offset: 4px;
}
.language-switch .lang-option:active { transform: none; }
.language-switch .lang-divider {
    display: inline-flex;
    align-items: center;
    height: 22px;
    color: rgba(203, 213, 225, 0.72);
    font-size: 12px;
    line-height: 1;
}

.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(56, 189, 248, 0.24);
    border-radius: 8px;
    background: rgba(56, 189, 248, 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; }


/* Local robot analysis panels */
.robot-panel {
    border: 1px solid rgba(72, 199, 244, 0.22);
    background: rgba(7, 15, 22, 0.72);
}
.robot-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    align-items: center;
    margin: 0.55rem 0;
}
.robot-row label {
    color: var(--muted, #9fb3c8);
    font-size: 0.92rem;
}
.robot-buttons {
    margin: 0.75rem 0;
}
.robot-analysis {
    max-height: 380px;
    overflow: auto;
    padding: 0.7rem;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.22);
    font-size: 0.88rem;
    line-height: 1.38;
}
.robot-analysis h3, .robot-analysis h4 {
    margin: 0.5rem 0 0.35rem;
}
.robot-analysis ol {
    margin: 0.35rem 0 0.7rem 1.25rem;
    padding: 0;
}
.robot-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.robot-chip {
    display: inline-flex;
    padding: 0.22rem 0.45rem;
    border-radius: 999px;
    background: rgba(72,199,244,0.12);
    border: 1px solid rgba(72,199,244,0.2);
}

/* Compact language icon menu */
.language-switch.compact-language { position: relative; display: inline-flex; align-items: center; gap: 0; padding: 0; border: 0; background: transparent; box-shadow: none; overflow: visible; }
.language-switch.compact-language .language-icon-button { width: 40px; height: 40px; border: 0; border-radius: 999px; background: transparent; color: #dff8ff; display: inline-grid; place-items: center; cursor: pointer; box-shadow: none; }
.language-switch.compact-language .language-popover { display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 70; min-width: 132px; padding: 8px; border: 1px solid rgba(125, 211, 252, 0.34); border-radius: 14px; background: rgba(6, 11, 18, 0.98); box-shadow: 0 18px 38px rgba(0,0,0,.38); }
.language-switch.compact-language:hover .language-popover, .language-switch.compact-language:focus-within .language-popover { display: grid; gap: 6px; }
.language-switch.compact-language .lang-option { width: 100%; justify-content: center; }
.language-switch.compact-language .lang-divider { display: none; }

/* R3 coordinate plane filter */
.r3-filter-control { border-color: rgba(125, 211, 252, 0.24); background: rgba(8, 13, 20, 0.58); }
.r3-filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.r3-filter-grid input { min-width: 0; text-align: center; }

/* R3 slice controls: x/y/z empty means full board; values are 1-based layers. */
.r3-slice-filter {
    border: 1px solid rgba(125, 211, 252, 0.28);
    border-radius: 14px;
    padding: 12px;
    background: rgba(8, 13, 20, 0.72);
}
.r3-slice-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
}
.r3-slice-row input {
    min-width: 0;
    width: 100%;
    text-align: center;
    font-weight: 800;
}
