/* ---------------------------------------------------------------
   Theme colours. Light is the default; [data-theme="dark"] on <html>
   switches every colour below (set before paint by the layout).
---------------------------------------------------------------- */
:root {
    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-soft: #eef2ff;
    --brand-ink: #3730a3;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #e2e8f0;
    --bg: #f6f7fb;
    --card: #ffffff;
    --surface: #f8fafc;
    --hover: #f1f4f9;
    --side-bg: #fbfcfe;
    --figure-bg: #ffffff;
    --star-off: #d6dbe3;
    --shadow: rgba(15, 23, 42, .06);
}

[data-theme="dark"] {
    --brand: #6366f1;
    --brand-hover: #818cf8;
    --brand-soft: rgba(99, 102, 241, .16);
    --brand-ink: #c7d2fe;
    --ink: #e5e7eb;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --faint: #64748b;
    --line: #1f2a3c;
    --bg: #0b1120;
    --card: #111827;
    --surface: #0f172a;
    --hover: #1b2437;
    --side-bg: #111827;
    --figure-bg: #000000;
    --star-off: #334155;
    --shadow: rgba(0, 0, 0, .4);
    color-scheme: dark;
}

/* Star colours by importance: 5 = deep red, 3-4 = yellow, 1-2 = ash */
.stars-high {
    --star: #c81e1e;
}

.stars-mid {
    --star: #eab308;
}

.stars-low {
    --star: #9ca3af;
}

[data-theme="dark"] .stars-high {
    --star: #ef4444;
}

[data-theme="dark"] .stars-mid {
    --star: #facc15;
}

[data-theme="dark"] .stars-low {
    --star: #8b95a5;
}

html {
    scroll-padding-top: 80px;
    /* Keep the scrollbar's space reserved so switching pages never shifts the layout sideways */
    scrollbar-gutter: stable;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    transition: background-color .2s, color .2s;
}

a {
    color: var(--brand);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 500;
}

.btn-soft {
    color: var(--ink-2);
    background: var(--card);
    border: 1px solid var(--line);
}

.btn-soft:hover {
    color: var(--ink);
    background: var(--hover);
    border-color: var(--faint);
}

.btn-primary {
    box-shadow: 0 2px 6px rgba(79, 70, 229, .25);
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-hover);
    --bs-btn-hover-border-color: var(--brand-hover);
}

.pagination {
    --bs-pagination-active-bg: var(--brand);
    --bs-pagination-active-border-color: var(--brand);
    --bs-pagination-color: var(--brand);
    margin: 0;
}

.form-control {
    background-color: var(--card);
    color: var(--ink);
    border-color: var(--line);
}

.form-control:focus {
    background-color: var(--card);
    color: var(--ink);
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.text-muted {
    color: var(--muted) !important;
}

/* ---------------- Navbar ---------------- */
.site-navbar {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
    z-index: 1030;
}

.nav-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}

.site-navbar .navbar-brand {
    color: var(--ink);
    font-size: 21px;
    text-decoration: none;
    flex-shrink: 0;
}

/* Categories in one line; the arrows (or the mouse wheel) slide them, no scrollbar */
.nav-strip {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.nav-scroll {
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px 0;
}

.nav-scroll::-webkit-scrollbar {
    display: none;
}

.nav-arrow {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    box-shadow: 0 2px 8px var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) scale(.85);
    transition: opacity .15s, transform .15s, background .15s;
}

.nav-arrow.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) scale(1);
}

.nav-arrow:hover {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.nav-arrow-left {
    left: 0;
}

.nav-arrow-right {
    right: 0;
}

/* Soft fade behind each arrow so pills slide under it */
.nav-arrow::before {
    content: "";
    position: absolute;
    top: -8px;
    bottom: -8px;
    width: 44px;
    z-index: -1;
    pointer-events: none;
}

.nav-arrow-left::before {
    left: -2px;
    background: linear-gradient(to right, var(--card) 55%, transparent);
}

.nav-arrow-right::before {
    right: -2px;
    background: linear-gradient(to left, var(--card) 55%, transparent);
}

.nav-pill {
    flex-shrink: 0;
    white-space: nowrap;
    color: var(--muted);
    font-weight: 500;
    font-size: 14.5px;
    padding: 6px 12px;
    border-radius: 8px;
    text-decoration: none;
}

.nav-pill:hover {
    color: var(--ink);
    background: var(--hover);
}

.nav-pill.active {
    color: var(--brand);
    background: var(--brand-soft);
}

.nav-pill i {
    font-size: 11px;
    opacity: .7;
}

.nav-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--hover);
}

/* Light shows the moon (switch to dark); dark shows the sun */
.theme-icon-light,
[data-theme="dark"] .theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-icon-light {
    display: inline;
    color: #fbbf24;
}

/* Dark: the sun sits on a warm glow */
[data-theme="dark"] .theme-toggle {
    background: rgba(251, 191, 36, .14);
    border-color: rgba(251, 191, 36, .45);
    box-shadow: 0 0 0 3px rgba(251, 191, 36, .08);
}

[data-theme="dark"] .theme-toggle:hover {
    background: rgba(251, 191, 36, .24);
}

@media (max-width: 767.98px) {
    .nav-inner {
        flex-wrap: wrap;
        gap: 8px 12px;
    }

    .nav-actions {
        margin-left: auto;
    }

    .nav-strip {
        order: 3;
        flex: 1 1 100%;
    }
}

/* ---------------- Toolbar: search, stars, page size, PDF ---------------- */
.list-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 1px 2px var(--shadow);
}

.list-search {
    position: relative;
    flex: 1 1 280px;
    min-width: 0;
    display: flex;
}

.list-search > i {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.list-search .form-control {
    height: 42px;
    padding-left: 38px;
    border-radius: 10px 0 0 10px;
    border-right: 0;
    background: var(--surface);
}

.list-search .btn {
    border-radius: 0 10px 10px 0;
    padding: 0 18px;
    box-shadow: none;
}

.bar-group {
    height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 0 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.bar-label {
    font-size: 13px;
    color: var(--muted);
    margin-right: 4px;
}

.page-size a {
    min-width: 34px;
    text-align: center;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink-2);
    text-decoration: none;
    padding: 4px 6px;
    border-radius: 7px;
}

.page-size a:hover {
    background: var(--hover);
}

.page-size a.active {
    color: #fff;
    background: var(--brand);
}

.bar-pdf,
.bar-read {
    height: 40px;
    padding: 0 12px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 14.5px;
}

@media (max-width: 575.98px) {
    .list-search {
        flex-basis: 100%;
    }

    .list-bar {
        gap: 8px;
    }

    .bar-group {
        padding: 0 8px;
    }

    .bar-group.star-filter {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
        padding: 0 6px;
    }

    .bar-group.star-filter a {
        font-size: 15px;
        padding: 0;
    }

    .page-size a {
        min-width: 27px;
        padding-left: 4px;
        padding-right: 4px;
    }

    .bar-pdf,
    .bar-read {
        flex-shrink: 0;
    }

    .page-size .bar-label {
        display: none;
    }

    .bar-pdf,
    .bar-read {
        width: 40px;
        padding: 0;
    }
}

/* ---------------- Search ---------------- */
.page-search {
    position: relative;
    display: flex;
    gap: 8px;
}

.page-search > i {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.page-search .form-control {
    padding: 12px 14px 12px 40px;
    border-radius: 12px;
    box-shadow: 0 1px 2px var(--shadow);
}

.page-search .btn {
    border-radius: 12px;
    padding: 0 22px;
}

.filter-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--brand-soft);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
}

.filter-info a {
    text-decoration: none;
}

/* ---------------- Sidebar ---------------- */
.side-card {
    background: var(--side-bg);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 12px;
}

/* Desktop: the sidebar sticks under the navbar, so a long category list scrolls inside it (hidden scrollbar) */
@media (min-width: 992px) {
    .side-card {
        max-height: calc(100vh - 88px);
        overflow-y: auto;
        overscroll-behavior: contain;
        /* Scrolls with the wheel / touch, but no scrollbar is drawn */
        scrollbar-width: none;
    }

    .side-card::-webkit-scrollbar {
        display: none;
    }

    /* Counts sit as far from the right edge as names do from the left (14px), all in one column;
       the expand arrow of a parent category sits just before its count */
    .side-card .side-row .side-link,
    .side-card > a.side-link {
        padding-right: 14px;
    }

    .side-card .side-link .count {
        min-width: 24px;
    }

    .side-card .side-row:has(.side-toggle) .side-link .count {
        margin-left: 26px;
    }

    .side-card .side-row .side-toggle {
        right: 40px;
    }
}

.side-title {
    font-size: 12.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    padding: 4px 12px 12px;
}

.side-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    margin-bottom: 2px;
    border-radius: 9px;
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 400;
    font-size: 14px;
}

.side-link:hover {
    background: var(--hover);
    color: var(--ink);
}

.side-link.active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 500;
}

.side-lock {
    font-size: 11px;
    color: var(--faint);
    margin-left: 3px;
}

.side-row {
    position: relative;
}

/* Every link keeps room for the expand button, so all counts line up in one column */
.side-card .side-link {
    padding-right: 30px;
}

.side-link > span:first-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.side-toggle {
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--faint);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.side-toggle:hover {
    background: var(--line);
    color: var(--ink);
}

.side-toggle i {
    transition: transform .15s;
}

.side-row.open > .side-toggle i {
    transform: rotate(90deg);
}

.side-link.side-sub {
    /* --depth is set per link: 1 = sub, 2 = sub sub, ... */
    padding-top: 8px;
    padding-bottom: 8px;
    padding-left: calc(14px + var(--depth, 1) * 10px);
    font-size: 13.5px;
    position: relative;
}

.side-link.side-sub::before {
    content: "";
    position: absolute;
    left: calc(2px + var(--depth, 1) * 10px);
    top: 50%;
    width: 6px;
    height: 1px;
    background: var(--faint);
}

.side-link .count {
    flex-shrink: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
    color: var(--faint);
    padding: 0;
}

/* ---------------- Index ---------------- */
.index-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 18px;
}

.index-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.index-head h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
}

.index-head h1 span {
    color: var(--muted);
    font-weight: 500;
    font-size: 16px;
}

.index-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13.5px;
    color: var(--muted);
}

.index-meta .pagination {
    margin: 0;
}

/* Laravel's pagination view stretches to full width; keep it compact and pinned to the right */
.index-meta {
    margin-left: auto;
}

.index-meta nav > .d-sm-flex {
    flex: 0 1 auto !important;
    gap: 14px;
    justify-content: flex-end !important;
}

.index-meta nav p {
    margin: 0;
    font-size: 13.5px;
}

.index-meta .page-link {
    padding: 3px 12px;
    font-size: 13px;
}

/* Two columns read top to bottom; each row is number, one-line title, stars */
.index-list {
    columns: 2;
    column-gap: 36px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.index-list li {
    break-inside: avoid;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 7px;
    counter-increment: topic;
}

.index-list li:hover {
    background: var(--hover);
}

.index-list li::before {
    content: counter(topic) ".";
    min-width: 2.2em;
    text-align: right;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

.index-list a {
    flex: 1;
    min-width: 0;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.index-list a:hover {
    color: var(--brand);
}

@media (max-width: 767px) {
    .index-list {
        columns: 1;
    }
}

/* ---------------- Stars ---------------- */

/* Star filter in the toolbar: star N = N or more stars; the active star clears it */
.star-filter {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.star-filter a {
    color: var(--star-off);
    font-size: 17px;
    line-height: 1;
    padding: 1px;
    text-decoration: none;
    transition: color .1s, transform .1s;
}

.star-filter a.on {
    color: var(--star, #f59e0b);
}

/* Hover previews the filter a click would apply */
.star-filter:hover a {
    color: var(--star-off);
}

.star-filter a:hover,
.star-filter a:has(~ a:hover) {
    color: #fbbf24;
    transform: scale(1.1);
}

.star-filter-hint {
    font-size: 12px;
    font-weight: 600;
    color: var(--star, #b45309);
    margin-left: 6px;
}

/* Stars in a topic header (read-only for visitors, clickable when logged in) */
.topic-stars {
    display: inline-flex;
    gap: 2px;
    font-size: 18px;
    line-height: 1;
    white-space: nowrap;
}

.topic-stars i {
    color: var(--star-off);
}

.topic-stars i.on,
.topic-stars button.on i {
    color: var(--star);
}

.topic-stars button {
    border: 0;
    background: transparent;
    padding: 1px;
    cursor: pointer;
    line-height: 1;
}

.topic-stars button:hover i,
.topic-stars button:has(~ button:hover) i {
    color: #fbbf24;
}

.index-stars {
    display: inline-flex;
    gap: 2px;
    flex-shrink: 0;
    color: var(--star, #eab308);
    font-size: 14px;
    line-height: 1;
}

/* ---------------- Topic card ---------------- */
.snippet-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    min-width: 0;
    transition: box-shadow .3s, border-color .3s;
}

.snippet-card.flash {
    animation: flash 1.6s ease;
}

@keyframes flash {
    0%, 40% {
        border-color: var(--brand);
        box-shadow: 0 0 0 4px rgba(79, 70, 229, .18);
    }

    100% {
        border-color: var(--line);
        box-shadow: none;
    }
}

/* One line: number, title, categories, stars ... Index */
.snippet-head {
    display: flex;
    gap: 10px;
    /* The number stays level with the first line of the title when the title wraps (phones) */
    align-items: flex-start;
    margin-bottom: 10px;
}

.snippet-head-main {
    flex: 1;
    min-width: 0;
    /* Centres the first line of the title on the 32px number */
    padding-top: 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
}

.serial {
    flex-shrink: 0;
    min-width: 32px;
    height: 32px;
    padding: 0 7px;
    border-radius: 8px;
    font-size: 14px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.min-w-0 {
    min-width: 0;
}

.snippet-title {
    font-size: 17px;
    font-weight: 700;
    margin: 0;
    line-height: 1.35;
}

.snippet-title a {
    color: var(--ink);
    text-decoration: none;
}

.snippet-title a:hover {
    color: var(--brand);
}

.chip {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 1px 10px;
    text-decoration: none;
    white-space: nowrap;
}

a.chip:hover {
    color: var(--brand);
}

.snippet-question {
    background: var(--surface);
    border-left: 3px solid var(--brand);
    border-radius: 0 8px 8px 0;
    padding: 8px 12px;
    margin-bottom: 8px;
}

.snippet-question .label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--brand);
    margin-bottom: 2px;
}

/* ---------------- Code ---------------- */
/* Editor look (same as the admin import editor): dark body, window dots, name chip, line numbers */
.code-block {
    border-radius: 12px;
    overflow: hidden;
    background: #1e1e2e;
    border: 1px solid transparent;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .12);
    margin-bottom: 12px;
}

[data-theme="dark"] .code-block {
    border-color: #2a2b3d;
    box-shadow: none;
}

.code-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px 8px 14px;
    background: #181825;
    color: #a6adc8;
    font-size: 12.5px;
    min-width: 0;
}

.code-dots {
    display: inline-flex;
    gap: 6px;
    flex-shrink: 0;
}

.code-dots i {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #f38ba8;
}

.code-dots i:nth-child(2) {
    background: #f9e2af;
}

.code-dots i:nth-child(3) {
    background: #a6e3a1;
}

.code-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 3px 10px;
    border-radius: 7px;
    background: #313244;
    color: #cdd6f4;
}

.code-chip i {
    color: #89b4fa;
    flex-shrink: 0;
}

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

.code-lang {
    color: #89b4fa;
    font-weight: 500;
    flex-shrink: 0;
}

.code-meta {
    margin-left: auto;
    color: #7f849c;
    white-space: nowrap;
}

.code-bar button {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #45475a;
    color: #cdd6f4;
    border-radius: 7px;
    font-size: 12px;
    padding: 2px 10px;
    transition: background .15s, border-color .15s;
}

.code-bar button:hover {
    background: #313244;
    border-color: #585b70;
}

.code-body {
    display: flex;
    align-items: flex-start;
}

.code-gutter {
    flex-shrink: 0;
    padding: 12px 10px 12px 14px;
    min-width: 44px;
    text-align: right;
    color: #585b70;
    border-right: 1px solid #313244;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre;
    user-select: none;
}

.code-block pre {
    margin: 0;
    flex: 1;
    min-width: 0;
}

.code-block pre code.hljs,
.code-block pre code {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 13px;
    font-variant-ligatures: none;
    line-height: 1.6;
    padding: 12px 16px;
    display: block;
    overflow-x: auto;
    background: transparent;
    color: #cdd6f4;
}

/* Program output: darker, green text, terminal icon */
.output-block {
    background: #11111b;
}

.output-block .code-bar {
    background: #0b0b12;
}

.output-block .code-chip i {
    color: #a6e3a1;
}

.output-block pre code,
.output-block pre code.hljs {
    color: #a6e3a1;
}

/* ---------------- Notes ---------------- */
.snippet-section {
    margin-top: 10px;
}

.snippet-section h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
}

.snippet-section h3 i {
    color: var(--brand);
}

.text-block {
    margin-bottom: 8px;
    line-height: 1.6;
}

.text-block .rich-text p {
    margin-bottom: 6px;
}

.text-block h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

.rich-text > :last-child {
    margin-bottom: 0;
}

.rich-text pre,
.rich-text code {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 13px;
}

.rich-text ul,
.rich-text ol {
    padding-left: 1.3em;
}

.rich-text table {
    width: auto;
    min-width: 50%;
    border-collapse: collapse;
    margin: 8px 0 12px;
    font-size: 14px;
}

.rich-text th,
.rich-text td {
    border: 1px solid var(--line);
    padding: 6px 12px;
}

.rich-text th {
    background: var(--surface);
    font-weight: 600;
}

.rich-text pre {
    background: #282c34;
    color: #abb2bf;
    border-radius: 10px;
    padding: 12px 14px;
}

.rich-text :not(pre) > code {
    background: var(--brand-soft);
    color: var(--brand-ink);
    padding: 1px 5px;
    border-radius: 4px;
}

/* Figures: every image gets the same 16:9 frame; the unused space is filled with the
   theme colour (white in light, black in dark) so small and odd-shaped images line up */
.rich-text img {
    display: block;
    width: min(100%, 760px) !important;
    height: auto !important;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: var(--figure-bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    margin: 12px auto;
    float: none !important;
}

@media (max-width: 767px) {
    .rich-text table {
        display: block;
        overflow-x: auto;
    }
}

.qa-list {
    padding-left: 1.4em;
    margin: 0;
}

.qa-list li {
    padding: 6px 0;
    border-bottom: 1px dashed var(--line);
}

.qa-list li:last-child {
    border-bottom: 0;
}

.qa-q {
    font-weight: 600;
    margin-bottom: 4px;
}

.qa-a {
    color: var(--ink-2);
}

/* ---------------- Links / buttons ---------------- */
.back-link {
    font-size: 13px;
    text-decoration: none;
    color: var(--muted);
}

.back-link:hover {
    color: var(--brand);
}

.index-link {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 2px 8px;
    border-radius: 6px;
}

.index-link:hover {
    background: var(--brand-soft);
}

.btn-pdf {
    color: #dc2626;
    background: rgba(239, 68, 68, .08);
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: 8px;
    font-weight: 500;
}

.btn-pdf:hover {
    color: #fff;
    background: #dc2626;
    border-color: #dc2626;
}

/* ---------------- Footer / misc ---------------- */
.site-footer {
    position: relative;
    margin-top: 48px;
    background: var(--card);
    border-top: 1px solid var(--line);
    font-size: 14.5px;
    color: var(--muted);
}

/* Thin brand-coloured line across the top edge */
.site-footer::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -1px;
    height: 3px;
    background: linear-gradient(90deg, var(--brand), #8b5cf6, #06b6d4);
}

.footer-grid {
    display: grid;
    grid-template-columns: 1.5fr .8fr .8fr 1.3fr;
    gap: 40px;
    padding: 44px 0 36px;
}

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 19px;
    font-weight: 700;
    color: var(--ink);
    text-decoration: none;
    margin-bottom: 14px;
}

.footer-about p {
    line-height: 1.7;
    margin-bottom: 18px;
    max-width: 360px;
}

.footer-social {
    display: flex;
    gap: 10px;
}

.footer-social a {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    text-decoration: none;
    transition: all .15s;
}

.footer-social a:hover {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    transform: translateY(-2px);
}

.footer-title {
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 16px;
}

.footer-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-col li + li {
    margin-top: 10px;
}

.footer-col a {
    color: var(--muted);
    text-decoration: none;
    transition: color .15s;
}

.footer-col a:hover {
    color: var(--brand);
}

.author-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.author-avatar {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), #8b5cf6);
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: .03em;
}

.author-name {
    color: var(--ink);
    font-weight: 700;
    font-size: 16px;
}

.author-role {
    font-size: 13.5px;
}

.author-facts {
    list-style: none;
    padding: 0;
    margin: 0 0 14px;
    font-size: 13.5px;
}

.author-facts li {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.author-facts i {
    color: var(--brand);
}

.author-phone {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 10px;
}

.author-phone i {
    color: #25d366;
    font-size: 16px;
}

.author-phone:hover {
    color: #25d366;
}

.author-link {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 14px;
    color: var(--brand);
    text-decoration: none;
}

.author-link i {
    transition: transform .15s;
}

.author-link:hover i {
    transform: translateX(3px);
}

.footer-bottom {
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding: 16px 0;
    font-size: 13.5px;
}

.footer-bottom .page-wrap {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.footer-bottom a {
    color: var(--ink-2);
    font-weight: 600;
    text-decoration: none;
}

.footer-bottom a:hover {
    color: var(--brand);
}

@media (max-width: 991.98px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        padding: 34px 0 28px;
    }

    .footer-about,
    .footer-author {
        grid-column: 1 / -1;
    }

    /* Second category column sits beside the first, so its empty heading lines them up */
    .footer-title-spacer {
        display: block;
    }
}

@media (max-width: 575.98px) {
    .footer-bottom .page-wrap {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
}

.to-top {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 0;
    background: var(--brand);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.to-top.show {
    opacity: 1;
    pointer-events: auto;
}

/* ---------------- Page layout ---------------- */
.page-wrap {
    max-width: 1320px;
    padding-left: 24px;
    padding-right: 24px;
}

@media (max-width: 767px) {
    .page-wrap {
        padding-left: 12px;
        padding-right: 12px;
    }
}

@media (min-width: 992px) {
    .side-col {
        width: 320px;
    }
}

.list-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 10px;
}

.snippet-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Phones and small tablets */
@media (max-width: 991.98px) {
    /* Categories become a wrapping row of chips instead of a tall card */
    .side-card {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        padding: 0;
        background: transparent;
        border: 0;
    }

    .side-title {
        display: none;
    }

    .side-link {
        padding: 5px 12px;
        font-size: 14px;
        border: 1px solid var(--line);
        border-radius: 20px;
        background: var(--card);
    }

    .side-link .count {
        padding: 0 0 0 2px;
        min-width: 0;
    }

    .side-card .side-link {
        padding-right: 12px;
    }

    .side-card .side-row:has(.side-toggle) .side-link {
        padding-right: 34px;
    }

    .side-link.side-sub {
        padding-left: 12px;
        font-size: 13.5px;
        border-style: dashed;
    }

    .side-link.side-sub::before {
        display: none;
    }
}

@media (max-width: 575.98px) {
    body {
        font-size: 14.5px;
    }

    .snippet-card {
        padding: 12px;
        border-radius: 10px;
    }

    .snippet-title {
        font-size: 16px;
    }

    .serial {
        min-width: 28px;
        height: 28px;
        font-size: 13px;
    }

    .snippet-head-main {
        padding-top: 3px;
    }

    .code-block pre code.hljs,
    .code-block pre code {
        font-size: 12.5px;
        padding: 10px 12px;
    }

    .code-gutter {
        font-size: 12.5px;
        padding: 10px 8px 10px 10px;
        min-width: 36px;
    }

    .code-meta,
    .code-lang {
        display: none;
    }

    .code-dots {
        display: none;
    }

    .index-card {
        padding: 12px 14px;
    }

    .index-head h1 {
        font-size: 18px;
    }

    .page-search .btn {
        padding: 0 14px;
    }

    .filter-info {
        flex-wrap: wrap;
    }

    .list-toolbar .pagination {
        flex-wrap: wrap;
    }
}

/* ---------------- Reading mode ---------------- */
/* Only the index, the topics and the page numbers stay; everything else steps aside */
html.reading {
    scroll-padding-top: 20px;
}

html.reading .site-navbar,
html.reading .side-col,
html.reading .list-bar,
html.reading .filter-info,
html.reading .site-footer,
html.reading .back-link-sm {
    display: none !important;
}

/* A comfortable reading column in the middle, with wide margins on both sides */
html.reading .page-wrap > .row > .col-lg {
    max-width: 1040px;
    margin: 0 auto;
}

html.reading main {
    padding-top: 56px;
}

.reading-exit {
    display: none;
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    align-items: center;
    gap: 8px;
    padding: 7px 8px 7px 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 8px 24px var(--shadow);
}

.reading-exit > .bi {
    color: var(--brand);
}

.reading-exit-x {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--hover);
    font-size: 12px;
    transition: background .15s, color .15s;
}

.reading-exit:hover .reading-exit-x {
    background: #ef4444;
    color: #fff;
}

html.reading .reading-exit {
    display: inline-flex;
}

.bar-read {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
    font-weight: 500;
}

.bar-read:hover {
    border-color: var(--brand);
    color: var(--brand);
}

/* ---------------- Private (locked) category ---------------- */
/* Takes the full width of the content column; the text stays in a readable centre line */
.locked-card {
    margin: 0;
    padding: 48px 32px;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
}

.locked-icon {
    width: 88px;
    height: 88px;
    margin: 0 auto 20px;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #06b6d4);
    box-shadow: 0 14px 34px rgba(99, 102, 241, .35);
}

.locked-card h2 {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 10px;
}

.locked-card p {
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
    color: var(--muted);
    line-height: 1.7;
    margin-bottom: 16px;
}

.locked-count {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 22px;
}

.locked-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.locked-ip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 auto 20px;
    padding: 6px 6px 6px 14px;
    border-radius: 12px;
    border: 1px dashed var(--line);
    background: var(--surface);
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: center;
}

.locked-ip-label {
    font-size: 13px;
    color: var(--muted);
}

.locked-ip code {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    background: transparent;
    word-break: break-all;
}

.locked-ip-copy {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
}

.locked-ip-copy:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.btn-whatsapp {
    background: #25d366;
    border-color: #25d366;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(37, 211, 102, .3);
}

.btn-whatsapp:hover {
    background: #1ebe5b;
    border-color: #1ebe5b;
    color: #fff;
}

.locked-contact {
    margin-top: 18px;
    font-size: 13.5px;
    color: var(--muted);
}

.locked-contact .bi-whatsapp {
    color: #25d366;
}

.locked-contact a {
    color: var(--ink-2);
    font-weight: 600;
    text-decoration: none;
}

.locked-contact a:hover {
    color: var(--brand);
}

.locked-sep {
    margin: 0 6px;
}

.btn-soft-outline {
    border: 1px solid var(--line);
    color: var(--ink-2);
    background: transparent;
}

.btn-soft-outline:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.back-link-sm {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

/* Phones: title, category chips and stars share one line when they fit, and wrap only when needed */
@media (max-width: 767px) {
    .snippet-head {
        gap: 8px;
    }

    .snippet-head-main {
        gap: 4px 6px;
    }

    .snippet-title {
        font-size: 16px;
    }

    .snippet-head .chip {
        font-size: 11px;
        padding: 1px 8px;
    }

    .topic-stars {
        font-size: 13px;
        gap: 1px;
    }

    .topic-stars button {
        padding: 0;
    }

    /* The index link keeps just its icon */
    .index-link {
        padding: 2px 4px;
        font-size: 0;
    }

    .index-link i {
        font-size: 15px;
    }
}

/* ---------------- Edit mode (logged-in admin) ---------------- */
.edit-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 6px 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 500;
}

.edit-mode-state {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: var(--hover);
    color: var(--muted);
}

.edit-mode-toggle.on {
    border-color: #f59e0b;
    color: var(--ink);
}

.edit-mode-toggle.on .edit-mode-state {
    background: #f59e0b;
    color: #fff;
}

/* Edit button in each topic header (before Index), only while edit mode is on */
.topic-edit-btn {
    display: none;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 2px 10px;
    border-radius: 7px;
    border: 1px solid rgba(245, 158, 11, .55);
    background: rgba(245, 158, 11, .14);
    color: #f59e0b;
    font-size: 13px;
    font-weight: 600;
}

.topic-edit-btn:hover {
    background: #f59e0b;
    color: #fff;
}

html.edit-mode .topic-edit-btn {
    display: inline-flex;
}

.snippet-card.is-editing .topic-edit-btn {
    display: none;
}

.snippet-card.is-editing {
    outline: 2px solid rgba(245, 158, 11, .6);
    outline-offset: 2px;
}

/* Note being edited: the text itself becomes editable */
.rich-text[contenteditable="true"] {
    outline: 2px solid #f59e0b;
    outline-offset: 6px;
    border-radius: 6px;
    background: rgba(245, 158, 11, .05);
}

/* Code being edited: a plain text box in the code block */
.inline-code-input {
    display: block;
    width: 100%;
    min-height: 120px;
    padding: 12px 16px;
    border: 0;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    background: #11111b;
    color: #cdd6f4;
    font: 13px/1.6 'JetBrains Mono', Consolas, monospace;
    white-space: pre;
    overflow: auto hidden;
    resize: vertical;
    tab-size: 4;
}

.inline-edit-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 10px;
    margin-top: 10px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.inline-edit-hint {
    margin-right: auto;
    font-size: 12px;
    color: var(--muted);
}

.site-flash.is-error {
    background: #dc2626;
    box-shadow: 0 10px 26px rgba(220, 38, 38, .35);
}

@media (max-width: 767px) {
    .inline-edit-hint {
        display: none;
    }

    .edit-mode-toggle {
        padding: 0 5px 0 10px;
    }

    .topic-edit-btn span {
        display: none;
    }
}

.site-flash {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1060;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: #16a34a;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 10px 26px rgba(22, 163, 74, .35);
    transition: opacity .4s, transform .4s;
}

.site-flash.hide {
    opacity: 0;
    transform: translate(-50%, -10px);
    pointer-events: none;
}
