:root {
    color-scheme: light;
    --bg: #111827;
    --panel: rgba(255, 255, 255, 0.96);
    --panel-strong: #f8fafc;
    --text: #111827;
    --muted: #4b5563;
    --accent: #5b6bff;
    --accent-soft: #dde0ff;
    --danger: #dc2626;
    --border: rgba(148, 163, 184, 0.25);
    --board-light: #f5f0dc;
    --board-dark: #c79b5d;
    --square: rgba(255,255,255,0.8);
    --shadow: 0 22px 60px rgba(15, 23, 42, 0.22);
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, rgba(91, 107, 255, 0.3), transparent 20%),
        linear-gradient(180deg, #e2e8f0 0%, #f8fafc 45%, #e5e7eb 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
}

body.dark {
    color-scheme: dark;
    --bg: #0f172a;
    --panel: rgba(15, 23, 42, 0.95);
    --panel-strong: #111827;
    --text: #f8fafc;
    --muted: #a5b4fc;
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.18);
    --danger: #fb7185;
    --border: rgba(100, 116, 139, 0.35);
    --board-light: #374151;
    --board-dark: #1f2937;
    --square: rgba(255,255,255,0.08);
    --shadow: 0 22px 60px rgba(15, 23, 42, 0.44);
}

* {
    box-sizing: border-box;
}

button,
select {
    font: inherit;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.screen {
    min-height: calc(100vh - 48px);
}

.hidden {
    display: none !important;
}

.menu-screen,
.game-screen {
    display: flex;
    justify-content: center;
    align-items: center;
}

.card,
.mini-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.panel {
    width: min(100%, 560px);
    padding: 24px;
}

.panel-header h1 {
    margin: 0 0 12px;
    font-size: clamp(2rem, 2.5vw, 2.6rem);
}

.panel-header p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.field-group {
    margin-top: 20px;
}

.field-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 700;
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.mode-button,
.primary-button,
.secondary-button,
.danger-button {
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 14px 18px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.mode-button {
    background: var(--board-light);
    color: var(--text);
    min-width: 120px;
}

.mode-button.active,
.mode-button:hover {
    background: var(--accent);
    color: white;
}

.primary-button {
    width: 100%;
    background: linear-gradient(135deg, #5b6bff, #7c3aed);
    color: white;
    border-color: transparent;
    font-weight: 700;
}

.secondary-button {
    width: 100%;
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.danger-button {
    width: 100%;
    background: #fee2e2;
    color: #991b1b;
    border-color: transparent;
}

button:hover {
    transform: translateY(-1px);
}

select {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--panel-strong);
    color: var(--text);
}

.game-header {
    display: flex;
    gap: 24px;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.game-header h2 {
    margin: 0 0 8px;
}

.status-box {
    min-width: 220px;
    padding: 18px 20px;
    border-radius: 22px;
    border: 1px solid var(--border);
    background: var(--panel);
}

.status-box div {
    margin-bottom: 10px;
}

#statusText {
    font-size: 1rem;
    font-weight: 700;
}

#turnLabel {
    color: var(--muted);
}

.game-grid {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 360px;
    gap: 22px;
    align-items: start;
}

.board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 10;
    border-radius: 28px;
    overflow: hidden;
    background: linear-gradient(180deg, var(--board-light) 0%, var(--board-dark) 100%);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}

.board {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
    gap: 0;
    padding: 12px;
    background-image:
        linear-gradient(to right, rgba(255,255,255,0.25) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.25) 1px, transparent 1px);
    background-size: calc(100% / 9) calc(100% / 10);
}

.board::after {
    content: "SÔNG TRUNG BỘ";
    position: absolute;
    inset: 34% 0 auto;
    width: 100%;
    text-align: center;
    color: rgba(255,255,255,0.3);
    font-size: 1.1rem;
    letter-spacing: 0.35em;
    font-weight: 700;
    pointer-events: none;
}

.board.flipped::after {
    transform: rotate(180deg);
}

.square {
    position: relative;
    display: grid;
    place-items: center;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.square:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.08);
}

.square.active {
    background: rgba(255,255,255,0.18);
    border: 2px solid rgba(96, 165, 250, 0.75);
}

.square.move-target {
    background: rgba(59, 130, 246, 0.25);
}

.piece {
    width: 82%;
    height: 82%;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: clamp(1.2rem, 2.6vw, 2.4rem);
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: transform 0.2s ease;
}

.piece.red {
    background: radial-gradient(circle at top, #fef3c7, #f97316 55%);
    color: #7c2d12;
}

.piece.black {
    background: radial-gradient(circle at top, #d1d5db, #475569 55%);
    color: #f8fafc;
}

.piece.face-down {
    background: radial-gradient(circle at top, #334155, #0f172a 60%);
    color: transparent;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}

.piece.face-down::after {
    content: "?";
    color: #e2e8f0;
    font-size: 1.4rem;
    font-weight: 800;
}

.sidebar {
    display: grid;
    gap: 20px;
}

.mini-panel {
    padding: 20px;
}

.panel-title {
    font-weight: 700;
    margin-bottom: 14px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    color: var(--muted);
}

.info-row strong {
    color: var(--text);
}

.history-list {
    max-height: 460px;
    overflow-y: auto;
    display: grid;
    gap: 12px;
    padding-right: 4px;
}

.chat-list {
    max-height: 260px;
}

.chat-input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-top: 10px;
}

.chat-input-row input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    background: var(--panel-strong);
    color: var(--text);
}

.chat-message,
.history-item {
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.chat-message.sender {
    background: rgba(219, 234, 254, 0.9);
}

.chat-message.self {
    background: rgba(220, 252, 231, 0.95);
}

.chat-message span {
    display: block;
}

.history-item {
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.history-item span {
    display: block;
    color: var(--muted);
    font-size: 0.92rem;
}

.history-item strong {
    display: block;
    margin-top: 6px;
}

.control-panel button {
    margin-bottom: 12px;
}

.pause-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.72);
    display: grid;
    place-items: center;
    z-index: 30;
}

.pause-card {
    background: var(--panel);
    padding: 28px;
    border-radius: 28px;
    border: 1px solid var(--border);
    width: min(90%, 420px);
    text-align: center;
}

.pause-card h3 {
    margin: 0 0 18px;
}

.overlay-message {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.45);
    color: white;
    font-size: 1.4rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    pointer-events: none;
}

@media (max-width: 1100px) {
    .game-grid {
        grid-template-columns: 1fr;
    }
    .sidebar {
        width: min(100%, 100%);
    }
}

@media (max-width: 720px) {
    .app {
        padding: 16px;
    }
    .panel,
    .mini-panel {
        padding: 18px;
    }
    .board-container {
        aspect-ratio: 1 / 1.2;
    }
    .panel-footer {
        display: grid;
        gap: 12px;
    }
    .radio-group {
        flex-direction: column;
        align-items: stretch;
    }
}
