body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    margin: 0;
    padding-top: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.container {
    background: white;
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: fit-content;
    width: auto;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 15px;
}

.game-layout {
    display: flex;
    gap: 20px;
    align-items: stretch;
    min-height: 600px;
}

.move-history-panel {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.board-area {
    flex: 0 0 auto;
}

#myBoard {
    width: 500px;
}

.sidebar {
    flex: 0 0 auto;
    min-width: 200px;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

button {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    margin: 0;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
    width: 100%;
}

button:hover {
    background: #5568d3;
}

.info {
    padding: 10px;
    background: #f5f5f5;
    border-radius: 5px;
    text-align: center;
    color: #666;
    font-size: 13px;
}

.stats {
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 5px;
}

.stat-label {
    font-weight: bold;
    color: #667eea;
}

.stat-value {
    color: #333;
}

.player-info {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 15px;
    padding: 10px 15px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 2px solid #ddd;
    transition: all 0.3s;
}

.player-info.top-player {
    margin-bottom: 15px;
}

.player-info.bottom-player {
    margin-top: 15px;
}

.player-selector-wrapper {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

.player-controls {
    flex-direction: row;
    gap: 3px;
    flex-wrap: nowrap;
    width: 100%;
}

.player-controls button {
    flex: 1;
    width: auto;
}

.resign-btn {
    background: #ef5350;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
}

.resign-btn:hover {
    background: #e53935;
}

.draw-btn {
    background: #66bb6a;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
}

.draw-btn:hover {
    background: #57a85c;
}

.draw-btn.draw-available {
    background: #ffa726;
    animation: pulse-draw 1.5s ease-in-out infinite;
}

.draw-btn.draw-available:hover {
    background: #fb8c00;
}

@keyframes pulse-draw {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 167, 38, 0.7);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(255, 167, 38, 0);
    }
}

.player-select {
    width: 100%;
    padding: 8px 15px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 5px;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
}

.player-select:hover {
    border-color: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.player-select:focus {
    outline: none;
    border-color: #5568d3;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.time-control-selection {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 15px;
}

.time-control-selection label {
    font-weight: bold;
    color: #667eea;
    font-size: 13px;
    white-space: nowrap;
}

.time-control-selection select {
    padding: 8px 12px;
    font-size: 14px;
    border: 2px solid #667eea;
    border-radius: 5px;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.time-control-selection select:hover {
    border-color: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.time-control-selection select:focus {
    outline: none;
    border-color: #5568d3;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.move-time-selection {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 15px;
}

.move-time-selection label {
    font-weight: bold;
    color: #667eea;
    font-size: 13px;
    white-space: nowrap;
}

.move-time-selection select {
    padding: 8px 12px;
    font-size: 14px;
    border: 2px solid #667eea;
    border-radius: 5px;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.move-time-selection select:hover {
    border-color: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.move-time-selection select:focus {
    outline: none;
    border-color: #5568d3;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.analysis-engine-selection {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 15px;
}

.analysis-engine-selection label {
    font-weight: bold;
    color: #667eea;
    font-size: 13px;
    white-space: nowrap;
}

.analysis-engine-selection select {
    padding: 8px 12px;
    font-size: 14px;
    border: 2px solid #667eea;
    border-radius: 5px;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.analysis-engine-selection select:hover {
    border-color: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.analysis-engine-selection select:focus {
    outline: none;
    border-color: #5568d3;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.analysis-display-options {
    background: #f9f9f9;
    border-radius: 5px;
    padding: 12px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analysis-option {
    display: flex;
    align-items: center;
}

.analysis-option label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: #333;
    user-select: none;
    font-size: 13px;
    font-weight: 500;
}

.analysis-option input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #667eea;
    flex-shrink: 0;
}

.analysis-option label:hover {
    color: #667eea;
}

/* Evaluation Graph */
.eval-graph-container {
    background: #e8e8e8;
    border-radius: 3px;
    padding: 4px;
    margin: 8px 0;
    position: relative;
    min-height: 60px;
}

#evalGraph {
    width: 100%;
    height: 52px;
    cursor: pointer;
    border-radius: 2px;
    display: block;
}

.eval-graph-score {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
}

.clock-compact {
    padding: 8px 20px;
    border-radius: 6px;
    background: #f5f5f5;
    border: 2px solid #ddd;
    transition: all 0.3s;
    min-width: 100px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clock-compact.active {
    border-color: #4a90e2;
    box-shadow: 0 0 12px rgba(74, 144, 226, 0.5);
    background: #4a90e2;
}

.clock-compact.active .clock-time {
    color: white;
}

/* Time warnings override active state */
.clock-compact.time-low {
    border-color: #ff9800;
    background: #fff3e0;
}

.clock-compact.time-low .clock-time {
    color: #333;
}

.clock-compact.time-critical {
    border-color: #f44336;
    background: #ffebee;
    animation: pulse 1s infinite;
}

.clock-compact.time-critical .clock-time {
    color: #333;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(244, 67, 54, 0.8);
    }
}

.clock-time {
    font-size: 24px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
    color: #333;
}

.move-history {
    background: #f9f9f9;
    border-radius: 5px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
}

.move-history-header {
    background: #667eea;
    color: white;
    padding: 10px;
    font-weight: bold;
    text-align: center;
    font-size: 14px;
}

.move-history-footer {
    display: flex;
    gap: 6px;
    padding: 8px;
    background: #f0f0f0;
    border-top: 1px solid #e0e0e0;
}

.history-footer-btn {
    flex: 1;
    background: #667eea;
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
}

.history-footer-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.move-history-text {
    flex: 1 1 0;
    width: calc(100% - 8px);
    height: 0;
    min-height: 200px;
    max-height: 100%;
    padding: 12px;
    margin: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    border: 2px solid #e0e0e0;
    border-radius: 3px;
    background: #fafafa;
    color: #333;
    resize: none;
    overflow-y: auto !important;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.move-history-text:focus {
    outline: none;
    background: #ffffff;
    border-color: #667eea;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05), 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.move-history-text::placeholder {
    color: #999;
    font-style: italic;
}

.navigation-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    background: #f0f0f0;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: nowrap;
}

.nav-btn {
    background: #667eea;
    border: none;
    color: white;
    padding: 4px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    min-width: 28px;
}

.nav-btn:hover:not(:disabled) {
    background: #5568d3;
    transform: translateY(-1px);
}

.nav-btn:active:not(:disabled) {
    transform: translateY(0);
}

.nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.position-indicator {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    font-weight: bold;
    color: #333;
    min-width: 40px;
    text-align: center;
}

/* Opening Display Styles - Compact Single Line in Sidebar */
.opening-compact {
    padding: 8px 10px;
    background: linear-gradient(135deg, #fff9e6 0%, #ffe8cc 100%);
    border-radius: 5px;
    border-left: 3px solid #ffb74d;
    font-size: 12px;
    color: #333;
    font-weight: 500;
    text-align: left;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.opening-compact #openingText {
    color: #333;
    font-weight: 600;
}

/* Variant Controls Bottom - Aligned with History Footer */
.variant-controls-bottom {
    margin-top: auto;
    padding-top: 0;
}

.variant-bottom-btn {
    width: 100%;
    background: #667eea;
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
}

.variant-bottom-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

/* Custom Dialog Styles */
.custom-dialog {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s;
}

.dialog-content {
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 75px rgba(0, 0, 0, 0.25);
    width: 90%;
    max-width: 420px;
    animation: dialogSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

@keyframes dialogSlideIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.dialog-header {
    background: transparent;
    padding: 35px 30px 10px 30px;
    text-align: center;
}

.dialog-icon {
    font-size: 64px;
    display: block;
    animation: iconPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    line-height: 1;
}

@keyframes iconPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.dialog-body {
    padding: 20px 35px 35px 35px;
    text-align: center;
}

.dialog-message {
    font-size: 18px;
    color: #545454;
    line-height: 1.5;
    margin: 0;
    word-wrap: break-word;
    font-weight: 400;
}

.dialog-footer {
    padding: 0 30px 30px 30px;
    background: transparent;
    border-top: none;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.dialog-btn {
    padding: 13px 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-width: 110px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dialog-btn-ok {
    background: #667eea;
    color: white;
}

.dialog-btn-ok:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.35);
}

.dialog-btn-ok:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.dialog-btn-cancel {
    background: #e0e0e0;
    color: #666;
}

.dialog-btn-cancel:hover {
    background: #d0d0d0;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.dialog-btn-cancel:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: #fefefe;
    border-radius: 10px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 22px;
    color: white;
}

.modal-close {
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    padding: 0 5px;
}

.modal-close:hover,
.modal-close:focus {
    color: #ffeb3b;
    transform: scale(1.2);
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
}

.modal-info {
    margin: 0 0 20px 0;
    font-size: 16px;
    color: #555;
}

.game-table-container {
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.game-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.game-table thead {
    position: sticky;
    top: 0;
    background: #667eea;
    color: white;
    z-index: 10;
}

.game-table th {
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #5568d3;
}

.game-table th:first-child {
    width: 50px;
    text-align: center;
}

.game-table tbody tr {
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid #eee;
}

.game-table tbody tr:hover {
    background-color: #f0f4ff;
    transform: scale(1.01);
}

.game-table tbody tr:active {
    background-color: #e0e8ff;
}

.game-table td {
    padding: 12px 10px;
    color: #333;
}

.game-table td:first-child {
    text-align: center;
    font-weight: bold;
    color: #667eea;
}

.modal-footer {
    padding: 15px 25px;
    background: #f9f9f9;
    border-radius: 0 0 10px 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid #eee;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.modal-btn-cancel {
    background: #9e9e9e;
    color: white;
}

.modal-btn-cancel:hover {
    background: #757575;
}

/* Opening Loading Progress Bar */
.opening-loading-bar {
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f4ff;
    border-radius: 5px;
    border: 1px solid #667eea;
}

.loading-bar-text {
    font-size: 13px;
    color: #667eea;
    font-weight: 600;
    margin-bottom: 8px;
    text-align: center;
}

.loading-bar-container {
    width: 100%;
    height: 8px;
    background: #e0e8ff;
    border-radius: 4px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

/* CodeMirror Chess Notation Styling */
.CodeMirror {
    height: 100% !important;
    max-height: 100%;
    flex: 1 1 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    border: 2px solid #e0e0e0;
    border-radius: 3px;
    background: #fafafa;
    margin: 4px;
}

.CodeMirror-scroll {
    max-height: 100%;
    overflow-y: auto !important;
}

.CodeMirror-lines {
    padding: 12px;
}

/* Chess move number styling */
.cm-chess-move-number {
    color: #333;
    font-weight: 900;
}

/* Regular chess moves */
.cm-chess-move {
    color: #333;
    font-weight: 700;
}

/* Check moves (ending with +) */
.cm-chess-check {
    color: #ff6b35;
    font-weight: 700;
}

/* Checkmate moves (ending with #) */
.cm-chess-checkmate {
    color: #d32f2f;
    font-weight: 700;
    text-shadow: 0 0 2px rgba(211, 47, 47, 0.3);
}

/* Promotion moves */
.cm-chess-promotion {
    color: #7e57c2;
    font-weight: 600;
}

/* Game result */
.cm-chess-result {
    color: #666;
    font-weight: 600;
    font-style: italic;
}

/* Annotations (!!, !, !?, ?!, ?, ??) */
.cm-chess-annotation {
    color: #1976d2;
    font-weight: 600;
}

/* Comments */
.cm-chess-comment {
    color: #4caf50;
    font-style: italic;
}

/* Variations */
.cm-chess-variation {
    color: #9c27b0;
}

/* NAG (Numeric Annotation Glyph) */
.cm-chess-nag {
    color: #ff9800;
    font-size: 11px;
}

/* Current move highlight */
.chess-current-move {
    background: #667eea;
    color: white;
    border-radius: 2px;
    font-weight: 700;
    box-shadow: 0 0 4px rgba(102, 126, 234, 0.6);
}

/* Selected variant highlight */
.chess-selected-variant {
    background: #667eea;
    color: white;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(102, 126, 234, 0.6);
}

/* Future moves (after current position) - slightly grayed out */
.chess-future-move {
    opacity: 0.4;
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

/* iPad Mini landscape and similar devices (1100-1150px) - Compact desktop layout */
@media screen and (min-width: 1100px) and (max-width: 1150px) {
    .container {
        padding: 15px 20px;
        max-width: 95%;
        width: 95%;
        box-sizing: border-box;
    }
    
    .game-layout {
        gap: 15px;
        justify-content: center;
    }
    
    #myBoard {
        width: 480px;
    }
    
    .move-history-panel {
        flex: 1 1 280px;
        max-width: 320px;
    }
    
    .sidebar {
        flex: 0 0 auto;
        min-width: 180px;
        max-width: 200px;
    }
    
    button {
        padding: 8px 15px;
        font-size: 13px;
    }
}

/* Tablet and smaller screens - Stack vertically for better fit */
@media screen and (max-width: 1099px) {
    .container {
        padding: 15px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
    
    h1 {
        font-size: 17px;
        margin-bottom: 11px;
    }
    
    /* Stack the layout vertically */
    .game-layout {
        flex-direction: column;
        gap: 15px;
        min-height: auto;
    }
    
    /* Board area takes full width */
    .board-area {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    /* Scale board to fit tablet screen */
    #myBoard {
        width: 100% !important;
        max-width: 500px;
    }
    
    /* Player info adjustments */
    .player-info {
        width: 100%;
        max-width: 500px;
        padding: 10px 15px;
    }
    
    .player-select {
        font-size: 15px;
    }
    
    .clock-compact {
        padding: 8px 18px;
        min-width: 90px;
    }
    
    .clock-time {
        font-size: 22px;
    }
    
    /* Move history panel full width */
    .move-history-panel {
        width: 100%;
        flex: 0 0 auto;
        order: 2;
    }
    
    .move-history {
        min-height: 280px;
        max-height: none;
        overflow: visible;
    }
    
    .move-history-text {
        min-height: 180px;
    }
    
    /* Sidebar full width */
    .sidebar {
        width: 100%;
        min-width: auto;
        max-width: 100%;
        order: 3;
    }
}

/* iPad Mini and similar tablets in portrait - Additional refinements */
@media screen and (max-width: 900px) {
    body {
        padding: 10px;
        min-height: auto;
    }
    
    .container {
        padding: 15px;
        border-radius: 8px;
    }
    
    h1 {
        font-size: 17px;
        margin-bottom: 11px;
    }
    
    /* Stack the layout vertically */
    .game-layout {
        flex-direction: column;
        gap: 15px;
        min-height: auto;
    }
    
    /* Board area takes full width */
    .board-area {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    /* Scale board to fit tablet screen */
    #myBoard {
        width: 100% !important;
        max-width: 500px;
    }
    
    /* Player info adjustments */
    .player-info {
        width: 100%;
        max-width: 500px;
        padding: 10px 15px;
    }
    
    .player-select {
        font-size: 15px;
    }
    
    .clock-compact {
        padding: 8px 18px;
        min-width: 90px;
    }
    
    .clock-time {
        font-size: 22px;
    }
    
    /* Move history panel full width */
    .move-history-panel {
        width: 100%;
        flex: 0 0 auto;
        order: 2;
    }
    
    .move-history {
        min-height: 280px;
        max-height: none;
        overflow: visible;
    }
    
    .move-history-text {
        min-height: 180px;
    }
    
    /* Sidebar full width */
    .sidebar {
        width: 100%;
        min-width: auto;
        max-width: 100%;
        order: 3;
    }
}

/* Mobile devices - Stack layout vertically */
@media screen and (max-width: 768px) {
    body {
        padding: 5px;
        min-height: auto;
    }
    
    .container {
        padding: 10px;
        border-radius: 8px;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
        width: 95%;
        max-width: 95%;
    }
    
    h1 {
        font-size: 15px;
        margin-bottom: 8px;
    }
    
    /* Stack the layout vertically */
    .game-layout {
        flex-direction: column;
        gap: 10px;
        min-height: auto;
    }
    
    /* Board area takes full width */
    .board-area {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        order: 1;
    }
    
    /* Scale board to use 95% of container width */
    #myBoard {
        width: 95% !important;
        max-width: none;
    }
    
    /* Player info adjustments */
    .player-info {
        width: 95%;
        max-width: none;
        padding: 8px 12px;
        gap: 10px;
    }
    
    .player-select {
        font-size: 14px;
        padding: 6px 10px;
    }
    
    .clock-compact {
        padding: 6px 15px;
        min-width: 80px;
        max-width: 120px;
    }
    
    .clock-time {
        font-size: 20px;
    }
    
    /* Eval graph styling for mobile - match board width */
    .eval-graph-container {
        width: 95%;
        margin: 15px auto 10px auto;
    }
    
    .eval-graph-container canvas {
        width: 100% !important;
    }
    
    /* Move history panel full width */
    .move-history-panel {
        width: 100%;
        flex: 0 0 auto;
        order: 2;
    }
    
    /* Fix move history overflow on mobile */
    .move-history {
        overflow: visible;
        padding-bottom: 10px;
        max-height: none;
    }
    
    /* Make move history text scrollable with proper border */
    .move-history-text,
    .CodeMirror {
        min-height: 200px !important;
        max-height: 250px !important;
        height: 200px !important;
        overflow-y: auto !important;
        border: 1px solid #ccc !important;
        border-radius: 5px !important;
        margin: 8px !important;
        box-sizing: border-box !important;
    }
    
    /* Sidebar full width */
    .sidebar {
        width: 100%;
        min-width: auto;
        max-width: 100%;
        order: 3;
    }
    
    /* Adjust button sizes */
    button {
        padding: 8px 15px;
        font-size: 13px;
    }
    
    .controls {
        gap: 6px;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .game-table {
        font-size: 12px;
    }
    
    .game-table th,
    .game-table td {
        padding: 8px 6px;
    }
}

/* Small mobile devices */
@media screen and (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 10px;
        border-radius: 5px;
    }
    
    h1 {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .game-layout {
        gap: 10px;
    }
    
    /* Board uses 95% width on small screens too */
    #myBoard {
        width: 95% !important;
        max-width: none;
    }
    
    .player-info {
        width: 95%;
        max-width: none;
        padding: 6px 10px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .player-select {
        font-size: 13px;
        padding: 5px 8px;
        flex: 1 1 100%;
        order: 1;
    }
    
    .player-controls {
        order: 2;
        flex: 1 1 auto;
    }
    
    .clock-compact {
        padding: 5px 12px;
        min-width: 70px;
        order: 3;
        flex: 1 1 auto;
    }
    
    .clock-time {
        font-size: 18px;
    }
    
    .resign-btn,
    .draw-btn {
        padding: 3px 6px;
        font-size: 10px;
    }
    
    /* Compact navigation controls */
    .navigation-controls {
        gap: 2px;
        padding: 5px 3px;
    }
    
    .nav-btn {
        padding: 3px 5px;
        font-size: 11px;
        min-width: 24px;
    }
    
    /* Smaller buttons */
    button {
        padding: 7px 12px;
        font-size: 12px;
    }
    
    .history-footer-btn,
    .variant-bottom-btn {
        padding: 7px 12px;
        font-size: 12px;
    }
    
    /* Compact move history */
    .move-history {
        min-height: 200px;
        max-height: none;
        overflow: visible;
    }
    
    .move-history-text {
        min-height: 120px;
        font-size: 12px;
    }
    
    .move-history-header {
        padding: 8px;
        font-size: 13px;
    }
    
    /* Compact form elements */
    .time-control-selection,
    .analysis-engine-selection {
        gap: 4px;
        margin-bottom: 10px;
    }
    
    .time-control-selection label,
    .analysis-engine-selection label {
        font-size: 12px;
    }
    
    .time-control-selection select,
    .analysis-engine-selection select {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .analysis-display-options {
        padding: 10px;
        gap: 8px;
    }
    
    .analysis-option label {
        font-size: 12px;
    }
    
    .info {
        padding: 8px;
        font-size: 12px;
    }
    
    .opening-compact {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    /* Modal adjustments for small screens */
    .modal-content {
        width: 98%;
        max-height: 90vh;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h2 {
        font-size: 16px;
    }
    
    .modal-close {
        font-size: 28px;
    }
    
    .modal-body {
        padding: 10px;
    }
    
    .modal-info {
        font-size: 14px;
        margin-bottom: 15px;
    }
    
    .game-table {
        font-size: 11px;
    }
    
    .game-table th,
    .game-table td {
        padding: 6px 4px;
    }
    
    .game-table th:first-child {
        width: 35px;
    }
    
    .modal-footer {
        padding: 10px 15px;
    }
    
    .modal-btn {
        padding: 8px 15px;
        font-size: 13px;
    }
}

/* Landscape orientation adjustments for mobile */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .game-layout {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .board-area {
        flex: 0 0 auto;
        order: 1;
    }
    
    #myBoard {
        max-width: 350px;
    }
    
    .move-history-panel {
        flex: 1 1 250px;
        order: 2;
        min-width: 200px;
    }
    
    .sidebar {
        flex: 1 1 100%;
        order: 3;
    }
}

/* PGN Game Selector Modal - Mobile Optimizations */
@media screen and (max-width: 768px) {
    /* Hide less important columns on mobile */
    .game-table th:nth-child(5), /* Event */
    .game-table td:nth-child(5) {
        display: none;
    }
    
    .game-table th:nth-child(7), /* Opening */
    .game-table td:nth-child(7) {
        display: none;
    }
    
    /* Adjust remaining columns */
    .game-table th:nth-child(2), /* White */
    .game-table td:nth-child(2),
    .game-table th:nth-child(3), /* Black */
    .game-table td:nth-child(3) {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .game-table th:nth-child(4), /* Result */
    .game-table td:nth-child(4) {
        width: 50px;
    }
    
    .game-table th:nth-child(6), /* Date */
    .game-table td:nth-child(6) {
        font-size: 11px;
        max-width: 80px;
    }
}

@media screen and (max-width: 480px) {
    /* Even more compact on small screens */
    .game-table th:nth-child(6), /* Date */
    .game-table td:nth-child(6) {
        display: none;
    }
    
    .game-table th:nth-child(2), /* White */
    .game-table td:nth-child(2),
    .game-table th:nth-child(3), /* Black */
    .game-table td:nth-child(3) {
        max-width: 90px;
        font-size: 11px;
    }
    
    .game-table th:nth-child(4), /* Result */
    .game-table td:nth-child(4) {
        width: 40px;
        font-size: 11px;
    }
    
    /* Adjust game table container */
    .game-table-container {
        max-height: 400px;
    }
    
    /* Make rows more touch-friendly */
    .game-table tbody tr {
        min-height: 44px;
    }
    
    .game-table th,
    .game-table td {
        padding: 10px 4px;
    }
}

/* Ghost Pieces for PV Visualization */
.ghost-piece {
    opacity: 0.5 !important;
    pointer-events: none;
    z-index: 100;
    position: absolute;
    transition: opacity 0.2s ease-in-out;
}

.ghost-piece.ghost-fade-in {
    animation: ghostFadeIn 0.3s ease-in-out;
}

.ghost-piece.ghost-fade-out {
    animation: ghostFadeOut 0.3s ease-in-out;
}

@keyframes ghostFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 0.5;
    }
}

@keyframes ghostFadeOut {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 0;
    }
}
