/* Opening explorer: board + side panel layout */
body { overflow: hidden; }
#openings-app {
    display: flex;
    width: 100%;
    height: calc(100svh - 57px);
}

/* Landscape: panel on the right, iframe fills remaining */
@media (orientation: landscape) {
    #openings-app { flex-direction: row; }
    #openings-app #game-frame { flex: 1; height: 100%; border: none; }
    #openings-panel {
        width: 320px; height: 100%;
        border-left: 1px solid var(--bs-border-color);
        flex-shrink: 0;
    }
}

/* Portrait: panel on the bottom, iframe fills remaining */
@media (orientation: portrait) {
    body { overflow: auto; }
    #openings-app { flex-direction: column; height: auto; min-height: calc(100svh - 57px); }
    #openings-app #game-frame { width: 100%; height: calc(100svh - 57px - 200px); flex-shrink: 0; border: none; }
    #openings-panel {
        width: 100%;
        border-top: 1px solid var(--bs-border-color);
        flex-shrink: 0;
        max-height: 50vh;
    }
}

#openings-panel {
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    color: var(--bs-body-color);
}

/* ── Header ──────────────────────────────────────────────────── */
#openings-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
}

/* ── Nav buttons ─────────────────────────────────────────────── */
#openings-nav {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
}
#openings-nav button,
#openings-nav a {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--bs-body-color);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s;
    text-decoration: none;
}
#openings-nav button:hover:not(:disabled),
#openings-nav a:hover {
    background: var(--bs-table-hover-bg);
}
#openings-nav button:disabled {
    opacity: 0.4;
    cursor: default;
}
#openings-nav svg {
    width: 16px; height: 16px; flex-shrink: 0;
}

/* ── Move list ───────────────────────────────────────────────── */
#openings-moves {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ── Popularity chart ────────────────────────────────────────── */
#openings-popularity {
    padding: 8px 10px;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
    height: 100px;
}
#openings-popularity canvas {
    width: 100% !important;
    height: 100% !important;
}

.openings-status {
    text-align: center;
    padding: 24px 12px;
    color: var(--bs-secondary-color);
    font-size: 13px;
}

/* ── Move button ─────────────────────────────────────────────── */
.opening-move-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--bs-border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--bs-body-color);
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
    text-align: left;
}
.opening-move-btn:hover {
    background: var(--bs-table-hover-bg);
    border-color: var(--bs-secondary-color);
}

/* Piece icon token */
.opening-move-btn .piece-token {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}
.opening-move-btn .piece-token.white { background: #f0d9a0; }
.opening-move-btn .piece-token.black { background: #555; border: 1px solid #777; }
.opening-move-btn .piece-token img {
    width: 170%; height: 170%;
    flex-shrink: 0;
    transform: translateX(1px);
}

/* Move text + stats */
.opening-move-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.opening-move-name {
    font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.opening-move-stats {
    font-size: 11px;
    color: var(--bs-secondary-color);
}

/* Win rate column (right side) */
.opening-move-win {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.opening-move-win-text {
    font-size: 11px;
    color: #6a6;
    white-space: nowrap;
}

/* ── Percentage bar (stacked win/draw/loss) ──────────────────── */
.opening-move-bar {
    width: 80px;
    height: 6px;
    background: var(--bs-border-color);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
}
.opening-move-bar .bar-wins   { height: 100%; background: #6a6; }
.opening-move-bar .bar-draws  { height: 100%; background: #888; }
.opening-move-bar .bar-losses { height: 100%; background: #c66; }

/* ── Filters ─────────────────────────────────────────────────── */
#openings-filters {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
    align-items: flex-end;
}
.filter-group {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.filter-label {
    font-size: 11px;
    color: var(--bs-secondary-color);
    font-weight: 500;
}

/* Number input */
.filter-number {
    width: 100%;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    outline: none;
}
.filter-number:focus {
    border-color: var(--bs-secondary-color);
}

/* Custom dropdown (no Bootstrap dependency) */
.filter-dropdown {
    position: relative;
}
.filter-dropdown-btn {
    width: 100%;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.filter-dropdown-btn:hover {
    border-color: var(--bs-secondary-color);
}
.filter-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    padding: 4px 0;
    margin-top: 2px;
}
.filter-dropdown-menu.open {
    display: block;
}
.filter-dropdown-menu label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.filter-dropdown-menu label:hover {
    background: var(--bs-table-hover-bg);
}
.filter-dropdown-menu input[type="checkbox"] {
    accent-color: var(--bs-secondary-color);
}
