/* ===== CSS Variables ===== */
:root {
    --primary-color: #1a1a2e;
    --secondary-color: #16213e;
    --accent-color: #0f3d3e;
    --success-color: #2d6a4f;
    --danger-color: #9d0208;
    --warning-color: #e85d04;
    --light-bg: #f8f9fa;
    --dark-bg: #1a1a2e;
    --white: #ffffff;
    --text-dark: #1a1a2e;
    --text-light: #6c757d;
    --border-color: #dee2e6;
    --green-bg: #1b4332;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-hover: 0 2px 8px rgba(0, 0, 0, 0.15);
    --transition: all 0.2s ease;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ===== Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1b4332;
    min-height: 100vh;
    padding: 20px;
    color: var(--text-dark);
}

/* ===== Container ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* ===== Back Button ===== */
.back-button-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
}

/* Tablet and mobile: Make back button relative, not fixed */
@media (max-width: 1200px) {
    .back-button-container {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        margin-bottom: 12px;
        z-index: 1;
        text-align: left;
    }
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(27, 67, 50, 0.95);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 10px 18px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.back-btn:hover {
    background: rgba(27, 67, 50, 1);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translateY(-1px);
}

.back-btn svg {
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .back-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .back-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 24px;
}

.title {
    font-size: 2rem;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 400;
}

/* ===== Game Wrapper ===== */
.game-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
}

/* ===== Panels ===== */
.left-panel {
    flex: 1;
    max-width: 700px;
}

.right-panel {
    flex: 0 0 350px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===== Mode Selector ===== */
.mode-selector {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.mode-selector h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-dark);
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mode-btn {
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    text-align: left;
}

.mode-btn:hover {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.mode-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--white);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.mode-btn:hover .mode-icon {
    background: rgba(255, 255, 255, 0.2);
}

.mode-text {
    flex: 1;
}

.mode-name {
    font-weight: 500;
    font-size: 0.95rem;
    display: block;
}

.mode-desc {
    font-size: 0.8rem;
    opacity: 0.7;
    display: block;
    margin-top: 2px;
}

/* ===== Front Page Saved Games ===== */
.front-page-saved-games {
    margin-top: 20px;
}

.front-page-saved-section {
    margin-bottom: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.front-page-saved-section:last-child {
    margin-bottom: 0;
}

.front-page-saved-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.front-page-games-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.front-page-game-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--light-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.front-page-game-item:hover {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.front-page-game-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.front-page-game-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.front-page-game-meta {
    font-size: 0.7rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.front-page-game-delete {
    background: transparent;
    color: var(--text-light);
    border: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition);
    flex-shrink: 0;
    margin-left: 8px;
}

.front-page-game-delete:hover {
    background: var(--danger-color);
    color: var(--white);
}

.front-page-game-item:hover .front-page-game-delete {
    color: var(--white);
}

.front-page-game-item:hover .front-page-game-delete:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== Game Setup Selector ===== */
.game-setup-selector {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    max-width: 450px;
    margin-left: auto;
    margin-right: auto;
}

.setup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.setup-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.back-btn-small {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--success-color);
    color: var(--white);
    border: 1px solid var(--success-color);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.back-btn-small:hover {
    background: #1f5038;
    color: var(--white);
    border-color: #1f5038;
}

.back-btn-small svg {
    flex-shrink: 0;
}

.setup-section {
    margin-bottom: 24px;
}

.setup-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Time Toggle */
.time-toggle {
    display: flex;
    gap: 8px;
}

.time-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
    color: var(--text-dark);
}

.time-toggle-btn:hover {
    border-color: var(--success-color);
}

.time-toggle-btn.active {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.time-toggle-btn svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

/* Color Toggle */
.color-toggle {
    display: flex;
    gap: 8px;
}

.color-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
    color: var(--text-dark);
}

.color-toggle-btn:hover {
    border-color: var(--success-color);
}

.color-toggle-btn.active {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.color-icon {
    font-size: 0.9rem;
}

/* Difficulty Slider */
.difficulty-slider-container {
    padding: 0 4px;
}

.difficulty-slider-wrapper {
    position: relative;
    padding-top: 8px;
}

.difficulty-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    position: relative;
    z-index: 2;
}

.difficulty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--success-color);
    cursor: pointer;
    border: 3px solid var(--white);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.difficulty-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.difficulty-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--success-color);
    cursor: pointer;
    border: 3px solid var(--white);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Tick marks container */
.difficulty-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 2px;
    margin-top: -3px;
    position: relative;
    z-index: 1;
}

.difficulty-tick {
    width: 1px;
    height: 8px;
    background: var(--border-color);
}

.difficulty-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-light);
    padding: 0 2px;
}

.difficulty-value {
    text-align: center;
    margin-top: 12px;
    padding: 8px 16px;
    background: var(--light-bg);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--success-color);
}

/* Start Game Button */
.start-game-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    background: var(--success-color);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.start-game-btn:hover {
    background: #1f5038;
    transform: translateY(-1px);
}

.start-game-btn svg {
    flex-shrink: 0;
}

/* ===== Game Info Bar ===== */
.game-info {
    background: var(--white);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.info-label {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* ===== Timer ===== */
.timer-container {
    background: var(--white);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-around;
    margin-bottom: 12px;
}

.timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.timer-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-light);
}

.timer-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
}

.timer.active .timer-value {
    color: var(--success-color);
}

.timer.active {
    border: none;
    outline: none;
    box-shadow: none;
}

/* ===== Board Container with Evaluation Bar ===== */
.board-with-eval {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.board-container {
    background: var(--white);
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    flex: 1;
}

.board-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

#board {
    max-width: 100%;
    margin: 0 auto;
}

.arrow-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.arrow-overlay line {
    stroke-width: 10;
    stroke-linecap: round;
    opacity: 0.8;
}

.arrow-green {
    stroke: #15781B;
    marker-end: url(#arrowhead);
}

.arrow-red {
    stroke: #e74c3c;
    marker-end: url(#arrowhead-red);
}

.arrow-blue {
    stroke: #3498db;
    marker-end: url(#arrowhead-blue);
}

.circle-highlight {
    fill: none;
    stroke: #15781B;
    stroke-width: 5;
    opacity: 0.8;
}

/* ===== Evaluation Bar ===== */
.eval-bar {
    width: 20px;
    background: linear-gradient(to bottom, #1a1a1a 0%, #2d2d2d 50%, #e8e8e8 50%, #ffffff 100%);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.15);
}

.eval-bar-black {
    background: linear-gradient(to bottom, #1a1a1a, #3d3d3d);
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    height: 50%;
    position: relative;
}

.eval-bar-black::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.1));
}

.eval-bar-white {
    background: linear-gradient(to bottom, #e8e8e8, #ffffff);
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    height: 50%;
    flex: 1;
    position: relative;
}

.eval-bar-white::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.05), transparent);
}

.eval-bar-score {
    position: absolute;
    left: 100%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    padding: 2px 4px 2px 8px;
    white-space: nowrap;
    z-index: 10;
    color: var(--text-dark);
    transition: top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tick mark pointing to the bar */
.eval-bar-score::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 2px;
    background: var(--text-dark);
}

/* Highlight legal moves */
.highlight-move {
    background: radial-gradient(circle, rgba(52, 152, 219, 0.4) 25%, transparent 26%);
}

.highlight-capture {
    box-shadow: inset 0 0 0 4px rgba(231, 76, 60, 0.6);
}

/* Highlight selected piece */
.highlight-selected {
    background-color: rgba(255, 255, 0, 0.5) !important;
}

/* Last move highlight */
.highlight-last-move-from {
    background-color: rgba(255, 255, 0, 0.3) !important;
}

.highlight-last-move-to {
    background-color: rgba(255, 255, 0, 0.5) !important;
}

/* ===== Controls ===== */
.controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.control-btn {
    background: var(--white);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-btn:hover:not(:disabled) {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn svg {
    flex-shrink: 0;
}

.control-btn-primary {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.control-btn-primary:hover:not(:disabled) {
    background: #1f5038;
    border-color: #1f5038;
}

.control-btn-draw {
    background: var(--light-bg);
    color: var(--text-dark);
    border-color: var(--warning-color);
}

.control-btn-draw:hover:not(:disabled) {
    background: var(--warning-color);
    color: var(--white);
    border-color: var(--warning-color);
}

.control-btn-resign {
    background: var(--light-bg);
    color: var(--text-dark);
    border-color: var(--danger-color);
}

.control-btn-resign:hover:not(:disabled) {
    background: var(--danger-color);
    color: var(--white);
    border-color: var(--danger-color);
}

/* ===== Stockfish Hint ===== */
.stockfish-hint {
    background: var(--white);
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-top: 12px;
    width: 100%;
    box-sizing: border-box;
}

.stockfish-hint h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-dark);
}

.hint-content {
    background: var(--light-bg);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.hint-content p {
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.hint-content p:last-child {
    margin-bottom: 0;
}

.hint-content strong {
    color: var(--text-light);
    font-weight: 500;
}

#bestMove {
    color: var(--success-color);
    font-weight: 600;
    font-size: 0.95rem;
}

#evaluation {
    color: var(--text-dark);
    font-weight: 600;
}

/* ===== Right Panel Sections ===== */
.captured-pieces,
.move-history,
.game-status,
.statistics,
.saved-games,
.load-position-section {
    background: var(--white);
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    box-sizing: border-box;
}

.captured-pieces h3,
.move-history h3,
.statistics h3,
.saved-games h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Captured Pieces */
.captured-section {
    margin-bottom: 12px;
}

.captured-section:last-child {
    margin-bottom: 0;
}

.captured-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
}

.captured-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 32px;
    padding: 8px;
    background: var(--light-bg);
    border-radius: var(--radius-sm);
}

.captured-piece {
    font-size: 1.5rem;
}

/* Move History */
.move-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    background: var(--light-bg);
    border-radius: var(--radius-sm);
}

.move-item {
    padding: 6px 10px;
    margin-bottom: 4px;
    background: var(--white);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    transition: var(--transition);
}

.move-item:last-child {
    margin-bottom: 0;
}

.move-item:hover {
    background: var(--success-color);
    color: var(--white);
}

.move-number {
    font-weight: 600;
    margin-right: 8px;
    color: var(--text-light);
}

.move-item:hover .move-number {
    color: rgba(255, 255, 255, 0.8);
}

.move-notation {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.move-time {
    font-size: 0.7rem;
    color: var(--text-light);
    opacity: 0.7;
    font-weight: 400;
}

.move-item:hover .move-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Game Status */
.status-message {
    padding: 12px;
    background: var(--light-bg);
    border-radius: var(--radius-md);
    text-align: center;
    font-weight: 500;
    font-size: 0.9rem;
}

.status-message.check {
    background: var(--warning-color);
    color: var(--white);
}

.status-message.checkmate,
.status-message.gameover {
    background: var(--danger-color);
    color: var(--white);
}

.status-message.stalemate {
    background: var(--text-light);
    color: var(--white);
}

/* Statistics */
.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.btn-clear-stats {
    width: 100%;
    margin-top: 12px;
    padding: 8px 12px;
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.btn-clear-stats:hover {
    background: var(--danger-color);
    color: var(--white);
    border-color: var(--danger-color);
}

.stat-label {
    color: var(--text-light);
    font-size: 0.85rem;
}

.stat-value {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.95rem;
}

/* Saved Games */
#savedGamesList {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.saved-game-item {
    padding: 10px 12px;
    background: var(--light-bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.saved-game-item:last-child {
    margin-bottom: 0;
}

.saved-game-item:hover {
    background: var(--success-color);
    color: var(--white);
}

.saved-game-info {
    flex: 1;
}

.saved-game-date {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 2px;
}

.saved-game-delete {
    background: transparent;
    color: var(--text-light);
    border: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.saved-game-delete:hover {
    background: var(--danger-color);
    color: var(--white);
}

.saved-game-item:hover .saved-game-delete {
    color: var(--white);
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.btn-primary {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.btn-primary:hover {
    background: #1f5038;
    border-color: #1f5038;
}

.btn-secondary {
    background: var(--white);
    color: var(--text-dark);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--light-bg);
    border-color: var(--text-light);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    padding: 32px;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.modal-content p {
    font-size: 1rem;
    margin-bottom: 24px;
    color: var(--text-light);
}

.modal-buttons {
    display: flex;
    gap: 12px;
}

/* Promotion Modal */
.promotion-modal-content {
    padding: 24px;
    max-width: 320px;
}

.promotion-modal-content h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.promotion-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.promotion-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.8rem;
    font-weight: 500;
}

.promotion-btn:hover {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.promotion-piece {
    font-size: 2rem;
}

/* ===== Loading Indicator ===== */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    color: var(--white);
}

/* Keep timer visible above loading overlay when AI is thinking */
.timer-container.ai-thinking {
    position: relative;
    z-index: 1001;
}

/* No special animation or border for active timer during AI thinking */
.timer-container.ai-thinking .timer.active {
    border: none;
    outline: none;
    box-shadow: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.loading p,
.loading .loading-text {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Thinking Timer for AI */
.thinking-timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 16px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(4px);
}

.thinking-countdown {
    font-size: 2.5rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    color: var(--white);
    line-height: 1;
    animation: pulse-glow 1s ease-in-out infinite;
}

.thinking-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

.thinking-level {
    margin-top: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.6);
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
}

@keyframes pulse-glow {
    0%, 100% {
        opacity: 1;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }
    50% {
        opacity: 0.8;
        text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    }
}

/* ===== Utility Classes ===== */
.hidden {
    display: none !important;
}

/* Force repaint helper - used when tab visibility changes */
.force-repaint {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ===== Chrome Canvas Bug Workarounds ===== */
/* These styles help prevent blank page issues when switching tabs during AI thinking */

/* Ensure loading overlay renders properly after tab switch */
.loading {
    will-change: opacity, transform;
    backface-visibility: hidden;
    transform: translateZ(0);
    /* Ensure it stays on its own compositing layer */
    isolation: isolate;
}

/* Ensure board container renders properly after tab switch */
.board-container {
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Force canvas to maintain its own compositing layer */
#board {
    will-change: contents;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Ensure the board wrapper maintains compositing */
.board-wrapper {
    will-change: contents;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Main container should also be hardware accelerated */
.container {
    will-change: transform;
    backface-visibility: hidden;
}

/* Timer container needs to stay visible during AI thinking */
.timer-container {
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* ===== Animations ===== */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Responsive Design ===== */

/* Tablet and below */
@media (max-width: 1200px) {
    .game-wrapper {
        flex-direction: column;
        max-width: 100%;
    }

    .left-panel {
        max-width: 100% !important;
        flex: 1;
        width: 100%;
    }

    .right-panel {
        max-width: 100% !important;
        flex: none !important;
        width: 100%;
    }

    /* Ensure right panel children are full width */
    .right-panel .captured-pieces,
    .right-panel .move-history,
    .right-panel .game-status,
    .right-panel .statistics,
    .right-panel .saved-games,
    .right-panel .load-position-section,
    .stockfish-hint {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
}

/* Mobile landscape and small tablets */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }

    /* Header adjustments */
    .header {
        margin-bottom: 16px;
    }

    .title {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .back-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }

    /* Mode selector */
    .mode-selector {
        padding: 16px;
        max-width: 100%;
    }

    .mode-btn {
        padding: 14px 16px;
    }

    /* Game setup */
    .game-setup-selector {
        padding: 20px 16px;
        max-width: 100%;
    }

    .setup-section {
        margin-bottom: 20px;
    }

    /* Time and color toggles */
    .time-toggle,
    .color-toggle {
        gap: 6px;
    }

    .time-toggle-btn,
    .color-toggle-btn {
        padding: 10px 8px;
        font-size: 0.75rem;
        min-height: 44px;
    }

    /* Game info bar */
    .game-info {
        padding: 10px 12px;
        gap: 4px;
    }

    .info-label {
        font-size: 0.65rem;
    }

    .info-value {
        font-size: 0.85rem;
    }

    /* Timer */
    .timer-container {
        padding: 10px 12px;
        margin-bottom: 10px;
    }

    .timer-value {
        font-size: 1.1rem;
    }

    /* Board with eval bar */
    .board-with-eval {
        gap: 8px;
        margin-bottom: 10px;
    }

    .board-container {
        padding: 10px;
    }

    /* Evaluation bar - hide on small screens or make smaller */
    .eval-bar {
        width: 16px;
        min-width: 16px;
    }

    .eval-bar-score {
        font-size: 0.55rem;
        padding: 1px 2px 1px 6px;
    }

    .eval-bar-score::before {
        width: 4px;
    }

    /* Controls */
    .controls {
        gap: 6px;
    }

    .control-btn {
        flex: 1;
        min-width: calc(50% - 3px);
        padding: 10px 12px;
        font-size: 0.8rem;
        min-height: 44px;
    }

    .control-btn svg {
        width: 14px;
        height: 14px;
    }

    /* Right panel sections - full width */
    .right-panel {
        gap: 12px;
    }

    .captured-pieces,
    .move-history,
    .game-status,
    .statistics,
    .saved-games,
    .stockfish-hint,
    .load-position-section {
        padding: 14px;
        width: 100%;
        box-sizing: border-box;
    }

    .captured-pieces h3,
    .move-history h3,
    .statistics h3,
    .saved-games h3,
    .load-position-section h3 {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }

    /* Move history */
    .move-list {
        max-height: 150px;
    }

    .move-item {
        padding: 5px 8px;
        font-size: 0.8rem;
    }

    /* Statistics */
    .stat-item {
        padding: 6px 0;
        font-size: 0.85rem;
    }

    /* Saved games */
    #savedGamesList {
        max-height: 120px;
    }

    .saved-game-item {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    /* Modal */
    .modal-content {
        padding: 24px 16px;
        margin: 12px;
        width: calc(100% - 24px);
        max-width: none;
    }

    .modal-content h2 {
        font-size: 1.25rem;
    }

    .modal-buttons {
        flex-direction: column;
        gap: 8px;
    }

    /* Promotion modal */
    .promotion-modal-content {
        padding: 20px 16px;
        max-width: 280px;
    }

    .promotion-options {
        gap: 6px;
    }

    .promotion-btn {
        padding: 10px 6px;
        min-height: 70px;
    }

    .promotion-piece {
        font-size: 1.75rem;
    }

    /* Stockfish hint / Analysis */
    .stockfish-hint {
        margin-top: 10px;
        padding: 14px;
    }

    .stockfish-hint h4 {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }

    .hint-content {
        padding: 10px;
        margin-bottom: 10px;
    }

    .hint-content p {
        font-size: 0.8rem;
    }

    /* Load position section */
    .load-position-buttons {
        gap: 6px;
    }

    .load-position-section .btn-primary,
    .load-position-section .btn-secondary {
        padding: 10px 14px;
        font-size: 0.8rem;
        min-height: 44px;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    .header {
        margin-bottom: 12px;
    }

    .title {
        font-size: 1.2rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    /* Compact back button */
    .back-button-container {
        margin-bottom: 8px;
    }

    .back-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    /* Game info - more compact */
    .game-info {
        padding: 8px 10px;
        margin-bottom: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .info-item {
        min-width: 30%;
    }

    .info-label {
        font-size: 0.6rem;
    }

    .info-value {
        font-size: 0.8rem;
    }

    /* Timer - more compact */
    .timer-container {
        padding: 8px 10px;
        margin-bottom: 8px;
    }

    .timer-label {
        font-size: 0.65rem;
    }

    .timer-value {
        font-size: 1rem;
    }

    /* Board */
    .board-container {
        padding: 6px;
    }

    .board-with-eval {
        gap: 4px;
        margin-bottom: 8px;
    }

    /* Smaller eval bar on very small screens */
    .eval-bar {
        width: 12px;
        min-width: 12px;
    }

    .eval-bar-score {
        font-size: 0.5rem;
        padding: 1px 2px 1px 4px;
    }

    /* Controls - icon only on very small screens */
    .controls {
        gap: 4px;
    }

    .control-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
        min-width: calc(50% - 2px);
    }

    .control-btn span:not(:empty) {
        display: none;
    }

    .control-btn svg {
        margin: 0;
    }

    /* Right panel sections */
    .right-panel {
        gap: 10px;
    }

    .captured-pieces,
    .move-history,
    .game-status,
    .statistics,
    .saved-games,
    .stockfish-hint,
    .load-position-section {
        padding: 12px;
    }

    /* Captured pieces */
    .captured-list {
        min-height: 28px;
        padding: 6px;
    }

    .captured-piece {
        font-size: 1.25rem;
    }

    /* Move history - shorter on mobile */
    .move-list {
        max-height: 120px;
        padding: 6px;
    }

    /* Loading overlay */
    .spinner {
        width: 28px;
        height: 28px;
        margin-bottom: 12px;
    }

    .thinking-timer {
        padding: 12px 20px;
        margin-top: 12px;
    }

    .thinking-countdown {
        font-size: 2rem;
    }

    .thinking-level {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    /* Promotion modal - more compact */
    .promotion-modal-content {
        padding: 16px 12px;
        max-width: 260px;
    }

    .promotion-modal-content h3 {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    .promotion-btn {
        padding: 8px 4px;
        min-height: 60px;
    }

    .promotion-piece {
        font-size: 1.5rem;
    }

    .promotion-btn span:last-child {
        font-size: 0.7rem;
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    body {
        padding: 6px;
    }

    .title {
        font-size: 1.1rem;
    }

    .game-info {
        padding: 6px 8px;
    }

    .info-item {
        gap: 1px;
    }

    .timer-container {
        padding: 6px 8px;
    }

    .board-container {
        padding: 4px;
    }

    /* Hide eval bar on very small screens */
    .eval-bar {
        display: none;
    }

    .board-with-eval {
        gap: 0;
    }

    .control-btn {
        padding: 6px 8px;
        font-size: 0.7rem;
    }

    .captured-pieces,
    .move-history,
    .game-status,
    .statistics,
    .saved-games,
    .stockfish-hint,
    .load-position-section {
        padding: 10px;
    }

    .promotion-modal-content {
        max-width: 240px;
        padding: 14px 10px;
    }

    .promotion-piece {
        font-size: 1.3rem;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 8px;
    }

    .header {
        margin-bottom: 8px;
    }

    .title {
        font-size: 1rem;
    }

    .subtitle {
        display: none;
    }

    /* Back button - compact in landscape */
    .back-button-container {
        position: fixed !important;
        top: 8px !important;
        left: 8px !important;
        margin-bottom: 0;
        z-index: 100;
    }

    .back-btn {
        padding: 4px 10px;
        font-size: 0.75rem;
    }

    .game-wrapper {
        flex-direction: row !important;
        align-items: flex-start;
        gap: 12px;
    }

    .left-panel {
        flex: 0 0 auto !important;
        max-width: none !important;
        width: auto !important;
    }

    /* Force board to fit viewport height */
    .board-wrapper,
    .board-container,
    .board-with-eval {
        max-height: calc(100vh - 100px);
    }

    #board {
        max-width: calc(100vh - 120px) !important;
        max-height: calc(100vh - 120px) !important;
    }

    .right-panel {
        flex: 1 !important;
        max-width: none !important;
        width: auto !important;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }

    .game-info {
        padding: 4px 8px;
        margin-bottom: 4px;
        font-size: 0.7rem;
    }

    .info-label {
        font-size: 0.55rem;
    }

    .info-value {
        font-size: 0.75rem;
    }

    .timer-container {
        padding: 4px 8px;
        margin-bottom: 4px;
    }

    .timer-label {
        font-size: 0.6rem;
    }

    .timer-value {
        font-size: 0.9rem;
    }

    .board-container {
        padding: 4px;
    }

    /* Hide eval bar in landscape to save space */
    .eval-bar {
        display: none;
    }

    .board-with-eval {
        gap: 0;
        margin-bottom: 4px;
    }

    .controls {
        gap: 4px;
    }

    .control-btn {
        padding: 4px 6px;
        font-size: 0.65rem;
        min-height: 32px;
    }

    .control-btn span:not(:empty) {
        display: none;
    }

    .control-btn svg {
        margin: 0;
        width: 14px;
        height: 14px;
    }

    /* Compact right panel sections */
    .captured-pieces,
    .move-history,
    .statistics,
    .saved-games,
    .stockfish-hint,
    .load-position-section {
        padding: 8px 10px;
    }

    .captured-pieces h3,
    .move-history h3,
    .statistics h3,
    .saved-games h3,
    .load-position-section h3 {
        font-size: 0.7rem;
        margin-bottom: 6px;
    }

    .move-list {
        max-height: 80px;
    }

    .stockfish-hint {
        margin-top: 4px;
    }

    .stockfish-hint h4 {
        font-size: 0.7rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Ensure minimum touch target size */
    .control-btn,
    .mode-btn,
    .time-toggle-btn,
    .color-toggle-btn,
    .btn-primary,
    .btn-secondary,
    .promotion-btn,
    .side-toggle-btn,
    .view-toggle-btn,
    .sync-tab {
        min-height: 44px;
    }

    /* Improve scrolling */
    .move-list,
    #savedGamesList,
    .position-modal-content,
    .live-sync-modal-content {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== Position Import Modal ===== */
.position-modal-content {
    max-width: 500px;
    width: 95%;
    text-align: left;
    padding: 0;
    max-height: 90vh;
    overflow-y: auto;
}

.position-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.position-modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.position-modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.position-modal-close:hover {
    background: var(--light-bg);
    color: var(--text-dark);
}

.position-modal-body {
    padding: 20px 24px;
}

.position-input-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.position-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    resize: vertical;
    min-height: 70px;
    transition: border-color 0.2s ease;
    color: var(--text-dark);
    background-color: var(--white);
}

.position-textarea:focus {
    outline: none;
    border-color: var(--success-color);
}

.position-textarea::placeholder {
    color: var(--text-light);
    opacity: 0.7;
}

/* Clickable Label for Paste */
.clickable-label {
    cursor: pointer;
    transition: var(--transition);
    display: inline-block;
}

.clickable-label:hover {
    color: var(--success-color);
}

.clickable-label.focused {
    color: var(--success-color);
}

.label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-light);
    font-style: italic;
}

.clickable-label:hover .label-hint,
.clickable-label.focused .label-hint {
    color: var(--success-color);
    opacity: 0.8;
}

/* Screenshot Upload Section */
.screenshot-upload-section {
    margin-bottom: 16px;
}

.screenshot-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--light-bg);
}

.screenshot-dropzone:hover {
    border-color: var(--success-color);
    background: rgba(45, 106, 79, 0.05);
}

.screenshot-dropzone.drag-over {
    border-color: var(--success-color);
    background: rgba(45, 106, 79, 0.1);
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.dropzone-content svg {
    color: var(--text-light);
    width: 24px;
    height: 24px;
}

.dropzone-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-dark);
}

.dropzone-hint {
    font-size: 0.7rem;
    color: var(--text-light);
}

.screenshot-preview {
    margin-top: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--light-bg);
}

.screenshot-preview canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: var(--radius-sm);
    background: #f0f0f0;
}

.screenshot-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: center;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Responsive screenshot section */
@media (max-width: 480px) {
    .screenshot-actions {
        gap: 6px;
        margin-top: 8px;
    }

    .btn-sm {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .screenshot-preview canvas {
        max-width: 100%;
        height: auto;
    }
}

.extraction-status {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 10px;
    background: rgba(45, 106, 79, 0.1);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--success-color);
}

.extraction-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--success-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.extraction-message {
    font-size: 0.85rem;
    color: var(--success-color);
}

.extraction-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.extraction-progress-fill {
    height: 100%;
    background: var(--success-color);
    transition: width 0.3s ease;
    border-radius: 3px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.position-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 20px 0;
}

.position-divider::before,
.position-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.position-divider span {
    padding: 0 12px;
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Format Indicator */
.format-indicator {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--light-bg);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.format-indicator.valid-fen {
    background: rgba(45, 106, 79, 0.1);
    border: 1px solid var(--success-color);
}

.format-indicator.valid-fen .format-status {
    color: var(--success-color);
}

.format-indicator.valid-pgn {
    background: rgba(45, 106, 79, 0.1);
    border: 1px solid var(--success-color);
}

.format-indicator.valid-pgn .format-status {
    color: var(--success-color);
}

.format-indicator.invalid {
    background: rgba(157, 2, 8, 0.1);
    border: 1px solid var(--danger-color);
}

.format-indicator.invalid .format-status {
    color: var(--danger-color);
}

.format-indicator .format-icon {
    font-size: 1rem;
}

/* Side to Move Toggle */
.side-to-move-section {
    margin-top: 16px;
}

.side-toggle {
    display: flex;
    gap: 8px;
}

.side-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    color: var(--text-dark);
}

.side-toggle-btn:hover:not(:disabled) {
    border-color: var(--success-color);
}

.side-toggle-btn.active {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.side-toggle-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.side-toggle-btn:disabled:hover {
    border-color: var(--border-color);
}

.side-toggle-btn.active:disabled {
    background: var(--success-color);
    opacity: 0.8;
}

.side-toggle-btn .color-icon {
    font-size: 0.9rem;
}

/* Toggle Hint */
.toggle-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 6px;
    font-style: italic;
}

/* View As Section */
.view-as-section {
    margin-top: 16px;
}

.view-toggle {
    display: flex;
    gap: 8px;
}

.view-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    color: var(--text-dark);
}

.view-toggle-btn:hover {
    border-color: var(--success-color);
}

.view-toggle-btn.active {
    background: var(--success-color);
    color: var(--white);
    border-color: var(--success-color);
}

.view-toggle-btn .color-icon {
    font-size: 0.9rem;
}

/* Preview Board */
.preview-section {
    margin-top: 16px;
}

.preview-board-container {
    width: 200px;
    height: 200px;
    margin: 0 auto;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--light-bg);
}

#previewBoard {
    width: 100%;
    height: 100%;
}

/* Modal Footer */
.position-modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--light-bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.position-modal-footer .btn-secondary,
.position-modal-footer .btn-primary {
    flex: 1;
}

.position-modal-footer .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive adjustments for position modal */
@media (max-width: 768px) {
    .position-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 85vh;
    }

    .position-modal-header {
        padding: 16px 20px;
    }

    .position-modal-header h2 {
        font-size: 1.1rem;
    }

    .position-modal-body {
        padding: 16px 20px;
    }

    .position-textarea {
        min-height: 60px;
        font-size: 0.8rem;
    }

    .side-toggle-btn,
    .view-toggle-btn {
        padding: 10px 8px;
        font-size: 0.8rem;
    }

    .preview-board-container {
        width: 180px;
        height: 180px;
    }

    .position-modal-footer {
        padding: 14px 20px;
    }
}

@media (max-width: 480px) {
    .position-modal-content {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .position-modal-header {
        padding: 14px 16px;
    }

    .position-modal-body {
        padding: 14px 16px;
    }

    .preview-board-container {
        width: 150px;
        height: 150px;
    }

    .position-modal-footer {
        padding: 12px 16px;
    }

    .position-modal-footer .btn-primary,
    .position-modal-footer .btn-secondary {
        padding: 12px;
        font-size: 0.85rem;
    }
}


/* ===== Load Position Section (Right Panel) ===== */
.load-position-section {
    background: var(--white);
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.load-position-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.load-position-desc {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 12px;
}

.load-position-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.load-position-section .btn-primary,
.load-position-section .btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.load-position-section .btn-primary svg,
.load-position-section .btn-secondary svg {
    flex-shrink: 0;
}

/* ===== Live Sync Modal ===== */
.live-sync-modal-content {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.sync-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sync-modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
}

/* Sync Tabs */
.sync-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--light-bg);
    border-radius: var(--radius-md);
    padding: 4px;
}

.sync-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-light);
    transition: var(--transition);
}

.sync-tab:hover {
    color: var(--text-dark);
}

.sync-tab.active {
    background: var(--white);
    color: var(--success-color);
    box-shadow: var(--shadow);
}

/* Sync Tab Content */
.sync-tab-content {
    display: none;
}

.sync-tab-content.active {
    display: block;
}

/* Sync Input Group */
.sync-input-group {
    margin-bottom: 12px;
}

.sync-input-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.sync-input-group input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.sync-input-group input:focus {
    outline: none;
    border-color: var(--success-color);
}

.sync-help-link {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--success-color);
    text-decoration: none;
    margin-top: 4px;
}

.sync-help-link:hover {
    text-decoration: underline;
}

/* Sync Buttons */
.sync-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.sync-buttons .btn-primary,
.sync-buttons .btn-secondary {
    flex: 1;
}

/* Sync Status */
.sync-status {
    padding: 10px 12px;
    background: var(--light-bg);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
}

.sync-status.connecting {
    color: var(--warning-color);
    background: rgba(232, 93, 4, 0.1);
}

.sync-status.connected {
    color: var(--success-color);
    background: rgba(45, 106, 79, 0.1);
}

.sync-status.error {
    color: var(--danger-color);
    background: rgba(157, 2, 8, 0.1);
}

/* Sync Instructions */
.sync-instructions {
    background: var(--light-bg);
    padding: 12px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 0.8rem;
}

.sync-instructions h5 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.sync-instructions ol {
    margin: 0;
    padding-left: 20px;
    color: var(--text-light);
    line-height: 1.6;
}

.sync-instructions li {
    margin-bottom: 4px;
}

.sync-instructions a {
    color: var(--success-color);
    text-decoration: none;
}

.sync-instructions a:hover {
    text-decoration: underline;
}

.sync-instructions code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 0.85em;
}

.sync-note {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--warning-color);
    font-style: italic;
}

/* Chess.com Tab Styles */
.sync-info {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 12px;
    line-height: 1.5;
}

.sync-paste-btn {
    width: 100%;
    margin-bottom: 8px;
}

.sync-hint {
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
    font-style: italic;
}

/* ===== Sync Notification Toast ===== */
.sync-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.sync-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.sync-notification-success {
    background: var(--success-color);
    color: var(--white);
}

.sync-notification-error {
    background: var(--danger-color);
    color: var(--white);
}

.sync-notification-warning {
    background: var(--warning-color);
    color: var(--white);
}

.sync-notification-info {
    background: var(--primary-color);
    color: var(--white);
}

/* Live Sync Modal Responsive */
@media (max-width: 768px) {
    .live-sync-modal-content {
        width: 95%;
        max-width: 95%;
        padding: 20px;
        max-height: 85vh;
    }

    .sync-modal-header h2 {
        font-size: 1.1rem;
    }

    .sync-tabs {
        padding: 3px;
    }

    .sync-tab {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .sync-input-group input {
        padding: 10px;
        font-size: 0.85rem;
    }

    .sync-instructions {
        padding: 10px;
        font-size: 0.75rem;
    }

    .sync-instructions ol {
        padding-left: 16px;
    }
}

@media (max-width: 480px) {
    .live-sync-modal-content {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
        padding: 16px;
    }

    .sync-modal-header {
        margin-bottom: 16px;
        padding-bottom: 10px;
    }

    .sync-tabs {
        margin-bottom: 12px;
    }

    .sync-buttons {
        flex-direction: column;
    }

    .sync-buttons .btn-primary,
    .sync-buttons .btn-secondary {
        width: 100%;
    }
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ===== Inline API Setup ===== */
.api-setup-inline {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.api-setup-title {
    margin: 0 0 2px 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dark);
}

.api-setup-desc {
    margin: 0 0 8px 0;
    font-size: 0.7rem;
    color: var(--text-light);
    line-height: 1.3;
}

.api-setup-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.api-setup-form .api-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    background: var(--white);
    color: var(--text-dark);
    min-width: 0;
}

.api-setup-form .api-input:focus {
    outline: none;
    border-color: var(--success-color);
}

.api-setup-form .api-input::placeholder {
    font-size: 0.7rem;
    color: var(--text-light);
}

.api-setup-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.api-setup-actions .btn-secondary,
.api-setup-actions .btn-primary {
    padding: 5px 10px;
    font-size: 0.7rem;
    min-height: unset;
    white-space: nowrap;
}

.api-test-status {
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    text-align: center;
    display: none;
}

.api-test-status:not(:empty) {
    display: block;
}

.api-test-status.success {
    background: rgba(45, 106, 79, 0.12);
    color: var(--success-color);
}

.api-test-status.error {
    background: rgba(157, 2, 8, 0.08);
    color: var(--danger-color);
}

.api-setup-help {
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.api-help-toggle {
    font-size: 0.68rem;
    color: var(--text-light);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.api-help-toggle:hover {
    color: var(--success-color);
}

.api-help-toggle::after {
    content: '▼';
    font-size: 0.5rem;
    transition: transform 0.2s ease;
}

.api-help-toggle.expanded::after {
    transform: rotate(180deg);
}

.api-help-content {
    margin-top: 6px;
    padding: 0;
    text-align: left;
}

.api-steps-list {
    margin: 0;
    padding-left: 16px;
    font-size: 0.68rem;
    line-height: 1.5;
    color: var(--text-light);
}

.api-steps-list li {
    margin-bottom: 2px;
}

.api-steps-list a {
    color: var(--success-color);
    text-decoration: none;
}

.api-steps-list a:hover {
    text-decoration: underline;
}

/* Responsive: Mobile */
@media (max-width: 480px) {
    .api-setup-inline {
        padding: 8px 10px;
    }

    .api-setup-form {
        flex-wrap: wrap;
    }

    .api-setup-form .api-input {
        width: 100%;
        flex: none;
    }

    .api-setup-actions {
        width: 100%;
        margin-top: 4px;
    }

    .api-setup-actions .btn-secondary,
    .api-setup-actions .btn-primary {
        flex: 1;
    }
}
