/*
 * The Source — page-specific styling.
 * Sits on top of redesign.css and inherits every theme variable
 * (ember / abyss / parchment / frost / verdant / dusk).
 */

[data-theme="redesign"] {
    --source-rule:        rgba(var(--highlight-rgb), 0.22);
    --source-rule-strong: rgba(var(--highlight-rgb), 0.45);
    --source-faint:       rgba(var(--warm-white-rgb), 0.32);
    --source-deep:        color-mix(in srgb, var(--bg-body) 70%, black);
    --source-unsanc:      var(--error);
    --source-unsanc-deep: color-mix(in srgb, var(--error) 70%, black);
    --source-unsanc-bg:   var(--error-bg);
    --source-verified:    var(--accent);
}
@supports not (background: color-mix(in srgb, red, blue)) {
    [data-theme="redesign"] {
        --source-deep: rgba(0,0,0,.4);
        --source-unsanc-deep: var(--error);
    }
}

/* ----- SCRIPTORIUM HERO ----- */
.scriptorium {
    border-bottom: 1px solid var(--border);
    padding: 3.25rem 2rem 2.5rem;
    text-align: center;
    background:
        radial-gradient(circle at 50% 0%, var(--accent-muted), transparent 55%),
        linear-gradient(180deg, var(--bg-header) 0%, var(--bg-body) 100%);
    position: relative;
    overflow: hidden;
}
.scriptorium::after {
    content: '';
    position: absolute;
    top: -120px;
    left: 50%;
    transform: translateX(-50%);
    width: 540px;
    height: 540px;
    border: 1px solid var(--source-rule);
    border-radius: 50%;
    box-shadow:
        0 0 0 60px rgba(var(--highlight-rgb),.025) inset,
        0 0 0 120px rgba(var(--highlight-rgb),.018) inset,
        0 0 0 180px rgba(var(--highlight-rgb),.012) inset;
    pointer-events: none;
    opacity: .55;
}
.seal {
    width: 58px; height: 58px;
    margin: 0 auto 1.25rem;
    display: block;
    color: var(--highlight);
    filter: drop-shadow(0 0 18px rgba(var(--highlight-rgb),.18));
}
.codex-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(2.4rem, 5vw, 3.8rem);
    color: var(--text-bright);
    letter-spacing: -.01em;
    line-height: 1;
    margin: 0 0 .4rem;
}
.codex-title em { color: var(--highlight); font-style: italic; }
.codex-rubric {
    font-family: var(--font-prose);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .32em;
    color: var(--text-dim);
    margin-top: .65rem;
}
.codex-rubric .dot { color: var(--highlight); margin: 0 .5rem; }

.codex-search {
    margin: 2rem auto 0;
    max-width: 640px;
    position: relative;
}
.codex-search input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-bottom: 1px solid var(--source-rule);
    color: var(--text-bright);
    padding: .95rem 1.25rem .95rem 3rem;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.05rem;
    letter-spacing: .01em;
    outline: none;
    border-radius: var(--radius-sm);
    transition: border-color .25s, background .25s, box-shadow .25s;
}
.codex-search input::placeholder { color: var(--text-dim); font-style: italic; }
.codex-search input:focus {
    border-color: var(--source-rule-strong);
    background: var(--source-deep, var(--bg-secondary));
    box-shadow: 0 0 0 1px var(--source-rule-strong), 0 0 40px -8px rgba(var(--highlight-rgb),.15);
}
.codex-search .quill-icon {
    position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
    color: var(--highlight); width: 18px; height: 18px; pointer-events: none;
}
.codex-search .search-hint {
    position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
    font-size: .7rem; color: var(--text-dim);
    letter-spacing: .15em; text-transform: uppercase; pointer-events: none;
}
.codex-search .search-hint kbd {
    background: var(--bg-panel); border: 1px solid var(--border);
    padding: 2px 6px; font-family: var(--font-mono, monospace);
    font-size: .65rem; color: var(--text); margin: 0 2px;
    border-radius: var(--radius-sm);
}

/* ----- RUBRIC TABS ----- */
.rubric-bar {
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    padding: 0 2rem;
    position: sticky; top: 0; z-index: 30;
    backdrop-filter: blur(8px);
}
.rubric-list {
    display: flex; gap: 0;
    max-width: 1400px; margin: 0 auto;
    list-style: none; padding: 0;
    overflow-x: auto; scrollbar-width: none;
}
.rubric-list::-webkit-scrollbar { display: none; }
.rubric {
    flex-shrink: 0;
    padding: 1rem 1.25rem .9rem;
    color: var(--text-dim);
    text-decoration: none;
    transition: color .2s;
    position: relative;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 1rem;
    letter-spacing: .01em;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    display: flex; align-items: center; gap: .5rem;
}
.rubric .glyph { color: var(--source-faint); font-size: .9rem; transition: color .25s; }
.rubric:hover { color: var(--text-bright); }
.rubric:hover .glyph { color: var(--highlight); }
.rubric.active { color: var(--text-bright); border-bottom-color: var(--highlight); }
.rubric.active .glyph { color: var(--highlight); }
.rubric .count {
    font-family: var(--font-prose); font-style: normal; font-size: .65rem;
    color: var(--text-dim); margin-left: .4rem; letter-spacing: .05em; opacity: .7;
}
.rubric.active .count { color: var(--highlight); opacity: 1; }

/* ----- PAGE LAYOUT: left + main + right, full viewport ----- */
/* Escape the .container max-width and padding that the site layout
   wraps every page in. The :has() override widens .container; the
   negative margin eats its 1.5rem padding so the asides hug the
   actual viewport edges. */
.container:has(.codex-layout) { max-width: none; padding: 0; }
.codex-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 260px;
    gap: 0;
    align-items: start;
    margin: 0;
}
.scriptorium { margin: 0; }
@media (max-width: 1200px) {
    .codex-layout { grid-template-columns: 220px minmax(0, 1fr); }
    .codex-aside-right { display: none; }
}
@media (max-width: 900px) {
    .codex-layout { grid-template-columns: minmax(0, 1fr); }
    .codex-aside-left { display: none; }
}

.codex-aside {
    position: sticky;
    top: 32px;                 /* sit just under the sticky .navbar (32px tall) */
    align-self: stretch;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    background: var(--bg-sidebar, var(--bg-secondary));
    scrollbar-width: thin;
}
@media (max-width: 760px) {
    .codex-aside { top: 40px; max-height: calc(100vh - 40px); } /* mobile navbar */
}
.codex-aside::-webkit-scrollbar { width: 6px; }
.codex-aside::-webkit-scrollbar-thumb { background: var(--border); }
.codex-aside-left  { border-right: 1px solid var(--border); }
.codex-aside-right { border-left:  1px solid var(--border); }

.codex-main {
    padding: 2rem 2.5rem;
    min-width: 0;
}
.codex-main-feed > * { max-width: 920px; margin-left: auto; margin-right: auto; }
@media (max-width: 720px) {
    .codex-main { padding: 1.25rem 1rem; }
}

/* ----- DASHBOARD STATS BAR ----- */
.dashboard-stats {
    text-align: center;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .22em;
    color: var(--text-dim);
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}
.dashboard-stats strong {
    color: var(--highlight);
    font-family: var(--font-mono, monospace);
    font-weight: 500;
    margin: 0 .25rem;
    letter-spacing: 0;
}
.dashboard-stats .sep { color: var(--text-dim); margin: 0 .6em; opacity: .5; }

/* ----- TOPIC GRID (dashboard landing) ----- */
.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}
.topic-card {
    display: flex; flex-direction: column;
    padding: 1.1rem 1.2rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, background .15s, transform .15s;
    position: relative;
    overflow: hidden;
    min-height: 160px;
}
.topic-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background: var(--source-faint);
    transition: background .15s;
}
.topic-card:hover {
    border-color: var(--source-rule-strong);
    background: var(--bg-hover);
    transform: translateY(-1px);
}
.topic-card:hover::before { background: var(--highlight); }
.topic-card[data-kind="qrace"]::before,
.topic-card[data-kind="qclass"]::before { background: var(--source-unsanc-deep); }
.topic-card[data-kind="qrace"]:hover::before,
.topic-card[data-kind="qclass"]:hover::before { background: var(--source-unsanc); }

.topic-card-head {
    display: flex; align-items: baseline; gap: .55rem;
    margin-bottom: .6rem;
}
.topic-card-glyph {
    color: var(--highlight); font-size: 1rem; flex-shrink: 0;
}
.topic-card-title {
    flex: 1; margin: 0;
    font-family: var(--font-display); font-style: italic; font-weight: 600;
    font-size: 1.25rem; color: var(--text-bright);
    letter-spacing: -.005em; line-height: 1.1;
}
.topic-card-count {
    font-family: var(--font-mono, monospace);
    font-size: .76rem; color: var(--text-dim);
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 1px 8px;
    border-radius: 99px;
}
.topic-card-preview {
    margin: 0 0 .9rem;
    font-size: .9rem; line-height: 1.55;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.topic-card-foot {
    margin-top: auto;
    display: flex; justify-content: space-between; align-items: baseline;
    gap: .5rem;
    font-size: .72rem;
    color: var(--text-dim);
}
.topic-card-by {
    font-style: italic;
    font-family: var(--font-display);
    font-size: .82rem;
}
.topic-card-when {
    font-family: var(--font-mono, monospace);
    text-transform: uppercase;
    letter-spacing: .1em;
}

/* ----- FEED LAYOUT (filtered view) ----- */
.feed-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 2.5rem;
    align-items: start;
}
@media (max-width: 980px) {
    .feed-layout { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
    .feed-aside { display: none; }
}
.feed-aside {
    position: sticky; top: 70px;
    max-height: calc(100vh - 90px); overflow-y: auto;
    padding-right: .5rem;
}
.feed-main { min-width: 0; }

.crumb-back {
    text-decoration: none;
    color: var(--text-dim);
    font-style: normal;
    font-size: .7em;
    text-transform: uppercase;
    letter-spacing: .15em;
    margin-right: .35rem;
}
.crumb-back:hover { color: var(--highlight); }
.crumb-sep { color: var(--text-dim); margin: 0 .4rem; opacity: .5; font-style: normal; }
.sep { color: var(--text-dim); margin: 0 .5em; opacity: .5; }
.source-empty-hint {
    font-size: .85em; font-style: normal;
    font-family: var(--font-prose);
    letter-spacing: .15em; text-transform: uppercase;
    margin-top: .5rem;
}

/* Hide the legacy left/right rails — feed-layout has its own aside */
.left-rail, .right-rail { display: none; }

/* ----- ASIDE SECTIONS (left + right) ----- */
.aside-section + .aside-section { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.aside-heading {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 600;
    font-size: .92rem;
    color: var(--text-bright);
    margin-bottom: .55rem;
    letter-spacing: .01em;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}
.aside-meta {
    font-family: var(--font-prose);
    font-style: normal;
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: var(--text-dim);
    opacity: .7;
}
.aside-fold {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
.aside-fold::-webkit-details-marker { display: none; }
.aside-fold::before {
    content: '▸';
    color: var(--text-dim);
    margin-right: .35em;
    transition: transform .15s ease;
    display: inline-block;
}
.aside-section[open] .aside-fold::before { transform: rotate(90deg); }

.aside-list {
    list-style: none;
    padding: 0; margin: 0;
    display: flex; flex-direction: column;
    gap: .12rem;
}
.aside-topics { max-height: 50vh; overflow-y: auto; scrollbar-width: thin; }
.aside-topics::-webkit-scrollbar { width: 4px; }
.aside-topics::-webkit-scrollbar-thumb { background: var(--border-hover); }

.aside-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .28rem .4rem;
    color: var(--text);
    font-size: .82rem;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: background .12s, border-color .12s, color .12s;
}
.aside-row:hover { background: var(--bg-hover); color: var(--text-bright); }
.aside-row.active {
    background: var(--accent-muted);
    border-left-color: var(--highlight);
    color: var(--text-bright);
}
.aside-row[data-kind="qrace"],
.aside-row[data-kind="qclass"] { color: var(--source-unsanc); }
.aside-row[data-kind="qrace"]:hover,
.aside-row[data-kind="qclass"]:hover { color: var(--text-bright); background: var(--source-unsanc-bg); }
.aside-glyph {
    width: 16px;
    flex-shrink: 0;
    color: var(--source-faint);
    text-align: center;
    font-size: .85rem;
}
.aside-row:hover .aside-glyph,
.aside-row.active .aside-glyph { color: var(--highlight); }
.aside-row > :nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aside-count {
    font-family: var(--font-mono, monospace);
    font-size: .66rem;
    color: var(--text-dim);
    opacity: .65;
}

.aside-stat-row {
    font-size: .8rem;
    color: var(--text-dim);
    padding: .2rem 0;
    text-transform: uppercase;
    letter-spacing: .1em;
}
.aside-stat-row strong {
    color: var(--highlight);
    font-family: var(--font-mono, monospace);
    font-weight: 500;
    letter-spacing: 0;
}
.aside-stat-faint { color: var(--text-dim); opacity: .6; font-size: .68rem; }

/* ----- LEFT RAIL ----- */
.left-rail {
    position: sticky; top: 70px; align-self: start;
    max-height: calc(100vh - 90px); overflow-y: auto; padding-right: .5rem;
}
.rail-section + .rail-section { margin-top: 2rem; }
.rail-heading {
    font-family: var(--font-display); font-style: italic; font-weight: 600;
    font-size: .95rem; color: var(--text-bright); letter-spacing: .01em;
    padding-bottom: .5rem; margin-bottom: .75rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: baseline; justify-content: space-between;
}
.rail-heading .meta {
    font-family: var(--font-prose); font-style: normal; font-size: .65rem;
    letter-spacing: .15em; text-transform: uppercase; color: var(--text-dim); opacity: .7;
}

.topic-list { list-style: none; display: flex; flex-direction: column; gap: .15rem; padding: 0; }
.topic-row {
    display: flex; align-items: center; gap: .55rem;
    padding: .3rem .5rem;
    color: var(--text); font-size: .85rem;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: background .12s, border-color .12s, color .12s;
    font-family: var(--font-display); font-style: italic;
}
.topic-row:hover { background: var(--bg-hover); color: var(--text-bright); }
.topic-row.active {
    background: var(--accent-muted);
    border-left-color: var(--highlight);
    color: var(--text-bright);
}
.topic-row .topic-glyph {
    width: 18px; flex-shrink: 0;
    color: var(--source-faint);
    font-size: .9rem;
    text-align: center;
    transition: color .15s;
    font-style: normal;
}
.topic-row:hover .topic-glyph,
.topic-row.active .topic-glyph { color: var(--highlight); }
.topic-row .name { flex: 1; }
.topic-row .post-count {
    font-family: var(--font-mono, monospace); font-size: .68rem;
    color: var(--text-dim); opacity: .65; font-style: normal;
}

/* Foldable scribes/etc. sections in the left rail */
.rail-fold { padding: 0; }
.rail-fold-heading {
    list-style: none;
    cursor: pointer;
    padding-bottom: .5rem;
    user-select: none;
}
.rail-fold-heading::-webkit-details-marker { display: none; }
.rail-fold-heading::before {
    content: '▸';
    color: var(--text-dim);
    margin-right: .4em;
    transition: transform .15s ease;
    display: inline-block;
}
.rail-fold[open] .rail-fold-heading::before { transform: rotate(90deg); }

.author-list { list-style: none; display: flex; flex-direction: column; gap: .25rem; padding: 0; }
.author-row {
    display: flex; align-items: center; gap: .5rem;
    padding: .35rem .5rem;
    color: var(--text); font-size: .84rem;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: background .15s, border-color .15s, color .15s;
}
.author-row:hover { background: var(--bg-hover); color: var(--text-bright); }
.author-row.active {
    background: var(--accent-muted);
    border-left-color: var(--highlight);
    color: var(--text-bright);
}
.author-row .monogram {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--source-rule); color: var(--highlight);
    font-family: var(--font-display); font-style: italic; font-weight: 500;
    font-size: .78rem; flex-shrink: 0;
}
.author-row .name { flex: 1; }
.author-row .post-count {
    font-family: var(--font-mono, monospace); font-size: .7rem;
    color: var(--text-dim); opacity: .7;
}

/* ----- MAIN FEED ----- */
.feed-meta {
    display: flex; align-items: baseline; justify-content: space-between;
    padding-bottom: 1rem; border-bottom: 1px solid var(--border);
    margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.feed-meta .crumb {
    font-family: var(--font-display); font-style: italic; font-size: 1.4rem;
    color: var(--text-bright);
}
.feed-meta .crumb .of { color: var(--text-dim); margin: 0 .5rem; opacity: .6; }
.feed-meta .stat {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .2em; color: var(--text-dim);
}
.feed-meta .stat strong {
    color: var(--highlight); font-weight: 500;
    font-family: var(--font-mono, monospace); margin: 0 .25rem;
}

.day-divider {
    display: flex; align-items: center; gap: 1rem;
    margin: 2.5rem 0 1.5rem; color: var(--text-dim);
}
.day-divider::before, .day-divider::after {
    content: ''; flex: 1; height: 1px;
    background: linear-gradient(90deg, transparent, var(--source-rule) 40%, var(--source-rule) 60%, transparent);
}
.day-divider .day {
    font-family: var(--font-display); font-style: italic; font-size: 1rem;
    color: var(--text); letter-spacing: .02em;
}
.day-divider .ornament { color: var(--highlight); font-size: .95rem; }

.fragment {
    position: relative;
    padding: 1.4rem 1.5rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 2px solid transparent;
    margin-bottom: 1rem;
    transition: border-color .2s, background .2s;
    border-radius: var(--radius-sm);
    scroll-margin-top: 80px;
}
/* Compact variant used in the feed view */
.fragment-compact {
    padding: .85rem 1.1rem;
    margin-bottom: .6rem;
}
.fragment-compact .fragment-head {
    margin-bottom: .35rem;
    gap: .5rem;
}
.fragment-compact .author-name {
    font-size: .95rem;
    text-decoration: none;
}
.fragment-compact .author-name:hover { color: var(--highlight); }
.fragment-compact .fragment-body { font-size: 1rem; line-height: 1.65; }
.fragment-compact .fragment-foot { margin-top: .55rem; padding-top: .5rem; }
.fragment:hover {
    border-color: var(--border-hover);
    border-left-color: var(--highlight);
    background: var(--bg-hover);
}
.fragment.flagged-unsanctioned { border-left-color: var(--source-unsanc-deep); }
.fragment.flagged-unsanctioned:hover { border-left-color: var(--source-unsanc); }
.fragment:target {
    border-color: var(--source-rule-strong);
    box-shadow: 0 0 0 1px var(--source-rule-strong), 0 0 30px -8px rgba(var(--highlight-rgb),.25);
}

.fragment-head {
    display: flex; align-items: baseline; gap: .6rem;
    margin-bottom: .6rem; flex-wrap: wrap;
}
.fragment-head .monogram {
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--source-rule); color: var(--highlight);
    font-family: var(--font-display); font-style: italic; font-size: 1rem;
    flex-shrink: 0; align-self: center;
}
.fragment-head .author-name {
    font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
    color: var(--text-bright);
}
.fragment-head .timestamp {
    font-family: var(--font-mono, monospace); font-size: .72rem;
    color: var(--text-dim); letter-spacing: .02em; opacity: .85;
}
.fragment-head .timestamp::before { content: '·'; margin: 0 .4rem; color: var(--text-dim); opacity: .5; }
.fragment-head .category-tag {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: 2px 8px; border: 1px solid var(--source-rule);
    color: var(--highlight); font-size: .65rem;
    letter-spacing: .15em; text-transform: uppercase;
    margin-left: auto; font-family: var(--font-prose);
    border-radius: var(--radius-sm);
}
.fragment-head .category-tag.unsanctioned {
    border-color: var(--source-unsanc-deep); color: var(--source-unsanc);
}
.fragment-head .category-tag.verified {
    border-color: rgba(var(--accent-rgb),.35); color: var(--accent);
}

.fragment-body {
    color: var(--text); font-size: 1rem; line-height: 1.65;
}
.fragment-body p + p { margin-top: .6rem; }
.fragment-body code:not(pre code) {
    font-family: var(--font-mono, monospace); font-size: .85em;
    background: var(--bg-code); padding: .05em .4em;
    color: var(--highlight); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.fragment-body pre {
    background: var(--bg-code); border: 1px solid var(--border);
    border-left: 2px solid var(--source-rule-strong);
    padding: .9rem 1rem; margin: .8rem 0; overflow-x: auto;
    font-family: var(--font-mono, monospace); font-size: .83rem;
    line-height: 1.55; color: var(--text-bright);
    border-radius: var(--radius-sm);
}
.fragment-body blockquote {
    border-left: 2px solid var(--source-rule); padding-left: 1rem;
    margin: .8rem 0; color: var(--text-dim); font-style: italic;
    font-family: var(--font-display); font-size: 1rem;
}

.fragment-attachments {
    display: flex; flex-wrap: wrap; gap: .6rem;
    margin-top: .8rem;
}
.fragment-attachments .fragment-image {
    display: block;
    max-width: 320px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color .15s;
}
.fragment-attachments .fragment-image:hover { border-color: var(--source-rule-strong); }
.fragment-attachments .fragment-image img {
    display: block;
    width: 100%; height: auto;
    max-height: 280px;
    object-fit: cover;
    background: var(--bg-input);
}
.fragment-attachments .fragment-file {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .35rem .7rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono, monospace);
    font-size: .78rem;
}
.fragment-attachments .fragment-file:hover {
    color: var(--highlight); border-color: var(--source-rule);
}

.fragment-foot {
    display: flex; align-items: center; gap: .75rem;
    margin-top: .9rem; padding-top: .7rem;
    border-top: 1px dashed var(--border);
    opacity: 0; transition: opacity .2s;
}
.fragment:hover .fragment-foot,
.fragment:focus-within .fragment-foot,
.fragment:target .fragment-foot { opacity: 1; }
.fragment-foot a, .fragment-foot button {
    background: none; border: none;
    color: var(--text-dim); cursor: pointer; font: inherit;
    font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
    display: inline-flex; align-items: center; gap: .3rem;
    transition: color .15s; padding: 0; text-decoration: none;
}
.fragment-foot a:hover, .fragment-foot button:hover { color: var(--highlight); }
.fragment-foot .spacer { flex: 1; }
.fragment-foot .perma {
    font-family: var(--font-mono, monospace); color: var(--text-dim);
    font-size: .7rem; opacity: .65;
}

.thread {
    margin: -1rem 0 1rem 2.5rem;
    padding-left: 1.25rem;
    border-left: 1px solid var(--border);
}
.thread .fragment {
    background: var(--bg-secondary);
    padding: 1rem 1.25rem; margin-bottom: .5rem;
    font-size: .92rem;
}

/* ----- RIGHT RAIL ----- */
.right-rail {
    position: sticky; top: 70px; align-self: start;
    max-height: calc(100vh - 90px); overflow-y: auto; padding-left: .5rem;
}
.timeline {
    list-style: none; border-left: 1px solid var(--border);
    margin-left: .5rem; padding-left: 0; position: relative;
}
.timeline-year {
    font-family: var(--font-display); font-style: italic; font-weight: 600;
    color: var(--highlight); font-size: 1.05rem;
    padding: .6rem 0 .3rem .8rem; margin-left: -1px;
    border-left: 2px solid var(--highlight); letter-spacing: .04em;
    background: linear-gradient(90deg, var(--accent-muted), transparent 60%);
}
.timeline-year:not(:first-child) { margin-top: .8rem; }
.timeline-month {
    display: block;
    padding: .3rem .8rem .3rem 1rem;
    color: var(--text); font-size: .82rem;
    text-decoration: none;
    position: relative;
    transition: color .15s, background .15s;
    border-left: 2px solid transparent;
    margin-left: -1px;
}
.timeline-month::before {
    content: ''; position: absolute; left: -4px; top: 50%;
    transform: translateY(-50%);
    width: 6px; height: 6px;
    background: var(--text-dim); border-radius: 50%;
    transition: background .15s, transform .15s; opacity: .5;
}
.timeline-month:hover {
    color: var(--text-bright); background: var(--bg-hover);
}
.timeline-month:hover::before { background: var(--highlight); transform: translateY(-50%) scale(1.4); opacity: 1; }
.timeline-month.current { color: var(--text-bright); border-left-color: var(--highlight); }
.timeline-month.current::before { background: var(--highlight); opacity: 1; }
.timeline-month .count {
    color: var(--text-dim); font-family: var(--font-mono, monospace);
    font-size: .7rem; margin-left: .3rem; opacity: .7;
}

/* ----- FOOTER ----- */
.codex-foot {
    border-top: 1px solid var(--border);
    margin-top: 4rem; padding: 2.5rem 2rem;
    text-align: center;
    background: var(--bg-secondary);
    font-family: var(--font-display); font-style: italic;
    color: var(--text-dim);
    font-size: .95rem; letter-spacing: .02em;
}
.codex-foot p + p { margin-top: .5rem; }
.codex-foot .ornament-row {
    color: var(--source-rule-strong); letter-spacing: .4em;
    margin-bottom: 1rem; font-size: .85rem;
}
.codex-foot code {
    font-family: var(--font-mono, monospace); font-style: normal;
    background: var(--bg-input); padding: 2px 8px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--highlight);
}
.codex-foot .source-tag {
    display: inline-block; margin-top: 1rem;
    font-size: .75rem; color: var(--text-dim);
    letter-spacing: .18em; text-transform: uppercase;
    font-style: normal; font-family: var(--font-prose);
}

/* ----- FLOATING RIBBON ----- */
.unsanctioned-ribbon {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    background: var(--bg-panel); border: 1px solid var(--source-unsanc-deep);
    padding: .5rem .9rem; color: var(--source-unsanc);
    font-size: .66rem; letter-spacing: .22em; text-transform: uppercase;
    font-family: var(--font-prose); font-weight: 500;
    display: flex; align-items: center; gap: .5rem;
    z-index: 50; box-shadow: 0 6px 32px rgba(0,0,0,.6);
    border-radius: var(--radius-sm);
}
.unsanctioned-ribbon::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
    background: var(--source-unsanc);
    box-shadow: 0 0 8px var(--source-unsanc);
    animation: source-pulse 2.4s ease-in-out infinite;
}
@keyframes source-pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* Parchment nudge */
[data-theme="redesign"][data-scheme="parchment"] .scriptorium {
    background:
        radial-gradient(circle at 50% 0%, rgba(0,0,0,.04), transparent 55%),
        linear-gradient(180deg, var(--bg-header) 0%, var(--bg-body) 100%);
}
[data-theme="redesign"][data-scheme="parchment"] .seal {
    filter: drop-shadow(0 0 12px rgba(0,0,0,.08));
}

/* Empty state */
.source-empty {
    text-align: center; padding: 4rem 2rem;
    color: var(--text-dim);
    font-family: var(--font-display); font-style: italic; font-size: 1.1rem;
}
.source-empty p { margin: .5rem 0; }
.source-empty .ornament {
    color: var(--source-rule-strong); letter-spacing: .4em;
    margin-bottom: 1rem; font-size: 1rem;
}
