: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); }

/* Collapsible Details */
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-wrap: wrap; gap: 10px; padding: 10px; }
.history-log { padding: 10px; max-height: 150px; overflow-y: auto; font-family: monospace; background: #0f1b30; border-radius: 0 0 8px 8px; }

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

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

/* Maximized Board - STRICT GRID FIX FOR iOS */
.board-wrapper { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 0; width: 100%; padding: 5px 0; overflow: hidden; }
.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    /* width and height set equal by JS — always square */
    flex-shrink: 0;
    border: 4px solid var(--card-bg);
    border-radius: 4px;
    margin: auto; 
}

.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;
    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%; 
    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; z-index: 5;}
.sq.dot::after { content: ''; position: absolute; width: 25%; height: 25%; background: rgba(0,0,0,0.3); border-radius: 50%; pointer-events: none; z-index: 5; top: 37.5%; left: 37.5%;}
.sq.check { background-color: #e74c3c !important; }

/* PIECE STYLING FIX FOR iOS */
.piece { 
    position: absolute; /* Takes piece out of flow so it doesn't stretch the grid row */
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 10; 
    font-family: 'Segoe UI Symbol', Arial, sans-serif; 
    font-variant-emoji: text; /* Forces standard text rendering instead of Apple Emojis */
    font-size: clamp(20px, 7vw, 55px); /* Responsive sizing */
    line-height: 1; /* Prevents vertical stretching */
}
.piece.w { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 2px 4px rgba(0,0,0,0.8); }
.piece.b { color: #000; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 2px 4px rgba(0,0,0,0.8); }

.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; }
.close-btn { position: absolute; right: 15px; top: 10px; font-size: 2rem; cursor: pointer; }
.promo-pieces { display: flex; justify-content: space-around; font-size: 3rem; margin-top: 20px; }
.promo-pieces span { cursor: pointer; padding: 10px; border-radius: 5px; background: rgba(255,255,255,0.1); position: relative; }