* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    color-scheme: dark;
    --board-light: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --board-dark: linear-gradient(135deg, #334155 0%, #1e293b 100%);
}

body {
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #1e1e1e 0%, #2d2d2d 100%);
    color: #f1f5f9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
select,
input {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

.space-home-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 12px;
    border: 1px solid rgba(97, 174, 255, 0.42);
    border-radius: 999px;
    background: rgba(5, 12, 24, 0.92);
    color: #eef5ff;
    font-size: 13px;
    font-weight: 900;
    flex: 0 0 auto;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.space-home-link:hover,
.space-home-link:focus-visible {
    border-color: rgba(251, 191, 36, 0.86);
    color: #fde68a;
    outline: none;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    margin-bottom: 30px;
    text-align: center;
}

.header h1 {
    margin-bottom: 10px;
    color: #38bdf8;
    font-size: 2.85em;
    letter-spacing: 0;
}

.header p {
    color: #cbd5e1;
    font-size: 1.1em;
}

.main-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 350px;
    gap: 30px;
    align-items: start;
    margin-bottom: 30px;
}

.board-wrapper,
.sidebar,
.reference-panels-below-board {
    min-width: 0;
    max-width: 100%;
}

.board-wrapper {
    position: relative;
}

.game-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px 20px;
    border: 2px solid #38bdf8;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.9);
}

.timer-section {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 30px;
}

.player-timer {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 8px 16px;
    border-left: 4px solid #38bdf8;
    border-radius: 8px;
    background: rgba(51, 65, 85, 0.6);
}

.player-timer.active {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.15);
}

.timer-label {
    color: #cbd5e1;
    font-size: 0.9em;
    font-weight: 600;
}

.timer-value {
    color: #38bdf8;
    font-family: "Courier New", monospace;
    font-size: 1.1em;
    font-weight: 700;
}

.boundary-display {
    min-height: 42px;
    padding: 8px 16px;
    border-left: 4px solid #10b981;
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.15);
    color: #d1fae5;
    font-weight: 600;
}

.captured-pieces-container {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 15px;
}

.captured-side {
    flex: 1;
    min-height: 66px;
    padding: 10px;
    border: 2px solid rgba(56, 189, 248, 0.3);
    border-radius: 8px;
    background: rgba(51, 65, 85, 0.5);
}

.captured-label {
    margin-bottom: 5px;
    color: #cbd5e1;
    font-size: 0.75em;
    font-weight: 600;
}

.captured-icons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 30px;
    font-size: 1.3em;
}

.captured-piece {
    flex: 0 0 auto;
}

.board-container {
    padding: 20px;
    border: 3px solid #38bdf8;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1;
}

.board-stage {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1;
    margin: 0 auto;
}

.open-boundary-moves {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
}

.open-exit-move {
    position: absolute;
    display: grid;
    place-items: center;
    width: clamp(24px, 5.2vw, 34px);
    min-height: 0;
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid rgba(34, 197, 94, 0.9);
    border-radius: 50%;
    background: rgba(5, 46, 22, 0.94);
    color: #bbf7d0;
    font-size: clamp(14px, 3vw, 20px);
    line-height: 1;
    box-shadow: 0 0 16px rgba(34, 197, 94, 0.7);
    transform: translate(-50%, -50%);
    pointer-events: auto;
}

.open-exit-move:hover,
.open-exit-move:focus-visible {
    z-index: 2;
    border-color: #facc15;
    color: #fef08a;
    background: rgba(66, 32, 6, 0.96);
    transform: translate(-50%, -50%) scale(1.12);
}

.square {
    position: relative;
    display: flex;
    width: auto;
    min-width: 0;
    min-height: 0;
    padding: 0;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    cursor: pointer;
    user-select: none;
    font-size: clamp(34px, 7.2vmin, 58px);
    font-weight: 400;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.square.light {
    background: var(--board-light);
}

.square.dark {
    background: var(--board-dark);
}

.square:hover {
    transform: scale(1.05);
    z-index: 1;
}

.square.selected {
    background: #fbbf24 !important;
    box-shadow: inset 0 0 20px rgba(251, 191, 36, 0.5);
}

.square.legal-move {
    box-shadow: inset 0 0 15px rgba(34, 197, 94, 0.6);
}

.square.legal-move::after {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.7);
    content: "";
}

.square.capture-move::after {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(239, 68, 68, 0.74);
    background: transparent;
}

.square.castle-move {
    box-shadow: inset 0 0 0 4px rgba(251, 191, 36, 0.82), inset 0 0 18px rgba(251, 191, 36, 0.36);
}

.square.check {
    background: #ef4444 !important;
    animation: pulse 0.6s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: inset 0 0 15px rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: inset 0 0 30px rgba(239, 68, 68, 0.8);
    }
}

.piece-glyph {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
    font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols", "DejaVu Sans", sans-serif;
    font-size: 0.98em;
    font-style: normal;
    font-variant-emoji: text;
    font-weight: 400;
    line-height: 1;
    transform: none;
}

.piece-white {
    color: #f1f5f9;
    -webkit-text-stroke: 0;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.95), 0 5px 9px rgba(0, 0, 0, 0.82), 0 10px 18px rgba(0, 0, 0, 0.58), 0 0 6px rgba(255, 255, 255, 0.2);
}

.piece-black {
    color: #1a1a1a;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.3), 0 0 8px rgba(200, 100, 100, 0.4);
}

.sidebar {
    height: fit-content;
    padding: 25px;
    border: 3px solid #38bdf8;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.8);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.sidebar-header h2 {
    margin-bottom: 0;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
}

.sidebar h2 {
    margin-bottom: 20px;
    color: #38bdf8;
    font-size: 1.3em;
    letter-spacing: 0;
}

.status,
.info-section,
.piece-legend {
    border-radius: 8px;
    background: rgba(51, 65, 85, 0.6);
}

.status {
    margin-bottom: 20px;
    padding: 15px;
    border-left: 4px solid #38bdf8;
}

.status p {
    margin: 5px 0;
    font-size: 0.95em;
}

.status .player-turn {
    color: #38bdf8;
    font-size: 1.1em;
    font-weight: 700;
}

.status-line {
    color: #f1f5f9;
    line-height: 1.4;
}

.status .status-line {
    display: none;
}

.muted {
    color: #94a3b8;
    opacity: 0.9;
}

.control-group {
    margin-bottom: 25px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    color: #cbd5e1;
    font-size: 0.95em;
    font-weight: 500;
}

select,
button,
input {
    width: 100%;
    min-height: 44px;
    padding: 12px;
    border: 2px solid #38bdf8;
    border-radius: 8px;
    background: rgba(3, 102, 214, 0.1);
    color: #f1f5f9;
    font-size: 1em;
    font-weight: 500;
    transition: background 0.3s ease, border-color 0.3s ease, transform 0.12s ease;
}

select {
    background: #101827;
    color: #f8fafc;
}

select option {
    background: #101827;
    color: #f8fafc;
}

select option:checked {
    background: #fbbf24;
    color: #111827;
}

input {
    cursor: text;
}

select:hover,
button:hover {
    border-color: #0ea5e9;
    background: rgba(3, 102, 214, 0.2);
}

select:hover,
select:focus {
    background: #0b1220;
    color: #ffffff;
}

select:disabled,
button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

button:active {
    transform: scale(0.98);
}

.online-controls {
    display: none;
    margin-bottom: 15px;
    padding: 15px;
    border: 2px solid #10b981;
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.1);
}

.online-controls.active {
    display: block;
}

.connection-status {
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    text-align: center;
}

.connection-status.disconnected {
    border: 2px solid #ef4444;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.connection-status.connecting {
    border: 2px solid #fbbf24;
    background: rgba(251, 191, 36, 0.2);
    color: #fde047;
}

.connection-status.connected {
    border: 2px solid #10b981;
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.online-btn {
    margin-bottom: 8px;
}

.online-btn.create {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.2);
}

.online-btn.match {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.18);
}

.online-btn.join {
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.2);
}

.divider-text {
    margin: 10px 0;
    color: #94a3b8;
    font-size: 0.85em;
    text-align: center;
}

.room-info {
    margin: 10px 0;
    padding: 10px;
    border-radius: 6px;
    background: rgba(51, 65, 85, 0.6);
    font-size: 0.85em;
}

.room-info[hidden] {
    display: none;
}

.room-block {
    margin-bottom: 8px;
}

.room-id-display {
    color: #38bdf8;
    font-family: "Courier New", monospace;
    font-weight: 700;
    word-break: break-all;
}

.share-link-box {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.share-link-input {
    flex: 1;
    min-width: 0;
    padding: 8px;
    font-size: 0.75em;
}

.copy-btn {
    width: auto;
    padding: 8px 16px;
    background: #10b981;
    color: #ffffff;
    font-size: 0.85em;
}

.copy-btn:hover {
    background: #059669;
}

.boundary-info {
    margin-bottom: 15px;
    padding: 12px;
    border-left: 4px solid #10b981;
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.1);
    color: #d1fae5;
    font-size: 0.9em;
}

.controls {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.warning {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.2);
}

.info-section {
    max-height: 300px;
    margin-top: 20px;
    padding: 15px;
    overflow-y: auto;
}

.info-section h3 {
    margin-bottom: 10px;
    color: #38bdf8;
    font-size: 0.95em;
    letter-spacing: 0;
}

.move-history {
    height: 220px;
    min-height: 178px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
    color: #cbd5e1;
    font-size: 0.85em;
    line-height: 1.6;
}

.move-history-item {
    margin: 3px 0;
    padding: 5px;
    border-left: 2px solid #38bdf8;
    border-radius: 4px;
    background: rgba(3, 102, 214, 0.1);
}

.piece-legend {
    margin-top: 15px;
    padding: 12px;
    color: #cbd5e1;
    font-size: 0.85em;
    line-height: 1.8;
}

.piece-legend div {
    margin: 5px 0;
}

.color-board {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    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:hover {
    border-color: rgba(148, 163, 184, 0.8);
    background: transparent;
    transform: scale(1.05);
}

.color-swatch {
    width: 18px;
    height: 18px;
    border: 1px solid rgba(15, 23, 42, 0.6);
    border-radius: 4px;
}

.hints-toggle {
    position: fixed;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 2px solid #38bdf8;
    background: rgba(15, 23, 42, 0.95);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.hints-toggle {
    right: 20px;
    bottom: 20px;
    padding: 12px 16px;
    border-radius: 25px;
}

.hints-toggle label {
    color: #cbd5e1;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    user-select: none;
}

.toggle-switch {
    position: relative;
    padding: 0;
    background: rgba(51, 65, 85, 0.8);
}

.toggle-switch {
    width: 50px;
    min-height: 24px;
    border-radius: 12px;
}

.toggle-switch.active {
    background: #10b981;
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f1f5f9;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(26px);
}

body > .language-switch {
    position: fixed;
    top: 10px;
    right: 12px;
    z-index: 100;
    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);
}

body > .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;
}

body > .language-switch .lang-option:hover {
    background: transparent;
    color: #f8fafc;
}

body > .language-switch .lang-option.active {
    color: #38bdf8;
    text-decoration: underline;
    text-underline-offset: 4px;
}

body > .language-switch .lang-option:active {
    transform: none;
}

body > .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;
}

.promotion-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
}

.promotion-modal.active {
    display: flex;
}

.promotion-dialog {
    width: min(420px, calc(100vw - 32px));
    padding: 30px;
    border: 3px solid #38bdf8;
    border-radius: 12px;
    background: #1e293b;
    text-align: center;
}

.promotion-dialog h3 {
    margin-bottom: 20px;
    color: #38bdf8;
    font-size: 1.3em;
    letter-spacing: 0;
}

.promotion-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.promotion-btn {
    min-height: 70px;
    padding: 12px;
    border: 2px solid #38bdf8;
    border-radius: 8px;
    background: rgba(3, 102, 214, 0.2);
    color: #f1f5f9;
    font-size: 2em;
}

.promotion-btn:hover {
    background: rgba(3, 102, 214, 0.5);
    transform: scale(1.1);
}

@media (max-width: 900px) {
    body {
        padding: 14px;
    }

    .main-content {
        grid-template-columns: minmax(0, 1fr);
    }

    .header h1 {
        font-size: 2em;
    }

    #chessboard {
        max-width: 100%;
    }
}

@media (max-width: 560px) {
    .game-info-bar,
    .timer-section,
    .captured-pieces-container,
    .share-link-box {
        flex-direction: column;
        align-items: stretch;
    }

    .timer-section {
        gap: 10px;
    }

    .board-container {
        padding: 10px;
    }

    .square {
        font-size: 1.8em;
    }
}


.robot-panel {
    border: 1px solid rgba(125, 211, 252, 0.28);
    background: rgba(15, 23, 42, 0.48);
    border-radius: 14px;
    padding: 1rem;
    margin-top: 1rem;
}

.robot-panel h3,
.robot-panel h4 {
    margin: 0.35rem 0 0.55rem;
    color: #e0f2fe;
}

.compact-control {
    margin-bottom: 0.65rem;
}

.robot-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    margin: 0.7rem 0;
}

.robot-controls button.secondary {
    background: linear-gradient(135deg, #0369a1, #075985);
}

.robot-controls button:disabled {
    cursor: wait;
    opacity: 0.58;
}

.robot-analysis {
    max-height: 340px;
    overflow: auto;
    padding: 0.75rem;
    background: rgba(2, 6, 23, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 12px;
    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.55rem;
    margin-bottom: 0.7rem;
}

.robot-summary-grid > div {
    padding: 0.55rem;
    border-radius: 10px;
    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 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, #e5e7eb, #94a3b8);
}

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

/* Compact language icon menu */
body > .language-switch.compact-language {
    width: auto;
    gap: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}
.language-switch.compact-language { position: relative; display: inline-flex; align-items: center; }
.language-switch.compact-language .language-icon-button {
    width: 42px;
    height: 42px;
    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;
    bottom: 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, 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; }

body > .language-switch.compact-language {
    display: none;
}

.sidebar-header .language-switch.compact-language .language-popover {
    top: calc(100% + 8px);
    bottom: auto;
}
