/* Farewell web companion. Type system mirrors khoa.to:
   Stack Sans Notch for titles, Mona Sans for reading, Glass TTY for captions.
   Everything sits on one screen; app.js steps --k down until nothing scrolls. */

/* Stack Sans Notch and Mona Sans load from Google Fonts (same faces the
   portfolio gets via next/font/google). Glass TTY is not on Google: self-hosted. */
@font-face {
  font-family: "Glass TTY";
  src: url("./assets/fonts/glasstty-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #050505;
  --ink: #efeee9;
  --muted: #8d8c87;
  --dim: #4a4a46;
  --green: #86bc25;
  --gutter: clamp(16px, 2.4vw, 36px);
  --k: 1;
  --font-title: "Stack Sans Notch", ui-sans-serif, system-ui, sans-serif;
  --font-text: "Mona Sans", ui-sans-serif, system-ui, sans-serif;
  --font-caption: "Glass TTY", ui-monospace, SFMono-Regular, monospace;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  overflow-x: hidden;
}
::selection { background: var(--ink); color: var(--bg); }

.sr-only {
  position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.canvas {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100lvh;
  display: block;
  z-index: 0;
}

/* ---------- One-screen frame ---------- */

.frame {
  position: relative; z-index: 1;
  height: 100vh; height: 100svh;
  min-height: 320px;
  display: grid;
  grid-template-columns: minmax(0, 40fr) minmax(0, 60fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "hud     hud"
    "goodbye art"
    "copy    art"
    "copy    thanks";
  column-gap: var(--gutter);
  padding: var(--gutter);
  padding-bottom: max(var(--gutter), env(safe-area-inset-bottom));
}
.frame > * { min-width: 0; }

.hud {
  grid-area: hud;
  display: flex; align-items: center; gap: 28px;
  min-height: 28px;
  font: 20px/1 var(--font-caption);
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}
.hud__controls { margin-left: auto; display: flex; gap: 24px; }
.ctl {
  appearance: none; border: 0; padding: 4px 2px; background: none;
  color: var(--ink);
  font: 20px/1 var(--font-caption);
  text-transform: uppercase;
  cursor: pointer;
}
.ctl:hover, .ctl:focus-visible { color: var(--green); }
.ctl:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }

/* Titles: the h1 dissolves so each word can take its own grid area. */
.titles { display: contents; }
.title {
  display: block; overflow: hidden;
  margin: 0; padding: .02em .03em .12em;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: calc(var(--k) * var(--tfit) * min(9.4vw, 15.5vh, 190px));
  line-height: .86;
  letter-spacing: -.035em;
  pointer-events: none;
}
.title > span { display: inline-block; white-space: nowrap; transform: translateY(112%); }
.title { --tfit: 1; }
.title--goodbye { grid-area: goodbye; justify-self: start; margin-left: -.05em; margin-top: clamp(8px, 3vh, 40px); }
.title--thanks { grid-area: thanks; justify-self: end; text-align: right; margin-right: -.02em; }
.is-titled .title > span { transform: none; transition: transform 1.25s var(--ease-out); }
.is-titled .title--thanks > span { transition-delay: .12s; }

.art { grid-area: art; position: relative; min-height: 0; }

/* The dot is a real button for keyboard and touch; app.js sizes it. */
.reveal {
  position: absolute; z-index: 2;
  left: 50%; top: 50%;
  width: var(--hit, 120px); height: var(--hit, 120px);
  transform: translate(-50%, -50%);
  border: 0; border-radius: 50%;
  background: transparent; color: inherit;
  cursor: pointer;
  visibility: hidden;
}
.is-ready .reveal { visibility: visible; }
.reveal:focus-visible { outline: 1px solid var(--ink); outline-offset: 8px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Message ---------- */

/* The reveal lives inside the note: a phrase, marked with a small green block
   that echoes the dot. */
.hint-link {
  appearance: none; border: 0; margin: 0; padding: 0 0 1px;
  font: inherit; letter-spacing: inherit; color: var(--ink);
  background: linear-gradient(var(--green), var(--green)) 0 100% / 100% 1px no-repeat;
  cursor: pointer;
  transition: color .3s ease, background-size .4s var(--ease-out);
}
.hint-link::before {
  content: ""; display: inline-block;
  width: .5em; height: .5em; margin: 0 .32em .06em .1em;
  background: var(--green);
  animation: blink 1.06s steps(1) infinite;
}
.hint-link:hover, .hint-link:focus-visible { color: var(--green); outline: none; background-size: 100% 2px; }
.hint-link:focus-visible { outline: 1px solid var(--green); outline-offset: 3px; }
.is-revealed .hint-link { color: var(--green); }
.copy__body a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--green); text-underline-offset: .2em; text-decoration-thickness: 1px; }
.copy__body a:hover, .copy__body a:focus-visible { color: var(--green); outline: none; }
.is-revealed .hint-link--back { color: var(--muted); }
.hint-link--back::before { background: var(--muted); animation: none; }
.is-revealed .hint-link--back:hover, .is-revealed .hint-link--back:focus-visible { color: var(--ink); }
.is-revealed .hint-link::before { animation: none; }



.copy {
  grid-area: copy;
  align-self: end;
  display: flex; flex-direction: column;
  min-height: 0; max-height: 100%;
  gap: calc(var(--k) * clamp(14px, 2.6vh, 32px));
  max-width: 34em;
  padding-top: calc(var(--k) * clamp(12px, 3vh, 40px));
  outline: none;
  opacity: 0;
}
.is-titled .copy { opacity: 1; transition: opacity 1.1s ease .35s; }
.is-instant .title > span, .is-instant .copy { transition: none !important; }

/* The note scrolls inside its own frame when it outgrows the space. Its edges
   blend the way khoa.to does (components/site/scroll-edge-blur.css): stacked
   backdrop-blur bands, each masked to its own slice, over a soft alpha fade.
   Edges appear only where there is more text to read. */
@property --fade-top { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --fade-bottom { syntax: "<length>"; inherits: false; initial-value: 0px; }
.copy__frame { position: relative; display: flex; flex-direction: column; min-height: 0; }
.copy__scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  outline: none;
  --fade-top: 0px; --fade-bottom: 0px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
  transition: --fade-top .4s ease, --fade-bottom .4s ease;
}
.copy__scroll::-webkit-scrollbar { display: none; }
.copy__scroll:focus-visible { outline: 1px solid var(--dim); outline-offset: 6px; }
.copy__frame.is-scrolled .copy__scroll { --fade-top: 36px; }
.copy__frame.has-more .copy__scroll { --fade-bottom: 64px; }
.edge { position: absolute; left: 0; right: 0; z-index: 1; pointer-events: none; opacity: 0; transition: opacity .4s ease; }
.edge--top { top: 0; height: 44px; }
.edge--bottom { bottom: 0; height: 80px; }
.copy__frame.is-scrolled .edge--top, .copy__frame.has-more .edge--bottom { opacity: 1; }
.edge i {
  position: absolute; inset: 0;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  -webkit-backdrop-filter: blur(var(--b, 1px)); backdrop-filter: blur(var(--b, 1px));
}
.edge--bottom i:nth-child(1) { --b: 0.4px; -webkit-mask-image: linear-gradient(to bottom, transparent -16.67%, #000 0.00%, #000 16.67%, transparent 33.33%); mask-image: linear-gradient(to bottom, transparent -16.67%, #000 0.00%, #000 16.67%, transparent 33.33%); }
.edge--bottom i:nth-child(2) { --b: 0.8px; -webkit-mask-image: linear-gradient(to bottom, transparent 0.00%, #000 16.67%, #000 33.33%, transparent 50.00%); mask-image: linear-gradient(to bottom, transparent 0.00%, #000 16.67%, #000 33.33%, transparent 50.00%); }
.edge--bottom i:nth-child(3) { --b: 1.6px; -webkit-mask-image: linear-gradient(to bottom, transparent 16.67%, #000 33.33%, #000 50.00%, transparent 66.67%); mask-image: linear-gradient(to bottom, transparent 16.67%, #000 33.33%, #000 50.00%, transparent 66.67%); }
.edge--bottom i:nth-child(4) { --b: 3.2px; -webkit-mask-image: linear-gradient(to bottom, transparent 33.33%, #000 50.00%, #000 66.67%, transparent 83.33%); mask-image: linear-gradient(to bottom, transparent 33.33%, #000 50.00%, #000 66.67%, transparent 83.33%); }
.edge--bottom i:nth-child(5) { --b: 6.4px; -webkit-mask-image: linear-gradient(to bottom, transparent 50.00%, #000 66.67%, #000 83.33%, transparent 100.00%); mask-image: linear-gradient(to bottom, transparent 50.00%, #000 66.67%, #000 83.33%, transparent 100.00%); }
.edge--bottom i:nth-child(6) { --b: 12.8px; -webkit-mask-image: linear-gradient(to bottom, transparent 66.67%, #000 83.33%, #000 100.00%, transparent 116.67%); mask-image: linear-gradient(to bottom, transparent 66.67%, #000 83.33%, #000 100.00%, transparent 116.67%); }
.edge--top i:nth-child(1) { --b: 0.4px; -webkit-mask-image: linear-gradient(to top, transparent -16.67%, #000 0.00%, #000 16.67%, transparent 33.33%); mask-image: linear-gradient(to top, transparent -16.67%, #000 0.00%, #000 16.67%, transparent 33.33%); }
.edge--top i:nth-child(2) { --b: 0.8px; -webkit-mask-image: linear-gradient(to top, transparent 0.00%, #000 16.67%, #000 33.33%, transparent 50.00%); mask-image: linear-gradient(to top, transparent 0.00%, #000 16.67%, #000 33.33%, transparent 50.00%); }
.edge--top i:nth-child(3) { --b: 1.6px; -webkit-mask-image: linear-gradient(to top, transparent 16.67%, #000 33.33%, #000 50.00%, transparent 66.67%); mask-image: linear-gradient(to top, transparent 16.67%, #000 33.33%, #000 50.00%, transparent 66.67%); }
.edge--top i:nth-child(4) { --b: 3.2px; -webkit-mask-image: linear-gradient(to top, transparent 33.33%, #000 50.00%, #000 66.67%, transparent 83.33%); mask-image: linear-gradient(to top, transparent 33.33%, #000 50.00%, #000 66.67%, transparent 83.33%); }
.edge--top i:nth-child(5) { --b: 6.4px; -webkit-mask-image: linear-gradient(to top, transparent 50.00%, #000 66.67%, #000 83.33%, transparent 100.00%); mask-image: linear-gradient(to top, transparent 50.00%, #000 66.67%, #000 83.33%, transparent 100.00%); }
.edge--top i:nth-child(6) { --b: 12.8px; -webkit-mask-image: linear-gradient(to top, transparent 66.67%, #000 83.33%, #000 100.00%, transparent 116.67%); mask-image: linear-gradient(to top, transparent 66.67%, #000 83.33%, #000 100.00%, transparent 116.67%); }
.copy__body p {
  margin: 0 0 .8em;
  font-size: calc(var(--k) * clamp(15px, .72vw + 1.15vh, 23px));
  line-height: 1.38;
  font-weight: 400;
  letter-spacing: -.006em;
  text-wrap: pretty;
}
.copy__body p:last-child { margin-bottom: 0; }
/* The opening line is the same voice as the note, only heavier. */
.copy__body p:first-child { font-weight: 600; }
.copy__sign { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 32px; }
.signature {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: calc(var(--k) * clamp(26px, 1.6vw + 1.6vh, 44px));
  letter-spacing: -.03em;
  line-height: 1;
}
.contacts { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.contacts a {
  font: 20px/1 var(--font-caption);
  color: var(--ink); text-decoration: none;
  padding: 6px 0;
  border-bottom: 1px solid var(--dim);
}
.contacts a:hover, .contacts a:focus-visible { color: var(--green); border-color: var(--green); outline: none; }


/* ---------- Portrait: art in the top third, the note breathes below ---------- */

@media (orientation: portrait) {
  .frame {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(200px, 31svh) minmax(0, 1fr);
    grid-template-areas: "hud" "art" "copy";
    padding: max(20px, env(safe-area-inset-top)) max(24px, var(--gutter)) max(20px, env(safe-area-inset-bottom));
  }
  .hud, .ctl { font-size: 10px; letter-spacing: .1em; }
  .hud { min-height: 20px; }
  .hud__note { display: none; }
  .title { font-size: calc(var(--tfit) * min(11.5vw, 5.6svh, 92px)); letter-spacing: -.03em; }
  .title--goodbye { grid-area: art; align-self: start; margin-top: 10px; }
  .title--thanks { grid-area: art; align-self: end; margin-bottom: 2px; }
  .copy {
    max-width: 34em; align-self: stretch;
    padding-top: clamp(22px, 3.6svh, 40px);
    gap: clamp(18px, 2.8svh, 28px);
  }
  .copy__frame { flex: 1 1 auto; }
  .copy__body { padding-bottom: 6px; }
  .copy__body p { font-size: clamp(14px, 3.6vw, 16.5px); line-height: 1.62; margin-bottom: 1.05em; letter-spacing: 0; }
  .copy__sign { justify-content: space-between; align-items: center; flex-wrap: nowrap; padding-top: 2px; }
  .signature { font-size: clamp(21px, 5.6vw, 28px); }
  .contacts { gap: 0 18px; flex-wrap: nowrap; }
  .contacts a { font-size: 10px; letter-spacing: .1em; padding: 16px 0 10px; white-space: nowrap; }
}
@media (orientation: portrait) and (max-width: 440px) {
  .slash { display: none; }
}

/* ---------- Landscape phones: split, art left, note right ---------- */

@media (orientation: landscape) and (max-height: 560px) {
  .frame {
    grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "hud hud" "art copy";
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
  }
  .title { font-size: calc(var(--k) * var(--tfit) * min(7.4vw, 15svh)); }
  .title--goodbye { grid-area: art; align-self: start; margin-top: 0; }
  .title--thanks { grid-area: art; align-self: end; }
  .hud__note { display: none; }
  .copy { align-self: center; max-width: 36em; padding-top: 0; gap: calc(var(--k) * 10px); }
  .copy__body p { font-size: calc(var(--k) * clamp(13px, .9vw + 1.2svh, 16px)); line-height: 1.4; margin-bottom: .55em; }
  .signature { font-size: calc(var(--k) * clamp(22px, 1.4vw + 2.6svh, 30px)); }
  .contacts a { padding: 10px 0 8px; }
}

/* Touch targets for the caption controls. */
@media (pointer: coarse) {
  .ctl { min-height: 44px; padding-inline: 6px; }
}

/* Allow a scroll fallback only when even the smallest fit cannot hold. */
.is-overflow .frame { height: auto; min-height: 100svh; }
.is-overflow .canvas { position: absolute; height: 100%; }
.is-overflow { position: relative; }

@media (prefers-reduced-motion: reduce) {
  .title > span, .copy { transition: none !important; }
  .hint-link::before { animation: none; }
}
