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

* { 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: 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 minmax(0, 1fr);
    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-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; }
.score-box.black { border-color: rgba(255, 255, 255, 0.18); }
.score-box.white { border-color: rgba(237, 244, 246, 0.46); }

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

#reversiBoard {
    display: block;
    width: min(100%, 1180px);
    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 { 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 { min-height: 178px; max-height: 320px; 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; }
.color-board {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 4px;
    padding-top: 15px;
    border-top: 1px solid rgba(148, 163, 184, 0.3);
}
.color-pair {
    display: flex;
    gap: 2px;
    width: auto;
    min-height: 0;
    padding: 2px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
}
.color-pair.active {
    border-color: rgba(72, 199, 244, 0.72);
}
.color-pair:hover,
.color-pair:focus-visible {
    border-color: rgba(148, 163, 184, 0.8);
    background: transparent;
    transform: scale(1.05);
    outline: none;
}
.color-swatch {
    width: 18px;
    height: 18px;
    border: 1px solid rgba(15, 23, 42, 0.6);
    border-radius: 4px;
}
.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 (min-width: 981px) {
    .play-area { min-height: calc(100vh - 28px); }
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
}

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