* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a472a 0%, #2d5f3f 100%);
    color: #333;
    padding: 8px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #f5f5f5;
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    height: 90vh;
}

.game-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.layout-wrapper {
    display: flex;
    gap: 15px;
    flex: 1;
    overflow: hidden;
}

.main-content {
    flex: 1;
    overflow: hidden;
    padding-right: 8px;
    display: flex;
    flex-direction: column;
}

h1 {
    color: #1a472a;
    margin: 0 0 8px 0;
    font-size: 1.4em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 0 8px 0;
    padding: 6px 8px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

.rules-popup {
    position: fixed;
    top: 80px;
    right: 12px;
    width: 280px;
    max-height: 500px;
    background: #fff;
    border: 2px solid #1a472a;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 101;
    overflow-y: auto;
}

.rules-popup h3 {
    color: #1a472a;
    margin: 0 0 10px 0;
    font-size: 0.95em;
}

.rules-content {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

.rules-content p {
    font-size: 0.8em;
    line-height: 1.4;
    margin: 6px 0;
    color: #333;
}

.current-player, .game-status {
    font-size: 0.7em;
    font-weight: bold;
    color: #1a472a;
    margin: 0;
}

.main-layout {
    display: grid;
    grid-template-columns: 220px 100px auto 100px 180px;
    gap: 8px;
    margin-bottom: 8px;
    min-width: 0;
}

.reserve {
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-top: 0;
}

.reserve h3 {
    color: #1a472a;
    margin-bottom: 6px;
    font-size: 0.75em;
}

.reserve-pieces {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 8px;
    min-height: 60px;
}

.reserve-piece {
    background: #f0f0f0;
    border: 2px solid #d4af37;
    border-radius: 4px;
    padding: 2px;
    text-align: center;
    font-size: 0.9em;
    cursor: grab;
    transition: all 0.3s ease;
}

.reserve-piece:hover {
    background: #e8e8e8;
    transform: scale(1.05);
}

.reserve-piece.depleted {
    opacity: 0.5;
    color: #ccc;
    cursor: not-allowed;
}

.roll-btn, .action-btn {
    width: 100%;
    padding: 4px;
    margin: 2px 0;
    background: #d4af37;
    color: #1a472a;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.7em;
}

.roll-btn:hover, .action-btn:hover {
    background: #c9a227;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(212, 175, 55, 0.3);
}

.roll-btn:active, .action-btn:active {
    transform: translateY(0);
}

.dice-result {
    text-align: center;
    font-size: 1.5em;
    font-weight: bold;
    color: #1a472a;
    margin-top: 6px;
    min-height: 30px;
}

.board-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: fit-content;
}

.board-wrapper {
    display: grid;
    grid-template-columns: 30px repeat(8, 40px);
    grid-template-rows: auto auto;
    gap: 1px;
    gap: 1px 1px;
    align-items: start;
    width: fit-content;
    margin: 0 auto;
}

.rank-labels {
    display: flex;
    flex-direction: column;
    gap: 0;
    justify-content: space-between;
    min-height: 100%;
    grid-row: 1 / 2;
    grid-column: 1;
}

.rank-label {
    width: 30px;
    text-align: right;
    font-weight: bold;
    font-size: 0.75em;
    color: #1a472a;
    padding: 2px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-labels {
    display: grid;
    grid-template-columns: repeat(8, 40px);
    gap: 4px 4px;
    margin-top: 0;
    margin-left: 0;
    grid-row: 2;
    grid-column: 2 / 10;
}

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.75em;
    color: #1a472a;
    height: 24px;
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 40px);
    gap: 0;
    background: #8b7355;
    padding: 2px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2),
                inset 0 0 20px rgba(0,0,0,0.2);
    width: 320px;
    height: 320px;
    grid-row: 1;
    grid-column: 2 / 10;
}

.square {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.square.light {
    background: #f0d9b5;
}

.square.dark {
    background: #b58863;
}

.square.selected {
    border-color: #ffff00;
    box-shadow: inset 0 0 10px rgba(255,255,0,0.5);
}

.square.valid-move {
    box-shadow: inset 0 0 8px rgba(0,255,0,0.6);
}

.square.valid-move::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(0,255,0,0.6);
    border-radius: 50%;
    pointer-events: none;
}

.square.check {
    box-shadow: inset 0 0 15px rgba(255,0,0,0.8);
}

.square.landing-exempt {
    border-color: #00aaff;
    box-shadow: inset 0 0 8px rgba(0,170,255,0.4);
}

.piece {
    pointer-events: auto;
    user-select: none;
}

.piece.white {
    filter: drop-shadow(2px 2px 3px rgba(0,0,0,0.3));
}

.piece.black {
    filter: drop-shadow(-2px -2px 3px rgba(255,255,255,0.3));
}

.move-history {
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    max-height: 400px;
    min-width: 0;
    overflow: hidden;
}

.move-history h4 {
    color: #1a472a;
    margin-bottom: 6px;
    font-size: 0.75em;
    margin: 0 0 6px 0;
}

.history-list {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px;
    max-height: 360px;
    overflow-y: auto;
    font-size: 0.75em;
    flex: 1;
}

.history-item {
    padding: 2px;
    margin: 1px 0;
    background: #fff;
    border-radius: 2px;
    border-left: 3px solid #d4af37;
    padding-left: 6px;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.legend {
    width: 220px;
    flex-shrink: 0;
    background: #f9f5f0;
    border: 2px solid #d4af37;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: #333;
}

.legend h3 {
    color: #1a472a;
    margin: 0 0 10px 0;
    font-size: 0.95em;
    text-align: center;
    border-bottom: 2px solid #d4af37;
    padding-bottom: 8px;
}

.legend p {
    margin: 8px 0;
    font-size: 0.8em;
    line-height: 1.4;
}

.move-history-left {
    width: 220px;
    flex-shrink: 0;
    background: #f9f5f0;
    border: 2px solid #d4af37;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: #333;
    display: flex;
    flex-direction: column;
}

.move-history-left h3 {
    color: #1a472a;
    margin: 0 0 10px 0;
    font-size: 0.95em;
    text-align: center;
    border-bottom: 2px solid #d4af37;
    padding-bottom: 8px;
}

#moveHistoryLeft {
    flex: 1;
    overflow-y: auto;
}

@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 180px 100px auto 100px 150px;
        gap: 10px;
    }
    
    .square {
        font-size: 1.8em;
    }
    
    .reserve-piece {
        font-size: 1.2em;
        padding: 4px;
    }
}

@media (max-width: 1024px) {
    .container {
        max-width: 800px;
        padding: 15px;
    }
    
    .main-layout {
        grid-template-columns: 1fr;
    }
    
    .reserve {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    h1 {
        font-size: 1.6em;
        margin-bottom: 10px;
    }
    
    .square {
        font-size: 1.6em;
    }
}

@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding: 10px;
    }
    
    .main-layout {
        gap: 10px;
    }
    
    h1 {
        font-size: 1.4em;
        margin-bottom: 8px;
    }
    
    .square {
        font-size: 1.4em;
    }
    
    .reserve h3 {
        font-size: 0.8em;
    }
    
    .reserve-piece {
        font-size: 1em;
        padding: 3px;
    }
    
    .action-buttons {
        grid-template-columns: 1fr;
    }
    
    .roll-btn, .action-btn {
        font-size: 0.85em;
        padding: 8px;
    }
}

/* Standard Chess Mode - Hide move history */
.standard-chess-mode .move-history {
    display: none;
}

/* iPhone 14 and similar mobile devices - uniform piece size */
@media (max-width: 430px) and (max-height: 932px) {
    .square {
        font-size: 1.8em !important;
    }
    
    .piece {
        font-size: 1em !important;
    }
}

/* General mobile fix for consistent piece sizing */
@media (max-width: 480px) {
    .square {
        font-size: 1.6em !important;
    }
    
    .piece {
        font-size: 1em !important;
        line-height: 1;
    }
    
    /* Ensure all Unicode chess pieces render at the same size */
    .piece.white, .piece.black {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
    }
}
