/* The Ring design: the home page (ring splash, publications, tools), each
   publication's page, the tools page and the rocket game.
   Type rule: nothing smaller than the body text, no uppercase labels or
   eyebrow lines over headings. Secondary text is the same size, only greyer.
   Built from docs/design/mockups/ab-ring.html. It has its own palette, pale
   steel by day and dark steel by night, that shifts with the weather where
   the visitor is. home.js sets data-sky, data-light and data-rain on <html>. */

:root {
    --bg: #e3e9e9;
    --ink: #0c1416;
    --mid: #5b6e72;
    --line: #b3c0c2;
    --lit: #f7fbfb;
    --glow: #f7fbfb;
    --accent: #c43c00;
    --shade: rgba(12, 20, 22, 0.5);
    --gutter: clamp(16px, 4vw, 56px);
}
[data-sky="cloudy"] { --bg: #cfd6d6; --lit: #dde3e3; --glow: #dde3e3; --line: #a5b2b4; }
[data-sky="rain"] { --bg: #bcc7c9; --lit: #cdd6d8; --glow: #c9d3d5; --line: #98a7aa; --mid: #4c5f63; }
[data-light="night"] { --bg: #0b1214; --ink: #e3e9e9; --mid: #8a9ea2; --line: #2a383b; --lit: #16262a; --glow: #3d5a61; --accent: #ff8a4d; --shade: rgba(0, 0, 0, 0.65); }
[data-light="night"][data-sky="cloudy"] { --bg: #0f1516; --glow: #1b2a2e; }
[data-light="night"][data-sky="rain"] { --bg: #0a0f11; --glow: #142024; }

/* Hand the palette to the shared site styles (navigation, the publication record). */
[data-room="ring"] {
    --color-bg: var(--bg);
    --color-surface: var(--lit);
    --color-text: var(--ink);
    --color-text-muted: var(--mid);
    --color-rule: var(--line);
    --color-accent-text: var(--accent);
    --nav-bg: transparent;
    --nav-text: var(--ink);
    --nav-text-muted: var(--mid);
    position: relative;
}

/* On the home page and the game the navigation sits over the picture. */
[data-room="ring"] .navbar { padding-inline: var(--gutter); }
[data-room="ring"]:has(.home-hero, .game) .navbar { position: absolute; inset: 0 0 auto 0; z-index: 2; }
[data-room="ring"] .nav-link:hover,
[data-room="ring"] .nav-link:focus-visible { color: var(--accent); }

.home { padding-inline: var(--gutter); line-height: 1.5; }
.home :where(h1, h2, h3, p) { margin: 0; }
.home a { color: inherit; text-decoration: none; }

/* ---- Splash ---- */
.home-hero { position: relative; min-height: min(86vh, 860px); display: flex; flex-direction: column; justify-content: flex-end; padding: 120px var(--gutter) clamp(32px, 6vw, 72px); margin-inline: calc(var(--gutter) * -1); overflow: hidden; }
.home-hero h1 { margin: 0; position: relative; font-weight: 200; font-size: clamp(3.25rem, 13vw, 12rem); line-height: 0.88; letter-spacing: -0.045em; }
.home-lead { position: relative; margin-top: clamp(16px, 2.5vw, 32px); max-width: 36ch; font-size: clamp(1.0625rem, 1.6vw, 1.375rem); line-height: 1.4; }

.rings { position: absolute; inset: 0; width: 100%; height: 100%; }
.rings circle { fill: none; stroke: var(--ink); }
.rings .glow { stop-color: var(--glow); }
.rings .centre { fill: url("#lit"); stroke: none; }
.rings .figure * { fill: var(--ink); stroke: none; }

/* The rings move with the weather.
   Clear: light travels slowly out through the tunnel, ring by ring.
   Cloud: the rings fade and banks of shade drift across.
   Rain: the same wave runs fast, and drops land as spreading ripples;
         the harder it rains (data-rain 1 to 3), the more drops. */
.tunnel circle { opacity: var(--o); animation: wave 11s ease-in-out infinite; animation-delay: calc(var(--n) * -0.5s); }
@keyframes wave { 0%, 70%, 100% { opacity: var(--o); } 85% { opacity: calc(var(--o) + 0.4); } }
[data-sky="cloudy"] .tunnel { opacity: 0.5; }
[data-sky="cloudy"] .tunnel circle { animation: none; }
[data-sky="rain"] .tunnel { opacity: 0.45; }
[data-sky="rain"] .tunnel circle { animation-duration: 2.6s; animation-delay: calc(var(--n) * -0.12s); }

.shade, .drops { display: none; }
[data-sky="cloudy"] .shade, [data-sky="rain"] .drops { display: inline; }
.shade ellipse { fill: var(--ink); opacity: 0.12; animation: drift 70s linear infinite; }
.shade ellipse:nth-child(2) { animation-duration: 95s; animation-delay: -40s; }
.shade ellipse:nth-child(3) { animation-duration: 120s; animation-delay: -75s; }
@keyframes drift { from { transform: translateX(-900px); } to { transform: translateX(2500px); } }

.drop circle { transform-box: fill-box; transform-origin: center; opacity: 0; animation: ripple var(--t) ease-out infinite; animation-delay: var(--d); }
.drop circle:nth-child(2) { animation-delay: calc(var(--d) + 0.22s); }
.drop circle:nth-child(3) { animation-delay: calc(var(--d) + 0.44s); }
@keyframes ripple { 0% { transform: scale(0.05); opacity: 0; } 12% { opacity: 0.75; } 100% { transform: scale(1); opacity: 0; } }
.drop:nth-child(n+15) { display: none; }
[data-rain="2"] .drop:nth-child(-n+34), [data-rain="3"] .drop { display: inline; }

/* The drawings of abstracts (art.py) carry the same wave, ring by ring from the centre out. */
.pub-art .ring { animation: wave 11s ease-in-out infinite; animation-delay: calc(var(--n) * -0.5s); }
[data-sky="cloudy"] .pub-art .ring { animation: none; }
[data-sky="rain"] .pub-art .ring { animation-duration: 2.6s; animation-delay: calc(var(--n) * -0.12s); }

/* ---- Sections ---- */
.home section { border-top: 1px solid var(--ink); padding-block: clamp(40px, 7vw, 96px); }
.home-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 12px 24px; margin-bottom: clamp(24px, 4vw, 56px); }
.home h2 { font-weight: 200; font-size: clamp(2rem, 5vw, 4rem); letter-spacing: -0.035em; line-height: 1; }
.home-sort { display: flex; gap: 20px; color: var(--mid); }
.home-sort a:hover { color: var(--accent); }
.home-sort a[aria-current="true"] { color: var(--ink); border-bottom: 1px solid var(--ink); }
.home-empty { color: var(--mid); }

/* ---- Publications: one lead figure, then rows ---- */
.pub-lead, .pub-row { cursor: pointer; transition: transform 0.18s ease-out, background-color 0.18s ease-out; }
.pub-lead { display: grid; grid-template-columns: 1.1fr 1fr; gap: clamp(20px, 4vw, 64px); align-items: end; margin-bottom: clamp(32px, 5vw, 72px); }
.pub-frame { display: block; }
.pub-lead h3 { font-weight: 300; font-size: clamp(1.5rem, 3.2vw, 2.75rem); line-height: 1.1; letter-spacing: -0.025em; text-wrap: balance; }
.pub-lead .pub-meta { margin-top: 16px; }
.pub-meta { margin-top: 4px; color: var(--mid); }
.pub-meta .me { font-weight: 600; color: var(--ink); }

.pub-row { display: grid; grid-template-columns: clamp(64px, 9vw, 120px) 1fr; gap: clamp(12px, 3vw, 40px); align-items: baseline; padding: clamp(16px, 2.2vw, 26px) 16px; margin-inline: -16px; border-top: 1px solid var(--line); }
.pub-year { font-weight: 200; font-size: clamp(1.25rem, 2.2vw, 2rem); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pub-row h3 { font-weight: 400; font-size: clamp(1.0625rem, 1.7vw, 1.5rem); line-height: 1.25; letter-spacing: -0.01em; text-wrap: pretty; }
/* The publication under the pointer, or holding keyboard focus, grows. */
@media (hover: hover) {
    .pub-row:hover, .pub-row:focus-visible { transform: scale(1.045); background: var(--lit); position: relative; z-index: 1; border-top-color: transparent; box-shadow: 0 0 0 1px var(--ink); outline: none; }
    .pub-row:hover + .pub-row, .pub-row:focus-visible + .pub-row { border-top-color: transparent; }
    .pub-lead:hover, .pub-lead:focus-visible { transform: scale(1.02); }
    .pub-lead:hover h3, .pub-row:hover h3 { color: var(--accent); }
}

/* ---- The card: one publication's full record ---- */
.card { width: min(920px, calc(100vw - 32px)); max-height: min(88vh, 900px); padding: 0; border: 1px solid var(--ink); background: var(--bg); color: var(--ink); overflow: auto; overscroll-behavior: contain; }
.card::backdrop { background: var(--shade); }
.card[open] { animation: rise 0.2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.card-top { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; white-space: nowrap; padding: 12px clamp(16px, 3vw, 32px); background: var(--bg); border-bottom: 1px solid var(--line); }
.card-top a { color: var(--ink); }
.card-close { font: inherit; color: var(--ink); background: transparent; border: 1px solid var(--ink); border-radius: 999px; padding: 6px 16px; cursor: pointer; }
.card-close:hover { background: var(--ink); color: var(--bg); }
.card-tools { display: flex; align-items: center; margin-left: auto; gap: clamp(12px, 3vw, 28px); }
.card-body { padding: clamp(16px, 3vw, 32px); }
.card-body .me { background: var(--lit); box-shadow: 0 0 0 3px var(--lit); }

/* ---- Plain words: a switch that swaps the abstract for its plain version (plain.js) ---- */
.plain-switch { display: inline-flex; align-items: center; gap: 10px; font: inherit; color: var(--ink); background: none; border: 0; padding: 6px 0; cursor: pointer; }
.plain-switch[hidden] { display: none; }
.plain-switch .track { position: relative; width: 46px; height: 26px; border: 1px solid var(--ink); border-radius: 999px; transition: background-color 0.18s ease-out; }
.plain-switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); transition: transform 0.18s ease-out, background-color 0.18s ease-out; }
.plain-switch[aria-checked="true"] .track { background: var(--ink); }
.plain-switch[aria-checked="true"] .track::after { transform: translateX(20px); background: var(--bg); }
[data-words="abstract"] .pub-abstract + .pub-plain,
[data-words="plain"] .pub-abstract:has(+ .pub-plain) { display: none; }
.plain-list { list-style: none; margin: 0; padding: 0; font-size: 1.125rem; line-height: 1.5; }
.plain-list li { position: relative; padding: 14px 0 14px 32px; border-top: 1px solid var(--line); }
.plain-list li:first-child { border-top: 0; padding-top: 0; }
.plain-list li::before { content: ""; position: absolute; left: 2px; top: calc(14px + 0.3em); width: 11px; height: 11px; border: 1px solid var(--ink); border-radius: 50%; }
.plain-list li:first-child::before { top: 0.3em; }

/* ---- The paper agent: its note under AI-written text, and the question box (ask.js) ---- */
.ai-note { margin: 16px 0 0; color: var(--mid); }
.ask-log:empty { display: none; }
.ask-q { margin: 20px 0 6px; font-weight: 600; }
.ask-a { margin: 0; font-size: 1.125rem; line-height: 1.5; white-space: pre-wrap; }
.ask-a.typing::after { content: ""; display: inline-block; width: 9px; height: 9px; margin-left: 6px; border: 1px solid var(--ink); border-radius: 50%; --o: 0.3; animation: wave 1s ease-in-out infinite; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.ask-chip { font: inherit; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; cursor: pointer; }
.ask-chip:hover { border-color: var(--ink); }
.ask-form { display: flex; gap: 8px; margin-top: 16px; }
.ask-form input { flex: 1; min-width: 0; font: inherit; color: var(--ink); background: var(--lit); border: 1px solid var(--ink); border-radius: 0; padding: 10px 14px; }
.ask-form button { font: inherit; color: var(--bg); background: var(--ink); border: 1px solid var(--ink); padding: 10px 22px; cursor: pointer; }

/* ---- Tools ---- */
.tool-discs { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(16px, 3vw, 48px); }
.tool-disc { text-align: center; }
.tool-disc a { aspect-ratio: 1; border: 1px solid var(--ink); border-radius: 50%; display: grid; place-items: center; padding: 14%; font-weight: 300; font-size: clamp(1.25rem, 2.6vw, 2.25rem); line-height: 1.05; letter-spacing: -0.03em; background: radial-gradient(circle at 50% 50%, var(--lit), var(--bg) 62%); transition: background-color 0.2s, color 0.2s; }
.tool-disc a:hover, .tool-disc a:focus-visible { background: var(--ink); color: var(--lit); }
.tool-disc p { margin: 16px auto 0; max-width: 30ch; color: var(--mid); }

.home-foot { border-top: 1px solid var(--ink); padding-block: 28px 40px; display: flex; flex-wrap: wrap; gap: 8px 32px; justify-content: space-between; color: var(--mid); }
.home-foot a { color: var(--ink); border-bottom: 1px solid var(--line); margin-left: 16px; }
/* The way into the rocket game: a link dressed as the plain text it replaces. */
.home-foot a.home-egg { color: inherit; border: 0; margin: 0; cursor: default; }

/* ---- Pages under the navigation: a publication, the tools ---- */
.page { max-width: calc(68ch + var(--gutter) * 2); margin: 0 auto; padding: clamp(24px, 5vw, 64px) var(--gutter) clamp(64px, 10vw, 128px); line-height: 1.6; }
.page-wide { max-width: 1400px; }
.page a, .card-body a { color: var(--ink); text-decoration-color: var(--line); text-underline-offset: 0.2em; }
.page a:hover, .card-body a:hover { color: var(--accent); }
.page-back { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 24px; margin: 0 0 clamp(24px, 4vw, 48px); }
.page-title { margin: 0 0 clamp(24px, 4vw, 56px); font-weight: 200; font-size: clamp(2.5rem, 8vw, 6rem); line-height: 0.95; letter-spacing: -0.04em; }

.tool-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px clamp(24px, 5vw, 80px); padding-block: clamp(24px, 4vw, 48px); border-top: 1px solid var(--ink); }
.tool-row h2 { margin: 0; font-weight: 300; font-size: clamp(1.75rem, 3.6vw, 3rem); line-height: 1.05; letter-spacing: -0.03em; }
.tool-row h2 a { text-decoration: none; }
.tool-row p { margin: 0 0 12px; }
.tool-blurb { font-size: 1.125rem; }
.tool-row .prose { color: var(--mid); }

@media (max-width: 640px) {
    .tool-row { grid-template-columns: 1fr; }
    .pub-lead { grid-template-columns: 1fr; }
    .pub-row { grid-template-columns: 1fr; }
    .pub-year { grid-column: 1 / -1; font-size: 1rem; font-weight: 400; color: var(--mid); }
    .pub-year:empty { display: none; }
    .tool-discs { grid-template-columns: 1fr; }
    .tool-disc { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: center; text-align: left; }
    .tool-disc a { font-size: 1rem; padding: 10%; text-align: center; }
    .tool-disc p { margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .rings *, .pub-art *, .card[open] { animation: none !important; }
    .drop circle { opacity: 0.5; }
    .pub-lead, .pub-row { transition: none; }
}
