/* ==========================================================================
   CTO Notes v0.2: the night shift.
   A mad scientist's notebook: dark page, bone type, yellow marker
   annotations drawn over everything, alarm red only for risk.
   The same yellow highlighter as the homepage, used on ideas instead of paperwork.
   ========================================================================== */

body[data-register="cto"] { background-color: var(--bg); }
body[data-register="cto"]::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: var(--grain-op, .5);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E"); }
body[data-register="cto"] main, body[data-register="cto"] .gfoot { position: relative; z-index: 1; }

/* Marker annotations (hand-drawn SVG) */
.scrib { position: absolute; pointer-events: none; overflow: visible; }
.scrib path { fill: none; stroke: var(--mark); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.scrib.thin path { stroke-width: 2.2; }
.scrib.red path { stroke: var(--fail); }
.anno { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 12px; line-height: 1.45; color: var(--mark-ink); }
.anno.red { color: var(--fail); }
.mk { position: relative; display: inline-block; }
.mk-bg { background-image: linear-gradient(transparent 58%, rgba(242, 194, 48, .9) 58% 92%, transparent 92%); color: inherit; padding-inline: .05em; }

.night-sub { background: var(--bg); }
.night-sub .cto-mark { color: var(--ink); }
.night-sub .cto-mark i { background: var(--accent); }

/* ---- Masthead ---- */
.nm { padding-block: 64px 72px; }
.nm-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 56px; align-items: start; }
.nm-top { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11.5px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.nm h1 { font-family: var(--f-display); font-stretch: 125%; font-weight: 820; font-size: clamp(64px, 11vw, 168px); line-height: .82; letter-spacing: -.06em; margin-top: 20px; position: relative; display: inline-block; }
.nm h1 .scrib { left: -2%; bottom: -26px; width: 104%; height: 40px; }
.nm-thesis { font-family: var(--f-display); font-stretch: 112%; font-weight: 560; font-size: clamp(22px, 2.4vw, 31px); line-height: 1.3; letter-spacing: -.012em; margin-top: 52px; max-width: 30ch; color: var(--ink); }
.nm-thesis em { font-style: normal; color: var(--fail); }
.nm-author { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 16px; align-items: center; margin-top: 34px; max-width: 560px; }
.nm-author .ph { --ar: 1; }
.nm-author p { font-size: 14.5px; line-height: 1.5; color: var(--ink-2); }
.nm-author .meta { display: block; margin-top: 4px; }
.nm-disclaimer { margin-top: 28px; font-size: 13px; line-height: 1.5; color: var(--muted); border-left: 2px solid var(--line-strong); padding-left: 12px; max-width: 56ch; }
.nm-disclaimer a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 1000px) { .nm-grid { grid-template-columns: minmax(0, 1fr); gap: 48px; } }

/* The estimates instrument */
.est { background: var(--surface); border: 1px solid var(--line-strong); position: relative; }
.est-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: var(--f-mono); font-stretch: 87.5%; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.est-head b { color: var(--ink); font-weight: 600; }
.gauge-wrap { padding: 18px 16px 4px; display: grid; justify-items: center; position: relative; }
.gauge-wrap svg { width: 100%; max-width: 340px; height: auto; display: block; }
.gauge-num { font-family: var(--f-display); font-stretch: 125%; font-weight: 820; font-size: 72px; line-height: .9; letter-spacing: -.05em; margin-top: -4px; color: var(--ink); }
.gauge-lbl { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11px; color: var(--fail); letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; }
.gauge-def { font-size: 13px; line-height: 1.45; color: var(--muted); text-align: center; max-width: 34ch; margin: 8px auto 12px; }
.est-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.est-rows > div { padding: 14px 16px; display: grid; gap: 3px; }
.est-rows > div + div { border-left: 1px solid var(--line); }
.est-rows dt { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.est-rows dd { font-family: var(--f-display); font-stretch: 125%; font-weight: 760; font-size: 34px; letter-spacing: -.04em; line-height: 1; }
.est-rows .trail { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11px; color: var(--muted); }
.est-rows .trail s { color: var(--faint); }
.est-chart { border-top: 1px solid var(--line); padding: 12px 16px 6px; --ch-ink: var(--ink); --ch-muted: var(--muted); --ch-line: var(--line); }
.est-chart svg { width: 100%; height: auto; display: block; }
.est-foot { border-top: 1px solid var(--line); padding: 10px 16px; font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.est-foot a { color: var(--mark-ink); }
.est .scrib { right: 44px; top: 196px; width: 62px; height: 48px; }
.est .anno { position: absolute; right: 14px; top: 132px; transform: rotate(4deg); max-width: 96px; text-align: right; font-size: 11px; }
@media (max-width: 1000px) { .est .scrib, .est .anno { display: none; } }

/* ---- Manifesto ---- */
.manifesto { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); border: 1.5px solid var(--ink); background: var(--surface); transition: box-shadow var(--t-fast) var(--ease); }
.manifesto:hover { box-shadow: 8px 8px 0 var(--accent); }
.man-copy { padding: 36px; display: grid; gap: 20px; align-content: start; border-right: 1px solid var(--line); }
.man-copy h2 { font-family: var(--f-display); font-stretch: 125%; font-weight: 800; font-size: clamp(34px, 4.4vw, 60px); line-height: .96; letter-spacing: -.045em; }
.man-copy .dek { font-size: 18px; line-height: 1.55; color: var(--ink-2); max-width: 44ch; }
.man-copy .quote { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 13px; line-height: 1.6; color: var(--mark-ink); border-top: 1px solid var(--line); padding-top: 14px; }
.man-fig { padding: 24px; display: grid; gap: 10px; align-content: start; position: relative; }
.man-fig svg { width: 100%; height: auto; display: block; }
.man-fig .cap { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 10.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
@media (max-width: 1000px) { .manifesto { grid-template-columns: minmax(0, 1fr); } .man-copy { border-right: 0; border-bottom: 1px solid var(--line); padding: 22px; } .man-fig { padding: 16px; } }
.cc-cap { stroke: var(--ink); stroke-width: 3; fill: none; }
.cc-ctl { stroke: var(--mark); stroke-width: 2.5; fill: none; stroke-dasharray: 7 5; }
.cc-gap { fill: var(--fail); opacity: .22; }
.cc-axis { stroke: var(--line-strong); stroke-width: 1; }
.cc-t { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11px; fill: var(--muted); }
.cc-l { font-family: var(--f-display); font-size: 14px; font-weight: 650; fill: var(--ink); }
.cc-ly { font-family: var(--f-display); font-size: 14px; font-weight: 650; fill: var(--mark-ink); }
.cc-lr { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 12px; font-weight: 600; fill: var(--fail); }
.cc-an { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 12.5px; fill: var(--mark-ink); }
.cc-scrib { fill: none; stroke: var(--mark); stroke-width: 3; stroke-linecap: round; }

/* ---- Two timelines ---- */
.twot { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line-strong); }
.tl { padding: 28px; display: grid; gap: 4px; align-content: start; }
.tl + .tl { border-left: 1px solid var(--line-strong); background: linear-gradient(180deg, rgba(240, 112, 92, .06), transparent 60%); }
.tl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tl-head h3 { font-family: var(--f-display); font-stretch: 125%; font-weight: 780; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.04em; line-height: 1; }
.tl + .tl .tl-head h3 { color: var(--fail); }
.tl a { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); align-items: baseline; }
.tl a strong { font-weight: 600; font-size: 16.5px; line-height: 1.35; }
.tl a:hover strong { background-image: linear-gradient(transparent 60%, rgba(242, 194, 48, .55) 60%); }
@media (max-width: 860px) { .twot { grid-template-columns: minmax(0, 1fr); } .tl + .tl { border-left: 0; border-top: 1px solid var(--line-strong); } .tl { padding: 20px; } }

/* ---- Feed (night) ---- */
.nfeed { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 56px; align-items: start; }
@media (max-width: 1080px) { .nfeed { grid-template-columns: minmax(0, 1fr); } }
.npost { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 24px; padding: 34px 0; border-bottom: 1px solid var(--line); }
.npost-when { display: grid; gap: 8px; align-content: start; font-family: var(--f-mono); font-stretch: 87.5%; font-size: 11px; color: var(--muted); }
.npost-when .d { font-size: 13px; font-weight: 600; color: var(--ink); }
.npost-when .hr { color: var(--mark-ink); }
.npost-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; }
.npost h3 { font-family: var(--f-display); font-stretch: 118%; font-weight: 740; font-size: clamp(23px, 2.5vw, 32px); line-height: 1.08; letter-spacing: -.03em; }
.npost h3 a:hover { background-image: linear-gradient(transparent 62%, rgba(242, 194, 48, .6) 62%); }
.npost .dek { font-size: 16.5px; line-height: 1.55; color: var(--ink-2); max-width: 62ch; }
.npost .tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.npost .tag { border-color: var(--line-strong); color: var(--ink-2); }
.tag-red { border-color: var(--fail) !important; color: var(--fail) !important; }
@media (max-width: 640px) { .npost { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 24px 0; } .npost-when { grid-template-columns: repeat(3, auto); justify-content: start; gap: 10px; align-items: center; } }

.runlog { background: var(--panel); border: 1px solid var(--panel-line); font-family: var(--f-mono); font-stretch: 87.5%; font-size: 12px; }
.runlog { color: var(--panel-ink); }
.runlog .bar { display: flex; justify-content: space-between; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--panel-line); color: var(--panel-muted); font-size: 11px; flex-wrap: wrap; }
.runlog ol { list-style: none; padding: 8px 0; }
.runlog li { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 10px; padding: 5px 14px; color: var(--panel-ink); opacity: .9; line-height: 1.5; }
.runlog li span:first-child { color: var(--panel-muted); }
.runlog li.warn { color: #F2C230; }
.runlog li.bad { color: #F0705C; background: rgba(240, 112, 92, .08); }
.runlog li.end { color: var(--panel-ink); border-top: 1px solid var(--panel-line); margin-top: 6px; padding-top: 10px; }

.letter { background: #EDEBE3; color: #1E2022; padding: 30px 34px; transform: rotate(-.8deg); max-width: 620px; position: relative; box-shadow: 0 20px 40px -20px rgba(0, 0, 0, .8); font-family: var(--f-mono); font-stretch: 87.5%; font-size: 13.5px; line-height: 1.75; }
.letter p + p { margin-top: 12px; }
.letter .to { font-weight: 600; }
.letter .sgn { margin-top: 18px; font-size: 12px; color: #5B6568; }
.letter .scrib { right: -10px; top: -14px; width: 150px; height: 60px; }
.letter .scrib path { stroke: #C8402C; }
.letter::after { content: ""; position: absolute; inset: 0; pointer-events: none; background-image: repeating-linear-gradient(0deg, rgba(0, 0, 0, .03) 0 1px, transparent 1px 28px); background-position: 0 18px; }

.nfig { background: var(--surface); border: 1px solid var(--line-strong); }
.nfig .in { padding: 16px; overflow-x: auto; --ch-ink: var(--ink); --ch-muted: var(--muted); --ch-line: var(--line); }
.nfig .in svg { display: block; width: 100%; height: auto; }
.nfig .cap { padding: 9px 16px; border-top: 1px solid var(--line); font-family: var(--f-mono); font-stretch: 87.5%; font-size: 10.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Side column */
.nside { display: grid; gap: 40px; }
.nside h2 { font-family: var(--f-mono); font-stretch: 87.5%; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; border-top: 2px solid var(--ink); padding-top: 10px; margin-bottom: 4px; display: flex; justify-content: space-between; color: var(--ink); }
.nside h2 span:last-child { color: var(--muted); }
.nthought { padding: 18px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.nthought p { font-family: var(--f-display); font-stretch: 106%; font-weight: 580; font-size: 18px; line-height: 1.38; letter-spacing: -.005em; }
.nthought .row { gap: 10px; }
.nledger { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.nledger td { padding: 11px 0; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.4; }
.nledger td:first-child { padding-right: 10px; }
.nledger td:last-child { text-align: right; white-space: nowrap; font-family: var(--f-mono); font-stretch: 87.5%; font-size: 15px; font-weight: 600; }
.nledger .meta { display: block; font-size: 10.5px; margin-top: 3px; }
.nledger .x td:last-child { color: var(--fail); }

.basement .item { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; line-height: 1.4; }
.basement .led { width: 8px; height: 8px; border-radius: 50%; background: var(--pass); margin-top: 6px; animation: pulse 2.4s ease-in-out infinite; }
.basement .led.y { background: var(--accent); animation: none; }
.basement .led.r { background: var(--fail); }
.basement .meta { display: block; margin-top: 3px; font-size: 10.5px; }

/* Long reads + subscribe */
.nlong { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 2px solid var(--ink); }
.nlong a { padding: 26px 24px 30px 0; display: grid; gap: 12px; align-content: start; border-right: 1px solid var(--line); }
.nlong a + a { padding-left: 24px; }
.nlong a:last-child { border-right: 0; }
.nlong .mins { font-family: var(--f-mono); font-stretch: 100%; font-size: 56px; font-weight: 700; letter-spacing: -.05em; line-height: .9; color: var(--mark-ink); }
.nlong .mins small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: .06em; }
.nlong h3 { font-family: var(--f-display); font-stretch: 118%; font-weight: 720; font-size: 21px; line-height: 1.15; letter-spacing: -.02em; }
.nlong p { font-size: 14.5px; line-height: 1.5; color: var(--ink-2); }
@media (max-width: 900px) { .nlong { grid-template-columns: minmax(0, 1fr); } .nlong a, .nlong a + a { padding: 20px 0; border-right: 0; border-bottom: 1px solid var(--line); } }

.nsub { border: 1.5px solid var(--accent); padding: 36px; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 32px; align-items: center; position: relative; }
.nsub h2 { font-family: var(--f-display); font-stretch: 125%; font-weight: 800; font-size: clamp(28px, 3.6vw, 46px); line-height: .98; letter-spacing: -.04em; }
.nsub p { color: var(--ink-2); font-size: 15.5px; margin-top: 10px; }
.nsub form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.nsub input { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.nsub .btn { background: var(--accent); color: #15181A; border-color: var(--accent); }
.nsub .meta { grid-column: 1 / -1; }
@media (max-width: 800px) { .nsub { grid-template-columns: minmax(0, 1fr); padding: 22px; } }

/* Draw-on animation for marker scribbles */
.draw path { transition: stroke-dashoffset 900ms var(--ease); }
@media (prefers-reduced-motion: reduce) { .draw path { transition: none; } }

/* Light version (day shift) adjustments */
:root[data-theme="light"] body[data-register="cto"] .scrib path,
:root[data-theme="light"] body[data-register="cto"] .cc-scrib { stroke-width: 5; stroke-opacity: .9; }
:root[data-theme="light"] body[data-register="cto"] .cc-ctl { stroke-width: 3.5; }
:root[data-theme="light"] body[data-register="cto"] .letter { border: 1px solid var(--line-strong); box-shadow: 0 18px 32px -20px rgba(21, 24, 26, .45); background: #FBFAF5; }
:root[data-theme="light"] body[data-register="cto"] .manifesto:hover { box-shadow: 8px 8px 0 var(--ink); }
:root[data-theme="light"] body[data-register="cto"] .man-copy .btn-text,
:root[data-theme="light"] body[data-register="cto"] .man-copy .btn-text { color: var(--ink) !important; }
:root[data-theme="light"] body[data-register="cto"] .nsub .btn { color: #15181A; }

.ed-day { display: none; }
:root[data-theme="light"] body[data-register="cto"] .ed-night { display: none; }
:root[data-theme="light"] body[data-register="cto"] .ed-day { display: inline; }
