/*
   Shared site styling.

   Tufte CSS provides the page's base type and column layout. This file is
   loaded after it, so it only supplies the missing site-wide details and
   keeps the same currentColor/serif visual language across every page.
*/

:root {
    --site-line: rgba(128, 128, 128, 0.55);
    --site-line-soft: rgba(128, 128, 128, 0.28);
    --site-highlight: var(--highlight-weak, rgba(128, 128, 128, 0.2));
    --site-highlight-strong: var(--highlight-strong, rgba(128, 128, 128, 0.4));
    --site-radius: var(--radius-sm, 0.2rem);
    --site-control-height: 2.5rem;
}

html {
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

::selection {
    color: inherit;
    background: var(--site-highlight-strong);
}

/* Keep the page title aligned with the Tufte text column while preventing
   long article and paper titles from dominating or overflowing the page. */
article > h1 {
    width: 55%;
    max-width: 100%;
    margin-top: 2.5rem;
    margin-bottom: 0.6rem;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2.1rem, 1.65rem + 1.5vw, 2.8rem);
    line-height: 1.08;
    overflow-wrap: break-word;
    text-wrap: balance;
}

article > h1 + .page-author {
    width: 55%;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

/* tufte.css only defines sizes for h1-h3. Extend that scale rather than
   allowing h4-h6 to fall back to browser defaults. */
h4 {
    font-style: normal;
    font-weight: 600;
    font-size: 1.2rem;
    margin-top: 1.5rem;
    margin-bottom: 0.6rem;
    line-height: 1.25;
}

h5 {
    font-style: italic;
    font-weight: 400;
    font-size: 1.05rem;
    margin-top: 1.1rem;
    margin-bottom: 0.4rem;
    line-height: 1.3;
}

h6 {
    font-style: normal;
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 1rem;
    margin-bottom: 0.6rem;
    line-height: 1.3;
}

/* Links ------------------------------------------------------------------- */
a:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    border-radius: var(--site-radius);
}

/* Controls ---------------------------------------------------------------- */
button,
input,
select,
textarea {
    font: inherit;
    font-size: 1rem;
}

button,
input[type="button"],
input[type="submit"],
input[type="reset"],
.button {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--site-control-height);
    padding: 0.45rem 0.8rem;
    border: 1px solid currentColor;
    border-radius: var(--site-radius);
    color: inherit;
    background: transparent;
    box-shadow: none;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

button:hover,
button:focus-visible,
input[type="button"]:hover,
input[type="button"]:focus-visible,
input[type="submit"]:hover,
input[type="submit"]:focus-visible,
input[type="reset"]:hover,
input[type="reset"]:focus-visible,
.button:hover,
.button:focus-visible {
    background: var(--site-highlight) !important;
    color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
select,
textarea {
    max-width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid currentColor;
    border-radius: var(--site-radius);
    color: inherit;
    background: transparent;
}

textarea {
    min-height: 7rem;
    resize: vertical;
}

/* Brown-noise generator --------------------------------------------------- */
.noise-app {
    width: 55%;
    margin-top: 1.5rem;
}

.noise-description {
    width: 100%;
    margin: 0 0 1.5rem;
    font-size: 1.2rem;
}

/* Radio ------------------------------------------------------------------- */
.radio-app {
    width: min(100%, 48rem);
    margin-top: 1.5rem;
}

.radio-description,
.radio-note {
    width: 100%;
}

.radio-station-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin: 1.25rem 0 1.5rem;
}

.radio-station-list button[aria-pressed="true"] {
    background: var(--site-highlight-strong);
}

.radio-now {
    min-height: 6rem;
    margin: 1rem 0;
}

.radio-now h2 {
    margin: 0.2rem 0 0.25rem;
    font-style: normal;
}

.radio-status,
.radio-performer,
.radio-note {
    margin-top: 0.3rem;
}

.radio-status,
.radio-note {
    font-size: 0.95rem;
}

.radio-performer {
    font-style: italic;
}

.radio-player-shell {
    width: min(100%, 480px);
    aspect-ratio: 16 / 9;
    min-height: 200px;
    margin: 1rem 0;
    background: rgba(128, 128, 128, 0.12);
}

.radio-player-shell iframe,
.radio-player-shell > div {
    display: block;
    width: 100% !important;
    height: 100% !important;
    min-height: 200px;
}

.radio-ratings {
    display: flex;
    gap: 0.65rem;
    margin: 1rem 0;
}

.radio-ratings button {
    min-width: 3.25rem;
    font-size: 1.25rem;
}

/* Book reader structure. Controls intentionally inherit the global rules
   above; these selectors only describe the reader's content hierarchy. */
.book-lede {
    width: 55%;
}

.book-search {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    margin: 1.5rem 0 0.5rem;
    width: 55%;
}

.book-search label {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.35rem;
}

.book-search input {
    width: 100%;
    box-sizing: border-box;
}

.book-status {
    width: 55%;
    min-height: 1.5em;
}

.book-panel {
    box-sizing: border-box;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid currentColor;
    width: 55%;
}

.book-panel h3 {
    margin-bottom: 0.25rem;
}

.book-author,
.book-details {
    margin-top: 0.25rem;
    font-style: italic;
}

.book-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: center;
    margin: 1rem 0 0.5rem;
}

.book-actions a {
    display: inline-block;
    padding: 0.45rem 0;
}

.book-preview {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid currentColor;
    counter-reset: book-major book-minor;
    width: 100%;
}

.book-preview [data-book-level="1"] {
    counter-increment: book-major;
    counter-reset: book-minor;
}

.book-preview [data-book-level="1"]::before {
    content: counter(book-major) ". ";
}

.book-preview [data-book-level="2"] {
    counter-increment: book-minor;
}

.book-preview [data-book-level="2"]::before {
    content: counter(book-major) "." counter(book-minor) " ";
}

.book-source-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid currentColor;
}

.book-preview blockquote {
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 3px solid currentColor;
}

@media (max-width: 760px) {
    article > h1,
    article > h1 + .page-author,
    .noise-app {
        width: 100%;
    }

    .radio-app,
    .radio-player-shell {
        width: 100%;
    }

    .radio-station-list button {
        flex: 1 1 10rem;
    }

    .book-lede,
    .book-status,
    .book-panel {
        width: 100%;
    }

    .book-search {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .book-search label {
        width: 100%;
    }

    .book-search button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* PDF-backed presentation viewer ---------------------------------------- */
body.presentation-viewer-document {
    width: 100vw;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    background: Canvas;
}

main.presentation-viewer {
    display: block;
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    height: 100vh;
    margin: 0 !important;
    margin-inline: 0 !important;
    padding: 0;
}

.presentation-stage {
    width: 100vw !important;
    max-width: none !important;
    height: 100vh;
}

.presentation-viewer > .presentation-stage {
    display: grid;
    place-items: center;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    cursor: pointer;
}

.presentation-stage canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    background: white;
}

.presentation-fallback {
    display: inline-block;
    padding: 0.7rem 1rem;
    color: inherit;
    border: 1px solid currentColor;
    text-decoration: none;
}

.presentation-fallback[hidden] {
    display: none;
}

.presentation-fallback:not([hidden]) {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
}

.presentation-fallback-noscript {
    position: fixed;
    z-index: 1;
}

.presentation-viewer:fullscreen {
    width: 100vw;
    height: 100vh;
    background: Canvas;
}


/* Stable heading anchors should land below browser chrome and make direct
   theorem/section links visibly targetable without changing the page design. */
:is(h1, h2, h3, h4, h5, h6)[id] {
    scroll-margin-top: 1.5rem;
}

:is(h1, h2, h3, h4, h5, h6)[id]:target {
    background: var(--site-highlight);
}



/* Weekly digest ---------------------------------------------------------- */
.digest-meta,
.digest-page {
    box-sizing: border-box;
    width: min(72%, 58rem);
    max-width: 100%;
}

.digest-meta {
    margin: 0.15rem 0 1.6rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--site-line-soft);
    font-size: 0.92rem;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
}

.digest-page h2,
.digest-page h3,
.digest-page p,
.digest-page ul,
.digest-page ol,
.digest-page blockquote,
.digest-page table {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.digest-page h2 {
    margin: 2.5rem 0 0.8rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--site-line-soft);
    font-style: normal;
    font-size: 1.45rem;
    line-height: 1.2;
}

.digest-page h2:first-child {
    margin-top: 0;
}

.digest-page ul,
.digest-page ol {
    padding-left: 1.25rem;
}

.digest-weather > ul {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--site-line-soft);
    list-style: none;
}

.digest-weather li {
    margin: 0;
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--site-line-soft);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.digest-weather li:nth-child(odd) {
    border-right: 1px solid var(--site-line-soft);
}

.digest-details {
    box-sizing: border-box;
    width: 100%;
    margin: 0.45rem 0;
    border-bottom: 1px solid var(--site-line-soft);
}

.digest-summary {
    display: flex;
    gap: 0.55rem;
    align-items: baseline;
    padding: 0.62rem 0.15rem;
    list-style: none;
    cursor: pointer;
    line-height: 1.3;
}

.digest-summary::-webkit-details-marker {
    display: none;
}

.digest-summary::before {
    content: "+";
    flex: 0 0 1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    font-weight: 400;
    text-align: center;
}

.digest-details[open] > .digest-summary::before {
    content: "−";
}

.digest-summary:hover,
.digest-summary:focus-visible {
    background: var(--site-highlight);
}

.digest-summary:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.digest-details-body {
    box-sizing: border-box;
    padding: 0.15rem 0 0.9rem 1.7rem;
}

.digest-details-body > :first-child {
    margin-top: 0.2rem;
}

.digest-details-body > :last-child {
    margin-bottom: 0;
}

.digest-details-body p,
.digest-details-body ul,
.digest-details-body ol,
.digest-details-body blockquote,
.digest-details-body table {
    width: 100%;
    max-width: 100%;
}

.digest-event-day > .digest-summary,
.digest-feed-group > .digest-summary,
.digest-newsletter-sender > .digest-summary {
    font-size: 1.03rem;
}

.digest-rss-item,
.digest-newsletter-issue {
    margin-left: 0.5rem;
    width: calc(100% - 0.5rem);
}

.digest-rss-item > .digest-summary,
.digest-newsletter-issue > .digest-summary {
    font-size: 0.95rem;
}

.digest-newsletter-body {
    font-size: 0.95rem;
    line-height: 1.52;
    overflow-wrap: anywhere;
}

.digest-newsletter-body p {
    margin: 0.65rem 0;
}

.digest-newsletter-body h5,
.digest-newsletter-body h6 {
    margin: 1rem 0 0.35rem;
}

.digest-youtube-channel > a:has(img) {
    display: inline-block;
    width: min(12rem, 38%);
    margin: 0.35rem 0.8rem 0.25rem 0;
    vertical-align: top;
    box-shadow: none;
}

.digest-youtube-channel img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border: 1px solid var(--site-line-soft);
    border-radius: var(--site-radius);
}

@media (max-width: 760px) {
    .digest-meta,
    .digest-page {
        width: 100%;
    }

    .digest-weather > ul {
        grid-template-columns: 1fr;
    }

    .digest-weather li:nth-child(odd) {
        border-right: 0;
    }

    .digest-details-body {
        padding-left: 1.2rem;
    }

    .digest-rss-item,
    .digest-newsletter-issue {
        margin-left: 0;
        width: 100%;
    }

    .digest-youtube-channel > a:has(img) {
        width: min(100%, 18rem);
    }
}


/* Nested generated digest disclosures from older issues use the same visual
   hierarchy even before the explicit per-kind classes were introduced. */
.digest-details .digest-details {
    margin-left: 0.5rem;
    width: calc(100% - 0.5rem);
}

.digest-details .digest-details > .digest-summary {
    font-size: 0.95rem;
}
