:root {
    --bg: #2a2218;
    --surface: #382e24;
    --surface-hover: #453a2e;
    --border: #5c4d3c;
    --primary: #d4a04e;
    --primary-hover: #e2b468;
    --text: #f2ead9;
    --text-muted: #b8a88e;
    --success: #6ab866;
    --error: #d45a4a;
    --warning: #d4a04e;
    --badge-blunder-bg: rgba(212, 90, 74, 0.2);
    --badge-error-bg: rgba(212, 160, 78, 0.2);
    --drop-hover-bg: rgba(212, 160, 78, 0.08);
    --zebra: rgba(255, 255, 255, 0.03);
    --btn-text: #1a1410;
    --toggle-icon: '\263E';
}

[data-theme="light"] {
    --bg: #e8dece;
    --surface: #f2e8d8;
    --surface-hover: #e0d2be;
    --border: #c4b09a;
    --primary: #b8862e;
    --primary-hover: #a07528;
    --text: #3a2e1e;
    --text-muted: #7a6a52;
    --success: #4a8a46;
    --error: #b8432e;
    --warning: #b8862e;
    --badge-blunder-bg: rgba(184, 67, 46, 0.12);
    --badge-error-bg: rgba(184, 134, 46, 0.15);
    --drop-hover-bg: rgba(184, 134, 46, 0.08);
    --zebra: rgba(0, 0, 0, 0.04);
    --btn-text: #f2e8d8;
    --toggle-icon: '\2600';
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 560px;
    padding: 24px;
    transition: max-width 0.3s;
}

.container.batch-results {
    max-width: 720px;
}

.logo {
    text-align: center;
    margin-bottom: 32px;
}

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo h1 span { color: var(--primary); }

.logo p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 6px;
}

.theme-toggle {
    margin-top: 12px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    transition: all 0.2s;
}

.theme-toggle::after {
    content: var(--toggle-icon);
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
}

/* Login Form */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: var(--btn-text);
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--drop-hover-bg);
}

.drop-zone-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.drop-zone h3 {
    font-size: 16px;
    margin-bottom: 6px;
}

.drop-zone p {
    color: var(--text-muted);
    font-size: 13px;
}

.drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* Processing state */
.processing {
    text-align: center;
    padding: 32px;
}

.processing-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

/* Results */
.result {
    text-align: center;
    padding: 24px 0;
}

.result h3 { margin-bottom: 8px; }

.result-meta {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.result-empty {
    color: var(--text-muted);
}

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: var(--btn-text);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-download:hover { background: var(--primary-hover); }

.download-wrap { margin-top: 16px; }

.user-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.user-bar span {
    font-size: 13px;
    color: var(--text-muted);
}

.user-bar button {
    font-size: 13px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.user-bar button:hover { color: var(--text); }

.actions { margin-top: 16px; }

/* Error Summary */
.summary {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.summary-badge {
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--surface-hover);
    color: var(--text-muted);
}

.summary-badge.blunder { background: var(--badge-blunder-bg); color: var(--error); }
.summary-badge.error { background: var(--badge-error-bg); color: var(--warning); }

/* Error Table */
.error-table-wrap {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.error-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.error-table th {
    position: sticky;
    top: 0;
    background: var(--surface-hover);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-size: 11px;
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.error-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-align: center;
}

/* Column widths */
.error-table th:nth-child(1),
.error-table td:nth-child(1) { width: 50px; }   /* Game */
.error-table th:nth-child(2),
.error-table td:nth-child(2) { width: 50px; }   /* Move */
.error-table th:nth-child(5),
.error-table td:nth-child(5) { width: 50px; }   /* EQ */

.error-table tr:last-child td { border-bottom: none; }

.error-table tbody tr:nth-child(even) td { background: var(--zebra); }

.error-table tr:hover td { background: var(--surface-hover); }

.severity-blunder { color: var(--error); font-weight: 600; }
.severity-error { color: var(--warning); font-weight: 600; }

/* Progress List */
.progress-list {
    text-align: left;
    margin-top: 16px;
}

.progress-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.progress-item:last-child { border-bottom: none; }

.progress-name {
    color: var(--text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

.progress-status { font-size: 12px; font-weight: 600; }
.progress-status.pending { color: var(--text-muted); }
.progress-status.active { color: var(--primary); }
.progress-status.success { color: var(--success); }
.progress-status.failed { color: var(--error); }

/* File Accordion */
.file-accordion {
    margin-top: 20px;
    text-align: left;
}

.file-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
}

.file-section-failed { border-color: var(--error); }

.file-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    background: var(--surface-hover);
    font-size: 13px;
    list-style: none;
}

.file-header::-webkit-details-marker { display: none; }

.file-header::before {
    content: '\25B6';
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

details[open] > .file-header::before,
.file-section.peeking > .file-header::before {
    transform: rotate(90deg);
}

.file-section.peeking .file-body {
    animation: peek 2s ease-in-out forwards;
    overflow: hidden;
}

@keyframes peek {
    0%   { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; }
    25%  { max-height: 120px; opacity: 1; padding-top: 16px; padding-bottom: 16px; }
    75%  { max-height: 120px; opacity: 1; padding-top: 16px; padding-bottom: 16px; }
    100% { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; }
}

.file-name {
    font-weight: 600;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.file-count {
    font-size: 12px;
    color: var(--primary);
    white-space: nowrap;
}

.file-body {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.btn-download-sm {
    font-size: 13px;
    padding: 8px 16px;
}

.text-error { color: var(--error); }

/* Player Filter Dropdown */
.player-filter-wrap {
    margin-top: 16px;
    text-align: center;
}

.player-filter-wrap label {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 8px;
}

.player-filter {
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.player-filter:focus {
    border-color: var(--primary);
}

.player-filter option {
    background: var(--surface);
    color: var(--text);
}

/* Per-file filter dropdown (in results) */
.file-filter-wrap {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-filter-wrap label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.file-filter {
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, opacity 0.2s;
}

.file-filter:focus {
    border-color: var(--primary);
}

.file-filter:disabled {
    opacity: 0.5;
    cursor: wait;
}

.file-filter option {
    background: var(--surface);
    color: var(--text);
}

/* Single file result filter (centered) */
.result > .file-filter-wrap {
    justify-content: center;
    margin-top: 12px;
}

.hidden { display: none; }
