:root {
    color-scheme: dark;
    --bg: #0b0e12;
    --panel: #151a20;
    --panel-soft: #10151a;
    --line: rgba(226, 232, 240, 0.18);
    --text: #f1f5f9;
    --muted: #aab5bf;
    --cyan: #42c7df;
    --gold: #e8b44c;
    --green: #4fb27c;
    --danger: #ef7d72;
}

* { box-sizing: border-box; }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: #0b0e12;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.play-area,
.sidebar {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.play-area {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 12px;
    min-height: calc(100vh - 28px);
    padding: 14px;
}

.top-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--gold);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.top-bar h1,
.sidebar h2,
.panel h3 {
    margin: 0;
    letter-spacing: 0;
}

.top-bar h1 { font-size: clamp(28px, 4vw, 44px); }
.top-bar p:last-child { max-width: 760px; margin: 6px 0 0; color: var(--muted); line-height: 1.45; }

.game-info-bar,
.status-card,
.panel,
.boundary-info {
    border: 1px solid rgba(226, 232, 240, 0.14);
    border-radius: 8px;
    background: var(--panel-soft);
}

.game-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
}

.turn-pill,
.boundary-display {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid rgba(66, 199, 223, 0.55);
    border-radius: 999px;
    color: #e6fbff;
    font-weight: 850;
}

.score-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(76px, 1fr));
    gap: 8px;
}

.score-box {
    min-width: 0;
    display: grid;
    gap: 2px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #0b1015;
}

.score-box span,
.muted {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.score-box strong { font-size: 18px; }
.score-box.black { border-color: rgba(66, 199, 223, 0.5); }
.score-box.white { border-color: rgba(232, 180, 76, 0.55); }
.score-box.moves { border-color: rgba(79, 178, 124, 0.5); }

.board-panel {
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: auto;
    padding: 10px;
    border: 1px solid rgba(226, 232, 240, 0.1);
    border-radius: 8px;
    background: #080c10;
}

#hexBoard {
    display: block;
    width: min(100%, 1180px);
    height: auto;
    min-height: 0;
    aspect-ratio: 1.42;
    border-radius: 6px;
    background: #f6f7f5;
    touch-action: none;
    cursor: crosshair;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: visible;
    padding: 14px;
}

.sidebar-header,
.header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.header-actions { justify-content: flex-end; }

.space-home-link {
    width: auto;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 11px;
    border: 1px solid rgba(66, 199, 223, 0.46);
    border-radius: 999px;
    background: #0c1218;
    color: var(--text);
    text-decoration: none;
    font-weight: 850;
}

.language-button {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    box-shadow: none;
    cursor: pointer;
}

.language-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.35;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.status-card,
.panel,
.boundary-info { padding: 10px; }
.status-line { font-size: 14px; font-weight: 760; line-height: 1.4; overflow-wrap: anywhere; }
.status-line + .status-line { margin-top: 5px; }

.control-group { min-width: 0; display: grid; gap: 6px; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }

label { color: #dce8ec; font-size: 13px; font-weight: 850; }

select,
input,
button {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    border: 1px solid rgba(226, 232, 240, 0.22);
    border-radius: 7px;
    background: #0b1015;
    color: var(--text);
    font: inherit;
}

select,
input { padding: 0 10px; }
button { cursor: pointer; padding: 8px 10px; font-weight: 850; }
button:hover:not(:disabled),
button:focus-visible { border-color: var(--cyan); }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.primary-button { border-color: rgba(79, 178, 124, 0.8); background: #143a2a; }

.boundary-info { color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }

.robot-panel {
    border-color: rgba(66, 199, 223, 0.25);
    background: rgba(7, 13, 18, 0.78);
}

.robot-panel h3 {
    font-size: 18px;
    margin-bottom: 6px;
}

.robot-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin: 10px 0;
}

.robot-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0;
}

.robot-analysis {
    min-height: 72px;
    padding: 10px;
    border: 1px solid rgba(226, 232, 240, 0.14);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.18);
    font-size: 13px;
    line-height: 1.42;
    overflow-wrap: anywhere;
}

.robot-analysis h4 {
    margin: 8px 0 4px;
    color: #e6fbff;
    font-size: 13px;
}

.robot-muted {
    margin: 0;
    color: var(--muted);
}

.robot-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 8px;
}

.robot-summary-grid > div {
    min-width: 0;
    padding: 8px;
    border: 1px solid rgba(226, 232, 240, 0.12);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04);
}

.robot-label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
}

.robot-move-list {
    margin: 6px 0 0 20px;
    padding: 0;
}

.robot-move-list li { margin-bottom: 6px; }
.robot-move-list span { display: block; }

.robot-final-flow h4 {
    margin: 0 0 6px;
    color: #e6fbff;
    font-size: 14px;
}

.robot-final-bars {
    display: grid;
    gap: 8px;
    margin: 10px 0;
}

.robot-final-rate-row {
    display: grid;
    grid-template-columns: minmax(56px, 0.55fr) minmax(110px, 1fr) 52px;
    align-items: center;
    gap: 8px;
}

.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, #54c7e8, #208aa8); }
.robot-flow-white { background: linear-gradient(90deg, #ffd76a, #d49b15); }

.view-settings {
    display: grid;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(226, 232, 240, 0.14);
    border-radius: 8px;
    background: #10151a;
}

.view-settings summary {
    cursor: pointer;
    color: #e6fbff;
    font-weight: 850;
}

.range-grid label {
    display: grid;
    gap: 4px;
}

input[type="range"] {
    min-height: 30px;
    padding: 0;
    accent-color: var(--cyan);
}

.secondary-button { background: #0b1015; }

.online-controls {
    display: grid;
    gap: 9px;
    padding: 11px;
    border: 1px solid rgba(79, 178, 124, 0.5);
    border-radius: 8px;
    background: rgba(79, 178, 124, 0.08);
}

.online-controls[hidden],
.custom-size-input[hidden] { display: none; }
.connection-status { padding: 8px; border-radius: 7px; text-align: center; font-weight: 850; }
.connection-status.disconnected { background: rgba(239, 125, 114, 0.14); color: #ffc8c2; }
.connection-status.connecting { background: rgba(232, 180, 76, 0.14); color: #ffe0a3; }
.connection-status.connected { background: rgba(79, 178, 124, 0.16); color: #bff4d8; }
.divider-text { color: var(--muted); font-size: 11px; font-weight: 900; text-align: center; }
.online-btn.match { border-color: rgba(232, 180, 76, 0.7); }
.online-btn.create { border-color: rgba(79, 178, 124, 0.7); }
.online-btn.join { border-color: rgba(66, 199, 223, 0.7); }

.target-legend { display: grid; gap: 8px; margin-top: 10px; }
.target-legend > span { display: flex; align-items: center; gap: 8px; color: #dce5eb; font-size: 13px; }
.target-swatch { width: 24px; height: 5px; border-radius: 999px; }
.black-target { background: var(--cyan); }
.white-target { background: var(--gold); }

.move-history {
    min-height: 96px;
    max-height: 220px;
    display: grid;
    align-content: start;
    gap: 6px;
    overflow: auto;
    margin-top: 9px;
}

.move-history-item,
.history-empty {
    padding: 7px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.045);
    font-size: 13px;
}

.history-empty { color: var(--muted); }
.chat-panel { margin-top: auto; }
.chat-messages {
    min-height: 90px;
    max-height: 180px;
    display: grid;
    align-content: start;
    gap: 7px;
    overflow: auto;
    margin-top: 9px;
}

.chat-empty { color: var(--muted); font-size: 13px; }
.chat-message { padding: 7px 8px; border-radius: 7px; background: rgba(255, 255, 255, 0.05); font-size: 13px; overflow-wrap: anywhere; }
.chat-input-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 8px; margin-top: 8px; }

@media (max-width: 1040px) {
    .app-shell { grid-template-columns: 1fr; }
    .play-area { min-height: auto; }
    .board-panel { min-height: min(70vh, 680px); }
}

@media (max-width: 680px) {
    .app-shell { padding: 8px; gap: 8px; }
    .play-area,
    .sidebar { padding: 10px; }
    .game-info-bar { display: grid; grid-template-columns: 1fr; align-items: stretch; }
    .turn-pill,
    .boundary-display { justify-content: center; }
    .score-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .score-box { min-width: 0; padding: 7px; }
    .board-panel { min-height: 0; padding: 5px; }
    #hexBoard { width: 100%; height: auto; min-height: 0; }
    .sidebar-header { align-items: flex-start; }
    .control-grid,
    .robot-row,
    .robot-buttons,
    .robot-summary-grid { grid-template-columns: 1fr; }
    .chat-panel { margin-top: 0; }
}

@media (max-width: 390px) {
    .header-actions { display: grid; }
    .score-box span { font-size: 11px; }
    .chat-input-row { grid-template-columns: 1fr; }
}
