:root { --bg-dark: #1a1a2e; --card-bg: #16213e; --text-main: #fff; --white-sq: #f0d9b5; --black-sq: #b58863; --highlight: rgba(155, 199, 0, 0.5); --primary: #3949ab; --danger: #e53935; --accent: #e94560; }
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; user-select: none; }
body { background: var(--bg-dark); color: var(--text-main); height: 100dvh; display: flex; flex-direction: column; overflow: hidden; padding: env(safe-area-inset-top) 1rem 1rem; touch-action: manipulation; }
.app-container { max-width: 800px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; height: 100%; gap: 10px;}
header { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; flex-shrink:0;}
.header-left { display: flex; align-items: center; gap: 10px; }
.global-hub-btn { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; background: rgba(255,255,255,0.1); border-radius: 8px; text-decoration: none; font-size: 1.5rem; }
select { background: var(--card-bg); color: #fff; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--accent); font-size: 0.95rem; outline: none; touch-action: manipulation; }
h1 { font-size: 1.8rem; color: var(--accent); }

details.mobile-details { width: 100%; background: var(--card-bg); border-radius: 8px; flex-shrink:0;}
details.mobile-details summary { padding: 12px; font-weight: bold; text-align: center; cursor: pointer; outline: none; list-style: none; touch-action: manipulation; }
details.mobile-details summary::-webkit-details-marker { display: none; }
details.mobile-details[open] summary { border-bottom: 1px solid rgba(255,255,255,0.1); }
.control-panel { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
.tabs { display: flex; gap: 5px; width: 100%; }
.tabs button { flex: 1; padding: 10px; background: var(--card-bg); color: #aaa; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; touch-action: manipulation; }
.tabs button.active { background: var(--primary); font-weight: bold; }

.btn { flex: 1; padding: 12px; font-weight: bold; border-radius: 8px; border: none; background: var(--primary); color: #fff; cursor: pointer; touch-action: manipulation; }
.btn:active { transform: scale(0.98); }
.btn.danger { background: var(--danger); }

.status-bar { background: var(--card-bg); width: 100%; text-align: center; padding: 10px; border-radius: 8px; font-weight: bold; font-size: 1.2rem; flex-shrink:0;}

.board-wrapper { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 0; width: 100%; padding: 5px 0; overflow: hidden; }
.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    /* width and height set equal by JS — always square */
    border: 4px solid var(--card-bg);
    flex-shrink: 0;
}
.game-over-overlay {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(2.5rem, 10vw, 5rem);
    font-weight: bold;
    color: #4caf50; /* Bright Green */
    text-shadow: 2px 2px 10px rgba(0,0,0,0.9), -2px -2px 10px rgba(0,0,0,0.9);
    z-index: 100;
    text-align: center;
    pointer-events: none;
    width: 100%;
}

.sq { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; position: relative; cursor: pointer; }
.sq.light { background-color: var(--white-sq); }
.sq.dark { background-color: var(--black-sq); }
.sq.highlight::after { content: ''; position: absolute; width: 100%; height: 100%; background: var(--highlight); pointer-events: none; }

.piece { width: 80%; height: 80%; border-radius: 50%; box-shadow: 0 4px 6px rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; font-weight: bold; font-size: clamp(1rem, 4vw, 2rem); color: #fff; }
.piece.w { background: #f9f9f9; color: #000; border: 2px solid #ccc; }
.piece.b { background: #222; border: 2px solid #000; }
.piece.king::after { content: '👑'; font-size: 80%; }

.fab-rules { position: fixed; bottom: 15px; right: 15px; width: 50px; height: 50px; border-radius: 50%; background: var(--primary); color: #fff; border: none; font-size: 1.5rem; box-shadow: 0 4px 10px rgba(0,0,0,0.5); z-index: 50; touch-action: manipulation; }
.modal { display: none; position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.8); z-index: 100; justify-content:center; align-items:center; padding:1rem;}
.modal-content { background: var(--card-bg); padding: 20px; border-radius: 10px; max-width: 400px; width: 100%; position: relative; line-height: 1.5;}
.close-btn { position: absolute; right: 15px; top: 10px; font-size: 2rem; cursor: pointer; }