/* ==========================================================================
   Twinlight: the two lights. The few shared parts: the ground, the two discs, the leaf, the
   light control, focus, and the marks for whose words. Everything takes its colour from tokens.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  color-scheme: dark;
  background: var(--tw-ground);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--tw-ground);
  color: var(--tw-ink);
  font-family: var(--tw-serif);
  font-size: var(--tw-read);
  line-height: var(--tw-leading);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }

/* ---- Focus: a ring of the present light and a faint halo, the moon's way of spreading ---------- */
:focus { outline: none; }
:focus-visible {
  outline: var(--tw-focus-width) solid var(--tw-focus);
  outline-offset: var(--tw-focus-offset);
  box-shadow: 0 0 0 calc(var(--tw-focus-offset) + 7px) color-mix(in oklab, var(--tw-focus) 16%, transparent);
  border-radius: 2px;
}

.tw-skip {
  position: absolute; left: var(--tw-gutter); top: 0.75rem; z-index: 50;
  padding: 0.4em 0.8em; background: var(--tw-ground); color: var(--tw-ink);
  transform: translateY(-200%);
}
.tw-skip:focus-visible { transform: none; }

.tw-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- Small capitals for the quiet furniture: whose words, years, places --------------------- */
.tw-caps {
  font-variant-caps: all-small-caps;
  letter-spacing: var(--tw-tracking-caps);
  font-variant-numeric: lining-nums;
}

/* Whose words. Every block of words names its speaker. The library's own voice is set in italic and
   carries a small open ring, so it can never be mistaken for his.                                    */
.tw-who { color: var(--tw-ink-soft); font-size: var(--tw-t-small); }
.tw-library { font-style: italic; }
.tw-library-mark::before {
  content: ""; display: inline-block; width: 0.55em; height: 0.55em; margin-right: 0.4em;
  border: 1px solid currentColor; border-radius: 50%; vertical-align: 0.05em;
}

/* A rule: a streak of light, fading at both ends */
.tw-rule { height: var(--tw-hair); border: 0; margin: var(--tw-s-5) auto; background: var(--tw-rule); max-width: 18em; }

/* ==========================================================================
   The two discs. Equal in size, as in the sky. The sun is drawn as light going out (rays); the moon
   as light returning on itself (rings), a halo such as thin cloud makes around it.
   ========================================================================== */

.tw-sun, .tw-moon {
  position: absolute;
  width: var(--tw-disc); height: var(--tw-disc);
  border-radius: 50%;
  translate: -50% -50%;
}

.tw-sun {
  background: radial-gradient(circle, oklch(0.99 0.03 95) 0 55%, oklch(0.93 0.10 85) 80%, oklch(0.86 0.13 75) 100%);
  box-shadow:
    0 0 calc(var(--tw-disc) * 0.6) calc(var(--tw-disc) * 0.15) oklch(0.88 0.12 75 / calc(0.55 * var(--tw-sun))),
    0 0 calc(var(--tw-disc) * 3) calc(var(--tw-disc) * 0.8) oklch(0.75 0.12 60 / calc(0.30 * var(--tw-sun)));
  opacity: calc(0.55 + 0.45 * var(--tw-sun));
}
/* Rays: light going outward, faint and fading, never a star-burst */
.tw-sun::before {
  content: ""; position: absolute; inset: calc(var(--tw-disc) * -4.5);
  border-radius: 50%;
  background: repeating-conic-gradient(from 3deg, oklch(0.92 0.09 82 / 0.9) 0deg 0.7deg, transparent 0.7deg 7.5deg);
  -webkit-mask: radial-gradient(circle, transparent 11%, #000 13%, transparent 62%);
          mask: radial-gradient(circle, transparent 11%, #000 13%, transparent 62%);
  opacity: calc(0.38 * var(--tw-sun));
  animation: tw-turn 240s linear infinite;
}

.tw-moon { background: transparent; }
.tw-moon svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* Rings: the light returning, circle within circle */
.tw-moon::before {
  content: ""; position: absolute; inset: calc(var(--tw-disc) * -3.2);
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 calc(var(--tw-disc) * 0.42), oklch(0.90 0.02 240 / 0.9) calc(var(--tw-disc) * 0.42 + 0px) calc(var(--tw-disc) * 0.42 + 1px), transparent calc(var(--tw-disc) * 0.42 + 1px) calc(var(--tw-disc) * 0.5));
  -webkit-mask: radial-gradient(circle, transparent 14%, #000 16%, transparent 68%);
          mask: radial-gradient(circle, transparent 14%, #000 16%, transparent 68%);
  opacity: calc(0.42 * var(--tw-moon));
}
.tw-moon::after {
  content: ""; position: absolute; inset: calc(var(--tw-disc) * -1.4); border-radius: 50%;
  background: radial-gradient(circle, oklch(0.88 0.02 240 / calc(0.22 * var(--tw-moon))), transparent 65%);
}
.tw-moon .lit { fill: oklch(0.94 0.012 240); }
.tw-moon .dim { fill: oklch(0.42 0.02 250 / 0.55); }   /* earthshine: the disc stays whole */

@keyframes tw-turn { to { rotate: 360deg; } }

/* ==========================================================================
   The light control. One control, always in the same place. It moves the light, and it can hold
   the sky still. It never shows a number.
   ========================================================================== */

.tw-control {
  position: fixed; right: var(--tw-gutter); bottom: max(0.9rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.35rem 0.75rem 0.35rem 0.85rem;
  border-radius: 999px;
  background: color-mix(in oklab, var(--tw-ground) 82%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: var(--tw-ink-soft);
  font-size: 0.8rem;
}
.tw-control label { font-variant-caps: all-small-caps; letter-spacing: var(--tw-tracking-caps); }
.tw-control input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 7.5rem; height: 1.75rem; margin: 0; background: transparent; cursor: pointer;
}
.tw-control input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--tw-gold), var(--tw-silver));
}
.tw-control input[type="range"]::-moz-range-track {
  height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--tw-gold), var(--tw-silver));
}
.tw-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%;
  background: var(--tw-light); border: 0; box-shadow: 0 0 0 4px color-mix(in oklab, var(--tw-light) 22%, transparent);
}
.tw-control input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: 0; background: var(--tw-light);
}
.tw-control button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0.3rem 0.2rem; cursor: pointer;
  font-variant-caps: all-small-caps; letter-spacing: var(--tw-tracking-caps);
}
.tw-control button[aria-pressed="true"] { color: var(--tw-ink); }
html.tw-still .tw-sun::before { animation-play-state: paused; }
html.tw-still, html.tw-still * { transition-duration: 1ms !important; }

@media (prefers-reduced-motion: reduce) {
  .tw-sun::before { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; }
}

@media (max-width: 480px) {
  .tw-control { right: 50%; translate: 50% 0; }
  .tw-control input[type="range"] { width: 6.5rem; }
}
