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

:root {
    --board-size: 480px;
    --bg: #1a1a2e;
    --bg-panel: #16213e;
    --bg-panel-hover: #1a2744;
    --bg-header: #0f3460;
    --text: #e0e0e0;
    --text-muted: #8a8a9a;
    --accent: #e94560;
    --accent-dim: #c03050;
    --move-active: #e94560;
    --move-hover: rgba(233, 69, 96, 0.15);
    --border: #2a2a4a;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --radius: 6px;
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "Consolas", "Monaco", "Courier New", monospace;
}

/* Light theme overrides */
body[data-theme="light"] {
    --bg: #f5f5f5;
    --bg-panel: #ffffff;
    --bg-panel-hover: #eaeaea;
    --bg-header: #e0e0e0;
    --text: #1a1a1a;
    --text-muted: #666666;
    --accent: #d63031;
    --accent-dim: #b71c1c;
    --move-active: #d63031;
    --move-hover: rgba(214, 48, 49, 0.12);
    --border: #d0d0d0;
    --success: #2e7d32;
    --warning: #e65100;
    --error: #c62828;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
}

/* === Header === */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    min-height: 44px;
}

.app-title {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
}

.game-info {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Toolbar === */
.toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    min-height: 36px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.toolbar-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
}

.toolbar-btn:hover {
    background: var(--bg-panel-hover);
    border-color: var(--accent);
}

.toolbar-btn:active {
    background: var(--accent-dim);
}

.toolbar-btn-wrapper {
    position: relative;
}

/* === Recent Dropdown === */
.recent-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 280px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

.recent-dropdown.visible {
    display: block;
}

.recent-item {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.recent-item:hover {
    background: var(--bg-panel-hover);
}

.recent-name {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.recent-empty {
    padding: 16px 12px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.recent-clear {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--accent);
    text-align: center;
    cursor: pointer;
    transition: background 0.1s;
}

.recent-clear:hover {
    background: var(--bg-panel-hover);
}

/* === Main Layout === */
.app-layout {
    display: flex;
    height: calc(100vh - 44px - 36px);
    overflow: hidden;
}

/* === Panels (sidebars) === */
.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-heading {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Database view (game list inside notation panel) */
.database-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.database-view.hidden {
    display: none;
}

/* Game list header with ops buttons */
.game-list-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px 0 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.game-list-header .panel-heading {
    border-bottom: none;
}

.game-list-ops {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.game-list-btn {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.game-list-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--text);
}

.game-list-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Filter bar */
.game-filter {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.game-filter.hidden {
    display: none;
}

.game-filter-input {
    width: 100%;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 12px;
    font-family: var(--font);
}

.game-filter-input:focus {
    outline: none;
    border-color: var(--accent);
}

.game-filter-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.game-filter-row {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.game-filter-result-btn {
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.game-filter-result-btn:hover {
    border-color: var(--accent);
}

.game-filter-result-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.game-filter-elo {
    width: 52px;
    padding: 2px 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-size: 11px;
    text-align: center;
    font-family: var(--font);
}

.game-filter-elo:focus {
    outline: none;
    border-color: var(--accent);
}

.game-filter-elo-label {
    font-size: 11px;
    color: var(--text-muted);
}

.game-filter-clear {
    margin-left: auto;
    padding: 2px 6px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
}

.game-filter-clear:hover {
    color: var(--accent);
}

/* Game list container */
.game-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Column headers (sortable) */
.game-list-thead {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-panel);
}

.game-list-th {
    padding: 4px 6px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 2px;
    position: relative;
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    z-index: 1;
}

.col-resize-handle:hover {
    background: var(--accent);
    opacity: 0.4;
}

.game-list-th:hover {
    color: var(--text);
}

.game-list-th .sort-icon {
    font-size: 9px;
    opacity: 0.3;
}

.game-list-th.sorted .sort-icon {
    opacity: 1;
    color: var(--accent);
}

/* Virtual scroll container */
.game-list-scroll {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.game-list-spacer {
    width: 100%;
}

.game-list-viewport {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

/* Game rows */
.game-list-row {
    display: flex;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    height: 28px;
    align-items: center;
}

.game-list-row:hover {
    background: var(--bg-panel-hover);
}

.game-list-row.active {
    background: var(--accent-dim);
    color: #fff;
}

.game-list-row.selected {
    background: rgba(233, 69, 96, 0.1);
}

.game-list-row.selected.active {
    background: var(--accent-dim);
}

.game-list-cell {
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-list-cell-result {
    text-align: center;
}

/* Status bar */
.game-list-status {
    padding: 4px 8px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* === Board Section (center) === */
.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

/* Player info bars */
.player-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    font-size: 13px;
    min-height: 28px;
}

.player-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-elo {
    color: var(--text-muted);
    margin-left: 6px;
    font-size: 12px;
}

.player-result {
    font-weight: 700;
    margin-left: auto;
    padding-left: 8px;
    white-space: nowrap;
}

.player-result.win {
    color: var(--success);
}

.player-result.loss {
    color: var(--error);
}

.player-result.draw {
    color: var(--warning);
}

/* Board wrapper & container */
.board-wrapper {
    display: flex;
    gap: 4px;
    max-width: 100%;
    flex-shrink: 0;
    height: var(--board-size);
}

.board-container {
    width: var(--board-size);
    height: var(--board-size);
    flex-shrink: 0;
    overflow: hidden;
}

/* === Eval Bar === */
.eval-bar {
    width: 24px;
    height: 100%;
    background: #333;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.eval-bar.hidden {
    display: none;
}

.eval-bar-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: #f0f0f0;
    transition: height 0.3s ease;
}

.eval-bar-score {
    position: absolute;
    left: 0;
    width: 100%;
    bottom: 44%;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    color: #888;
    pointer-events: none;
    line-height: 1;
    z-index: 1;
    text-shadow: 0 0 3px rgba(0,0,0,0.5);
}

/* Chessground overrides */
cg-board {
    background-color: #b58863;
}

/* === Navigation Controls === */
.controls {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.nav-btn {
    width: 44px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
    line-height: 1;
}

.nav-btn:hover {
    background: var(--bg-panel-hover);
    border-color: var(--accent);
}

.nav-btn:active {
    background: var(--accent-dim);
}

/* === Notation Panel (right) === */
.notation-panel {
    width: var(--notation-width, 35%);
    flex-shrink: 0;
}

.move-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.7;
    cursor: default;
}

.move-list.hidden {
    display: none;
}

/* Game info header in inline notation */
.notation-game-header {
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-sans, sans-serif);
    line-height: 1.4;
}

.notation-game-players {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

.notation-game-info {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* Move number */
.move-number {
    color: var(--text-muted);
    margin-right: 2px;
    user-select: none;
}

/* Individual move */
.move {
    display: inline;
    padding: 1px 3px;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
}

.move:hover {
    background: var(--move-hover);
}

.move.active {
    background: var(--move-active);
    color: #fff;
    border-radius: 3px;
}

/* NAG annotations */
.nag {
    color: var(--accent);
    font-weight: 700;
    margin-left: 1px;
}

/* Comments */
.comment {
    color: var(--text-muted);
    font-family: var(--font);
    font-style: italic;
    font-size: 12px;
    margin: 0 3px;
}

/* Comment rows in table notation */
.comment-row .comment {
    display: block;
    padding: 3px 4px;
    line-height: 1.4;
    white-space: normal;
}

/* Variations */
.variation {
    display: block;
    margin: 2px 0 2px 16px;
    padding-left: 8px;
    border-left: 2px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.variation .move:hover {
    color: var(--text);
}

.variation .variation {
    font-size: 11px;
}

/* Result at end of notation */
.game-result {
    display: inline;
    font-weight: 700;
    margin-left: 6px;
    color: var(--text-muted);
}

/* === Context Menu === */
.move-context-menu {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 0;
    z-index: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    min-width: 200px;
    font-size: 12px;
    color: var(--text);
    user-select: none;
}

.move-context-menu-item {
    padding: 5px 12px 5px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.move-context-menu-item:hover {
    background: var(--bg-panel-hover);
}

.move-context-menu-item.disabled {
    opacity: 0.35;
    pointer-events: none;
}

.move-context-menu-item .ctx-check {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.move-context-menu-item .ctx-shortcut {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: auto;
    padding-left: 16px;
}

.move-context-menu-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* === Modal === */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.visible {
    display: flex;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-sm {
    width: 480px;
}

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

.modal-title {
    font-size: 15px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--text);
}

.modal-textarea {
    margin: 12px 16px 0;
    padding: 10px 12px;
    min-height: 200px;
    resize: vertical;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
}

.modal-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-input {
    margin: 12px 16px 0;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    width: calc(100% - 32px);
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-input::placeholder,
.modal-textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.modal-hint {
    margin: 4px 16px 0;
    font-size: 11px;
    color: var(--text-muted);
}

.modal-error {
    margin: 4px 16px 0;
    padding: 0;
    font-size: 12px;
    color: var(--error);
    min-height: 0;
    overflow: hidden;
    transition: min-height 0.15s;
}

.modal-error.visible {
    padding: 4px 0;
    min-height: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
}

.modal-btn {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.modal-btn:hover {
    background: var(--bg-panel-hover);
}

.modal-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.modal-btn-primary:hover {
    background: var(--accent-dim);
    border-color: var(--accent-dim);
}

/* === Drop Overlay === */
.drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 52, 96, 0.92);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.drop-overlay.visible {
    display: flex;
}

.drop-overlay-content {
    text-align: center;
    pointer-events: none;
}

.drop-overlay-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.drop-overlay-text {
    font-size: 24px;
    font-weight: 600;
    color: #fff;
}

/* === Loading Overlay === */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 350;
    align-items: center;
    justify-content: center;
}

.loading-overlay.visible {
    display: flex;
}

.loading-overlay-content {
    text-align: center;
}

.loading-overlay-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: loading-spin 0.8s linear infinite;
}

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

.loading-overlay-message {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

/* === Promotion Dialog === */
.promotion-backdrop {
    position: fixed;
    inset: 0;
    z-index: 400;
}

.promotion-dialog {
    position: fixed;
    z-index: 401;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.promotion-choice {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    border: none;
    background: var(--bg-panel);
    font-size: 36px;
    cursor: pointer;
    transition: background 0.1s;
}

.promotion-choice:hover {
    background: var(--accent);
}

/* Variation choice dialog */
.variation-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.variation-dialog {
    position: fixed;
    z-index: 401;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    max-width: 360px;
    text-align: center;
}

.variation-dialog-title {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 14px;
    line-height: 1.4;
}

.variation-dialog-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.variation-dialog-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.variation-dialog-btn:hover {
    background: var(--bg-panel-hover);
}

.variation-dialog-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.variation-dialog-btn-primary:hover {
    background: var(--accent-dim);
}

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    color: #fff;
    pointer-events: auto;
    animation: toast-in 0.3s ease-out;
    max-width: 360px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast.info {
    background: var(--bg-header);
    border: 1px solid var(--border);
}

.toast.error {
    background: var(--error);
}

.toast.success {
    background: var(--success);
}

.toast.fade-out {
    animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* === Settings Panel === */
.settings-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 250;
    justify-content: flex-end;
}

.settings-backdrop.visible {
    display: flex;
}

.settings-panel {
    width: 360px;
    max-width: calc(100vw - 16px);
    height: 100%;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slide-in-right 0.2s ease-out;
}

@keyframes slide-in-right {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.settings-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.settings-section {
    padding: 8px 16px 12px;
}

.settings-section + .settings-section {
    border-top: 1px solid var(--border);
}

.settings-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.settings-grid {
    display: grid;
    gap: 6px;
}

.piece-grid {
    grid-template-columns: repeat(4, 1fr);
}

.board-grid {
    grid-template-columns: repeat(5, 1fr);
}

.piece-swatch,
.board-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-family: var(--font);
    color: var(--text);
    font-size: 0;
}

.piece-swatch:hover,
.board-swatch:hover {
    border-color: var(--text-muted);
}

.piece-swatch.active,
.board-swatch.active {
    border-color: var(--accent);
    background: var(--move-hover);
}

.piece-swatch img {
    width: 36px;
    height: 36px;
}

.board-preview {
    width: 40px;
    height: 40px;
    border-radius: 3px;
}

.swatch-label {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.2;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.settings-label {
    font-size: 13px;
    color: var(--text);
}

.settings-slider {
    width: 120px;
    cursor: pointer;
    accent-color: var(--accent);
}

.settings-slider-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-slider-value {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
    font-family: var(--font-mono);
}

.settings-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.settings-btn:hover {
    background: var(--bg-panel-hover);
    border-color: var(--accent);
}

.settings-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
}

.settings-input:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-hint {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1.4;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 22px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* === Fullscreen === */
:fullscreen .app-header,
:fullscreen .toolbar {
    /* Keep visible in fullscreen */
}

:fullscreen .toast-container {
    z-index: 2000;
}

/* === Responsive === */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 44px - 36px);
    }

    .toolbar {
        padding: 4px 8px;
    }

    .board-section {
        padding: 8px;
    }

    .notation-panel {
        width: 100% !important;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .panel-resize-handle,
    .split-resize-handle {
        display: none !important;
    }

    .player-bar {
        width: 100%;
    }

    .board-wrapper {
        height: var(--board-size);
    }

    .eval-bar {
        display: none !important;
    }

    .engine-panel {
        flex: 1;
        min-height: 80px;
    }

    .eval-graph {
        height: 40px;
    }

    .modal {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 32px);
    }
}

/* === Notation Header with Tabs === */
.notation-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px 0 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.notation-header .panel-heading {
    border-bottom: none;
}

.notation-tabs {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.notation-tab {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

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

.notation-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* === Table Notation === */
.table-notation {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

.table-notation.hidden {
    display: none;
}

.table-notation table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-family: var(--font-mono);
}

.table-notation td {
    padding: 2px 6px;
    cursor: pointer;
}

.table-notation .move-num {
    color: var(--text-muted);
    width: 30px;
    text-align: right;
    user-select: none;
    cursor: default;
}

.table-notation .move-cell:hover {
    background: var(--move-hover);
}

.table-notation .move-cell.active {
    background: var(--move-active);
    color: #fff;
}

.table-notation tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.table-notation .variation-row {
    font-size: 11px;
    color: var(--text-muted);
}

.table-notation .variation-cell {
    padding-left: 20px;
    font-style: italic;
}

.table-notation .inline-var-move {
    display: inline;
    padding: 1px 3px;
    border-radius: 3px;
    cursor: pointer;
}

.table-notation .inline-var-move:hover {
    background: var(--move-hover);
}

.table-notation .inline-var-move.active {
    background: var(--move-active);
    color: #fff;
}

.table-notation .game-result {
    text-align: center;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px;
}

/* === Variation Fold/Unfold === */
.variation-toggle {
    display: inline-block;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 11px;
    margin-right: 4px;
    user-select: none;
    font-family: var(--font-mono);
}

.variation-toggle:hover {
    color: var(--accent);
}

.variation-collapsed > *:not(.variation-toggle):not(.variation-placeholder) {
    display: none;
}

.variation-placeholder {
    display: none;
    color: var(--text-muted);
    font-style: italic;
    font-size: 11px;
}

.variation-collapsed > .variation-placeholder {
    display: inline;
}

/* === Figurine Pieces in Notation === */
.figurine {
    font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", sans-serif;
}

/* === Engine Panel === */
.engine-panel {
    border-top: 1px solid var(--border);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.engine-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
}

.engine-toggle {
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.engine-toggle:hover {
    border-color: var(--accent);
    color: var(--text);
}

.engine-toggle.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.engine-toggle.loading {
    opacity: 0.6;
    cursor: wait;
}

.engine-stop-btn {
    margin-left: auto;
    padding: 2px 10px;
    border: 1px solid var(--error);
    border-radius: var(--radius);
    background: transparent;
    color: var(--error);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.engine-stop-btn:hover {
    background: var(--error);
    color: #fff;
}

.engine-stop-btn.hidden {
    display: none;
}

.engine-info {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.engine-multipv-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.engine-mpv-btn {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, border-color 0.1s;
    padding: 0;
    line-height: 1;
}

.engine-mpv-btn:hover {
    background: var(--bg-panel-hover);
    border-color: var(--accent);
}

.engine-mpv-count {
    font-family: var(--font-mono);
    font-size: 12px;
    min-width: 16px;
    text-align: center;
    color: var(--text);
}

.engine-loading {
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.engine-loading.hidden {
    display: none;
}

.engine-loading-bar {
    height: 2px;
    margin-top: 4px;
    background: var(--border);
    border-radius: 1px;
    overflow: hidden;
    position: relative;
}

.engine-loading-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 40%;
    height: 100%;
    background: var(--accent);
    border-radius: 1px;
    animation: engine-loading-pulse 1.2s ease-in-out infinite;
}

@keyframes engine-loading-pulse {
    0% { left: -40%; }
    100% { left: 100%; }
}

.engine-lines {
    padding: 0 8px 4px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.engine-lines.hidden {
    display: none;
}

.engine-line {
    display: flex;
    gap: 10px;
    padding: 4px 0;
    font-size: 13px;
    line-height: 1.5;
    align-items: baseline;
    border-bottom: 1px solid var(--border);
}

.engine-line.hidden {
    display: none;
}

.engine-line-score {
    font-family: var(--font-mono);
    font-weight: 700;
    min-width: 52px;
    text-align: right;
    flex-shrink: 0;
    font-size: 13px;
}

.engine-line-score.positive {
    color: var(--success);
}

.engine-line-score.negative {
    color: var(--error);
}

.engine-line-score.even {
    color: var(--text-muted);
}

.engine-line-pv {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    line-height: 1.6;
    word-break: break-word;
}

/* === Eval Graph === */
.eval-graph {
    width: var(--board-size);
    max-width: 100%;
    height: 60px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    cursor: crosshair;
    overflow: hidden;
}

.eval-graph.hidden {
    display: none;
}

.eval-graph canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* === Tablebase Section in Engine Panel === */
.engine-tablebase {
    padding: 4px 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.engine-tablebase.hidden {
    display: none;
}

.engine-tb-header {
    font-weight: 700;
    margin-bottom: 2px;
}

.engine-tb-category.win {
    color: var(--success);
}

.engine-tb-category.loss {
    color: var(--error);
}

.engine-tb-category.draw {
    color: var(--text-muted);
}

.engine-tb-moves {
    font-family: var(--font-mono);
    font-size: 11px;
}

.engine-tb-move {
    padding: 1px 0;
}

/* === Source Label in Engine Header === */
.engine-source {
    font-size: 10px;
    color: var(--text-muted);
    padding: 1px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    margin-left: 4px;
}


/* === Board Editor Modal === */
.editor-modal {
    width: 680px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    overflow: hidden;
}

.editor-body {
    display: flex;
    gap: 12px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Piece palette */
.editor-palette {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    align-content: start;
    flex-shrink: 0;
}

.editor-piece-btn {
    width: 38px;
    height: 38px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s;
}

.editor-piece-btn:hover {
    border-color: var(--text-muted);
}

.editor-piece-btn.active {
    border-color: var(--accent);
    background: var(--move-hover);
}

.editor-piece-btn img {
    width: 28px;
    height: 28px;
}

.editor-tool-btn {
    width: 100%;
    grid-column: 1 / -1;
    height: 32px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.editor-tool-btn:hover {
    border-color: var(--text-muted);
}

.editor-tool-btn.active {
    border-color: var(--accent);
    background: var(--move-hover);
}

/* Editor board */
.editor-board-wrap {
    width: 280px;
    height: 280px;
    flex-shrink: 0;
}

.editor-board-wrap .cg-wrap {
    width: 280px;
    height: 280px;
}

/* Editor controls */
.editor-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 150px;
    flex: 1;
}

.editor-control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.editor-control-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.editor-radio-group {
    display: flex;
    gap: 4px;
}

.editor-radio {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.editor-radio:hover {
    border-color: var(--text-muted);
}

.editor-radio.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.editor-castling-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.editor-castling-cb {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    cursor: pointer;
}

.editor-castling-cb input {
    accent-color: var(--accent);
    cursor: pointer;
}

.editor-select {
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
}

.editor-select:focus {
    outline: none;
    border-color: var(--accent);
}

.editor-number {
    width: 60px;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    text-align: center;
}

.editor-number:focus {
    outline: none;
    border-color: var(--accent);
}

.editor-fen-input {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
}

.editor-fen-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Editor footer */
.editor-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    align-items: center;
}

.editor-validate {
    font-size: 12px;
    margin-left: auto;
}

.editor-validate.valid {
    color: var(--success);
}

.editor-validate.invalid {
    color: var(--error);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .editor-modal {
        width: calc(100vw - 16px);
    }

    .editor-body {
        flex-direction: column;
        align-items: center;
    }

    .editor-palette {
        grid-template-columns: repeat(6, 1fr);
    }

    .editor-tool-btn {
        grid-column: span 3;
    }

    .editor-board-wrap,
    .editor-board-wrap .cg-wrap {
        width: 240px;
        height: 240px;
    }

    .editor-controls {
        width: 100%;
        min-width: unset;
    }
}

/* === Training Mode === */
.training-panel {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

.training-panel.hidden {
    display: none;
}

.training-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.training-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
}

.training-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}

.training-close:hover {
    background: var(--bg-panel-hover);
    color: var(--text);
}

.training-side-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.training-side-label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.training-select {
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    flex: 1;
}

.training-select:focus {
    outline: none;
    border-color: var(--accent);
}

.training-score {
    display: flex;
    gap: 12px;
    justify-content: center;
}

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

.training-score-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.training-score-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.training-score-correct .training-score-value {
    color: var(--success);
}

.training-score-wrong .training-score-value {
    color: var(--error);
}

.training-score-hints .training-score-value {
    color: var(--warning);
}

.training-progress-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.training-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

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

.training-progress-label {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-width: 32px;
    text-align: right;
}

.training-status {
    text-align: center;
    font-size: 13px;
    color: var(--text);
    min-height: 20px;
}

.training-buttons {
    display: flex;
    gap: 8px;
}

.training-btn {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.training-btn:hover {
    background: var(--bg-panel-hover);
    border-color: var(--accent);
}

/* Board flash animations */
@keyframes training-flash-correct {
    0% { box-shadow: inset 0 0 0 4px var(--success); }
    100% { box-shadow: inset 0 0 0 0 var(--success); }
}

@keyframes training-flash-wrong {
    0% { box-shadow: inset 0 0 0 4px var(--error); }
    100% { box-shadow: inset 0 0 0 0 var(--error); }
}

.training-flash-correct .cg-wrap {
    animation: training-flash-correct 0.5s ease-out;
}

.training-flash-wrong .cg-wrap {
    animation: training-flash-wrong 0.5s ease-out;
}

/* Disable nav buttons during training (except flip) */
.training-active .nav-btn {
    opacity: 0.3;
    pointer-events: none;
}

.training-active #btn-flip {
    opacity: 1;
    pointer-events: auto;
}

/* ================================
   Phase 10: Export Modal Styles
   ================================ */

.modal-lg {
    width: 640px;
}

.export-body {
    padding: 16px 20px;
    overflow-y: auto;
    max-height: calc(100vh - 160px);
}

.export-section {
    border-top: 1px solid var(--border);
    padding: 14px 0 6px;
}

.export-section:first-child {
    border-top: none;
    padding-top: 0;
}

.export-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.export-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.export-field {
    flex: 1;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
}

.export-textarea {
    flex: 1;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    resize: none;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}

.export-btn {
    background: var(--bg-panel-hover);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.export-btn:hover {
    background: var(--accent-dim);
    color: #fff;
    border-color: var(--accent-dim);
}

.export-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.export-btn-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.export-mode-row {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.export-mode-btn {
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.export-mode-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.export-image-row {
    display: flex;
    gap: 16px;
    align-items: center;
}

.export-image-preview {
    width: 160px;
    height: 160px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.export-image-preview svg {
    width: 100%;
    height: 100%;
}

.export-image-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ================================
   Phase 10: Print Options Styles
   ================================ */

.print-mode-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.print-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.print-radio input[type="radio"] {
    accent-color: var(--accent);
}

.print-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 16px;
}

.print-cb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.print-cb input[type="checkbox"] {
    accent-color: var(--accent);
}

/* ================================
   Phase 10: Print Area + @media print
   ================================ */

#print-area {
    display: none;
}

@media print {
    /* Hide all app UI */
    .app-header,
    .toolbar,
    .app-layout,
    .modal-backdrop,
    .settings-backdrop,
    .drop-overlay,
    .loading-overlay,
    .toast-container,
    #file-input {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        margin: 0;
        padding: 0;
    }

    #print-area {
        display: block !important;
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 12pt;
        color: #000;
        line-height: 1.5;
        max-width: 100%;
        padding: 10mm;
    }

    .print-game-header {
        margin-bottom: 12pt;
        text-align: center;
    }

    .print-game-title {
        font-size: 16pt;
        font-weight: bold;
        margin-bottom: 4pt;
    }

    .print-game-meta {
        font-size: 11pt;
        color: #444;
        margin-bottom: 2pt;
    }

    .print-moves {
        text-align: justify;
        margin: 8pt 0;
    }

    .print-move {
        font-weight: bold;
    }

    .print-move-number {
        font-weight: normal;
        color: #555;
    }

    .print-nag {
        font-weight: bold;
        color: #333;
        margin-left: 1px;
    }

    .print-comment {
        font-style: italic;
        color: #555;
    }

    .print-variation {
        font-size: 0.9em;
        color: #444;
    }

    .print-result {
        text-align: center;
        font-weight: bold;
        font-size: 14pt;
        margin-top: 12pt;
    }

    .print-diagram {
        text-align: center;
        margin: 12pt auto;
        page-break-inside: avoid;
    }

    .print-diagram svg {
        max-width: 280px;
    }

    .print-diagram-inline {
        float: right;
        margin: 4pt 0 4pt 12pt;
        page-break-inside: avoid;
    }

    .print-diagram-inline svg {
        max-width: 200px;
    }

    .print-scoresheet-table {
        width: 100%;
        border-collapse: collapse;
        margin: 8pt 0;
    }

    .print-scoresheet-table th,
    .print-scoresheet-table td {
        border: 1px solid #999;
        padding: 3pt 6pt;
        text-align: left;
        font-size: 11pt;
    }

    .print-scoresheet-table th {
        background: #eee;
        font-weight: bold;
    }

    .print-scoresheet-table td:first-child,
    .print-scoresheet-table th:first-child {
        width: 40px;
        text-align: center;
    }

    .print-blank-field {
        display: flex;
        align-items: baseline;
        margin-bottom: 6pt;
        font-size: 12pt;
    }

    .print-blank-label {
        font-weight: bold;
        width: 80px;
        flex-shrink: 0;
    }

    .print-blank-line {
        flex: 1;
        border-bottom: 1px solid #999;
        min-height: 16pt;
    }

    .print-page-break {
        page-break-before: always;
    }
}

/* ================================
   Phase 11: Advanced UI & Polish
   ================================ */

/* === Help Overlay === */
.help-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 16px 20px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

.help-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.help-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin-bottom: 4px;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.help-key {
    display: inline-block;
    min-width: 28px;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    text-align: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    white-space: nowrap;
}

.help-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* === Material Display === */
.player-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    width: var(--board-size);
    max-width: 100%;
}

.player-bar .player-info {
    flex: 1;
    min-width: 0;
}

.material-display {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
    flex-shrink: 0;
}

.material-pieces {
    display: flex;
    align-items: center;
}

.material-piece {
    font-size: 14px;
    line-height: 1;
    opacity: 0.8;
}

.material-balance {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-left: 2px;
}

/* === Clock Display === */
.player-clock {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
    padding-left: 8px;
    white-space: nowrap;
}

.player-clock:empty {
    display: none;
}

/* === Collapsible Panels === */
.notation-panel {
    transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.notation-panel.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    opacity: 0;
    border: none;
}

/* Panel expand tabs (visible when panel is collapsed) */
.panel-expand-tab {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    writing-mode: vertical-rl;
    padding: 12px 4px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.panel-expand-tab:hover {
    background: var(--bg-panel-hover);
    color: var(--text);
}

.panel-expand-tab-right {
    right: 0;
    border-radius: var(--radius) 0 0 var(--radius);
    border-right: none;
    text-orientation: sideways;
}

/* Show expand tab when notation panel is collapsed */
.app-layout:has(.notation-panel.collapsed) > .panel-expand-tab-right {
    display: block;
}

.panel-collapse-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    margin-left: auto;
}

.panel-collapse-btn:hover {
    background: var(--bg-panel-hover);
    color: var(--text);
}

/* === Layout Presets === */
.layout-preset-group {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.layout-preset-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.layout-preset-btn:hover {
    border-color: var(--accent);
}

.layout-preset-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* === Resize Handles === */
.panel-resize-handle {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
    z-index: 5;
}

.panel-resize-handle:hover,
.panel-resize-handle.dragging {
    background: var(--accent);
}

.split-resize-handle {
    height: 5px;
    cursor: row-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
}

.split-resize-handle:hover,
.split-resize-handle.dragging {
    background: var(--accent);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Tournament Table === */
.tournament-modal {
    width: 90vw;
    max-width: 900px;
}

.tournament-body {
    padding: 12px 16px;
    overflow: auto;
    max-height: calc(100vh - 120px);
}

.tournament-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.tournament-standings {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-family: var(--font-mono);
}

.tournament-standings th {
    padding: 5px 6px;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tournament-standings th.tt-player-col {
    text-align: left;
    min-width: 120px;
}

.tournament-standings td {
    padding: 4px 6px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.tournament-standings tbody tr:hover {
    background: var(--bg-panel-hover);
}

.tt-rank {
    color: var(--text-muted);
    width: 28px;
}

.tt-player {
    text-align: left !important;
    font-family: var(--font);
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tt-elo {
    color: var(--text-muted);
    font-size: 11px;
}

.tt-pts {
    font-weight: 700;
    color: var(--accent);
}

.tt-flag {
    font-size: 16px;
    text-align: center !important;
    width: 24px;
    padding: 4px 2px !important;
}

.tt-flag-col {
    width: 24px;
    min-width: 24px;
}

.tt-self {
    background: var(--border);
    color: var(--text-muted);
}

.tt-result {
    font-size: 11px;
    min-width: 24px;
}

.tt-result.clickable {
    cursor: pointer;
}

.tt-result.clickable:hover {
    background: var(--bg-panel-hover);
    text-decoration: underline;
}

.tt-tpr {
    color: var(--text-muted);
    font-size: 11px;
}

.tt-win { color: var(--success); font-weight: 600; }
.tt-loss { color: var(--error); }
.tt-draw { color: var(--text-muted); }

.tt-tb {
    color: var(--text-muted);
    font-size: 11px;
}


