/* ==========================================================================
   Home — the portfolio canvas behind the hero (48em and up).
   Composes the shared tokens; every class is ph-prefixed.

   Two layers. The hero section holds the Dispatch card, in the page's flow.
   The canvas ([data-ph-world]) is a body-level layer that home-canvas.js lays
   exactly over the hero. On the homepage it is out of sight until a pulse
   shows it; exploring turns it into a full-screen dialog while everything
   else is made inert.

   Below 48em the homepage keeps its own hero (.hero, in home.css) and none of
   this is shown.
   ========================================================================== */

/* ---------- Which hero ---------------------------------------------------- */

.ph-hero,
.ph-world:not(.is-exploring) { display: none; }

@media (min-width: 48em) {
  .hero { display: none; }
  .ph-hero { display: grid; }
  .ph-world:not(.is-exploring) { display: block; }
}

/* ---------- Hero ------------------------------------------------------------ */

.ph-hero {
  position: relative;
  place-items: center;
  height: calc(100svh - var(--header-h));
  min-height: 34rem;
  container-type: size;      /* the card is sized from the hero */
  cursor: pointer;           /* anywhere in the hero opens the canvas */
}

/* The card is one tile of the grid: 4:3, the size the canvas draws its tiles
   on the homepage (home-canvas.js matches the canvas to this width). About two
   and a half across, never taller than about half the hero. Solid paper, so
   nothing behind it can reach the message. */
.ph-card {
  position: relative;
  z-index: 2;
  container-type: inline-size;
  display: grid;
  align-content: center;
  justify-items: center;
  /* Its own size, from the hero's; spacing is a share of it. */
  --ph-card-w: min(38.5cqw, 68cqh, 38.75rem);
  gap: calc(var(--ph-card-w) * 0.03);
  width: var(--ph-card-w);
  aspect-ratio: 4 / 3;
  padding: calc(var(--ph-card-w) * 0.06) calc(var(--ph-card-w) * 0.07);
  overflow: hidden;
  border-radius: var(--radius-surface);
  background: var(--color-bg);
  box-shadow: var(--shadow-card);
  text-align: center;
  cursor: pointer;
  transition:
    opacity var(--dur-slow) var(--ease-standard),
    visibility 0s linear 0s;
}
/* Type sized from the card, so the message fills the tile at any size. */
.ph-card__mark {
  width: clamp(2.25rem, 11cqi, 4.5rem);
  height: auto;
  aspect-ratio: 1;
}
.ph-card__title { font-size: clamp(1.25rem, 6.4cqi, 2.375rem); }
.ph-card__lead {
  max-width: 34ch;
  font-size: clamp(0.875rem, 3.3cqi, 1.125rem);
  line-height: var(--leading-normal);
}
.ph-card__cta {
  margin-block-start: 1cqi;
  font-size: clamp(0.75rem, 2.7cqi, var(--text-sm));
}
/* Too little room at this size: the mark goes first (the header has the logo). */
.ph-card.is-tight .ph-card__mark { display: none; }

/* The whole card is the button's target: one keyboard stop, card-wide click. */
.ph-card__cta::after {
  content: "";
  position: absolute;
  inset: 0;
}
.ph-card:hover .ph-card__cta {
  background: var(--color-accent-deep);
  box-shadow: var(--shadow-tag-hover);
}
.ph-card:has(.ph-card__cta:focus-visible) {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}
.ph-card__cta:focus-visible { outline-offset: var(--space-1); }

/* Into the canvas and back: the card rides on its own tile (home-canvas.js
   moves and scales it every frame) above the growing canvas, and only what
   the tile does not have — the button and the shadow — fades. Once the canvas
   has the screen, the tile is the card, so the card itself simply goes. */
.ph-hero .ph-card {
  transform-origin: 50% 50%;
  transition: box-shadow var(--dur-slow) var(--ease-standard);
}
.ph-hero .ph-card__cta {
  transition:
    opacity var(--dur-base) var(--ease-standard),
    background-color var(--dur-fast) var(--ease-standard),
    transform var(--dur-instant) var(--ease-standard);
}
.ph-hero.is-handing .ph-card { box-shadow: none; }
.ph-hero.is-handing .ph-card__cta { opacity: 0; }
.ph-hero.is-leaving .ph-card { visibility: hidden; }
.ph-hero.is-lifted .ph-card { z-index: calc(var(--z-modal) + 1); }

/* ---------- The canvas layer ----------------------------------------------- */

.ph-world {
  position: absolute;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;      /* on the homepage, only the card is a target */
  opacity: 0;
  transition: opacity var(--dur-slower) var(--ease-standard);
}
.ph-world.is-ready { opacity: 1; }
.ph-world.is-exploring {
  position: fixed;
  z-index: var(--z-modal);
  pointer-events: auto;
  overscroll-behavior: none;
}

.ph-stage {
  position: absolute;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;        /* the page scrolls through it on the homepage */
}
.ph-world.is-exploring .ph-stage {
  cursor: grab;
  touch-action: none;
}
.ph-world.is-exploring .ph-stage.is-dragging { cursor: grabbing; }
.ph-stage:focus-visible { outline: none; }
.ph-stage:focus-visible::after {
  content: "";
  position: absolute;
  inset: var(--space-2);
  outline: var(--focus-ring-width) solid var(--color-focus);
  pointer-events: none;
}

/* Sized and positioned by home-canvas.js: the drawing buffer covers the largest
   frame, and only its top-left corner shows while the frame is smaller. */
.ph-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

/* Edge blur, as in the canvas prototype: none inside the sharp window, full at
   the edges, in two ramps so the window is a rectangle like the sheet. */
.ph-blur {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--ph-blur-op, 0);
  backdrop-filter: blur(var(--ph-blur, 3.5px));
  -webkit-backdrop-filter: blur(var(--ph-blur, 3.5px));
  -webkit-mask-image:
    linear-gradient(to right, #000 var(--ph-out, 0px), transparent var(--ph-in, 16%),
                    transparent calc(100% - var(--ph-in, 16%)), #000 calc(100% - var(--ph-out, 0px))),
    linear-gradient(to bottom, #000 var(--ph-out, 0px), transparent var(--ph-in, 16%),
                    transparent calc(100% - var(--ph-in, 16%)), #000 calc(100% - var(--ph-out, 0px)));
  mask-image:
    linear-gradient(to right, #000 var(--ph-out, 0px), transparent var(--ph-in, 16%),
                    transparent calc(100% - var(--ph-in, 16%)), #000 calc(100% - var(--ph-out, 0px))),
    linear-gradient(to bottom, #000 var(--ph-out, 0px), transparent var(--ph-in, 16%),
                    transparent calc(100% - var(--ph-in, 16%)), #000 calc(100% - var(--ph-out, 0px)));
}

/* The page is held still while the canvas has it. */
html.ph-locked { overflow: hidden; }

/* ---------- Exploring: controls ------------------------------------------- */

.ph-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-standard);
}
.ph-ui.is-in { opacity: 1; }
.ph-ui > * { pointer-events: auto; }

.ph-bar {
  position: absolute;
  top: max(var(--space-4), env(safe-area-inset-top));
  left: max(var(--space-4), env(safe-area-inset-left));
  right: max(var(--space-4), env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  pointer-events: none;
}
.ph-bar > * { pointer-events: auto; }

.ph-home,
.ph-chip,
.ph-zoom__btn,
.ph-back {
  min-height: 2.75rem;          /* 44px targets */
  border: var(--border-hairline) solid var(--color-hairline);
  border-radius: var(--radius-control);
  background: rgb(255 255 255 / 0.94);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
  box-shadow: 0 6px 18px -10px rgb(var(--color-ink-rgb) / 0.35);
}
.ph-home:hover,
.ph-chip:hover,
.ph-zoom__btn:hover,
.ph-back:hover { background: var(--color-paper); }

.ph-home {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
  border-color: var(--color-ink);
  background: var(--color-ink);
  color: var(--color-on-inverse);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}
.ph-home:hover { background: rgb(var(--color-ink-rgb) / 0.88); }

.ph-chips {
  display: flex;
  gap: var(--space-2);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.ph-chip {
  flex: none;
  padding: 0 var(--space-4);
  white-space: nowrap;
}
.ph-chip span { opacity: 0.5; font-variant-numeric: tabular-nums; }
.ph-chip[aria-pressed="true"] {
  border-color: var(--color-ink);
  background: var(--color-ink);
  color: var(--color-on-inverse);
}
.ph-chip[aria-pressed="true"] span { opacity: 0.65; }

.ph-zoom {
  position: absolute;
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  display: flex;
  gap: var(--space-1);
}
.ph-zoom__btn {
  min-width: 2.75rem;
  padding: 0 var(--space-3);
  font-size: var(--text-lg);
  line-height: 1;
}
.ph-zoom__reset { font-size: var(--text-xs); }

.ph-hint {
  position: absolute;
  left: 50%;
  bottom: max(var(--space-5), env(safe-area-inset-bottom));
  translate: -50% 0;
  margin: 0;
  padding: var(--space-2) var(--space-4);
  background: rgb(255 255 255 / 0.9);
  color: var(--color-text);
  font-size: var(--text-xs);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease-standard);
}
.ph-hint.is-gone { opacity: 0; }

.ph-back {
  position: absolute;
  left: 50%;
  bottom: max(var(--space-5), env(safe-area-inset-bottom));
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-standard);
}
.ph-back.is-in { opacity: 1; }
.ph-back kbd {
  padding: 0.1em 0.35em;
  border: 1px solid currentColor;
  font: inherit;
  font-size: 0.9em;
  opacity: 0.55;
}

/* ---------- Tablets and narrow windows: a larger share of the width ---------- */

@media (max-width: 63.99em) {
  .ph-card { --ph-card-w: min(58cqw, 68cqh, 38.75rem); }
}

/* ---------- Phones ----------------------------------------------------------- */

@media (max-width: 47.99em) {
  /* One tile across, with a margin either side. */
  .ph-card {
    --ph-card-w: min(calc(100cqw - 2 * var(--space-4)), 100cqh);
    gap: calc(var(--ph-card-w) * 0.026);
    padding: calc(var(--ph-card-w) * 0.05) calc(var(--ph-card-w) * 0.06);
  }
  .ph-blur { display: none; }          /* the shader's own softening is enough here */
  .ph-chips { flex-basis: 100%; }
  /* The zoom row owns the bottom edge; the hint and the way back sit above it. */
  .ph-hint,
  .ph-back { bottom: calc(max(var(--space-4), env(safe-area-inset-bottom)) + 2.75rem + var(--space-3)); }
  .ph-hint { width: max-content; max-width: calc(100% - 2 * var(--space-4)); white-space: normal; text-align: center; }
}

/* ---------- Reduced motion: state changes, not travel ---------------------- */

@media (prefers-reduced-motion: reduce) {
  .ph-world, .ph-ui, .ph-hint, .ph-back,
  .ph-hero .ph-card, .ph-hero .ph-card__cta { transition: none; }
}
