:root {
            color-scheme: light;
            --bg: #f3f3f3;
            --panel: #ffffff;
            --panel2: #fafafa;
            --line: #c9ced6;
            --text: #222222;
            --muted: #687383;
            --accent: #2468a9;
            --accent2: #65bc7b;
            --danger: #a12626;
            --success: #187b32;
            --neutral: #e8eefc;
            --error-text: #8a1f11;
            --error-line: #c0392b;
            --shadow: rgba(0, 0, 0, .08);
        }

        html[data-theme="dark"] {
            color-scheme: dark;
            --bg: #10141b;
            --panel: #171d27;
            --panel2: #1d2531;
            --line: #303b4d;
            --text: #edf2f7;
            --muted: #9ca9ba;
            --accent: #65a9ff;
            --accent2: #397ac7;
            --danger: #ff8a8a;
            --success: #8bd49c;
            --neutral: #263349;
            --error-text: #ffb3b3;
            --error-line: #7b3434;
            --shadow: rgba(0, 0, 0, .35);
        }

        * { box-sizing: border-box; }
        body {
            margin: 0;
            background: var(--bg);
            color: var(--text);
            font: 14px/1.35 Arial, sans-serif;
            transition: background-color .18s ease, color .18s ease;
        }

        a { color: var(--accent); }
        h1 { margin: 0; font-size: 1.55rem; }

        .page-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 10px;
        }

        .theme-toggle {
            width: auto;
            min-width: 140px;
            padding: 7px 11px;
            border: 1px solid var(--line);
            border-radius: 6px;
            background: var(--panel);
            color: var(--text);
            cursor: pointer;
        }

        .theme-toggle:hover {
            border-color: var(--accent);
        }
        .container { width: min(1360px, calc(100% - 24px)); margin: 14px auto 30px; }
        .panel, .card, .message {
            background: var(--panel);
            border: 1px solid var(--line);
            border-radius: 9px;
            box-shadow: 0 3px 12px var(--shadow);
        }
        .panel { padding: 13px; }
        .filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
        .field { min-width: 0; }
        .half { grid-column: span 2; }
        label, .title { display: block; font-weight: 700; margin-bottom: 4px; }
        input, button, textarea { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); color: var(--text); font: inherit; }
        textarea { min-height: 60px; resize: vertical; }
        .inline { display: flex; gap: 7px; }
        .inline > * { flex: 1; }
        .check, .mode label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 400; }
        .check { margin-top: 5px; }
        .check input, .mode input { width: auto; }
        .mode { display: flex; gap: 12px; margin-top: 7px; flex-wrap: wrap; }
        .actions { display: flex; gap: 9px; margin-top: 13px; }
        .actions button, .actions a { width: auto; min-width: 120px; padding: 8px 14px; text-align: center; text-decoration: none; border-radius: 7px; }
        .actions button { border: 0; background: var(--accent2); color: #fff; font-weight: 700; cursor: pointer; }
        .actions a { border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
        .details { color: var(--muted); font-size: .85rem; margin-top: 5px; }

        .filter-details, .result-details { border: 1px solid var(--line); border-radius: 7px; background: var(--panel2); overflow: hidden; }
        .filter-details > summary, .result-details > summary { cursor: pointer; padding: 8px 10px; font-weight: 700; user-select: none; }
        .filter-details[open] > summary, .result-details[open] > summary { border-bottom: 1px solid var(--line); }
        .filter-content, .result-content { padding: 8px; }

        .tri-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 4px; }
        .tri-list.icon-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; max-height: 180px; }
        .tri-row + .tri-row { margin-top: 3px; }
        .icon-list .tri-row + .tri-row { margin-top: 0; }
        .tri-option { display: flex; align-items: center; gap: 7px; text-align: left; cursor: pointer; padding: 6px 8px; transition: background .12s, border-color .12s; }
        .tri-option .tri-icon { width: 18px; height: 18px; flex: 0 0 18px; display: inline-grid; place-items: center; border-radius: 4px; border: 1px solid var(--line); font-weight: 700; }
        .tri-option.neutral { background: transparent; }
        .tri-option.neutral .tri-icon::before { content: '○'; color: var(--muted); }
        .tri-option.positive { border-color: #3e7650; background: rgba(70, 139, 88, .22); }
        .tri-option.positive .tri-icon::before { content: '✓'; color: var(--success); }
        .tri-option.negative { border-color: #844949; background: rgba(154, 67, 67, .22); }
        .tri-option.negative .tri-icon::before { content: '−'; color: var(--danger); }
        .tri-option:hover { border-color: var(--accent); }
        .tri-option-image { position: relative; justify-content: center; min-height: 30px; padding: 4px; }
        .tri-option-image .tri-icon { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; flex-basis: 12px; font-size: 9px; border-radius: 3px; background: var(--panel2); }
        .filter-icon { display: block; width: 20px; height: 20px; object-fit: contain; }
        .participant-main { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
        .participant-main img { max-width: 32px; max-height: 32px; }
        .tri-legend { display: flex; flex-wrap: wrap; gap: 9px; color: var(--muted); font-size: .82rem; margin-top: 5px; }

        .summary { display: flex; justify-content: space-between; color: var(--muted); margin: 12px 0; }
        .card { padding: 12px; margin-bottom: 10px; }
        .head { display: flex; justify-content: space-between; gap: 14px; }
        .battle-id { font-size: 1.1rem; font-weight: 700; }
        .battle-main-info { min-width: 0; }
        .battle-title-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 12px; }
        .monster-level { color: var(--muted); font-size: .85rem; }
        .related-battles { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 3px 0; color: var(--muted); font-size: .82rem; }
        .related-battle-link { padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel2); text-decoration: none; }
        .meta { text-align: right; color: var(--muted); }
        .battle-tags {
            margin-top: 8px;
        }

        .battle-tags-label {
            display: block;
            margin-bottom: 5px;
            color: var(--muted);
            font-size: .82rem;
            font-weight: 700;
        }

        .tags {
            display: flex;
            flex-wrap: wrap;
            gap: 5px;
        }

        .tag {
            padding: 3px 7px;
            border: 1px solid var(--line);
            background: var(--neutral);
            border-radius: 999px;
            font-size: .82rem;
        }

        .battle-details-grid {
            display: grid;
            grid-template-columns: minmax(0, 3fr) minmax(240px, 2fr);
            gap: 10px;
            margin-top: 10px;
            align-items: start;
        }

        .battle-section {
            min-width: 0;
            padding: 10px;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--panel2);
        }

        .battle-section-title {
            margin: 0 0 8px;
            padding-bottom: 6px;
            border-bottom: 1px solid var(--line);
            font-size: .95rem;
        }

        .participants-section,
        .drop-section {
            min-width: 0;
        }

        .participant { padding: 6px 0; border-top: 1px solid var(--line); }
        .participant:first-of-type { border-top: 0; padding-top: 0; }
        .participant:last-child { padding-bottom: 0; }
        .participant-details, .stats, .empty { color: var(--muted); font-size: .84rem; }
        .dead { color: var(--danger); }
        .alive { color: var(--success); }
        .death-status { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px; }
        .postbattle-icons { display: inline-flex; align-items: center; gap: 3px; }
        .postbattle-icon { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; }
        .drop-list {
            margin: 0;
            padding-left: 18px;
            overflow-wrap: anywhere;
        }
        .message { padding: 12px; margin: 12px 0; }
        .error { color: var(--error-text); border-color: var(--error-line); }
        .search-placeholder {
            margin-top: 0;
            color: var(--muted);
            text-align: center;
        }
        .pagination { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 15px; }
        .pagination a, .pagination span { min-width: 32px; padding: 6px 8px; text-align: center; text-decoration: none; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
        .pagination .current { background: var(--accent2); }

        @media (max-width: 1000px) {
            .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }

            .battle-details-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 700px) {
            .container { width: calc(100% - 14px); margin-top: 7px; }
            .page-header { align-items: stretch; }
            .theme-toggle { min-width: 0; }
            .filters { grid-template-columns: 1fr; }
            .half { grid-column: auto; }
            .head, .summary, .actions { flex-direction: column; }
            .meta { text-align: left; }
            .actions > * { width: 100% !important; }
        }

        /* Двухколоночная компоновка: фильтры слева, результаты справа. */
        .container {
            width: min(1680px, calc(100% - 24px));
        }

        .page-layout {
            display: grid;
            grid-template-columns: 350px minmax(0, 1fr);
            gap: 14px;
            align-items: start;
        }

        .search-sidebar {
            position: sticky;
            top: 10px;
            max-height: calc(100vh - 20px);
            overflow-y: auto;
            scrollbar-gutter: stable;
        }

        .search-panel {
            padding: 11px;
        }

        .sidebar-title {
            margin: 0 0 9px;
            padding-bottom: 7px;
            border-bottom: 1px solid var(--line);
            font-size: 1.05rem;
            font-weight: 700;
        }

        .search-sidebar .filters {
            grid-template-columns: 1fr;
            gap: 8px;
        }

        .search-sidebar .half {
            grid-column: auto;
        }

        .search-sidebar .actions {
            position: sticky;
            bottom: 0;
            z-index: 2;
            margin: 10px -4px -4px;
            padding: 8px 4px 4px;
            background: linear-gradient(
                to bottom,
                rgba(23, 29, 39, 0),
                var(--panel) 18%
            );
        }

        .search-sidebar .actions button,
        .search-sidebar .actions a {
            min-width: 0;
            flex: 1;
            padding-left: 8px;
            padding-right: 8px;
        }

        .results-column {
            min-width: 0;
        }

        .results-column .summary {
            margin-top: 0;
            padding: 8px 10px;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--panel);
        }

        .results-column .card:first-of-type {
            margin-top: 0;
        }

        @media (max-width: 1100px) {
            .page-layout {
                grid-template-columns: 1fr;
            }

            .search-sidebar {
                position: static;
                max-height: none;
                overflow: visible;
            }

            .search-sidebar .filters {
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }

            .search-sidebar .half {
                grid-column: span 2;
            }

            .search-sidebar .actions {
                position: static;
                margin: 10px 0 0;
                padding: 0;
                background: none;
            }
        }

        @media (max-width: 700px) {
            .search-sidebar .filters {
                grid-template-columns: 1fr;
            }

            .search-sidebar .half {
                grid-column: auto;
            }
        }


/* Группировка участников по battle_group. */
.participant-group + .participant-group {
    margin-top: 9px;
}

.participant-group {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

.participant-group-title {
    margin: 0;
    padding: 6px 8px;
    border-bottom: 1px solid var(--line);
    background: var(--neutral);
    font-size: .86rem;
}

.participant-group-content {
    padding: 6px 8px;
}

.clan-icon,
.participant-icon {
    vertical-align: middle;
}

.clan-icon-top {
    vertical-align: top;
}

.custom-drop-label {
    margin-top: 12px;
}

/* Отдельные страницы ошибок rate limiter. */
.standalone-error-body {
    margin: 0;
    padding: 24px;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Arial, sans-serif;
}

.standalone-error-panel {
    max-width: 560px;
    margin: 0 auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 3px 12px var(--shadow);
}

.standalone-error-panel h1 {
    margin: 0 0 10px;
    font-size: 20px;
}

.standalone-error-panel p {
    margin: 0;
    color: var(--muted);
}
