/* hasan.ee/writings — index and article.
   Layout is sized to #frame (a container), so desktop vs phone follows the
   frame's width. Colours match css/style.css. */

:root {
    --paper: #fffdfb;
    --ink: #303030;
    --muted: #737373;
    --rule: #969696;
    --rule-hover: #b5a6a6;
    --hair: #e9e2dc;
    --wash: #f4efea;
    --brick: #aa5353;
    --mint: #d1fae5;
    --display: "Climate Crisis", "Arial Black", sans-serif;
    --body: "Host Grotesk", system-ui, sans-serif;

    /* the index list */
    --ulh: 7px;
    --gap: 1.1svh;
    --tw: 500;
    --ts: 1.3rem;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--muted);
    font-family: var(--body);
    font-weight: 425;
    font-size: clamp(0.9375rem, 1.5vw, 1.375rem);
    line-height: 1.3;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}
::selection { background: var(--mint); color: var(--ink); }
.px { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); transition: color 0.3s, border-color 0.3s; }
.a:hover, .a:focus-visible { color: var(--rule-hover); border-bottom-color: var(--rule-hover); outline: none; }
.h { font-family: var(--display); font-weight: 400; color: var(--brick); letter-spacing: 0.05em; line-height: 1; margin: 0; }

#frame { position: absolute; inset: 0; container-type: size; overflow: hidden; background: var(--paper); --sunR: 6cqw; --fadeH: 7cqh; }

/* ---------- index ---------- */
#whead { position: absolute; top: 6cqh; left: max(16px, 6cqw); z-index: 6; display: flex; align-items: baseline; gap: 1.4rem; }
#whead .h { font-size: clamp(2.6rem, 10cqw, 9rem); }
#sc { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #d8cfc7 transparent; padding: calc(var(--hb, 30cqh) + var(--fadeH)) 0 2.6rem max(16px, 6cqw); z-index: 1; }
#ul { display: flex; flex-direction: column; align-items: flex-start; gap: var(--gap); max-width: calc(100cqw - var(--sunW) - 12cqw); }
.ur { display: flex; color: inherit; text-decoration: none; }
.ur:focus-visible { outline: none; }
.ro { display: inline-flex; flex-direction: column; gap: 4px; transition: transform 0.2s; }
.ur:hover .ro { transform: translateX(4px); }
.it { color: var(--ink); white-space: nowrap; font-size: clamp(0.95rem, var(--ts), 1.6cqw + 0.5rem); font-weight: var(--tw); line-height: 1.2; transition: background-color 0.2s, color 0.2s; }
.ur:hover .it, .ur:focus-visible .it { background-color: var(--mint); }
.ur.cur .it { color: var(--brick); }
.rl { display: flex; max-width: calc(100cqw - var(--sunW) - 12cqw); }
.rlp { flex: 1; height: var(--ulh); width: auto; min-width: 0; }
/* the top fade is solid behind the title, so rows vanish before they reach it */
#fadeT, #fadeB { position: absolute; left: 0; right: 14px; pointer-events: none; z-index: 4; }
#fadeT { top: 0; height: calc(var(--hb, 30cqh) + var(--fadeH)); background: linear-gradient(var(--paper) calc(100% - var(--fadeH)), rgba(255, 253, 251, 0)); }
#fadeB { bottom: 0; height: 11cqh; background: linear-gradient(rgba(255, 253, 251, 0), var(--paper)); opacity: 0; transition: opacity 0.2s; }
#fadeB.on { opacity: 1; }
#sun { position: absolute; bottom: 0; right: var(--sunR); z-index: 5; pointer-events: none; }
#suncap { position: absolute; right: var(--sunR); width: var(--sunW); text-align: center; bottom: calc(var(--sunH) + 0.4rem); font-size: 0.72em; color: var(--muted); z-index: 5; pointer-events: none; }

/* colour overlay used by the openings */
.ov { position: absolute; inset: 0; z-index: 25; pointer-events: none; }
.ov canvas { width: 100%; height: 100%; }

/* ---------- article ---------- */
#art { position: absolute; inset: 0; background: var(--paper); z-index: 20; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #d8cfc7 transparent; --c2: #ccc; --c3: #aaa; --c4: #888; --c5: #666; }
#ahero { position: relative; height: 30cqh; overflow: hidden; background: var(--wash); }
#ahero canvas, #ahero img { width: 100%; height: 100%; display: block; object-fit: cover; }
#aback { position: absolute; top: calc(30cqh + 1.1rem); left: 18px; font-size: 0.82em; z-index: 6; }
#ahead { padding: 3rem 18px 0; }
.tw { display: inline-flex; flex-direction: column; gap: 0.45rem; max-width: 100%; }
#atitle { font-family: var(--display); font-weight: 400; color: var(--brick); font-size: 1.7rem; letter-spacing: 0.04em; line-height: 1.08; margin: 0; text-wrap: balance; }
.hbar { display: block; height: 7px; width: calc(100% + 10cqw); max-width: calc(100cqw - 36px); background: var(--pbar) 0 0 / 100% 100% no-repeat; image-rendering: pixelated; }
#ameta { margin: 0.7rem 0 0; font-size: 0.74rem; color: var(--muted); display: flex; align-items: center; gap: 0.75em; position: relative; min-height: 1.6em; }
/* palette squares: the code hangs under the hovered square on a hairline */
#ameta .d { white-space: nowrap; font-variant-numeric: tabular-nums; }
#ameta .sq { display: inline-flex; gap: 3px; align-items: center; position: relative; }
#ameta .sq button { width: 11px; height: 11px; padding: 0; border: 0; cursor: copy; display: block; transition: transform 0.18s; }
#ameta .sq button.on { transform: translateY(-2px); }
#ameta .sq button:focus-visible { outline: 2px solid var(--brick); outline-offset: 2px; }
#ameta .under { position: absolute; top: calc(100% + 5px); transform: translate(-50%, -3px); display: flex; flex-direction: column; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s, left 0.18s; z-index: 3; }
#ameta .under::before { content: ""; width: 1px; height: 7px; background: var(--rule); }
#ameta.show .under { opacity: 1; transform: translate(-50%, 0); }
/* code and "COPIED!" share one centred slot, same caps, size and spacing */
.swap { display: inline-grid; justify-items: center; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; font-size: 0.95em; }
/* one word leaves before the other arrives, both ways */
.swap > span { grid-area: 1 / 1; transition: opacity 0.18s, transform 0.18s; }
.swap .code { transition-delay: 0.1s; }
.swap .cp { opacity: 0; transform: translateY(5px); transition-duration: 0.1s; }
.copied .swap .code { opacity: 0; transform: translateY(-5px); transition-duration: 0.1s; transition-delay: 0s; }
.copied .swap .cp { opacity: 1; transform: none; transition-duration: 0.18s; transition-delay: 0.1s; }
.pxb { position: absolute; width: 4px; height: 4px; pointer-events: none; z-index: 3; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#ahead { padding-bottom: 0.4rem; }
#abody { padding: 1.4rem 18px 0; color: var(--ink); font-size: 1rem; font-weight: 425; line-height: 1.65; }
#abody p { margin: 0 0 1.05em; text-wrap: pretty; }
#abody a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
#abody a:hover { color: var(--rule-hover); border-bottom-color: var(--rule-hover); }
#abody h2 { font-family: var(--body); font-weight: 650; font-size: 1.08em; color: var(--ink); margin: 2.1em 0 0.8em; line-height: 1.3; display: table; }
#abody h2::after { content: ""; display: block; height: 5px; width: calc(100% + 3.5rem); max-width: calc(100cqw - 36px); margin-top: 0.4em; background: var(--pbar) 0 0 / 100% 100% no-repeat; image-rendering: pixelated; }
#abody ul { list-style: none; margin: 0 0 1.2em; padding: 0; display: grid; gap: 0.45em; }
#abody li { position: relative; padding-left: 1.4em; }
#abody li::before { content: ""; position: absolute; left: 0.1em; top: 0.55em; width: 0.55em; height: 0.55em; background: var(--c3); }
#abody li:nth-child(4n+2)::before { background: var(--c4); }
#abody li:nth-child(4n+3)::before { background: var(--c5); }
#abody li:nth-child(4n)::before { background: var(--c2); }
#abody blockquote { position: relative; margin: 1.8em 0; padding: 0.2em 0 0.2em 1.3em; font-size: 1.25em; font-weight: 500; line-height: 1.4; color: var(--ink); }
#abody blockquote::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--pbarv) 0 0 / 100% 100% no-repeat; image-rendering: pixelated; }
#abody code { font-size: 0.9em; background: var(--wash); padding: 0.05em 0.3em; border-radius: 3px; }
.aimg, #abody figure { margin: 0 0 1.2em; }
.aimg img, #abody figure img { width: 100%; height: auto; display: block; }
.aimg figcaption, #abody figcaption { font-size: 0.72rem; color: var(--muted); margin-top: 0.45rem; }
/* the full planet signs off right under the last text */
.sign { display: flex; justify-content: center; margin: 1.8rem 0 1.4rem; }
.sec:last-child > p:last-of-type { margin-bottom: 0; }
/* reading rail, desktop only */
#rail { display: none; position: absolute; top: 30cqh; bottom: 0; width: 6px; z-index: 22; background: var(--hair); pointer-events: none; }
#rail.on { display: block; }
#rail i { position: absolute; left: 0; top: 0; width: 100%; height: var(--prog, 0%); background: var(--pbarv) 0 0 / 100% 100% no-repeat; image-rendering: pixelated; }

/* ---------- phone ---------- */
@container (max-width: 600px) {
    #frame { --fadeH: 4cqh; }
    #whead { top: 3.4rem; left: 0; right: 0; flex-direction: column; align-items: center; gap: 0.35rem; }
    #whead .h { font-size: min(13cqw, 4rem); letter-spacing: 0.03em; }
    #whead .back { font-size: 0.85rem; }
    #sc { padding: calc(var(--hb, 30cqh) + var(--fadeH)) 18px 1.6rem; }
    #ul { max-width: 100%; align-items: center; text-align: center; gap: 1.6cqh; }
    .ro { align-items: center; }
    .ur:hover .ro { transform: none; }
    .it { font-size: 1.05rem; white-space: normal; }
    .rl { max-width: calc(100cqw - 36px); }
    .rlp { height: 6px; }
    #sun, #suncap, #rail { display: none !important; }
}

/* ---------- desktop article ---------- */
@container (min-width: 601px) {
    /* The article scales with the screen: text grows a little on wide
       screens, margins grow with it (capped), and the pictures always run
       to the right margin so there is no dead space on the right. */
    #art { --m: clamp(24px, 6cqw, 10rem); }
    #atitle { font-size: clamp(2.4rem, 6.4cqw, 7.5rem); }
    #ahead { padding: 2.6rem var(--m) 0; }
    #aback { top: calc(30cqh + 2rem); left: auto; right: var(--m); }
    #abody { font-size: clamp(1.08rem, 0.5rem + 0.72cqw, 1.6rem); padding: 2.6em var(--m) 0; }
    #ameta { font-size: clamp(0.74rem, 0.3rem + 0.45cqw, 1rem); }
    #abody h2::after, .hbar { max-width: none; }
    /* text on the left, each section's picture filling the right column */
    .sec { display: grid; grid-template-columns: minmax(0, 38em) minmax(0, 1fr); column-gap: max(2.5rem, 5cqw); align-items: start; }
    .sec > * { grid-column: 1; }
    .sec > h2 { grid-row: 1; justify-self: start; }
    .sec > .aimg { grid-column: 2; grid-row: 2 / span 40; justify-self: end; width: 100%; max-width: 34em; margin: 0.25em 0 0; }
    .sign { margin: 2em 0 1.6em; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
