/*
 * Reader rails.
 * The Trails rail is always-on chrome on the right. It is fixed in the
 * margin, or stacked after the article below 1200px, so the text column
 * box does not move.
 * The browse and research rails stay with the ?mode=adaptive prototype:
 * without that flag the browse rail is hidden and the research rail
 * unwraps so backlinks and open questions stay in the article. With the
 * flag, those two rails are fixed in the side margins and the Trails
 * rail steps aside. Mode changes only opacity and emphasis, never the
 * text column's box.
 */

.reader-rail--browse {
    display: none;
}

.reader-rail--research {
    display: contents;
}

.reader-rail-search,
.reader-rail-kicker,
.reader-trail-list,
.reader-related,
.reader-rail-status,
.reader-rail-empty {
    display: none;
}

.post > .reader-rail--research > .garden-notes-panels,
.post > .reader-rail--research > .backlinks {
    grid-column: main;
    min-width: 0;
}

html.reader-adaptive .reader-rail {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    position: fixed;
    top: 7.2rem;
    z-index: 20;
    width: min(24rem, calc((100vw - 78ch) / 2 - 2.4rem));
    max-height: calc(100vh - 10rem);
    overflow: auto;
    padding: 1.4rem 1.2rem 1.6rem;
    background: color-mix(in srgb, var(--rp-surface) 94%, transparent);
    border: 1px solid var(--rp-highlight-med);
    border-radius: 0.8rem;
    transition: none;
}

html.reader-adaptive .reader-rail--browse {
    left: 1.2rem;
}

html.reader-adaptive .reader-rail--research {
    right: 1.2rem;
}

html.reader-adaptive .reader-rail-kicker,
html.reader-adaptive .reader-rail-status,
html.reader-adaptive .reader-trail-list,
html.reader-adaptive .reader-related,
html.reader-adaptive .reader-rail-search,
html.reader-adaptive .reader-rail-empty {
    display: block;
}

html.reader-adaptive .reader-rail-kicker {
    font-size: 1.2rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rp-subtle);
    margin: 0;
}

html.reader-adaptive .reader-rail-status {
    font-size: 1.5rem;
    color: var(--rp-text);
    margin: 0;
}

html.reader-adaptive .reader-trail-list,
html.reader-adaptive .reader-related,
html.reader-adaptive .reader-rail-search ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.6rem;
}

html.reader-adaptive .reader-rail a {
    color: var(--rp-foam);
    text-decoration: none;
    font-size: 1.4rem;
}

html.reader-adaptive .reader-rail a:hover {
    color: var(--rp-rose);
    text-decoration: underline;
    text-underline-offset: 0.2rem;
}

html.reader-adaptive .reader-rail-search label {
    display: block;
    font-size: 1.2rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rp-subtle);
    margin-bottom: 0.4rem;
}

html.reader-adaptive .reader-rail-search input {
    width: 100%;
    font: inherit;
    font-size: 1.4rem;
    color: var(--rp-text);
    background: var(--rp-base);
    border: 1px solid var(--rp-highlight-med);
    border-radius: 0.4rem;
    padding: 0.6rem 0.8rem;
}

html.reader-adaptive .reader-rail .garden-notes-panels,
html.reader-adaptive .reader-rail .backlinks {
    margin: 0;
}

html.reader-adaptive .reader-rail .garden-panel,
html.reader-adaptive .reader-rail .backlinks {
    background: transparent;
    border: 0;
    padding: 0;
}

/* Emphasis only. Opacity and outline do not change the text column box. */
html.reader-adaptive[data-reader-mode="browse"] .reader-rail--research {
    opacity: 0.42;
}

html.reader-adaptive[data-reader-mode="research"] .reader-rail--browse {
    opacity: 0.42;
}

html.reader-adaptive[data-reader-mode="research"] .reader-rail--research {
    border-color: var(--rp-iris);
}

html.reader-adaptive[data-reader-mode="deep-read"] .reader-rail {
    opacity: 0.08;
}

html.reader-adaptive[data-reader-mode="deep-read"] .navigation {
    opacity: 0.5;
}

html.reader-adaptive[data-reader-mode="deep-read"] .post-meta,
html.reader-adaptive[data-reader-mode="deep-read"] .post-tags,
html.reader-adaptive[data-reader-mode="deep-read"] .share-meta {
    opacity: 0.45;
}

html.reader-adaptive[data-reader-mode="browse"] .trail-row {
    outline: 2px solid color-mix(in srgb, var(--rp-foam) 75%, transparent);
    outline-offset: 4px;
}

html.reader-adaptive[data-reader-mode="research"] .search-bar,
html.reader-adaptive[data-reader-mode="research"] .filter-panel {
    outline: 2px solid color-mix(in srgb, var(--rp-iris) 80%, transparent);
    outline-offset: 4px;
}

html.reader-adaptive[data-reader-mode="deep-read"] .trail-section,
html.reader-adaptive[data-reader-mode="deep-read"] .signal-section {
    opacity: 0.4;
}

.reader-mode-root {
    position: fixed;
    left: 1.2rem;
    bottom: 1.2rem;
    z-index: 40;
    display: grid;
    gap: 0.6rem;
    max-width: min(36rem, calc(100vw - 2.4rem));
}

.reader-mode-chip,
.reader-mode-pref,
.reader-mode-debug {
    background: var(--rp-surface);
    color: var(--rp-text);
    border: 1px solid var(--rp-highlight-med);
    border-radius: 0.8rem;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--rp-base) 40%, transparent);
}

.reader-mode-chip {
    padding: 1rem 1.2rem;
}

.reader-mode-live {
    margin: 0 0 0.8rem;
    font-size: 1.4rem;
}

.reader-mode-actions {
    display: flex;
    gap: 0.6rem;
}

.reader-mode-actions button,
.reader-mode-debug button,
.reader-mode-pref select {
    font: inherit;
    font-size: 1.3rem;
    color: var(--rp-text);
    background: var(--rp-overlay);
    border: 1px solid var(--rp-highlight-high);
    border-radius: 0.4rem;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
}

.reader-mode-pref {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: fit-content;
    padding: 0.4rem 0.8rem;
    font-size: 1.2rem;
    color: var(--rp-subtle);
}

.reader-mode-debug {
    position: fixed;
    right: 1.2rem;
    bottom: 1.2rem;
    z-index: 45;
    width: min(34rem, calc(100vw - 2.4rem));
    max-height: 22rem;
    overflow: auto;
    padding: 1.2rem;
    font-size: 1.2rem;
}

.reader-mode-debug h2,
.reader-mode-debug h3 {
    font-size: 1.4rem;
    margin: 0.8rem 0 0.4rem;
}

.reader-mode-debug-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.2rem 0;
}

.reader-mode-debug pre,
.reader-mode-debug textarea {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--rp-base);
    color: var(--rp-text);
    border-radius: 0.4rem;
    padding: 0.6rem;
    max-height: 16rem;
    overflow: auto;
    font-size: 1.1rem;
}

.reader-mode-debug textarea {
    width: 100%;
    min-height: 8rem;
    margin-top: 0.6rem;
}

@media (max-width: 1200px) {
    html.reader-adaptive .reader-rail {
        position: static;
        width: auto;
        max-height: none;
        margin-top: 1.6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.reader-adaptive .reader-rail,
    html.reader-adaptive .reader-mode-chip,
    html.reader-adaptive .navigation,
    .trails-rail,
    .trails-rail a {
        transition: none;
        animation: none;
    }
}

/*
 * Always-on Trails rail (NES-160).
 * Desktop: reserved in the right margin with position: fixed, same idea
 * as the prototype rails (fade or reserve, do not pull the column wider).
 * Under 1200px: stack it after the article instead of covering the text.
 * Do not use display: contents here.
 * Share notes already fill the container, so the rail only sits in the
 * margin once the viewport has room beside that container. Otherwise it
 * stacks, still without resizing the notes column.
 */
.trails-rail {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    position: fixed;
    top: 7.2rem;
    right: 1.2rem;
    z-index: 20;
    width: min(24rem, calc((100vw - 78ch) / 2 - 2.4rem));
    max-height: calc(100vh - 10rem);
    overflow: auto;
    padding: 1.4rem 1.2rem 1.6rem;
    background: color-mix(in srgb, var(--rp-surface) 94%, transparent);
    border: 1px solid var(--rp-highlight-med);
    border-radius: 0.8rem;
    transition: none;
    animation: none;
}

.trails-rail-label {
    font-size: 1.2rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rp-subtle);
    margin: 0;
}

.trails-rail-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.6rem;
}

.trails-rail a {
    color: var(--rp-foam);
    text-decoration: none;
    font-size: 1.4rem;
}

.trails-rail a:hover {
    color: var(--rp-rose);
    text-decoration: underline;
    text-underline-offset: 0.2rem;
}

.trails-rail a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--rp-foam) 65%, transparent);
    outline-offset: 4px;
    border-radius: 0.35rem;
}

@media (max-width: 1200px) {
    .trails-rail {
        position: static;
        width: auto;
        max-height: none;
        margin-top: 1.6rem;
        right: auto;
        top: auto;
    }
}

@media (max-width: 1560px) {
    .share-page .trails-rail {
        position: static;
        width: auto;
        max-height: none;
        margin-top: 1.6rem;
        right: auto;
        top: auto;
    }
}

/* The adaptive prototype already places Trails on the left rail and
   research chrome on the right. Step this rail out of that test without
   display: contents and without handing its space to the text column. */
html.reader-adaptive .trails-rail {
    position: absolute;
    width: min(24rem, calc((100vw - 78ch) / 2 - 2.4rem));
    max-height: calc(100vh - 10rem);
    margin: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
