/* Display Time — full screen clock. Tokens first, then clock, then prose. */

/* Clock digits only (0-9 and colon) — 17KB instead of 90KB, and the only
   Archivo the page needs above the fold. Preloaded in index.html. */
@font-face {
  font-family: 'Archivo Digits';
  font-style: normal;
  font-weight: 100 500;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url('/fonts/archivo-digits.woff2') format('woff2');
  unicode-range: U+0030-0039, U+003A;
}

/* Full latin, for the prose below the fold. Deliberately not preloaded. */
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 500;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url('/fonts/archivo-var-latin.woff2') format('woff2');
}

@property --time-wght { syntax: "<number>"; inherits: true; initial-value: 340; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------
   Tokens. The bare :root carries the complete light palette; the
   two blocks below redefine only palette values for dark.
   --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --ground:         oklch(95.5% 0.003 85);
  --ground-aod:     oklch(92% 0.003 85);
  --ink:            oklch(17% 0.005 85);
  --ink-aod:        oklch(58% 0.004 85);
  --ink-soft:       oklch(45% 0.004 85);
  --ink-soft-aod:   oklch(72% 0.003 85);
  --hairline:       oklch(86% 0.003 85);
  --hairline-aod:   oklch(89% 0.002 85);
  --line-strong:    oklch(74% 0.004 85);
  --accent:         oklch(48% 0.075 170);
  --accent-aod:     oklch(80% 0.020 170);
  --focus:          oklch(17% 0.005 85);

  /* Semantic aliases — the AOD block swaps these, nothing else. */
  --bg:     var(--ground);
  --fg:     var(--ink);
  --fg-2:   var(--ink-soft);
  --line:   var(--hairline);
  --signal: var(--accent);

  --time-wght: 340;
  --time-wdth: 92;
  --colon-dim: 0.24;
  --rail-op: 1;

  --fs-time: clamp(4rem, 26vw, 26rem);
  --fs-meta: clamp(11px, 1.05vw, 12.5px);
  --fs-date: clamp(13px, 1.5vw, 15.5px);
  --fs-ui:   clamp(12.5px, 1.2vw, 14px);

  --dur-fast: 160ms;
  --dur: 320ms;
  --dur-aod: 1100ms;
  --dur-drift: 9s;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: 'Archivo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-clock: 'Archivo Digits', 'Archivo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-key: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  transition: --time-wght var(--dur-aod) var(--ease);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground:       oklch(11.5% 0.004 250);
    --ground-aod:   oklch(5.5% 0.003 250);
    --ink:          oklch(94% 0.003 85);
    --ink-aod:      oklch(44% 0.004 250);
    --ink-soft:     oklch(61% 0.004 250);
    --ink-soft-aod: oklch(30% 0.004 250);
    --hairline:     oklch(23% 0.005 250);
    --hairline-aod: oklch(12% 0.004 250);
    --line-strong:  oklch(35% 0.005 250);
    --accent:       oklch(74% 0.085 170);
    --accent-aod:   oklch(36% 0.030 170);
    --focus:        oklch(94% 0.003 85);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground:       oklch(11.5% 0.004 250);
  --ground-aod:   oklch(5.5% 0.003 250);
  --ink:          oklch(94% 0.003 85);
  --ink-aod:      oklch(44% 0.004 250);
  --ink-soft:     oklch(61% 0.004 250);
  --ink-soft-aod: oklch(30% 0.004 250);
  --hairline:     oklch(23% 0.005 250);
  --hairline-aod: oklch(12% 0.004 250);
  --line-strong:  oklch(35% 0.005 250);
  --accent:       oklch(74% 0.085 170);
  --accent-aod:   oklch(36% 0.030 170);
  --focus:        oklch(94% 0.003 85);
}

/* Always-on: the display doesn't just dim, it thins and sheds parts. */
:root[data-aod="on"] {
  --bg:     var(--ground-aod);
  --fg:     var(--ink-aod);
  --fg-2:   var(--ink-soft-aod);
  --line:   var(--hairline-aod);
  --signal: var(--accent-aod);
  --time-wght: 145;
  --colon-dim: 0.55;
  --rail-op: 0;
}

:root[data-aod="on"][data-idle="on"] { cursor: none; }
:root[data-always="on"] { overflow: hidden; }
:root[data-always="on"] .prose,
:root[data-always="on"] .site-foot,
:root[data-always="on"] .cue { display: none; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  transition: background-color var(--dur-aod) var(--ease);
}

/* ------------------------------------------------------------ clock */

.page {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(14px, 3vh, 36px);
  padding: clamp(14px, 3.4vmin, 40px);
}

.bar { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }

.wordmark, .zone {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-meta);
  font-variation-settings: "wdth" 100, "wght" 400;
  color: var(--fg-2);
  transition: opacity var(--dur) var(--ease), color var(--dur-aod) var(--ease);
}
.wordmark { font-variation-settings: "wdth" 100, "wght" 500; color: var(--fg); }
.zone { text-align: right; font-variant-numeric: tabular-nums; }

.center { display: grid; place-items: center; min-width: 0; }

.stack {
  --dx: 0px;
  --dy: 0px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 2.6vh, 34px);
  /* Slow burn-in drift plus a nudge above true centre, which reads level. */
  transform: translate3d(var(--dx), calc(var(--dy) - 1.1vh), 0);
  transition: transform var(--dur-drift) cubic-bezier(0.45, 0, 0.55, 1);
}

.readout { display: flex; flex-direction: column; gap: clamp(12px, 1.6vh, 24px); }

.time {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--font-clock);
  font-size: var(--fs-time);
  line-height: 0.86;
  letter-spacing: -0.035em;
  padding-block: 0.04em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-variation-settings: "wdth" var(--time-wdth), "wght" var(--time-wght);
  color: var(--fg);
  transition: color var(--dur-aod) var(--ease), font-variation-settings var(--dur-aod) var(--ease);
}

.colon {
  animation: colon-breathe 1s cubic-bezier(0.4, 0, 0.6, 1) infinite alternate;
  padding-inline: 0.015em;
}
@keyframes colon-breathe { from { opacity: 1 } to { opacity: var(--colon-dim) } }
:root[data-aod="on"] .colon { animation: none; opacity: var(--colon-dim); }

.meridiem {
  font-family: var(--font-display);
  font-size: 0.15em;
  font-variation-settings: "wdth" 100, "wght" 500;
  margin-inline-start: 0.28em;
  color: var(--fg-2);
  transition: color var(--dur-aod) var(--ease);
}

/* Linear seconds indicator: fills across the minute, resets on the turn. */
.rail {
  height: 2px;
  width: 100%;
  background: var(--line);
  opacity: var(--rail-op);
  transition: opacity var(--dur-aod) var(--ease), background-color var(--dur-aod) var(--ease);
}
.rail-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--signal);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 1s linear, background-color var(--dur-aod) var(--ease);
}

.date {
  margin: 0;
  text-align: center;
  font-size: var(--fs-date);
  color: var(--fg-2);
  transition: color var(--dur-aod) var(--ease);
}
.date .day { font-variation-settings: "wdth" 100, "wght" 500; color: var(--fg); }
.date .full { font-variation-settings: "wdth" 100, "wght" 400; }

/* ----------------------------------------------------------- controls */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 1.4vh, 16px);
  transition: opacity var(--dur) var(--ease);
}
.buttons { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: clamp(14px, 2.4vw, 26px); }

.btn {
  font-family: var(--font-display);
  font-size: var(--fs-ui);
  font-variation-settings: "wdth" 100, "wght" 500;
  line-height: 1;
  color: var(--fg-2);
  background: transparent;
  border: 0;
  padding: 0.7em 0.15em;
  cursor: pointer;
  text-underline-offset: 0.3em;
  transition: color var(--dur-fast) var(--ease);
}
.btn:hover { color: var(--fg); text-decoration: underline; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* One control carries the weight; the other two stay text. */
.btn--primary {
  color: var(--bg);
  background: var(--fg);
  padding: 0.85em 1.5em;
  transition: background-color var(--dur-fast) var(--ease);
}
.btn--primary:hover { color: var(--bg); background: var(--fg-2); text-decoration: none; }

a.btn { display: inline-block; text-decoration: none; }
a.btn--primary:hover { text-decoration: none; }

.status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-size: var(--fs-ui);
  color: var(--fg-2);
}
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--signal);
  animation: dot-breathe 2.4s ease-in-out infinite;
}
.status[data-ok="no"] .dot { background: var(--fg-2); animation: none; }
@keyframes dot-breathe { 0%, 100% { opacity: 1 } 50% { opacity: 0.3 } }

.cue {
  font-size: var(--fs-ui);
  color: var(--fg-2);
  text-decoration: none;
  text-underline-offset: 0.3em;
  padding: 0.5em 0.2em;
  transition: color var(--dur-fast) var(--ease);
}
.cue:hover { color: var(--fg); text-decoration: underline; }
.cue:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* Idle: chrome recedes. Focus keeps it — this rule follows, so it wins. */
:root[data-idle="on"] .bar,
:root[data-idle="on"] .controls { opacity: 0; pointer-events: none; }
.controls:focus-within { opacity: 1; pointer-events: auto; }

/* -------------------------------------------------------------- prose */

.prose {
  max-width: 65ch;
  margin-inline: auto;
  padding: clamp(56px, 10vh, 120px) clamp(20px, 5vw, 32px) clamp(48px, 8vh, 88px);
  display: flex;
  flex-direction: column;
  gap: clamp(40px, 6vh, 64px);
  scroll-margin-top: 0;
}


.prose h1 {
  margin: 0 0 0.5em;
  font-size: clamp(1.75rem, 4.2vw, 2.7rem);
  font-variation-settings: "wdth" 96, "wght" 500;
  line-height: 1.08;
  letter-spacing: -0.025em;
  text-wrap: balance;
  color: var(--fg);
}
.prose h2 {
  margin: 0 0 0.7em;
  font-size: clamp(1.1rem, 2.2vw, 1.4rem);
  font-variation-settings: "wdth" 96, "wght" 500;
  line-height: 1.25;
  letter-spacing: -0.012em;
  text-wrap: balance;
  color: var(--fg);
}
.prose h3 {
  margin: 2em 0 0.5em;
  font-size: 1rem;
  font-variation-settings: "wdth" 96, "wght" 500;
  line-height: 1.35;
  color: var(--fg);
}

.prose p, .prose li {
  font-size: clamp(0.95rem, 1.3vw, 1.05rem);
  line-height: 1.65;
  color: var(--fg-2);
}
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { font-variation-settings: "wght" 500; color: var(--fg); }

.prose .lead {
  font-size: clamp(1.02rem, 1.6vw, 1.18rem);
  line-height: 1.6;
  color: var(--fg);
}

.prose ul { margin: 0 0 1em; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.7em; }
.prose li { padding-inline-start: 1.1em; position: relative; }
.prose li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0.72em;
  width: 5px;
  height: 1px;
  background: var(--line-strong);
}

.prose kbd {
  font-family: var(--font-key);
  font-size: 0.78em;
  font-weight: 500;
  letter-spacing: 0.05em;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  padding: 0.15em 0.45em;
  color: var(--fg);
  white-space: nowrap;
}

.block { border-top: 1px solid var(--hairline); padding-top: clamp(28px, 4vh, 40px); }

.site-foot {
  border-top: 1px solid var(--hairline);
  padding: clamp(28px, 4vh, 40px) clamp(20px, 5vw, 32px) clamp(40px, 6vh, 56px);
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  max-width: 65ch;
  margin-inline: auto;
}
.site-foot p {
  margin: 0;
  font-size: var(--fs-meta);
  color: var(--fg-2);
}

/* -------------------------------------------------------------- writing */

.site-nav {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  max-width: 65ch;
  margin-inline: auto;
  padding: clamp(20px, 4vh, 34px) clamp(20px, 5vw, 32px) 0;
}
a.wordmark { text-decoration: none; }
a.wordmark:hover { text-decoration: underline; text-underline-offset: 0.3em; }
.nav-link {
  font-size: var(--fs-meta);
  color: var(--fg-2);
  text-decoration: none;
  text-underline-offset: 0.3em;
}
.nav-link:hover { color: var(--fg); text-decoration: underline; }

.post-head { border-bottom: 1px solid var(--hairline); padding-bottom: clamp(24px, 3.5vh, 36px); }
.post-meta {
  margin: 0.9em 0 0;
  font-size: var(--fs-meta);
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}
.post > *:not(.post-head) { margin-bottom: 0; }

/* Links inside running text: underlined, because a colour shift alone would
   need an accent, and the accent is reserved for liveness. */
.prose a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--line-strong);
  transition: text-decoration-color var(--dur-fast) var(--ease);
}
.prose a:hover { text-decoration-color: var(--fg); }
.prose a:focus-visible,
.site-foot a:focus-visible,
.site-nav a:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.prose code {
  font-family: var(--font-key);
  font-size: 0.88em;
  color: var(--fg);
}
.prose ol { margin: 0 0 1em; padding-inline-start: 1.3em; display: flex; flex-direction: column; gap: 0.7em; }
.prose ol li { padding-inline-start: 0.2em; }
.prose ol li::before { content: none; }

.post-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0; }
.post-item {
  padding: clamp(26px, 4vh, 38px) 0;
  border-bottom: 1px solid var(--hairline);
}
/* .prose li::before is (0,1,2); this must out-specify it or the list markers
   and hanging indent leak into the post list. */
.prose .post-item { padding-inline-start: 0; }
.prose .post-item::before { content: none; }
.post-item:last-child { border-bottom: 0; }
.post-item h2 { margin: 0 0 0.45em; }
.post-item h2 a { text-decoration: none; color: var(--fg); }
.post-item h2 a:hover { text-decoration: underline; text-underline-offset: 0.15em; }
.post-item p { margin: 0; }
.post-item .post-meta { margin-top: 0.6em; }

.site-foot a { color: var(--fg-2); text-decoration: underline; text-underline-offset: 0.25em; text-decoration-color: var(--line-strong); }
.site-foot a:hover { color: var(--fg); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .colon { animation: none; opacity: 1; }
  .dot { animation: none; }
  .rail-fill { transition: none; }
  .stack { transition: none; }
  .btn:active { transform: none; }
}
