/* issue 5: DIFFUSION. A short story on a plain page: black on
   white, nothing precious. The things that intrude on it keep
   their own registers — a phone notification, a reddit thread,
   and the Diffusion itself, flat grey and lit by nothing in the
   room. At the end, the button. Once pressed, it glows from
   within, and it stays that way. */

:root {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #767676;
  --accent: #bf6a45; /* peach pie */
  --card: #ffffff;
  --card-line: #e3e3e3;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 26px rgba(0, 0, 0, 0.09);

  /* the Diffusion: identical in every light */
  --diffusion: #f1f4f8;
  --diffusion-ink: #1d1f21;

  /* the glow: lumen is the light itself; spill is how it reads on
     the page, deeper on white so it shows at all */
  --lumen: 143, 246, 232;
  --spill: 52, 190, 178;
  --spill-alpha: 0.42;
  --halo-alpha: 0.75;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --ink: #ececec;
    --muted: #8f8f8f;
    --accent: #e09270;
    --card: #1e1e1e;
    --card-line: #2f2f2f;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 26px rgba(0, 0, 0, 0.45);
    --spill: var(--lumen);
    --spill-alpha: 0.34;
    --halo-alpha: 0.45;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Literata', Georgia, serif;
  font-optical-sizing: auto;
  font-size: 1.2rem;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

a {
  color: inherit;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.18em;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

article {
  width: min(34rem, 100% - 2.6rem);
  margin: 0 auto;
}

/* ---- title page -------------------------------------------------- */

.title {
  padding: 18vh 0 7vh;
  text-align: center;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
}

.kicker {
  margin: 0 0 2.2rem;
  font-size: 0.78rem;
/* 
  letter-spacing: 0.24em;
 */
  text-transform: uppercase;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 6.5vw, 2.4rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
}

.dek {
  margin: 1.1rem 0 0;
  font-style: italic;
  color: var(--muted);
}

/* ---- the story --------------------------------------------------- */

.story > p {
  margin: 0;
  hanging-punctuation: first;
}

.story > p + p {
  text-indent: 1.6em;
}

/* section break: three small points */
.story hr {
  width: 3.4rem;
  height: 1rem;
  margin: 2.6rem auto;
  border: 0;
  background: radial-gradient(circle, var(--muted) 0 1.6px, transparent 2.2px) center / 1.15rem 100% repeat-x;
  opacity: 0.8;
}

.story figure {
  margin: 2.2rem 0;
}

/* ---- the text message: a notification, buzzing ------------------- */

.story .sms {
  max-width: 26rem;
  margin: 2.2rem auto;
  padding: 0.85rem 1rem 0.95rem;
  border-radius: 1.15rem;
  background: var(--card);
  box-shadow: var(--card-shadow);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.93rem;
  line-height: 1.42;
}

.sms p {
  margin: 0;
}

.sms .sms-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.sms-app {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 0.3rem;
  background:
    radial-gradient(ellipse 34% 26% at 50% 46%, #fff 98%, transparent),
    linear-gradient(180deg, #74d58f, #2fae57);
}

.sms-time {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
}

.sms-from {
  font-weight: 600;
}

/* ---- the broadcast: flat, featureless, unlit by the room --------- */

.broadcast {
  padding: 1.6rem 1.7rem 1.4rem;
  background: var(--diffusion);
  color: var(--diffusion-ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.62;
  border-radius: 1rem;
}

.broadcast figcaption {
  margin-bottom: 1rem;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

/* transcript segments: a timestamp pill in a fixed gutter, then the words */
.broadcast p {
  display: grid;
  grid-template-columns: 3rem 1fr;
  column-gap: 0.8rem;
  align-items: start;
  margin: 0 0 0.9em;
}

.broadcast time {
  justify-self: start;
  /* centre the pill on the first line of text. In here 1em is the
     pill's own size (0.8 of the text's), so the text's 1.62 line box
     is 2.025em, and the pill is 1.5em + 0.2rem of padding tall:
     (2.025em - 1.5em - 0.2rem) / 2 */
  margin-top: calc(0.2625em - 0.1rem);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: rgba(29, 31, 33, 0.13);
  font-size: 0.8em;
  font-weight: 500;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.broadcast p:last-child {
  margin-bottom: 0;
}

.broadcast ::selection {
  background: var(--diffusion-ink);
  color: var(--diffusion);
}

/* ---- the thread -------------------------------------------------- */

.thread {
  --orange: #ff4500;
  border: 1px solid var(--card-line);
  border-radius: 0.6rem;
  background: var(--card);
  box-shadow: var(--card-shadow);
  font-family: 'Reddit Sans', system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow: hidden;
}

.thread p {
  margin: 0;
}

.thread-post {
  padding: 0.95rem 1.2rem 0.9rem;
  border-bottom: 1px solid var(--card-line);
}

.thread-sub {
  font-size: 0.8rem;
  font-weight: 700;
}

.thread .thread-title {
  margin-top: 0.2rem;
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.3;
}

.thread-comment {
  position: relative;
  padding: 0.95rem 1.2rem 0.8rem 3.1rem;
}

/* the reply rail */
.thread-comment::before {
  content: '';
  position: absolute;
  left: 1.82rem;
  top: 2.75rem;
  bottom: 1rem;
  width: 2px;
  border-radius: 1px;
  background: var(--card-line);
}

.thread .thread-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.5rem;
  margin: 0 0 0.55rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.thread-avatar {
  position: absolute;
  left: 1.2rem;
  top: 0.85rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #fff 0 22%, transparent 24%), #d1a3f0;
}

.thread-user {
  font-weight: 700;
  color: var(--ink);
}

.thread-pin {
  padding: 0.05em 0.45em;
  border-radius: 0.3em;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: #1a8a52;
}

.thread-age::before {
  content: '· ';
}

.thread-comment > p:not([class]) {
  margin-bottom: 0.75em;
}

.thread .thread-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.thread-up {
  color: var(--orange);
}

.thread-down {
  margin-right: 0.6rem;
}

/* ---- the button -------------------------------------------------- */

/* the coda: the button and the colophon, which closes the page. Its
   bottom edge is the bottom of the document. */
.coda {
  --size: clamp(7.5rem, 34vw, 10rem);
  --lead: 2rem; /* space above the bezel */
  --reach: calc(var(--size) * 2.2); /* how far the light climbs into the story */
  position: relative;
}

.beacon {
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--lead) 0 7rem;
}

/* The spill is far bigger than the page under the button, and it
   breathes by scaling. Anything transformed counts toward the page's
   scrollable height, so left loose it would resize the document on
   every breath and yank the reader's scroll position. This box clips
   it: full width, reaching up into the story, and ending exactly where
   the document ends — so nothing the light does can move the page. */
.glow {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--reach) * -1);
  bottom: 0;
  overflow: clip;
  pointer-events: none;
}

/* light the button throws on the page around it */
.spill {
  position: absolute;
  left: 50%;
  top: calc(var(--reach) + var(--lead) + var(--size) * 0.62);
  width: calc(var(--size) * 5);
  height: calc(var(--size) * 5);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(var(--spill), var(--spill-alpha)) 0%,
    rgba(var(--spill), calc(var(--spill-alpha) * 0.35)) 28%,
    rgba(var(--spill), 0) 62%
  );
  opacity: 0;
  pointer-events: none;
}

/* the bezel: a brushed-steel ring around a recessed well */
.housing {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(var(--size) * 1.24);
  height: calc(var(--size) * 1.24);
  border-radius: 50%;
  background: conic-gradient(
    from 210deg,
    #e7e9ea, #9da2a6 12%, #f4f5f6 24%, #868b90 38%, #d6d9db 52%,
    #8f9499 66%, #eef0f1 78%, #a2a7ab 90%, #e7e9ea
  );
  box-shadow:
    0 calc(var(--size) * 0.03) 0 #6e7378,
    0 calc(var(--size) * 0.08) calc(var(--size) * 0.14) rgba(0, 0, 0, 0.3),
    inset 0 1px 1px rgba(255, 255, 255, 0.9);
}

.housing::before {
  /* the well the cap sits in */
  content: '';
  position: absolute;
  inset: calc(var(--size) * 0.07);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #2a2d31, #0d0f11 72%);
  box-shadow:
    inset 0 calc(var(--size) * 0.03) calc(var(--size) * 0.05) rgba(0, 0, 0, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.5);
}

/* the cap: a smoked translucent dome, dark until it isn't */
.cap {
  --travel: calc(var(--size) * 0.05);
  position: relative;
  width: var(--size);
  height: var(--size);
  padding: 0;
  margin: 0 0 var(--travel);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 50% 64%, #3c4851 0%, #1f272d 52%, #10161a 78%, #080b0d 100%);
  box-shadow:
    0 var(--travel) 0 #050708,
    0 calc(var(--travel) + 0.3rem) 0.8rem rgba(0, 0, 0, 0.55),
    inset 0 calc(var(--size) * -0.05) calc(var(--size) * 0.1) rgba(0, 0, 0, 0.6),
    inset 0 calc(var(--size) * 0.02) calc(var(--size) * 0.04) rgba(255, 255, 255, 0.14);
  transition:
    transform 0.07s ease-out,
    box-shadow 0.07s ease-out,
    margin 0.07s ease-out;
}

.cap:active {
  transform: translateY(calc(var(--travel) * 0.8));
  box-shadow:
    0 calc(var(--travel) * 0.2) 0 #050708,
    0 calc(var(--travel) * 0.2 + 0.15rem) 0.35rem rgba(0, 0, 0, 0.6),
    inset 0 calc(var(--size) * -0.05) calc(var(--size) * 0.1) rgba(0, 0, 0, 0.6),
    inset 0 calc(var(--size) * 0.02) calc(var(--size) * 0.04) rgba(255, 255, 255, 0.14);
}

.cap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: calc(var(--size) * 0.14);
}

.cap span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

/* the light inside */
.core {
  background: radial-gradient(
    circle at 50% 58%,
    #fbfffe 0%,
    rgb(var(--lumen)) 22%,
    rgba(48, 186, 178, 0.92) 50%,
    rgba(14, 92, 98, 0.95) 76%,
    rgba(6, 40, 44, 1) 100%
  );
  opacity: 0;
}

/* a specular highlight on the dome, lit or not */
.shine {
  background:
    radial-gradient(ellipse 46% 26% at 42% 20%, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 30% 9% at 50% 88%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 80%);
}

/* ---- lit: it breathes, and it does not stop ---------------------- */

.lit .core {
  animation: breathe 2.8s ease-in-out infinite;
}

.lit .spill {
  animation: spill 2.8s ease-in-out infinite;
}

.lit .cap {
  box-shadow:
    0 var(--travel) 0 #04282b,
    0 calc(var(--travel) + 0.3rem) 0.8rem rgba(0, 0, 0, 0.45),
    0 0 calc(var(--size) * 0.28) rgba(var(--spill), var(--halo-alpha)),
    inset 0 calc(var(--size) * -0.05) calc(var(--size) * 0.1) rgba(0, 0, 0, 0.35);
}

.lit .cap:active {
  box-shadow:
    0 calc(var(--travel) * 0.2) 0 #04282b,
    0 calc(var(--travel) * 0.2 + 0.15rem) 0.35rem rgba(0, 0, 0, 0.5),
    0 0 calc(var(--size) * 0.28) rgba(var(--spill), var(--halo-alpha)),
    inset 0 calc(var(--size) * -0.05) calc(var(--size) * 0.1) rgba(0, 0, 0, 0.35);
}

@keyframes breathe {
  0%, 100% { opacity: 0.74; }
  50% { opacity: 1; }
}

@keyframes spill {
  0%, 100% { opacity: 0.45; transform: translate(-50%, -50%) scale(0.92); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
}

/* the first time only: it catches */
.lit .ignite .core {
  animation:
    catch 0.9s cubic-bezier(0.2, 0.8, 0.3, 1),
    breathe 2.8s ease-in-out 0.9s infinite;
}

.lit .ignite .spill {
  animation:
    flare 1.2s cubic-bezier(0.2, 0.8, 0.3, 1),
    spill 2.8s ease-in-out 1.2s infinite;
}

@keyframes catch {
  0% { opacity: 0; filter: brightness(1); }
  12% { opacity: 1; filter: brightness(1.8); }
  100% { opacity: 0.74; filter: brightness(1); }
}

@keyframes flare {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  100% { opacity: 0.45; transform: translate(-50%, -50%) scale(0.92); }
}

/* ---- colophon ---------------------------------------------------- */

footer {
  position: relative; /* paint above the light, not under it */
  padding: 0 1.2rem 3rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ---- small screens ----------------------------------------------- */

@media only screen and (max-width: 480px) {
  body {
    font-size: 1.08rem;
    line-height: 1.62;
  }

  .title {
    padding-top: 12vh;
  }

  .broadcast {
    padding: 1.3rem 1.2rem 1.1rem;
  }

  .thread-comment {
    padding-left: 2.8rem;
    padding-right: 1rem;
  }

  .thread-avatar {
    left: 0.95rem;
  }

  .thread-comment::before {
    left: 1.57rem;
  }
}

/* ---- decency ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .sms.buzz {
    animation: none;
  }

  /* still lit, just not breathing */
  .lit .core,
  .lit .ignite .core {
    animation: none;
    opacity: 0.9;
  }

  .lit .spill,
  .lit .ignite .spill {
    animation: none;
    opacity: 0.8;
  }

  .cap {
    transition: none;
  }
}
