/* chessboardviewer.css - Fixed mobile: board visible, names on same line */
* {
    box-sizing: border-box;
}

.viewer {
    display: flex;
    gap: 24px;
    padding: 12px;
    max-width: 1600px;
    margin: 0 auto;
    margin-top: 70px;
    align-items: flex-start;
}

/* Left column: board + controls */
.left-panel {
    flex: 0 0 45%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 280px;
    max-width: 650px;
    align-items: center;
}

/* Board container – must have explicit size for chessboard.js */
#boardContainer {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    background: var(--panel);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 5px;
    box-sizing: border-box;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Board – chessboard.js needs explicit dimensions */
#board {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    position: relative !important;
    transform: none !important;
    touch-action: manipulation;
}

/* Chessboard.js inner elements */
#board .chessboard-1-0-0 {
    width: 100% !important;
    height: 100% !important;
}

#board .chessboard-1-0-0 table {
    width: 100% !important;
    height: 100% !important;
}

#board .chessboard-63f37,
#board .board-b72b1 {
    width: 100% !important;
    height: 100% !important;
}

#board .board-b72b1 {
    border: 0 !important;
    box-sizing: border-box !important;
}

#board .row-5277c {
    width: 100% !important;
    height: 12.5% !important;
}

#board .square-55d63 {
    width: 12.5% !important;
    height: 100% !important;
}

#board .piece-417db {
    width: 100% !important;
    height: 100% !important;
}

/* Controls row */
.move-controls {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: var(--panel-2);
    border-radius: var(--radius);
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
    width: 100%;
}

/* Right panel */
#right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 250px;
    max-width: 55%;
}

/* Moves container */
#moves {
    flex: 1;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
    padding: 10px 14px;
    overflow-y: auto;
    scroll-behavior: smooth;
    min-height: 200px;
    border: 1px solid rgba(255,255,255,0.05);
}

#moves::-webkit-scrollbar {
    width: 6px;
}
#moves::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
}
#moves::-webkit-scrollbar-thumb {
    background: #4a90d9;
    border-radius: 3px;
}
#moves {
    scrollbar-width: thin;
    scrollbar-color: #4a90d9 rgba(255,255,255,0.05);
}

.gameInfo {
    background: var(--panel-2);
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 14px;
    flex-shrink: 0;
    width: 100%;
}

/* Fix: Player names on same line */
.gameInfo .player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
}

.gameInfo .player-card {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    border-radius: 8px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
}

.gameInfo .player-card .piece-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.gameInfo .player-card .player-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.gameInfo .player-card .player-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gameInfo .player-card .player-details {
    font-size: 10px;
    color: var(--muted);
}

.gameInfo .result-badge {
    border-radius: 8px;
    padding: 4px 12px;
    min-width: 40px;
    text-align: center;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 16px;
}

.gameInfo .result-badge.win {
    background: #4CAF50;
    color: white;
}
.gameInfo .result-badge.loss {
    background: #f44336;
    color: white;
}
.gameInfo .result-badge.draw {
    background: #FFC107;
    color: #333;
}
.gameInfo .result-badge.unknown {
    background: #e0e0e0;
    color: #888;
}

.gameInfo .event-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    background: var(--panel);
    border-radius: 6px;
    padding: 2px 8px;
    border: 1px solid var(--border);
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.gameInfo .event-bar span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.move-controls button {
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.move-controls button:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#exit-variation-btn {
    background: #f44336;
    color: white;
    border: none;
}
#exit-variation-btn:hover {
    background: #d32f2f;
}

#status {
    padding: 4px 10px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    flex-shrink: 0;
    width: 100%;
}

/* Move rows & variations */
.move-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-wrap: wrap;
    padding: 2px 0;
}
.move-number {
    font-weight: bold;
    margin-right: 2px;
    min-width: 22px;
    color: #888;
    font-size: 13px;
}
.move-span {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 14px;
}
.move-span:hover {
    background: rgba(255,255,255,0.08);
}
.move-span.active {
    background: #333;
    color: white;
    font-weight: bold;
    box-shadow: 0 0 12px rgba(51, 51, 51, 0.3);
}
.move-span.variation-active {
    outline: 2px solid #4a90d9;
    outline-offset: 2px;
}
.move-comment {
    font-size: 12px;
    color: #888;
    margin-left: 1px;
    font-style: italic;
    display: inline;
    white-space: nowrap;
}
.variation-indicator {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    opacity: 0.7;
    transition: all 0.2s;
}
.variation-indicator:hover {
    opacity: 1;
}
.variations-container {
    width: 100%;
    margin-top: 4px;
    margin-bottom: 4px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.06);
    border-radius: 6px;
    border-left: 3px solid #4a90d9;
    color: #b0c4de;
}
.variation-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    flex-wrap: wrap;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}
.variation-row:hover {
    background: rgba(255,255,255,0.05);
}
.variation-row .var-label {
    font-size: 13px;
    color: #8aadc8;
    font-weight: 500;
}
.variation-row .var-moves {
    font-size: 13px;
    color: #c8d8e8;
}
.variation-row .var-comment {
    font-size: 11px;
    color: #7a9db8;
    font-style: italic;
}
.variation-row .enter-btn {
    padding: 1px 10px;
    font-size: 12px;
    cursor: pointer;
    background: #4a90d9;
    color: white;
    border: none;
    border-radius: 4px;
    transition: background 0.2s;
    line-height: 22px;
}
.variation-row .enter-btn:hover {
    background: #3a7bc8;
}

/* ========== MOBILE ========== */
@media (max-width: 900px) {
    .viewer {
        flex-direction: column;
        gap: 16px;
        align-items: center;
        padding: 10px;
    }

    .left-panel {
        flex: none;
        width: 100%;
        max-width: 600px;
        margin: 0 auto;
        align-items: center;
    }

    #boardContainer {
        max-width: 100%;
        width: 100%;
        aspect-ratio: 1 / 1;
        min-height: 300px;
    }

    #right-panel {
        flex: none;
        width: 100%;
        max-width: 100%;
        min-height: 300px;
    }

    .move-controls {
        width: 100%;
        justify-content: center;
    }

    .gameInfo {
        font-size: 13px;
        padding: 6px 10px;
    }

    /* Fix: Player names on same line on tablet */
    .gameInfo .player-row {
        flex-wrap: nowrap;
    }
    .gameInfo .player-card .player-name {
        font-size: 12px;
    }
}

@media (max-width: 600px) {
    .viewer {
        padding: 6px;
        gap: 6px;
        margin-top: 58px;
        height: calc(100vh - 58px);
        height: calc(100svh - 58px);
        min-height: 0;
        overflow: hidden;
    }

    .left-panel {
        max-width: 100%;
        padding: 0;
        width: 100%;
        gap: 6px;
        min-height: 0;
        flex: 0 0 auto;
    }

    #boardContainer {
        max-width: 100%;
        width: 100%;
        aspect-ratio: 1 / 1;
        min-height: 0;
        padding: 4px;
    }

    #board {
        min-height: 0 !important;
    }

    .move-controls {
        padding: 5px 6px;
        gap: 4px;
        flex-wrap: wrap;
        border-radius: 8px;
    }

    .move-controls button {
        font-size: 11px;
        padding: 0 6px;
        height: 30px;
        min-width: 32px;
        flex: 0 1 auto;
    }

    #right-panel {
        width: 100%;
        max-width: 100%;
        min-height: 0;
        flex: 1 1 auto;
        gap: 6px;
        overflow: hidden;
    }

    #moves {
        padding: 6px 8px;
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
    }

    .move-span {
        font-size: 12px;
        padding: 1px 3px;
    }

    .gameInfo {
        font-size: 11px;
        padding: 4px 6px;
    }

    .gameInfo > div {
        gap: 4px !important;
        padding: 0 !important;
    }

    /* Fix: Player names on same line on phone */
    .gameInfo .player-row {
        align-items: center !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
    }
    .gameInfo .player-card {
        min-width: 0 !important;
        padding: 4px 5px !important;
        gap: 4px !important;
        align-self: stretch;
    }
    .gameInfo .player-card > div:not(.piece-icon) {
        min-width: 0 !important;
    }
    .gameInfo .player-card span {
        display: block;
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .gameInfo .player-card span:first-child {
        font-size: 10px !important;
        line-height: 1.15;
    }
    .gameInfo .player-card span:last-child {
        font-size: 8px !important;
        line-height: 1.15;
    }
    .gameInfo .player-card .piece-icon {
        font-size: 14px;
    }
    .gameInfo .player-row > div:nth-child(2) {
        min-width: 36px !important;
        padding: 0 !important;
        flex: 0 0 auto;
    }
    .gameInfo .player-row > div:nth-child(2) > div {
        min-width: 34px !important;
        padding: 2px 6px !important;
    }
    .gameInfo .player-row > div:nth-child(2) span {
        font-size: 11px !important;
        line-height: 1.2;
        letter-spacing: 0 !important;
    }
    .gameInfo .player-card .player-name {
        font-size: 10px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .gameInfo .player-card .player-details {
        font-size: 8px;
    }
    .gameInfo .result-badge {
        font-size: 11px !important;
        padding: 2px 6px !important;
        min-width: 34px !important;
    }
    .gameInfo .event-bar {
        font-size: 9px !important;
        gap: 4px !important;
        padding: 2px 6px !important;
        max-height: 20px;
        overflow: hidden;
        white-space: nowrap;
    }
    .gameInfo .event-bar span {
        font-size: 9px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .gameInfo .event-bar span:not(:first-child) {
        display: none !important;
    }
    .gameInfo > div > div:last-child {
        gap: 4px !important;
        padding: 2px 6px !important;
        max-height: 20px;
        overflow: hidden;
        white-space: nowrap;
    }
    .gameInfo > div > div:last-child span {
        font-size: 9px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .gameInfo > div > div:last-child span:not(:first-child) {
        display: none !important;
    }

    #status {
        font-size: 11px;
        padding: 0 6px;
        min-height: 14px;
    }
}

/* Extra small phones */
@media (max-width: 400px) {
    #boardContainer {
        min-height: 0;
    }

    #board {
        min-height: 0 !important;
    }

    .move-controls button {
        font-size: 10px;
        padding: 0 4px;
        height: 28px;
        min-width: 28px;
    }

    .gameInfo .player-card .player-name {
        font-size: 9px;
    }
    .gameInfo .result-badge {
        font-size: 10px;
        padding: 2px 6px;
        min-width: 24px;
    }
}


/* =============================================
   NEW STATE CLASSES – used by viewer.js
   ============================================= */

.hidden {
    display: none !important;
}

/* Active state for main moves */
.move-span.active {
    background: #333 !important;
    color: white !important;
    font-weight: bold !important;
    box-shadow: 0 0 12px rgba(51, 51, 51, 0.3) !important;
}

/* Active state for variation moves – same style */
.variation-move.active {
    background: #333 !important;
    color: white !important;
    font-weight: bold !important;
    box-shadow: 0 0 12px rgba(51, 51, 51, 0.3) !important;
}

/* Parent move highlight when variation is active */
.move-span.variation-active {
    outline: 2px solid #4a90d9 !important;
    outline-offset: 2px !important;
}

/* Exit variation button – hidden by default, shown via .visible */
#exit-variation-btn {
    display: none;
}
#exit-variation-btn.visible {
    display: inline-block !important;
}

/* Variation container – hidden by default, shown via .hidden toggle */
.variations-container.hidden {
    display: none !important;
}


/* =============================================
   Responsive move list – more compact on mobile
   ============================================= */

@media (max-width: 600px) {
    .move-row {
        gap: 2px;                /* reduce gap between moves */
        padding: 1px 0;
    }
    .move-number {
        font-size: 11px;
        min-width: 18px;
        margin-right: 1px;
    }
    .move-span {
        font-size: 12px;
        padding: 1px 3px;
    }
    .move-comment {
        font-size: 10px;
    }
    .move-container {
        gap: 1px;
    }
    .variation-move {
        font-size: 11px;
        padding: 1px 4px;
    }
    .variation-label {
        font-size: 11px;
    }
    .variation-preamble {
        font-size: 10px;
    }
    .variation-move-number {
        font-size: 10px;
    }
    .variation-nag {
        font-size: 10px;
    }
    .variation-comment {
        font-size: 9px;
    }
    .variation-indicator-btn {
        font-size: 10px;
        padding: 0 2px;
    }
    .variation-count-badge {
        font-size: 8px;
        min-width: 14px;
        line-height: 14px;
    }

     .gameInfo .event-bar {
        display: none !important;
    }
}

/* =============================================
   MOBILE OPTIMIZATIONS – more vertical space
   ============================================= */

/* Hide location (site) on small screens */
@media (max-width: 600px) {
    /* Hide the site span (contains 📍) */
    .gameInfo .event-bar span:has(.fi) { /* if flag icons are used */
        display: none;
    }
    /* Alternatively, if the site is in a span without a flag */
    .gameInfo .event-bar span[class*="site"] {
        display: none;
    }
    /* Simpler: hide the third span (if order is event, site, date, round, eco) */
    .gameInfo .event-bar span:nth-child(2) {
        display: none;
    }
    /* Or target the specific text: "📍 ${site}" – we can use attribute? */
    /* Best: give the site span a class in the HTML, but we can just hide based on content */
    .gameInfo .event-bar span:not(:first-child):not(:nth-child(3)) {
        /* This is tricky; we'll use a simpler approach: hide all but event and date? */
    }
}

/* More robust: hide any span containing a flag icon (if site has flag) */
@media (max-width: 600px) {
    .gameInfo .event-bar .fi {
        display: none;
    }
    /* If the site is the only one with a flag, the whole span becomes empty */
    .gameInfo .event-bar span:empty {
        display: none;
    }
}

/* Shrink the header/navigation bar on mobile */
@media (max-width: 600px) {
    nav, .navbar, .header, #header-placeholder + * {
        padding: 4px 8px !important;
        min-height: 40px !important;
        font-size: 12px !important;
    }
    nav a, .navbar a, .header a {
        font-size: 12px !important;
        padding: 4px 6px !important;
    }
    /* If there's a logo or title, make it smaller */
    nav .logo, .navbar .logo, .header .logo {
        font-size: 14px !important;
    }
}

/* Compact event bar: reduce spacing and font size */
@media (max-width: 600px) {
    .gameInfo .event-bar {
        padding: 2px 6px !important;
        gap: 4px !important;
        font-size: 10px !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
    }
    .gameInfo .event-bar span {
        white-space: nowrap !important;
    }
}

/* Reduce game info padding on mobile */
@media (max-width: 600px) {
    .gameInfo {
        padding: 4px 6px !important;
    }
    .gameInfo .player-card {
        padding: 4px 8px !important;
        min-width: 80px !important;
    }
    .gameInfo .player-card .piece-icon {
        font-size: 16px !important;
    }
    .gameInfo .player-card .player-name {
        font-size: 11px !important;
    }
    .gameInfo .player-card .player-details {
        font-size: 9px !important;
    }
    .gameInfo .result-badge {
        font-size: 12px !important;
        padding: 2px 8px !important;
        min-width: 30px !important;
    }
}