* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a2e;
    color: #eee;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
}

.hidden {
    display: none !important;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #e94560;
    font-size: 2em;
    text-shadow: 0 0 10px rgba(233, 69, 96, 0.3);
}

#game-container {
    max-width: 900px;
    width: 100%;
}

#game-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

#left-panel {
    width: 220px;
    flex-shrink: 0;
}

.panel-box {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.panel-box div {
    margin: 4px 0;
    font-size: 14px;
}

.dead-pieces {
    font-size: 24px;
    line-height: 1.4;
    min-height: 30px;
    letter-spacing: 4px;
}

.dead-piece-white {
    color: #fff;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.7), 0 0 1px #000;
}

.dead-piece-black {
    color: #222;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5), 0 0 1px #666;
}

#game-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#game-buttons button {
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#btn-new-game, #btn-play-again {
    background: #0f3460;
    color: white;
}

#btn-new-game:hover, #btn-play-again:hover {
    background: #1a4a7a;
}

#btn-end-turn {
    background: #e94560;
    color: white;
}

#btn-end-turn:hover:not(:disabled) {
    background: #ff6b81;
}

#btn-end-turn:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

#btn-undo {
    background: #f39c12;
    color: white;
}

#btn-undo:hover:not(:disabled) {
    background: #f1c40f;
}

#btn-undo:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

#btn-back-menu, #btn-back-menu-from-overlay {
    background: #555;
    color: white;
}

#btn-back-menu:hover, #btn-back-menu-from-overlay:hover {
    background: #777;
}

#board-container {
    position: relative;
    flex-grow: 1;
}

#board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 480px;
    height: 480px;
    border: 3px solid #0f3460;
    border-radius: 4px;
    overflow: hidden;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 42px;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.square.light {
    background: #f0d9b5;
}

.square.dark {
    background: #b58863;
}

.square.piece-white {
    color: #fff;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.8), 0 0 12px rgba(255, 255, 255, 0.4), 0 0 1px #000;
}

.square.piece-black {
    color: #1a1a1a;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.5), 0 0 1px #333;
}

.square.selected {
    background: #7fc97f !important;
}

.square.highlight {
    background: #a0d8a0 !important;
}

.square.highlight::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.square.highlight-capture {
    background: #e8a0a0 !important;
}

.square.highlight-capture::after {
    content: '';
    position: absolute;
    width: 36px;
    height: 36px;
    border: 4px solid rgba(200, 0, 0, 0.4);
    border-radius: 50%;
}

.square.revive-target {
    background: #a0d8ff !important;
}

.square.revive-target::after {
    content: '';
    position: absolute;
    width: 36px;
    height: 36px;
    border: 3px dashed #2196F3;
    border-radius: 50%;
}

.square.in-check {
    background: #ff4444 !important;
    animation: check-pulse 1s ease-in-out infinite;
}

@keyframes check-pulse {
    0%, 100% { box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8); }
    50% { box-shadow: inset 0 0 40px rgba(255, 0, 0, 1); }
}

/* ===== MAIN MENU ===== */
#main-menu {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    width: 100%;
}

#menu-content {
    text-align: center;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 16px;
    padding: 50px 60px;
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.2);
    max-width: 500px;
    width: 100%;
}

#menu-content h1 {
    font-size: 2.2em;
    margin-bottom: 8px;
}

.menu-subtitle {
    color: #888;
    margin-bottom: 40px;
    font-size: 1.1em;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.menu-btn {
    padding: 16px 40px;
    font-size: 18px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    min-width: 220px;
}

.menu-btn.small {
    padding: 12px 30px;
    font-size: 15px;
    min-width: 160px;
}

#btn-play-ai {
    background: #e94560;
    color: white;
}

#btn-play-ai:hover {
    background: #ff6b81;
}

#btn-multiplayer {
    background: #2196F3;
    color: white;
}

#btn-multiplayer:hover {
    background: #42a5f5;
}

.mp-row {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: center;
    margin-top: 20px;
}

.mp-or {
    color: #888;
    font-size: 14px;
}

#btn-create-room {
    background: #4CAF50;
    color: white;
}

#btn-create-room:hover {
    background: #66bb6a;
}

#btn-join-room {
    background: #FF9800;
    color: white;
}

#btn-join-room:hover {
    background: #ffb74d;
}

.room-code {
    font-size: 28px;
    font-weight: bold;
    color: #e94560;
    background: #0f3460;
    padding: 12px 24px;
    border-radius: 8px;
    display: inline-block;
    letter-spacing: 3px;
    margin: 10px 0;
    font-family: monospace;
}

.mp-hint {
    color: #888;
    font-size: 13px;
    margin-top: 4px;
}

#room-code-input {
    padding: 12px 16px;
    font-size: 18px;
    border: 2px solid #0f3460;
    border-radius: 8px;
    background: #1a1a2e;
    color: #fff;
    text-align: center;
    width: 200px;
    margin: 10px 0;
    letter-spacing: 2px;
    font-family: monospace;
}

#room-code-input:focus {
    outline: none;
    border-color: #e94560;
}

#btn-connect {
    background: #4CAF50;
    color: white;
    margin-left: 8px;
}

#btn-connect:hover {
    background: #66bb6a;
}

/* ===== SETTINGS PANEL ===== */
#settings-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    width: 100%;
}

#settings-panel.hidden {
    display: none;
}

#settings-content {
    text-align: center;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 16px;
    padding: 40px 50px;
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.2);
    max-width: 450px;
    width: 100%;
}

#settings-content h2 {
    color: #e94560;
    margin-bottom: 24px;
    font-size: 1.8em;
}

.settings-section {
    margin-bottom: 20px;
    text-align: left;
}

.settings-section h3 {
    color: #2196F3;
    margin-bottom: 12px;
    font-size: 1.1em;
    border-bottom: 1px solid #0f3460;
    padding-bottom: 6px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    gap: 12px;
}

.setting-row label {
    font-size: 14px;
    flex: 1;
}

.setting-row select {
    padding: 6px 10px;
    background: #0f3460;
    color: #eee;
    border: 1px solid #1a4a7a;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

.setting-row input[type="range"] {
    flex: 1;
    max-width: 120px;
    accent-color: #e94560;
}

#volume-display {
    font-size: 14px;
    color: #aaa;
    min-width: 36px;
    text-align: right;
}

.setting-row.sound-toggle label {
    flex: 1;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background-color: #4CAF50;
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

.settings-btn {
    background: #555;
    color: white;
    margin-top: 8px;
}

.settings-btn:hover {
    background: #777;
}

#btn-settings-back {
    background: #e94560;
    color: white;
    padding: 12px 40px;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 16px;
}

#btn-settings-back:hover {
    background: #ff6b81;
}

.exit-btn {
    background: #c0392b !important;
    color: white !important;
    margin-top: 8px;
}

.exit-btn:hover {
    background: #e74c3c !important;
}

#mp-connection-status, #connection-status, #opponent-status {
    margin-top: 12px;
    font-size: 14px;
    color: #aaa;
}

/* ===== GAME OVER OVERLAY ===== */
#game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 4px;
}

#game-over-overlay.hidden {
    display: none;
}

#game-over-content {
    background: #16213e;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid #e94560;
}

#game-over-content h2 {
    font-size: 2em;
    margin-bottom: 10px;
    color: #e94560;
}

#game-over-content p {
    font-size: 1.2em;
    margin-bottom: 20px;
}

#game-over-content button {
    padding: 12px 30px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    margin: 4px;
}

#game-over-content #btn-play-again {
    background: #e94560;
    color: white;
}

#game-over-content #btn-play-again:hover {
    background: #ff6b81;
}

/* Check banner */
#check-banner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 0, 0, 0.85);
    color: white;
    font-size: 48px;
    font-weight: bold;
    padding: 20px 40px;
    border-radius: 12px;
    border: 3px solid #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    z-index: 50;
    pointer-events: none;
    animation: check-banner-pulse 1s ease-in-out infinite;
}

@keyframes check-banner-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.05); opacity: 0.9; }
}

#check-banner.fade-in {
    animation: check-banner-pulse 1s ease-in-out infinite;
}

#check-banner.fade-out {
    animation: check-banner-fade-out 0.5s ease-out forwards;
}

@keyframes check-banner-fade-out {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Revive UI */
#revive-panel {
    background: #16213e;
    border: 2px solid #2196F3;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

#revive-panel h3 {
    color: #2196F3;
    margin-bottom: 8px;
    font-size: 14px;
}

#revive-pieces-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.revive-piece-btn {
    font-size: 28px;
    padding: 8px 14px;
    background: #0f3460;
    color: white;
    border: 2px solid #2196F3;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.revive-piece-btn:hover {
    background: #1a4a7a;
}

.revive-piece-btn.selected-revive {
    background: #2196F3;
    border-color: #fff;
}

#revive-instruction {
    margin-top: 8px;
    font-size: 13px;
    color: #aaa;
}

#right-panel {
    width: 220px;
    flex-shrink: 0;
}

/* ===== CARD AREA ===== */
#card-area {
    text-align: center;
}

#card-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
}

#card-face {
    width: 100px;
    height: 140px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: background 0.3s ease;
    cursor: default;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#card-face.card-back {
    background: linear-gradient(135deg, #1a1a2e 25%, #0f3460 50%, #1a1a2e 75%);
    border: 3px solid #e94560;
    animation: pulse-glow 1.5s ease-in-out infinite;
}

#card-face.card-back #card-icon {
    font-size: 36px;
    opacity: 1;
    color: #e94560;
}

#card-face.card-back #card-label {
    display: none;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(233, 69, 96, 0.4); }
    50% { box-shadow: 0 0 25px rgba(233, 69, 96, 0.8); }
}

#card-face.card-revealed {
    border: 3px solid #fff;
}

#card-face.card-revealed #card-icon {
    font-size: 42px;
    margin-bottom: 4px;
}

#card-face.card-revealed #card-label {
    display: block;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

#card-face.card-number {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
}

#card-face.card-reverse {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

#card-face.card-plus2 {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

#card-face.card-plus4 {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

#card-face.card-drawing {
    animation: card-draw 0.7s ease-out forwards;
}

@keyframes card-draw {
    0% { transform: translateY(-60px) rotate(-10deg) scale(0.7); opacity: 0; }
    50% { transform: translateY(8px) rotate(3deg) scale(1.05); opacity: 1; }
    70% { transform: translateY(-4px) rotate(-1deg) scale(0.98); }
    100% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
}

#card-face.card-shown {
    animation: card-appear 0.3s ease-out forwards;
}

@keyframes card-appear {
    0% { transform: scale(0.95); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

#card-info-text {
    margin-top: 4px;
    font-size: 13px;
}

@media (max-width: 800px) {
    #game-layout { flex-direction: column; align-items: center; }
    #left-panel { width: 100%; max-width: 480px; }
    #board { width: 360px; height: 360px; }
    .square { font-size: 32px; }
    #card-face { width: 80px; height: 110px; }
    #card-face.card-revealed #card-icon { font-size: 32px; }
}