/* =====================================================================
   PROBLEMS AREA — page styles
   Loaded by templates in src/templates/problem/ (after style.css, so
   token overrides here win ties). Uses the design tokens defined in
   style.css: --brand, --sp-*, --radius-*, --shadow-e*, --fs-*,
   --surface*, --text-*, --focus-ring, and the .dark variable layer.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Shared bits (list + detail + admin pages)
   --------------------------------------------------------------------- */
.text-brand {
    color: var(--brand);
}

/* Tag pills: quiet brand tint, readable in both modes */
.tag-pill {
    display: inline-block;
    padding: var(--sp-1) var(--sp-3);
    margin: 2px 4px 2px 0;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(116, 31, 34, 0.22);
    background: rgba(116, 31, 34, 0.08);
    color: var(--brand) !important;
    font-size: var(--fs-75);
    font-weight: 600;
    letter-spacing: 0.01em;
    text-align: center;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

a.tag-pill:hover,
a.tag-pill:focus-visible {
    background: rgba(116, 31, 34, 0.16);
    border-color: rgba(116, 31, 34, 0.45);
}

a.tag-pill:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.tag-pill--empty {
    background: var(--surface-2);
    border-color: var(--surface-border);
    color: var(--text-muted) !important;
}

.tag-pill--action {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff !important;
}

a.tag-pill--action:hover,
a.tag-pill--action:focus-visible {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

/* Scrollable table wrapper */
.table-scroll {
    overflow-x: auto;
    margin-top: var(--sp-4);
}

/* Right-aligned numeric columns with lined-up digits */
.cell-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------
   2. Problems list — header, banner, quick filters
   --------------------------------------------------------------------- */
.problems-page-head {
    margin-bottom: var(--sp-4);
}

.problems-page-head .display-heading {
    margin: var(--sp-1) 0 var(--sp-3);
}

.problems-page-head .con-rule {
    max-width: 220px;
    margin: 0;
}

.problems-intro {
    color: var(--text-muted);
    margin-bottom: var(--sp-4);
}

.problems-intro b {
    color: var(--text-strong);
}

.problems-intro b.text-brand {
    color: var(--brand);
}

.smart-suggestions-banner {
    background: var(--rose-50);
    border: var(--border-thick) solid var(--structure);
    border-left: var(--border-bold) solid var(--brand);
    padding: var(--sp-4) var(--sp-5);
}

.smart-suggestions-banner p {
    color: var(--text-muted);
}

.smart-suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--sp-4);
}

.smart-widget {
    border: var(--border-thick) solid var(--structure);
    box-shadow: var(--shadow-hard);
    background: var(--surface) !important;
}

.smart-widget .list-group-item {
    border: none;
    padding-left: 0;
    padding-right: 0;
    background: transparent;
}

.smart-widget__meta {
    font-size: var(--fs-875);
    color: var(--text-muted);
}

.smart-widget__actions .btn {
    text-align: left;
}

.pagination-slot {
    display: inline-block;
    min-height: 42px;
}

.sort-hint {
    display: block;
    color: var(--text-muted);
    font-size: var(--fs-875);
    margin-bottom: var(--sp-2);
}

/* ---------------------------------------------------------------------
   3. Problems list — filter buttons
   One restrained family: outline (default), solid brand, destructive.
   --------------------------------------------------------------------- */
.filter-btn {
    border-radius: var(--radius-md);
    border: 1px solid rgba(116, 31, 34, 0.35);
    background: var(--surface);
    color: var(--brand);
    font-weight: 600;
    font-size: var(--fs-875);
    padding: 0.45rem 1rem;
    line-height: 1.4;
    transition: background-color 0.18s ease, border-color 0.18s ease,
                color 0.18s ease, box-shadow 0.18s ease, transform 0.08s ease;
}

.filter-btn:hover {
    background: rgba(116, 31, 34, 0.08);
    border-color: rgba(116, 31, 34, 0.55);
    color: var(--brand-dark);
    box-shadow: var(--shadow-e1);
}

.filter-btn:active {
    transform: translateY(1px);
}

.filter-btn:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.filter-btn--outline {
    /* same look as the base; kept as an explicit variant for markup/JS */
    background: var(--surface);
    color: var(--brand);
}

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

.filter-btn--primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}

.filter-btn--danger {
    background: transparent;
    border-color: rgba(220, 53, 69, 0.45);
    color: #b02a37;
}

.filter-btn--danger:hover {
    background: rgba(220, 53, 69, 0.08);
    border-color: #b02a37;
    color: #842029;
}

.quick-filter {
    border-radius: var(--radius-pill);
}

.quick-filter.filter-btn {
    padding: 0.35rem 1.1rem;
}

.quick-filter.active,
.quick-filter[aria-pressed="true"] {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* ---------------------------------------------------------------------
   4. Problems list — active filter chips
   --------------------------------------------------------------------- */
.filter-chips-panel {
    border: var(--border-thick) solid var(--structure);
    border-left: var(--border-bold) solid var(--brand);
    background: var(--rose-50);
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-5);
}

.filter-chips-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-2);
}

.filter-chips-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    align-items: center;
    margin-bottom: 0;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.3rem 0.8rem;
    border: var(--border-thin) solid var(--structure);
    background: rgba(116, 31, 34, 0.07);
    font-size: var(--fs-875);
    color: var(--text-strong);
}

.filter-chip__label {
    font-weight: 600;
    color: var(--text-muted);
}

.filter-chip__clear {
    margin-left: 2px;
    padding: var(--sp-1);
    opacity: 0.65;
    transition: opacity 0.15s ease;
}

.filter-chip__clear:hover {
    opacity: 1;
}

.filter-chip__clear:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.filter-badge {
    background: var(--brand) !important;
}

/* ---------------------------------------------------------------------
   5. Problems list — table
   --------------------------------------------------------------------- */
.problem-layout {
    align-items: flex-start;
    gap: var(--sp-6);
}

.problem-table-wrap {
    flex: 3.1;
    min-width: 0;
    overflow-x: auto;
}

.problem-sidebar {
    flex: 1.4;
    min-width: 260px;
}

.problems-table thead.table-dark {
    --bs-table-bg: var(--brand-darker);
}

.problems-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 600;
    font-size: var(--fs-875);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.problems-table th[data-sort] {
    cursor: pointer;
}

.problems-table th[data-sort]:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Column widths (table-layout: fixed) */
.problems-table .col-status   { width: 8%; }
.problems-table .col-name     { width: 26%; }
.problems-table .col-tags     { width: 23%; }
.problems-table .col-cat      { width: 14%; }
.problems-table .col-value    { width: 8%; }
.problems-table .col-rating   { width: 11%; }
.problems-table .col-likes    { width: 8%; }
.problems-table .col-users    { width: 8%; }

.problems-table {
    --bs-table-hover-bg: rgba(116, 31, 34, 0.06);
}

.problems-table tbody td {
    vertical-align: middle;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.problems-table tbody tr:nth-child(odd) {
    background-color: var(--surface-2);
}

.problems-table tbody tr:nth-child(even) {
    background-color: var(--surface);
}

.solve-status-icon {
    width: 24px;
    height: 24px;
}

.rating-star {
    color: #b8860b;
}

.problems-empty-state {
    border: var(--border-thick) solid var(--structure);
    background: var(--rose-50) !important;
    box-shadow: var(--shadow-hard);
    min-height: 280px;
}

.problems-empty-state__icon,
.rankings-empty-state__icon,
.noexist-icon {
    width: 64px;
    height: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    background: rgba(116, 31, 34, 0.10);
    color: var(--brand);
    font-size: var(--fs-150);
    margin-bottom: var(--sp-3);
}

/* ---------------------------------------------------------------------
   6. Problems list — filter sidebar
   --------------------------------------------------------------------- */
.problem-filter-card {
    border: var(--border-thick) solid var(--structure);
    box-shadow: var(--shadow-hard);
    background: var(--surface) !important;
    overflow-y: auto;
    height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    margin-bottom: var(--sp-4);
}

.problem-filter-card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--surface-border);
    padding: var(--sp-4) var(--sp-5) var(--sp-2);
}

.problem-filter-card .card-header h2 {
    font-size: var(--fs-125);
    margin-bottom: var(--sp-1);
}

.filter-section {
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--surface-border);
}

.filter-section:last-of-type {
    border-bottom: none;
}

.filter-section-title {
    font-size: var(--fs-75);
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: var(--sp-2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.filter-advanced {
    background: rgba(116, 31, 34, 0.06);
    border-radius: var(--radius-md);
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-4);
}

.filter-advanced .form-check-label {
    font-weight: 600;
    color: var(--text-strong);
}

.filter-field-row {
    display: flex;
    gap: var(--sp-2);
    align-items: flex-start;
}

.filter-field-row .form-floating {
    flex: 1;
}

.filter-field-row .filter-btn {
    height: 58px; /* match the form-floating input height */
    min-width: 5.5rem;
    margin-top: 0;
}

.category-menu {
    max-height: 250px;
    overflow-y: auto;
    z-index: 1050;
}

.category-option--current {
    background-color: var(--surface-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

.points-range-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-4);
}

.points-range-label {
    font-weight: 700;
    font-size: var(--fs-100);
    color: var(--text-strong);
}

.points-range-row .values {
    margin-left: var(--sp-2);
    display: block;
}

#slider-1 {
    display: block;
    transform: translateY(-350%);
}

#slider-2 {
    display: block;
    transform: translateY(-450%);
}

/* Tag checklist */
#tag-search .tag-list-panel {
    height: 250px;
    overflow-y: auto;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: var(--sp-2);
    background: var(--surface);
}

#tag-search #taglist {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
}

#tag-search #taglist .list-group-item {
    border: none;
    border-radius: var(--radius-sm);
    padding: var(--sp-2) var(--sp-2);
    background: transparent;
    transition: background-color 0.15s ease;
}

#tag-search #taglist .list-group-item:hover {
    background: rgba(116, 31, 34, 0.06);
}

#tag-search .check-container {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding-left: 0;
    font-size: var(--fs-875);
    font-weight: 500;
    color: var(--text-strong);
}

#tag-search .checkmark {
    position: relative;
    top: auto;
    left: auto;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border-radius: 0;
    border: 1px solid rgba(0, 0, 0, 0.25);
    background: var(--surface-2);
}

#tag-search .check-container input:focus-visible + .checkmark {
    outline: none;
    border-color: rgba(116, 31, 34, 0.55);
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

#tag-search .check-container input:checked + .checkmark {
    border-color: var(--brand);
    background: var(--brand);
}

#tag-search .check-container .checkmark:after {
    left: 6px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid #ffffff;
    border-width: 0 2px 2px 0;
}

#tag-search .tag-label {
    color: inherit;
}

/* Stack the sidebar under the table on small screens */
@media (max-width: 990.98px) {
    .flex-desktop {
        display: flex;
        flex-direction: column;
        gap: var(--sp-6);
    }

    .problem-sidebar {
        width: 100%;
    }

    .problem-filter-card {
        height: auto;
        max-height: none;
        overflow-y: visible;
    }
}

/* ---------------------------------------------------------------------
   7. Problem detail — statement, hints, tags, navigation
   --------------------------------------------------------------------- */
.problem-main {
    flex: 3;
    padding: var(--sp-1);
    word-break: break-word;
    min-width: 0;
}

.problem-side {
    flex: 1;
    padding: var(--sp-1);
    min-width: 240px;
}

@media (max-width: 768px) {
    .flex {
        flex-direction: column;
    }
}

.problem-detail-title {
    font-weight: var(--fw-display);
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.problem-detail-rule {
    max-width: 200px;
    margin: var(--sp-3) 0 var(--sp-4);
}

.bookmark-form {
    display: inline;
}

.bookmark-btn {
    vertical-align: baseline;
}

#problem-description {
    max-width: 75ch;
    line-height: 1.7;
    color: var(--text-strong);
}

#problem-description p {
    margin-bottom: var(--sp-4);
}

#problem-description img {
    max-width: 100%;
    height: auto;
}

#problem-description pre,
#problem-description code {
    border-radius: var(--radius-sm);
}

#hint-container {
    margin-top: var(--sp-3);
}

#togglehint {
    cursor: pointer;
    margin-top: 0; /* cancel the global button margin */
    border-radius: var(--radius-md);
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
}

#togglehint:hover {
    box-shadow: var(--shadow-e1);
}

#togglehint:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

#hint.card {
    margin-top: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border: var(--border-thick) solid var(--structure);
    border-left: var(--border-bold) solid var(--brand);
    background: var(--rose-50) !important;
    box-shadow: var(--shadow-hard);
}

.problem-detail-tags summary {
    cursor: pointer;
    border-radius: var(--radius-md);
    padding: var(--sp-2);
    font-size: var(--fs-875);
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
    list-style: none;
    display: inline-block;
}

.problem-detail-tags summary::-webkit-details-marker {
    display: none;
}

.problem-detail-tags summary:hover {
    box-shadow: var(--shadow-e1);
}

.problem-detail-tags summary:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.problem-nav-btn {
    margin-top: var(--sp-3);
    margin-right: var(--sp-1);
}

#confirm form {
    margin-bottom: var(--sp-4);
}

/* ---------------------------------------------------------------------
   8. Problem detail — answer form, meta card, timer
   --------------------------------------------------------------------- */
.problem-answer-form {
    margin-bottom: var(--sp-2);
}

#answer {
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-2);
}

#answer:focus {
    border-color: rgba(116, 31, 34, 0.55);
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.problem-submit-button:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.problem-submit-button--disabled {
    cursor: not-allowed;
}

.problem-meta-card {
    border: var(--border-thick) solid var(--structure);
    border-top: var(--border-bold) solid var(--brand);
    background: var(--rose-50);
    box-shadow: var(--shadow-hard);
    padding: var(--sp-4) var(--sp-5);
    line-height: 1.9;
}

.problem-meta-card a {
    text-decoration: none;
}

.problem-meta-card a:hover {
    text-decoration: underline;
}

.problem-timer {
    background: var(--rose-50);
    border: var(--border-thick) solid var(--structure);
    display: inline-block;
    padding: 0.4rem 1rem;
    box-shadow: var(--shadow-e1);
}

.problem-timer-controls {
    display: flex;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
}

.problem-timer .timer-value {
    font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.problem-report-note {
    color: #b02a37;
}

.dark .problem-report-note {
    color: var(--dark-danger);
}

.problem-timer-controls label {
    cursor: pointer;
}

.problem-timer-controls label:focus-within {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   9. Problem detail — engagement panel
   (difficulty vote / upvote / report / private notes)
   --------------------------------------------------------------------- */
#engagement-panel.engagement-card {
    border: var(--border-thick) solid var(--structure);
    background: var(--rose-50);
    box-shadow: var(--shadow-hard);
    padding: var(--sp-4) var(--sp-5);
}

.engagement-card__title {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--brand);
    margin: 0 0 var(--sp-3);
}

.engagement-section { margin-bottom: 0.9rem; }
.engagement-section:last-child { margin-bottom: 0; }

.engagement-label {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

.engagement-label b { color: var(--text-strong); }
#eng-diff-avg { font-weight: 700; color: var(--brand); }

/* Segmented difficulty pills */
.eng-diff-group { display: flex; gap: 0.3rem; width: 100%; }

.eng-diff-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1;
    color: var(--brand);
    background: var(--surface);
    border: 1px solid rgba(116, 31, 34, 0.30);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-top: 0;
    padding: 0;
    transition: background-color 0.15s ease, color 0.15s ease,
                border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.eng-diff-btn:hover {
    background: rgba(116, 31, 34, 0.08);
    border-color: rgba(116, 31, 34, 0.55);
    transform: translateY(-1px);
}

.eng-diff-btn:active { transform: translateY(0); }

.eng-diff-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.eng-diff-btn.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-e1);
}

.eng-diff-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Engagement action buttons */
#eng-upvote-btn,
#eng-report-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    min-height: 44px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-top: 0;
    transition: background-color 0.15s ease, color 0.15s ease,
                border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

#eng-upvote-btn:active,
#eng-report-btn:active { transform: translateY(0); }

#eng-upvote-btn {
    color: #1c7c4a;
    background: var(--surface);
    border: 1px solid rgba(28, 124, 74, 0.40);
    font-size: 0.92rem;
    margin-bottom: var(--sp-2);
}

#eng-upvote-btn:hover {
    background: rgba(28, 124, 74, 0.10);
    border-color: rgba(28, 124, 74, 0.65);
    transform: translateY(-1px);
}

#eng-upvote-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(28, 124, 74, 0.30);
}

/* Active/upvoted state (JS toggles .btn-success) */
#eng-upvote-btn.btn-success {
    color: #fff;
    background: #1c7c4a;
    border-color: #1c7c4a;
    box-shadow: var(--shadow-e1);
}

.eng-upvote-arrow { font-size: 0.78rem; line-height: 1; }

#eng-report-btn {
    color: #8a6d1b;
    background: transparent;
    border: 1px solid rgba(138, 109, 27, 0.35);
    font-size: 0.82rem;
    font-weight: 500;
}

#eng-report-btn:hover {
    background: rgba(138, 109, 27, 0.10);
    border-color: rgba(138, 109, 27, 0.55);
    transform: translateY(-1px);
}

#eng-report-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(138, 109, 27, 0.30);
}

/* Notes */
.eng-notes {
    margin-top: var(--sp-3);
    border-top: 1px solid var(--surface-border);
    padding-top: var(--sp-3);
}

.eng-notes > summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-strong);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 44px;
    border-radius: var(--radius-sm);
}

.eng-notes > summary::-webkit-details-marker { display: none; }

.eng-notes > summary::before {
    content: "\25B8";
    font-size: 0.7rem;
    color: var(--brand);
    transition: transform 0.15s ease;
}

.eng-notes[open] > summary::before { transform: rotate(90deg); }

.eng-notes > summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

#eng-note {
    border-radius: var(--radius-md);
    margin-top: var(--sp-1);
    font-size: 0.88rem;
}

#eng-note:focus {
    border-color: rgba(116, 31, 34, 0.55);
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.eng-note-row { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); }

#eng-note-save {
    min-height: 44px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--brand);
    background: var(--surface);
    border: 1px solid rgba(116, 31, 34, 0.30);
    border-radius: var(--radius-md);
    padding: 0 1rem;
    margin-top: 0;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease,
                border-color 0.15s ease, box-shadow 0.15s ease;
}

#eng-note-save:hover {
    background: rgba(116, 31, 34, 0.08);
    border-color: rgba(116, 31, 34, 0.55);
}

#eng-note-save:active { transform: translateY(1px); }

#eng-note-save:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

#eng-note-status { font-size: 0.8rem; color: var(--text-muted); }

/* ---------------------------------------------------------------------
   10. Editorial page
   --------------------------------------------------------------------- */
.editorial-head {
    margin-bottom: var(--sp-2);
}

.editorial-head-rule {
    max-width: 200px;
    margin: 0 0 var(--sp-4);
}

.editorial-head a {
    text-decoration: none;
}

.editorial-head a:hover {
    text-decoration: underline;
}

.editorial-surface {
    border: var(--border-thick) solid var(--structure);
    background: var(--surface);
    box-shadow: var(--shadow-hard);
    padding: var(--sp-6) var(--sp-6);
    font-size: 1.0625rem;
    line-height: 1.7;
    color: var(--text-strong);
}

.editorial-surface p {
    margin-bottom: var(--sp-4);
}

.editorial-surface img {
    max-width: 100%;
    height: auto;
}

.editorial-surface pre,
.editorial-surface code {
    border-radius: var(--radius-sm);
}

.editorial-surface a {
    color: var(--brand);
}

/* ---------------------------------------------------------------------
   11. Rankings page
   --------------------------------------------------------------------- */
.rankings-head-rule {
    max-width: 200px;
    margin: 0 0 var(--sp-4);
}

.rankings-back {
    display: inline-block;
    margin-bottom: var(--sp-3);
    font-size: var(--fs-100);
    padding: var(--sp-2) var(--sp-4) !important;
    text-decoration: none;
    transition: box-shadow 0.15s ease;
}

.rankings-back:hover {
    box-shadow: var(--shadow-e1);
}

.rankings-back:focus-visible {
    outline: 2px solid transparent;
    box-shadow: 0 0 0 0.2rem var(--focus-ring);
}

.rankings-table thead.table-dark {
    --bs-table-bg: var(--brand-darker);
}

.rankings-table tbody td {
    vertical-align: middle;
}

.rankings-table .col-rank { width: 10%; }
.rankings-table .col-user { width: 35%; }
.rankings-table .col-time { width: 25%; }

.rank-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 var(--sp-2);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: rgba(116, 31, 34, 0.08);
    color: var(--brand);
}

.rank-pill--1 { background: #f6d976; color: #6b4e07; }
.rank-pill--2 { background: #d8dde3; color: #3a4149; }
.rank-pill--3 { background: #e3b07e; color: #5a3411; }

.rankings-empty-state {
    border: var(--border-thick) solid var(--structure);
    background: var(--rose-50);
    box-shadow: var(--shadow-hard);
    padding: var(--sp-10) var(--sp-6);
    text-align: center;
    margin-top: var(--sp-4);
}

/* ---------------------------------------------------------------------
   12. Nonexistent problem page
   --------------------------------------------------------------------- */
.noexist-card {
    max-width: 560px;
    margin: var(--sp-12) auto;
    border: var(--border-thick) solid var(--structure);
    border-top: var(--border-bold) solid var(--brand);
    background: var(--rose-50);
    box-shadow: var(--shadow-hard);
    padding: var(--sp-10) var(--sp-8);
    text-align: center;
}

.noexist-icon {
    width: 72px;
    height: 72px;
    font-size: var(--fs-200);
    margin-bottom: var(--sp-4);
}

.noexist-code {
    display: inline-block;
    font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
    background: rgba(116, 31, 34, 0.08);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.5rem;
}

.noexist-card .btn {
    border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------
   13. Editor pages (create / edit problem / edit editorial)
   --------------------------------------------------------------------- */
.editor-page h1 {
    margin-bottom: var(--sp-5);
}

.editor-form {
    max-width: 960px;
}

.md-editor-row {
    margin-top: var(--sp-2);
    margin-bottom: var(--sp-4);
    border: var(--border-thick) solid var(--structure);
    background: var(--surface);
    padding: var(--sp-4);
    margin-left: 0;
    margin-right: 0;
}

.md-pane {
    min-width: 0;
    overflow-x: auto;
}

.md-pane-title {
    font-size: var(--fs-875);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--sp-3);
}

.editor-help {
    display: block;
    color: var(--text-muted);
    font-size: var(--fs-875);
    margin-bottom: var(--sp-2);
}

.editor-form .input-group .btn {
    margin-top: 0;
}

.editor-form .form-check {
    margin-bottom: var(--sp-4);
}

/* "New answer + rejudge" row on the edit page */
.answer-rejudge-row {
    position: relative;
}

.answer-rejudge-row .rejudge-box {
    position: absolute;
    right: 0;
    top: 0;
    width: initial;
}

.tag-remove-icon {
    height: 16px;
    width: 16px;
    cursor: pointer;
}

.editor-actions {
    margin-top: var(--sp-4);
}

.editor-actions .btn + .btn,
.editor-actions .btn + input[type="submit"] {
    margin-left: var(--sp-2);
}

.editorial-md-preview {
    border: var(--border-thick) solid var(--structure);
    background: var(--surface-2);
    padding: var(--sp-4);
    overflow-x: auto;
}

.editorial-html-preview {
    border: var(--border-thick) solid var(--structure);
    background: var(--surface);
    padding: var(--sp-4);
    overflow-x: auto;
}

.editor-section-title {
    margin-top: var(--sp-4);
    font-size: var(--fs-1125);
    font-weight: 700;
}

.editor-subhead {
    margin-top: var(--sp-4);
}

/* Draft problems table */
.draft-table .draft-col-name  { width: 65%; }
.draft-table .draft-col-cat   { width: 22%; }
.draft-table .draft-col-value { width: 13%; }

/* ---------------------------------------------------------------------
   14. Dark mode
   --------------------------------------------------------------------- */
.dark .tag-pill {
    background: rgba(242, 207, 208, 0.12);
    border-color: rgba(242, 207, 208, 0.28);
    color: #f2cfd0 !important;
}

.dark a.tag-pill:hover,
.dark a.tag-pill:focus-visible {
    background: rgba(242, 207, 208, 0.2);
    border-color: rgba(242, 207, 208, 0.5);
}

.dark .tag-pill--empty {
    background: var(--dark-surface-2);
    border-color: var(--dark-border);
    color: var(--dark-muted) !important;
}

.dark .tag-pill--action {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff !important;
}

.dark .problems-intro,
.dark .sort-hint {
    color: var(--dark-muted);
}

.dark .problems-intro b {
    color: var(--dark-text);
}

.dark .problems-intro b.text-brand {
    color: #f2cfd0;
}

.dark .smart-suggestions-banner {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    border-left-color: var(--brand);
}

.dark .smart-suggestions-banner p,
.dark .smart-suggestions-banner .text-muted,
.dark .smart-widget__meta {
    color: var(--dark-muted) !important;
}

.dark .smart-widget {
    background: var(--dark-surface-2) !important;
    border-color: var(--structure);
}

.dark .filter-btn {
    background: var(--dark-surface);
    border-color: rgba(242, 207, 208, 0.35);
    color: #f2cfd0;
}

.dark .filter-btn:hover {
    background: rgba(242, 207, 208, 0.10);
    border-color: rgba(242, 207, 208, 0.55);
    color: #fff;
}

.dark .filter-btn--primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.dark .filter-btn--primary:hover {
    background: #8c2a2e;
    border-color: #8c2a2e;
    color: #fff;
}

.dark .filter-btn--danger {
    background: transparent;
    border-color: rgba(240, 123, 135, 0.45);
    color: var(--dark-danger);
}

.dark .filter-btn--danger:hover {
    background: rgba(240, 123, 135, 0.12);
    border-color: var(--dark-danger);
    color: #f7a6ae;
}

.dark .quick-filter.active,
.dark .quick-filter[aria-pressed="true"] {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.dark .filter-chips-panel {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    border-left-color: var(--brand);
}

.dark .filter-chip {
    background: rgba(242, 207, 208, 0.12);
    border-color: var(--structure);
    color: var(--dark-text);
}

.dark .filter-chip__label {
    color: var(--dark-muted);
}

.dark .problems-table thead.table-dark {
    --bs-table-bg: var(--dark-surface-2);
}

.dark .problems-table {
    --bs-table-hover-bg: rgba(242, 207, 208, 0.08);
}

.dark .problems-table tbody tr:nth-child(odd),
.dark .problems-table tbody tr:nth-child(even) {
    background-color: transparent;
}

.dark .rating-star {
    color: #e2c067;
}

.dark .problems-empty-state {
    background: var(--dark-surface-2) !important;
    border-color: var(--structure);
}

.dark .problems-empty-state__icon,
.dark .rankings-empty-state__icon,
.dark .noexist-icon {
    background: rgba(242, 207, 208, 0.14);
    color: #f0c6c8;
}

.dark .problem-filter-card {
    background: var(--dark-surface) !important;
    border-color: var(--structure);
}

.dark .problem-filter-card .card-header {
    border-bottom-color: var(--dark-border);
}

.dark .filter-section {
    border-bottom-color: var(--dark-border);
}

.dark .filter-section-title {
    color: #e2b9bb;
}

.dark .filter-advanced {
    background: rgba(242, 207, 208, 0.08);
}

.dark .filter-advanced .form-check-label,
.dark .points-range-label {
    color: var(--dark-text);
}

.dark .category-option--current {
    background-color: var(--dark-surface-2);
    color: var(--dark-muted);
}

.dark #tag-search .tag-list-panel {
    background: var(--dark-surface);
    border-color: var(--dark-border);
}

.dark #tag-search #taglist .list-group-item {
    background: transparent;
}

.dark #tag-search #taglist .list-group-item:hover {
    background: rgba(242, 207, 208, 0.08);
}

.dark #tag-search .check-container,
.dark #tag-search .tag-label {
    color: var(--dark-text);
}

.dark #tag-search .checkmark {
    background: var(--dark-surface-2);
    border-color: var(--dark-border);
}

.dark #problem-description {
    color: var(--dark-text);
}

.dark #hint.card {
    background: var(--dark-surface-2) !important;
    border-color: var(--structure);
    border-left-color: var(--brand);
}

.dark .problem-meta-card {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    border-top-color: var(--brand);
    box-shadow: var(--shadow-hard);
}

.dark .problem-timer {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    box-shadow: var(--shadow-e1);
}

.dark #answer:focus {
    border-color: rgba(242, 207, 208, 0.55);
    box-shadow: 0 0 0 0.2rem rgba(242, 207, 208, 0.25);
}

/* Engagement panel (dark) */
body.dark #engagement-panel.engagement-card {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    box-shadow: var(--shadow-hard);
}
body.dark .engagement-card__title { color: var(--dark-text); }
body.dark .engagement-label { color: var(--dark-muted); }
body.dark .engagement-label b { color: var(--dark-text); }
body.dark #eng-diff-avg { color: #f2cfd0; }
body.dark .eng-diff-btn { color: #f2cfd0; background: var(--dark-surface); border-color: var(--dark-border); }
body.dark .eng-diff-btn:hover { background: rgba(242, 207, 208, 0.10); border-color: rgba(242, 207, 208, 0.45); }
body.dark .eng-diff-btn:focus-visible { box-shadow: 0 0 0 0.2rem rgba(242, 207, 208, 0.30); }
body.dark .eng-diff-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
body.dark #eng-upvote-btn { color: #6fd29b; background: var(--dark-surface); border-color: rgba(111, 210, 155, 0.40); }
body.dark #eng-upvote-btn:hover { background: rgba(111, 210, 155, 0.12); border-color: rgba(111, 210, 155, 0.65); }
body.dark #eng-upvote-btn.btn-success { color: #fff; background: #1c7c4a; border-color: #1c7c4a; }
body.dark #eng-report-btn { color: #e2c067; border-color: rgba(226, 192, 103, 0.35); }
body.dark #eng-report-btn:hover { background: rgba(226, 192, 103, 0.12); border-color: rgba(226, 192, 103, 0.55); }
body.dark .eng-notes { border-top-color: var(--dark-border); }
body.dark .eng-notes > summary { color: var(--dark-text); }
body.dark .eng-notes > summary::before { color: #f2cfd0; }
body.dark #eng-note { background: var(--dark-surface); border-color: var(--dark-border); color: var(--dark-text); }
body.dark #eng-note:focus { border-color: rgba(242, 207, 208, 0.55); box-shadow: 0 0 0 0.2rem rgba(242, 207, 208, 0.22); }
body.dark #eng-note-save { color: #f2cfd0; background: var(--dark-surface); border-color: var(--dark-border); }
body.dark #eng-note-save:hover { background: rgba(242, 207, 208, 0.10); border-color: rgba(242, 207, 208, 0.45); }
body.dark #eng-note-status { color: var(--dark-muted); }

/* Editorial / rankings / noexist (dark) */
.dark .editorial-surface {
    background: var(--dark-surface);
    border-color: var(--structure);
    box-shadow: var(--shadow-hard);
    color: var(--dark-text);
}

.dark .editorial-surface a {
    color: var(--dark-link);
}

.dark .rankings-table thead.table-dark {
    --bs-table-bg: var(--dark-surface-2);
}

.dark .rank-pill {
    background: rgba(242, 207, 208, 0.14);
    color: #f0c6c8;
}

.dark .rank-pill--1 { background: #f6d976; color: #6b4e07; }
.dark .rank-pill--2 { background: #d8dde3; color: #3a4149; }
.dark .rank-pill--3 { background: #e3b07e; color: #5a3411; }

.dark .rankings-empty-state,
.dark .noexist-card {
    background: var(--dark-surface-2);
    border-color: var(--structure);
    box-shadow: var(--shadow-hard);
}

.dark .noexist-card {
    border-top-color: var(--brand);
}

.dark .noexist-code {
    background: rgba(242, 207, 208, 0.12);
    color: var(--dark-text);
}

/* Editor pages (dark) */
.dark .md-editor-row,
.dark .editorial-html-preview {
    background: var(--dark-surface);
    border-color: var(--structure);
}

.dark .editorial-md-preview {
    background: var(--dark-surface-2);
    border-color: var(--structure);
}

.dark .md-pane-title {
    color: #e2b9bb;
}

.dark .editor-help {
    color: var(--dark-muted);
}

/* ---------------------------------------------------------------------
   15. Reduced motion
   --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .filter-btn,
    .filter-chip__clear,
    .tag-pill,
    .eng-diff-btn,
    #eng-upvote-btn,
    #eng-report-btn,
    #eng-note-save,
    #togglehint,
    .problem-detail-tags summary,
    .eng-notes > summary::before,
    .rankings-back {
        transition: none;
    }

    .filter-btn:active,
    .eng-diff-btn:hover,
    #eng-upvote-btn:hover,
    #eng-report-btn:hover,
    #eng-note-save:active {
        transform: none;
    }
}
