/* problems-redesign.css - Clean, user-friendly layout for NAMSSN Problems */

:root {
    --prob-card-bg: #ffffff;
    --prob-card-border: #e2e8f0;
    --prob-card-hover: #f8fafc;
    --prob-pill-bg: #f1f5f9;
    --prob-pill-text: #475569;
    --prob-accent: #10b981;
    /* Green accent from screenshot */
    --text-main: #0f172a;
    --text-soft: #64748b;
}

body.theme-dark {
    --prob-card-bg: #1e293b;
    --prob-card-border: #334155;
    --prob-card-hover: #1e293b;
    --prob-pill-bg: #334155;
    --prob-pill-text: #cbd5e1;
    --prob-accent: #34d399;
}

/* Page Layout */
.problem-layout {
    max-width: 100%;
    margin: 0;
    padding: 0;
    /* Let main handle the padding */
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 3rem;
    align-items: start;
}

@media (max-width: 900px) {
    .problem-layout {
        grid-template-columns: 1fr;
        padding: 0;
        /* Consistent with desktop: let main handle it */
        gap: 2rem;
        margin-top: 0;
        /* Remove negative margin and let natural flow handle it */
    }

    .page-heading {
        margin-bottom: 1.5rem;
        margin-top: 0;
    }
}

/* Headings */
.page-heading {
    margin-bottom: 2rem;
}

.page-heading h1 {
    font-size: 1.8rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}

.page-subtitle {
    font-size: 0.95rem;
    color: var(--text-soft);
    max-width: 45rem;
    line-height: 1.5;
}

/* Redesigned Toolbar Overhaul */
/* Modern Tabbed Interface */
.problem-tabs-container {
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-soft);
}

.problem-tabs {
    display: flex;
    overflow-x: auto;
    gap: 1.5rem;
    padding-bottom: 1px;
    /* To overlap border */
    scrollbar-width: none;
}

.problem-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    /* default hidden border */
    color: var(--text-soft);
    padding: 0.8rem 0.2rem;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--prob-accent);
    border-bottom-color: var(--prob-accent);
    font-weight: 600;
}

/* Modern Control Bar (Search & Sort) */
.problem-toolbar-modern {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1.5rem 0;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.search-container {
    flex: 1;
    min-width: 280px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-icon-fixed {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.1rem;
    height: 1.1rem;
    color: var(--text-soft);
    pointer-events: none;
    z-index: 1;
    /* Ensure high layer */
}

/* Specific ID targeting to override ANY previous styles */
#problem-search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3rem !important;
    /* Force left padding */
    border: 1px solid var(--prob-card-border);
    border-radius: 99px;
    background: var(--prob-card-bg);
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
}

#problem-search-input:focus {
    border-color: var(--prob-accent);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

.sort-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.sort-label-text {
    font-size: 0.9rem;
    color: var(--text-soft);
}

.sort-select-modern {
    padding: 0.5rem 2rem 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--prob-card-border);
    background-color: var(--prob-card-bg);
    color: var(--text-main);
    font-size: 0.9rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
    min-width: 140px;
}

.sort-select-modern:focus {
    outline: none;
    border-color: var(--prob-accent);
}

@media (max-width: 700px) {
    .problem-toolbar-modern {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .sort-container {
        justify-content: flex-end;
    }
}

.modern-select {
    width: 100%;
    padding: 0.5rem 2rem 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--prob-card-border);
    background: var(--prob-card-bg);
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
}

.modern-select:focus {
    outline: none;
    border-color: var(--prob-accent);
}

.custom-select select {
    background: var(--prob-card-bg);
    border: 1px solid var(--prob-card-border);
    border-radius: 0.5rem;
    padding: 0.3rem 1.5rem 0.3rem 0.8rem;
    /* Padding for arrow */
    color: var(--text-main);
    font-size: 0.9rem;
    cursor: pointer;
}

/* Submit Strip - Card Style */
.submit-strip {
    background: var(--prob-card-bg);
    border: 1px solid var(--prob-card-border);
    border-radius: 1rem;
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    /* Align top */
    justify-content: space-between;
    gap: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
}

.submit-content {
    flex: 1;
}

.submit-strip-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.submit-strip p {
    font-size: 0.9rem;
    color: var(--text-soft);
    line-height: 1.5;
    margin-bottom: 0.8rem;
}

.problem-link {
    font-size: 0.85rem;
    color: var(--prob-accent);
    text-decoration: none;
    font-weight: 500;
}

.problem-link:hover {
    text-decoration: underline;
}

.submit-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    text-align: right;
}

.submit-action .btn-primary {
    background: #10b981;
    /* Green */
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 99px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
    transition: transform 0.2s;
    font-size: 0.9rem;
    white-space: nowrap;
}

.submit-action .btn-primary:hover {
    transform: translateY(-1px);
    background: #059669;
}

.sub-text {
    font-size: 0.75rem;
    color: var(--text-soft);
    max-width: 180px;
}

@media (max-width: 700px) {
    .submit-strip {
        flex-direction: column;
        gap: 1.5rem;
    }

    .submit-action {
        align-items: flex-start;
        text-align: left;
    }

    .sort-control {
        margin-left: 0;
    }
}

/* Problem Cards */
#problems-list {
    display: grid;
    gap: 1rem;
}

.prob-card {
    background: var(--prob-card-bg);
    border: 1px solid var(--prob-card-border);
    border-radius: 1rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

@media (max-width: 600px) {
    .prob-card {
        padding: 1rem;
    }

    .prob-card-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    .prob-meta-top {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

.prob-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    gap: 1rem;
}

.prob-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
    line-height: 1.3;
}

.prob-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
    font-weight: 700;
    white-space: nowrap;
    align-self: flex-start;
}

.badge-difficulty.medium {
    color: #f59e0b;
    background: #fffbeb;
}

.badge-difficulty.easy {
    color: #10b981;
    background: #ecfdf5;
}

.badge-difficulty.hard {
    color: #ef4444;
    background: #fef2f2;
}

.prob-snippet {
    font-size: 0.95rem;
    color: var(--text-main);
    margin-bottom: 1rem;
    line-height: 1.6;
    overflow-wrap: break-word;
}

.prob-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.prob-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.prob-tag {
    font-size: 0.75rem;
    background: var(--prob-pill-bg);
    color: var(--text-soft);
    padding: 0.25rem 0.7rem;
    border-radius: 99px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.prob-stats {
    font-size: 0.85rem;
    color: var(--text-soft);
    display: flex;
    gap: 1rem;
    white-space: nowrap;
    margin-left: auto;
    /* Push to right if wrapped */
}

/* Sidebar */
.content-block {
    background: var(--prob-card-bg);
    border: 1px solid var(--prob-card-border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.content-block h2 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.clean-list li {
    font-size: 0.9rem;
    color: var(--text-soft);
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* =========================================
   Submit Problem Page Specific Styles (Redesign)
   ========================================= */

body.page-submit-problem .problem-layout {
    grid-template-columns: 340px 1fr;
    gap: 1.4rem;
}

@media (max-width: 900px) {
    body.page-submit-problem .problem-layout {
        grid-template-columns: 1fr;
    }

    body.page-submit-problem .problem-layout>div:first-child {
        order: 2;
    }

    body.page-submit-problem .problem-layout>div:last-child {
        order: 1;
    }
}

body.page-submit-problem #submit-problem {
    margin-left: 0;
    max-width: 100%;
}

/* Scoped to submit page to avoid regressions on problems */
body.page-submit-problem main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem 3rem;
    position: relative;
    /* from alt */
}

body.page-submit-problem main::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 140px;
    pointer-events: none;
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0) 0%,
            rgba(148, 163, 184, 0.08) 65%,
            rgba(148, 163, 184, 0.12) 100%);
    opacity: 0.55;
}

body.theme-dark.page-submit-problem main::after {
    background: linear-gradient(to bottom,
            rgba(15, 23, 42, 0) 0%,
            rgba(2, 6, 23, 0.35) 65%,
            rgba(2, 6, 23, 0.55) 100%);
    opacity: 0.7;
}

/* Top Sections */
section.submit-top {
    margin-bottom: 0.85rem !important;
}

section.submit-top .section-heading {
    margin-bottom: 0.5rem;
}

/* Form Container */
#submit-problem {
    max-width: 700px;
    margin-left: auto;
}

@media (max-width: 980px) {
    #submit-problem {
        max-width: 100%;
        margin-left: 0;
    }
}

/* --- Micro UI components --- */
.mini-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.mini-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.mini-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    padding: 0.42rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: var(--card);
    cursor: pointer;
    color: var(--text-soft);
    transition: 0.16s ease-out;
    user-select: none;
}

.mini-btn:hover {
    border-color: rgba(34, 197, 94, 0.85);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(34, 197, 94, 0.10);
}

.mini-btn.danger:hover {
    border-color: rgba(239, 68, 68, 0.75);
    color: #ef4444;
    box-shadow: 0 10px 25px rgba(239, 68, 68, 0.10);
}

.field-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.7rem;
    flex-wrap: wrap;
    align-items: baseline;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-soft);
}

.counter strong {
    color: var(--text-main);
}

.error-banner {
    display: none;
    margin: 0.7rem 0 0.8rem;
    padding: 0.72rem 0.85rem;
    border-radius: 0.9rem;
    border: 1px solid rgba(239, 68, 68, 0.45);
    background: rgba(239, 68, 68, 0.06);
    color: var(--text-main);
}

.error-banner.show {
    display: block;
}

.error-banner .title {
    font-weight: 800;
    margin-bottom: 0.2rem;
}

.error-banner .body {
    color: var(--text-soft);
    font-size: 0.88rem;
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    max-width: 380px;
    z-index: 10000;
    background: var(--card);
    border: 1px solid var(--border-soft);
    border-radius: 1rem;
    padding: 0.9rem 1rem;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
    color: var(--text-main);
}

.toast .t-title {
    font-weight: 800;
    margin-bottom: 0.2rem;
}

.toast .t-body {
    color: var(--text-soft);
    font-size: 0.92rem;
}

/* --- Premium form card (subtle) --- */
/* allow dropdowns to overflow the card */
#submit-problem.form-card {
    border-radius: 1.25rem;
    padding: 0.95rem 1.05rem;
    position: relative;
    overflow: visible;
    /* was hidden */
    box-shadow:
        0 24px 60px rgba(15, 23, 42, 0.10),
        0 10px 22px rgba(15, 23, 42, 0.08);
    transform: translateY(-2px);
}

body.theme-dark #submit-problem.form-card {
    box-shadow:
        0 26px 70px rgba(0, 0, 0, 0.50),
        0 12px 26px rgba(0, 0, 0, 0.35);
}

/* keep glow behind content AND behind dropdowns */
#submit-problem.form-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background:
        radial-gradient(circle at 0 0, rgba(34, 197, 94, 0.16), transparent 55%),
        radial-gradient(circle at 100% 0, rgba(56, 189, 248, 0.10), transparent 55%),
        radial-gradient(circle at 70% 100%, rgba(168, 85, 247, 0.08), transparent 55%);
    opacity: 0.75;
    pointer-events: none;
    z-index: -1;
}

#submit-problem .card-inner {
    position: relative;
    z-index: 1;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
    margin-bottom: 0.2rem;
}

.card-head-left {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    min-width: 0;
}

.spark {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    background:
        radial-gradient(circle at 30% 20%, rgba(34, 197, 94, 0.18), transparent 55%),
        radial-gradient(circle at 80% 90%, rgba(56, 189, 248, 0.12), transparent 55%),
        var(--card);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

body.theme-dark .spark {
    border-color: rgba(148, 163, 184, 0.35);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.spark span {
    font-weight: 900;
    font-size: 1.03rem;
    color: var(--accent);
}

.card-title {
    margin: 0;
    font-size: 1.02rem;
    color: var(--text-main);
    font-weight: 880;
    letter-spacing: -0.01em;
}

.card-sub {
    margin-top: 0.1rem;
    font-size: 0.82rem;
    color: var(--text-soft);
    line-height: 1.42;
    max-width: 46rem;
}

.pill-row {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 0.5rem;
}

.tiny-pill {
    font-size: 0.72rem;
    padding: 0.16rem 0.56rem;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: rgba(148, 163, 184, 0.06);
    color: var(--text-soft);
    white-space: nowrap;
}

.tiny-pill.good {
    border-color: rgba(34, 197, 94, 0.55);
    background: rgba(34, 197, 94, 0.08);
    color: var(--accent);
    font-weight: 750;
}

#submit-problem input[type="text"],
#submit-problem textarea,
#submit-problem select {
    border-radius: 0.85rem !important;
    padding: 0.6rem 0.72rem !important;
    transition: border-color 0.15s ease-out, box-shadow 0.15s ease-out, transform 0.15s ease-out;
    background: var(--card) !important;
}

#submit-problem input[type="text"]:focus,
#submit-problem textarea:focus,
#submit-problem select:focus {
    outline: none !important;
    border-color: rgba(34, 197, 94, 0.95) !important;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12) !important;
    transform: translateY(-1px);
}

#submit-problem textarea {
    min-height: 170px;
    line-height: 1.6;
}

.select-nice {
    width: 100%;
    padding: 0.6rem 0.72rem;
    border-radius: 0.85rem;
    border: 1px solid var(--border-soft);
    background: var(--card);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
}

/* ============================
   Tag suggestions + guidance
   ============================ */
.tag-suggest-wrap {
    margin-top: 0.45rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.9rem;
    border: 1px dashed rgba(148, 163, 184, 0.55);
    background: rgba(148, 163, 184, 0.05);
}

.tag-suggest-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.6rem;
    font-size: 0.78rem;
    color: var(--text-soft);
    margin-bottom: 0.35rem;
}

.tag-suggest-head strong {
    color: var(--text-main);
    font-weight: 850;
    font-size: 0.80rem;
}

.tag-suggest-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.tag-chip {
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.65);
    padding: 0.22rem 0.62rem;
    font-size: 0.78rem;
    cursor: pointer;
    transition: 0.15s ease-out;
    color: var(--text-soft);
    user-select: none;
}

body.theme-dark .tag-chip {
    background: rgba(15, 23, 42, 0.35);
}

.tag-chip:hover {
    border-color: rgba(34, 197, 94, 0.85);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(34, 197, 94, 0.10);
}

.tag-chip.active {
    border-color: rgba(34, 197, 94, 0.75);
    background: rgba(34, 197, 94, 0.10);
    color: var(--accent);
    font-weight: 800;
}

.tag-suggest-note {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-soft);
    line-height: 1.45;
}

/* ============================
   Modern tag input (tokenized)
   ============================ */
.tagbox {
    position: relative;
    border: 1px solid var(--border-soft);
    background: var(--card);
    border-radius: 1rem;
    padding: 0.55rem 0.6rem 0.5rem;
    transition: 0.15s ease-out;

    /* create a clean stacking context so dropdown wins everywhere */
    isolation: isolate;
    z-index: 20;
}

.tagbox:focus-within {
    border-color: rgba(34, 197, 94, 0.95);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
    transform: translateY(-1px);
}

.tagbox-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 0.4rem;
}

.tagpill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    background: rgba(148, 163, 184, 0.06);
    color: var(--text-main);
    padding: 0.25rem 0.55rem;
    font-size: 0.82rem;
    font-weight: 750;
    max-width: 100%;
}

.tagpill .t {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 28ch;
}

.tagpill button {
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--text-soft);
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.05rem 0.2rem;
    border-radius: 999px;
}

.tagpill button:hover {
    color: #ef4444;
}

.tagbox-input {
    width: 100%;
    border: 0 !important;
    outline: none !important;
    background: transparent !important;
    padding: 0.25rem 0.2rem !important;
    border-radius: 0.6rem !important;
    box-shadow: none !important;
    transform: none !important;
    font-size: 0.92rem;
    color: var(--text-main);
}

.tagbox-meta {
    margin-top: 0.35rem;
    display: flex;
    justify-content: space-between;
    gap: 0.7rem;
    flex-wrap: wrap;
    align-items: baseline;
    font-size: 0.78rem;
    color: var(--text-soft);
}

.tagbox-meta .hint {
    opacity: 0.9;
}

/* dropdown scroll + higher stacking + no page takeover */
.tagbox-menu {
    position: absolute;
    left: 0.55rem;
    right: 0.55rem;
    top: calc(100% + 0.5rem);
    border-radius: 1rem;
    border: 1px solid var(--border-soft);

    /* Truly opaque surface; use theme vars */
    background: var(--card);
    opacity: 1;

    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    display: none;

    /* Must beat everything in the card */
    z-index: 10050;

    max-height: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;

    /* avoid any weird blending/ghosting */
    mix-blend-mode: normal;
    backdrop-filter: none;
}

.tagbox-menu.open {
    display: block;
}

.tagopt {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    padding: 0.65rem 0.75rem;
    cursor: pointer;
    color: var(--text-main);
    font-weight: 750;
    font-size: 0.9rem;
    background: transparent;
}

.tagopt:hover,
.tagopt[aria-selected="true"] {
    background: rgba(148, 163, 184, 0.08);
}

.tagopt small {
    font-weight: 650;
    color: var(--text-soft);
    opacity: 0.95;
}

/* ============================
   Editor + preview (FIXED FOR SAFARI)
   ============================ */
.editor-grid {
    position: relative;
    min-width: 0;
}

.editor-grid .eg-track {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.90fr);
    gap: 0.85rem;
    align-items: start;
    width: 100%;
}

.editor-grid .eg-panel {
    min-width: 0;
}

.preview-card {
    background: rgba(148, 163, 184, 0.04);
    border: 1px dashed rgba(148, 163, 184, 0.7);
    border-radius: 1rem;
    padding: 0.65rem 0.75rem;
    position: sticky;
    top: 0.9rem;
    min-width: 0;
    overflow: hidden;
}

/* Mobile: sliding Editor <-> Preview */
.mobile-views {
    display: none;
    margin-top: 0.55rem;
    border-radius: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.55);
    background: rgba(148, 163, 184, 0.05);
    padding: 0.35rem;
    gap: 0.35rem;
    align-items: center;
    justify-content: space-between;
}

.mobile-views button {
    flex: 1 1 auto;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: var(--card);
    padding: 0.42rem 0.7rem;
    font-size: 0.82rem;
    color: var(--text-soft);
    cursor: pointer;
    transition: 0.15s ease-out;
    font-weight: 800;
}

.mobile-views button.active {
    border-color: rgba(34, 197, 94, 0.75);
    background: rgba(34, 197, 94, 0.10);
    color: var(--accent);
}

@media (max-width: 760px) {
    .mobile-views {
        display: flex;
    }

    .preview-card {
        position: static;
    }

    .editor-grid {
        overflow: hidden;
        border-radius: 1rem;
    }

    .editor-grid .eg-track {
        display: flex;
        width: 200%;
        transition: transform 240ms ease;
        will-change: transform;
    }

    .editor-grid[data-view="preview"] .eg-track {
        transform: translateX(-50%);
    }

    .editor-grid[data-view="editor"] .eg-track {
        transform: translateX(0%);
    }

    .editor-grid .eg-panel {
        width: 50%;
        min-width: 50%;
    }

    .preview-card {
        border-style: solid;
        background: rgba(148, 163, 184, 0.04);
    }
}

.preview-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 0.4rem;
}

.preview-head strong {
    color: var(--text-main);
    font-size: 0.86rem;
}

.preview-head span {
    color: var(--text-soft);
    font-size: 0.78rem;
}

.title-preview {
    margin-top: 0.5rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.9rem;
    border: 1px solid rgba(148, 163, 184, 0.55);
    background: rgba(148, 163, 184, 0.06);
}

.title-preview .label {
    font-size: 0.74rem;
    color: var(--text-soft);
    margin-bottom: 0.28rem;
}

#title-preview-render {
    color: var(--text-main);
    font-weight: 760;
    line-height: 1.45;
    overflow-wrap: anywhere;
    min-height: 1.1em;
}

/* ========================
   Custom Scrollbar
   ======================== */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-soft);
    border: 3px solid transparent;
    border-radius: 99px;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-soft);
}

/* For the preview specifically - ensure scrollbar is at the bottom of the box */
#problem-preview {
    color: var(--text-main);
    line-height: 1.7;
    overflow-wrap: anywhere;
    min-height: 120px;
    font-size: 0.95rem;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Inline math: do NOT break the line */
#problem-preview mjx-container[display="false"],
#title-preview-render mjx-container[display="false"] {
  display: inline-block;
  vertical-align: middle;
}

/* Display math: keep as block, but reduce the "paragraph" gap */
#problem-preview mjx-container[display="true"],
#title-preview-render mjx-container[display="true"] {
  display: block;
  max-width: 100%;
  margin: 0.15em 0;          /* ✅ controls the extra space */
}

/* MathJax often puts margins on the SVG too */
#problem-preview mjx-container[display="true"] > svg,
#title-preview-render mjx-container[display="true"] > svg {
  margin: 0 !important;     /* ✅ kills the extra SVG margin */
}

/* Keep your SVG sizing rules */
#problem-preview mjx-container svg,
#title-preview-render mjx-container svg {
  max-width: none !important;
  width: auto !important;
  height: auto !important;
}

.typeset-busy {
    opacity: 0.85;
    filter: saturate(1.02);
}

.typeset-busy::after {
    content: "Typesetting…";
    display: block;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-soft);
    opacity: 0.85;
}

.latex-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 0.45rem;
    padding: 0.45rem 0.5rem;
    border-radius: 0.95rem;
    border: 1px solid rgba(148, 163, 184, 0.55);
    background: rgba(148, 163, 184, 0.06);
    font-size: 0.78rem;
    color: var(--text-soft);
}

.latex-toolbar-label {
    font-weight: 850;
    margin-right: 0.12rem;
    color: var(--text-main);
    opacity: 0.9;
}

.latex-btn {
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: rgba(255, 255, 255, 0.65);
    padding: 0.24rem 0.65rem;
    font-size: 0.78rem;
    cursor: pointer;
    transition: 0.15s ease-out;
    color: var(--text-soft);
}

body.theme-dark .latex-btn {
    background: rgba(15, 23, 42, 0.35);
}

.latex-btn:hover {
    border-color: rgba(34, 197, 94, 0.85);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(34, 197, 94, 0.10);
}

#submit-btn.btn.btn-primary {
    width: 100%;
    padding: 0.62rem 1rem;
    border-radius: 999px;
    font-size: 0.92rem;
    letter-spacing: 0.01em;
}

#submit-problem .field-group {
    margin-bottom: 0.78rem;
}

footer {
    margin-top: 2.1rem;
    position: relative;
    z-index: 1;
}

/* ============================
   Guest lock wall
   ============================ */
.auth-wall {
    margin: 0.75rem 0 0.95rem;
    border: 1px solid var(--border-soft);
    border-radius: 1rem;
    padding: 0.9rem 1rem;
    background:
        radial-gradient(circle at 0 0, rgba(56, 189, 248, 0.10), transparent 60%),
        radial-gradient(circle at 100% 100%, rgba(34, 197, 94, 0.12), transparent 60%),
        var(--card);
    box-shadow: var(--shadow-soft);
}

.auth-wall strong {
    color: var(--text-main);
}

.auth-wall p {
    margin: 0.35rem 0 0.65rem;
    color: var(--text-soft);
}

.auth-wall .row {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
    align-items: center;
}

.auth-wall .btn {
    white-space: nowrap;
}

.guest-locked .card-inner {
    filter: saturate(0.95);
}

.guest-locked form {
    opacity: 0.65;
    pointer-events: none;
    user-select: none;
}

.guest-locked input,
.guest-locked textarea,
.guest-locked select {
    cursor: not-allowed;
}