/* styles/tokens.css */
/*
  Layout is drawn in "card units" (u), mirroring business_card.svg's 900×500
  viewBox. 1u scales with the viewport (width and height) and is capped so
  the card never gets absurdly large on wide screens.
*/
:root {
  --u: min(0.1vw, 0.19vh, 1.8px);
  /* always dark, whatever the browser's color scheme */
  color-scheme: dark;
  --ink: #f2f2f2;
  --paper: #0d0d0d;
  --accent: #7d9bff;
  --accent-contrast: hsl(106deg 100% 75%); /* --accent hue - 119°; see index.js */
  --radius: calc(8 * var(--u));

  /* One device pixel, in CSS px. Browsers snap border widths and box edges
     to device pixels, so the stroke and any offsets the pointer must line up
     on are snapped to this grid too (see .pointer). */
  --dpx: 1px;
  --stroke: max(var(--dpx), round(calc(3 * var(--u)), var(--dpx)));
}
@media (min-resolution: 1.2dppx)  { :root { --dpx: calc(1px / 1.25); } }
@media (min-resolution: 1.45dppx) { :root { --dpx: calc(1px / 1.5); } }
@media (min-resolution: 1.7dppx)  { :root { --dpx: calc(1px / 1.75); } }
@media (min-resolution: 1.95dppx) { :root { --dpx: calc(1px / 2); } }
@media (min-resolution: 2.2dppx)  { :root { --dpx: calc(1px / 2.25); } }
@media (min-resolution: 2.45dppx) { :root { --dpx: calc(1px / 2.5); } }
@media (min-resolution: 2.95dppx) { :root { --dpx: calc(1px / 3); } }

/* styles/typography.css */
/* Variable Cooper first; browsers without variable-font support fall back
   to the static Black cut. */
@font-face {
  font-family: "Cooper";
  src: url("../assets/fonts/Cooper[wght].woff2") format("woff2") tech(variations),
       url("../assets/fonts/Cooper-Black.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

/* the address */
h1 {
  font-family: "Cooper", Georgia, serif;
  font-weight: 600;
  font-size: calc(60 * var(--u));
  line-height: 1;
  letter-spacing: -0.005em;
  white-space: nowrap;
}

/* the highlighted part of the address goes from semi-bold to black; the
   links' parts also glow like neon (below), first/last name only go black */
.seg:has(> .brace > .label:hover),
.seg:has(> .brace > a.label:focus-visible),
.seg.active {
  font-weight: 900;
}

/* The glow is the letter drawn twice more, behind itself: ::before glows in
   --accent, ::after in --accent-contrast (index.js picks a new pair on each
   hover). The glyphs are transparent so only their text-shadow shows, and
   only opacity animates, which the browser can composite without repainting
   the blur. index.js wraps each letter in
   <span class="char" data-ch="a" style="--i: n">. */
.char {
  /* inline-block so the letter sits in a line box exactly like its absolutely
     positioned copies do (same top, same baseline); as a plain inline span its
     box is the font's taller content area and the copies land too high */
  display: inline-block;
  position: relative;
  isolation: isolate; /* keeps the z-index: -1 layers behind this letter only */
}
.char::before,
.char::after {
  content: attr(data-ch);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: transparent;
  opacity: 0;
  pointer-events: none;
}
.char::before {
  transition: opacity .15s ease;
  text-shadow:
    0 0 0.05em var(--paper),
    0 0 0.15em var(--accent),
    0 0 0.4em var(--accent),
    0 0 0.8em var(--accent);
}
.char::after {
  text-shadow:
    0 0 0.05em var(--paper),
    0 0 0.15em var(--accent-contrast),
    0 0 0.4em var(--accent-contrast),
    0 0 0.8em var(--accent-contrast);
}
@keyframes glow-swap { to { opacity: 1; } }
.seg:has(> .brace > a.label:hover) .char::before,
.seg:has(> .brace > a.label:focus-visible) .char::before,
.seg.active .char::before {
  opacity: 1;
}
/* the contrast layer fades in and out over the accent one; each letter
   starts 0.06s after the one to its left, so the color sweeps rightward */
.seg:has(> .brace > a.label:hover) .char::after,
.seg:has(> .brace > a.label:focus-visible) .char::after,
.seg.active .char::after {
  animation: glow-swap 1.5s ease-in-out calc(var(--i) * 0.06s) infinite alternate;
}

/* the bracket labels; they sit inside the h1 but stay in the body face */
small {
  font-family: "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-weight: 400;
  font-size: calc(28 * var(--u));
  letter-spacing: normal;
  text-shadow: none;
  line-height: 1;
  white-space: nowrap;
}

/* links are the bracket labels themselves (<a class="label"><small>…), so
   they take the label size too; the label's em padding is measured from it */
a {
  color: inherit;
  text-decoration: none;
  font-size: calc(28 * var(--u));
}

/* styles/base.css */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: hidden;
}

main {
  /* reserve room for the labels/brackets that hang above & below the line */
  padding: calc(110 * var(--u)) 0 calc(212 * var(--u));
}

.address {
  margin: 0;
}

.seg {
  cursor: default;
  position: relative;
  display: inline-block;
  transition: color .15s ease, font-weight .15s ease;
  user-select: none;
}

.name {
  cursor: default;
  user-select: none;
}

/* styles/brace.css */
/* ---------- brackets ---------- */
.brace {
  position: absolute;
  left: calc(6 * var(--u));
  right: calc(6 * var(--u));
  display: flex;
  color: var(--ink);
  pointer-events: none;
  transition: color .15s ease;
}
.brace .arm {
  flex: 1;
  align-self: stretch;
  border: var(--stroke) solid currentColor;
}

/* opening upward (labels above the address) */
.brace.up {
  bottom: calc(100% + 24 * var(--u));
  height: calc(30 * var(--u));
  align-items: flex-start;
}
.brace.up .arm { border-bottom: 0; }
.brace.up .arm:first-of-type { border-right: 0; border-top-left-radius: var(--radius); }
.brace.up .arm:last-of-type { border-left: 0;  border-top-right-radius: var(--radius); }
/* pointer's bottom edge = bottom of the arms' top border */
.brace.up .pointer { margin-top: calc(var(--stroke) - var(--pointer-h)); }

/* opening downward (labels below the address) */
.brace.down {
  top: calc(100% + 33 * var(--u));
  height: calc(var(--leg, 30) * var(--u));
  align-items: flex-end;
}
.brace.down .arm { border-top: 0; }
.brace.down .arm:first-of-type { border-right: 0; border-bottom-left-radius: var(--radius); }
.brace.down .arm:last-of-type { border-left: 0;  border-bottom-right-radius: var(--radius); }
/* pointer's top edge = top of the arms' bottom border */
.brace.down .pointer { margin-bottom: calc(var(--stroke) - var(--pointer-h)); }

.email > .brace.down {
  --leg: 120;
  --radius: calc(20 * var(--u));
}

/* styles/pointer.css */
/* ---------- pointer ----------
   The curly tip from the card. Markup:
     <svg class="pointer"><use href="#pointer"/></svg>            (points up)
     <svg class="pointer pointer--down"><use href="#pointer"/></svg>
   The #pointer symbol (index.html) has its baseline on the bottom edge of
   its viewBox and a non-scaling stroke, so:
   - the shape scales smoothly with --u,
   - the line is exactly --stroke thick, the same as a border of --stroke,
   - the line occupies the box's bottom --stroke (top, for --down), and the
     box height is snapped to device pixels, so anything that aligns its
     edge to that band lands on the same pixel rows.
   The path bleeds 1 unit past each side to overlap neighbours seamlessly. */
.pointer {
  --pointer-h: max(var(--stroke), round(calc(11.5 * var(--u)), var(--dpx)));
  display: block;
  flex: none;
  width: calc(var(--pointer-h) * 32.38 / 11.5);
  height: var(--pointer-h);
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: var(--stroke);
}
/* the outer <svg> has no viewBox, so these lengths are plain CSS px */
.pointer use        { transform: translateY(calc(var(--stroke) / -2)); }
.pointer--down use  { transform: translateY(calc(var(--pointer-h) + var(--stroke) / 2)) scaleY(-1); }

/* styles/label.css */
/* ---------- labels ---------- */
.label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  padding: 0.15em 0.3em;
  border-radius: 0.2em;
  outline-offset: 2px;
}
.brace.up   .label { bottom: calc(100% + 26 * var(--u) - 0.15em); }
.brace.down .label { top:    calc(100% + 28 * var(--u) - 0.15em); }

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

/* brackets with plain labels (first/last name) are muted so the links stand
   out; arms, pointer and label all pick this up via currentColor/inherit */
.brace:not(:has(> a.label)) { color: color-mix(in srgb, var(--ink) 50%, var(--paper)); }

/* hovering/focusing a label recolors its bracket; the part of the address it
   names glows (see typography.css) */
.seg:has(> .brace > a.label:hover) > .brace,
.seg:has(> .brace > a.label:focus-visible) > .brace,
.seg.active > .brace {
  color: var(--accent);
}

/* the links open elsewhere, so each ends in the "open in new" icon
   (#open-in-new in index.html), drawn in the label's current color. When its
   link is highlighted it glows in --accent like the letters' ::before layer
   (typography.css); a drop-shadow, since an SVG has no text-shadow. */
.icon {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.15em;
  vertical-align: -0.1em;
  fill: currentColor;
  transition: filter .15s ease;
}
a.label:hover .icon,
a.label:focus-visible .icon,
.seg.active > .brace > a.label .icon {
  filter:
    drop-shadow(0 0 0.15em var(--accent))
    drop-shadow(0 0 0.4em var(--accent));
}
