:root {
    color-scheme: dark;
    --panel: rgba(21, 26, 32, 0.94);
    --line: rgba(224, 232, 220, 0.18);
    --text: #edf4f6;
    --muted: #aab6bd;
    --accent: #48c7f4;
    --gold: #f2c464;
}

* { 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 18% 8%, rgba(72, 199, 244, 0.12), transparent 32%),
        linear-gradient(135deg, #111418, #171c22 52%, #0f1318);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 14px;
    padding: 14px;
    align-items: start;
}

.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 minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
    min-height: calc(100vh - 28px);
    align-self: start;
}

.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-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: 850;
}

.score-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.score-box {
    display: grid;
    gap: 3px;
    min-width: 92px;
    padding: 8px 10px;
    border: 1px solid rgba(224, 232, 220, 0.13);
    border-radius: 7px;
    background: rgba(10, 14, 18, 0.55);
}
.score-box span, .muted { color: var(--muted); font-size: 12px; font-weight: 850; text-transform: uppercase; }
.score-box strong { font-size: 18px; }

.board-frame {
    height: 100%;
    min-height: clamp(620px, calc(100vh - 150px), 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));
}

#reversiBoard {
    display: block;
    width: 100%;
    height: 100%;
    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; }
.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;
}
input[type="range"] { padding: 0; accent-color: var(--gold); }
select, input:not([type="range"]) { 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 { opacity: 0.55; cursor: not-allowed; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.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 { height: 260px; min-height: 178px; max-height: 260px; 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; }
.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; }
.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; }
    .play-area { min-height: auto; }
    .board-frame { height: min(62vh, 620px); min-height: 420px; }
}

@media (max-width: 620px) {
    .app-shell { padding: 8px; }
    .game-info-bar { display: grid; grid-template-columns: 1fr; }
    .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; }
}


/* 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);
}

.robot-final-flow h4 {
    margin: 0 0 0.45rem;
    color: #e0f2fe;
}

.robot-final-bars {
    display: grid;
    gap: 0.5rem;
    margin: 0.7rem 0;
}

.robot-final-rate-row {
    display: grid;
    grid-template-columns: minmax(64px, 0.6fr) minmax(120px, 1fr) 56px;
    gap: 0.5rem;
    align-items: center;
}

.robot-final-rate-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.22);
}

.robot-final-rate-track i {
    display: block;
    height: 100%;
    border-radius: inherit;
}

.robot-flow-black {
    background: linear-gradient(90deg, #0f172a, #475569);
}

.robot-flow-white {
    background: linear-gradient(90deg, #f8fafc, #cbd5e1);
}

/* 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;
}
