/* cube.css — the spatial layer.
 *
 * Loaded on top of styles.css. EVERY rule that repositions content into 3D is
 * scoped behind `.cube-ready`, a class main.js adds only after the module boots.
 * With JS off (or if the module fails), none of this applies: the six panels
 * fall back to normal block flow and index.html reads as the same flat document
 * styles.css already styles. The cube is pure progressive enhancement.
 *
 * Reader content is styled by styles.css defaults, not by `.panel` rules, so a
 * flattened face reads like a clean document (that's the whole point of the
 * focus -> flatten split).
 */

/* ---- shared chrome (hidden until the cube is live) ---------------------- */

.skip-link {
  position: fixed;
  top: -60px;
  left: 12px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--paper);
  transition: top 140ms ease;
}
.skip-link:focus { top: 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.face-rail { display: none; }

/* ---- cube stage --------------------------------------------------------- */

.cube-ready {
  --cube: min(72vmin, 620px);
  --half: calc(var(--cube) / 2);
  --rx: -22deg;
  --ry: 34deg;
  --scale: 1;
  --cube-face: #ffffff;
  --cube-edge: rgba(26, 26, 26, 0.14);
  --cube-shadow: rgba(26, 26, 26, 0.18);
}

@media (prefers-color-scheme: dark) {
  .cube-ready {
    --cube-face: #242424;
    --cube-edge: rgba(255, 255, 255, 0.12);
    --cube-shadow: rgba(0, 0, 0, 0.55);
  }
}

html:has(body.cube-ready),
body.cube-ready {
  height: 100%;
  overflow: hidden;
}

body.cube-ready {
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, var(--grain) 0.7px, transparent 0.8px),
    radial-gradient(120vmax 90vmax at 50% 28%,
      color-mix(in oklab, var(--paper) 100%, var(--ink) 7%),
      var(--paper) 70%);
  background-size: 7px 7px, auto;
}

.cube-ready main {
  max-width: none;
  margin: 0;
  padding: 0;
}

.cube-ready .viewport {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  perspective: 3200px;
  perspective-origin: 50% 46%;
  touch-action: none;
  z-index: 1;
  outline: none;
  cursor: grab; /* the cube always reads as grabbable */
}
body.is-dragging { cursor: grabbing; }

/* The library owns the rig transform (an inline matrix3d it writes each frame);
 * this is just the initial pose + the 3D context. In page mode we neutralise the
 * leftover inline transform so the same markup lays out as a normal document. */
.cube-ready .rig {
  position: relative;
  width: var(--cube);
  height: var(--cube);
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transform-style: preserve-3d;
}
.cube-ready .rig.is-moving { will-change: transform; }
body:not(.cube-ready) #rig { transform: none !important; }

/* Faces carry NO drop-shadow: a box-shadow on a 3D-transformed element renders
 * in the face's own plane and smears out past the silhouette. Depth comes from
 * the border + an inset edge instead. */
.cube-ready .panel {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: clamp(1rem, 3.2vmin, 1.6rem);
  overflow: hidden;
  border: 1px solid var(--cube-edge);
  border-radius: 16px;
  background: var(--cube-face);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--cube-face) 100%, var(--ink) 3%);
  backface-visibility: hidden;
  transform-style: preserve-3d;
  cursor: grab;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.cube-ready .panel--front { transform: translateZ(var(--half)); }
.cube-ready .panel--back { transform: rotateY(180deg) translateZ(var(--half)); }
.cube-ready .panel--right { transform: rotateY(90deg) translateZ(var(--half)); }
.cube-ready .panel--left { transform: rotateY(-90deg) translateZ(var(--half)); }
.cube-ready .panel--top { transform: rotateX(90deg) translateZ(var(--half)); }
.cube-ready .panel--bottom { transform: rotateX(-90deg) translateZ(var(--half)); }

/* Hover ring — a crisp inset ring on the face the pointer is geometrically over
 * (JS-picked). No outer bleed, so nothing smears past the cube silhouette. */
.cube-ready .panel.is-hovered {
  border-color: color-mix(in oklab, var(--link) 55%, var(--cube-edge));
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--link) 45%, transparent);
}

.cube-ready .panel.is-focused {
  border-color: color-mix(in oklab, var(--link) 55%, var(--cube-edge));
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--link) 30%, transparent);
}

/* Unfocused faces preview their content: inert (so a press orbits/focuses) and
 * clamped with a fade. */
.cube-ready .panel .panel__content {
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-mask-image: linear-gradient(180deg, #000 68%, transparent 98%);
  mask-image: linear-gradient(180deg, #000 68%, transparent 98%);
}

/* Focused face: read it in place. Selectable text, clickable links, and it
 * scrolls with a visible scrollbar when the content overflows the face. */
.cube-ready .panel.is-focused .panel__content {
  pointer-events: auto;
  -webkit-user-select: text;
  user-select: text;
  overflow-y: auto;
  -webkit-mask-image: none;
  mask-image: none;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in oklab, var(--ink) 32%, transparent) transparent;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.cube-ready .panel.is-focused .panel__content::-webkit-scrollbar { width: 9px; }
.cube-ready .panel.is-focused .panel__content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in oklab, var(--ink) 30%, transparent);
}
.cube-ready .panel.is-focused iframe { pointer-events: auto; }

.cube-ready .panel .panel__content > :first-child { margin-top: 0; }
.cube-ready .panel h2 { margin-top: 1.25rem; font-size: 1.15rem; }
.cube-ready .panel h2:first-child { margin-top: 0; }
.cube-ready .panel h3 { margin-top: 1rem; }
.cube-ready .panel iframe { pointer-events: none; }

.cube-ready .panel--front .panel__content {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.cube-ready .panel--front h1 { font-size: clamp(1.6rem, 5vmin, 2.3rem); }
.cube-ready .panel--front .hero { margin: 0; }
.cube-ready .panel--front .tagline {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}
.cube-ready .panel--front .social-banner {
  justify-content: center;
  gap: 0.15rem;
  margin: 0.4rem 0 0.1rem;
  border: 0;
  padding: 0;
}
.cube-ready .panel--front .social-banner a { width: 34px; height: 34px; font-size: 1.05rem; }
/* the contact table lost its `header dd { margin:0 }` when it moved out of the
 * hero — restore tight rows. */
.panel--front dl { gap: 0.15rem 1rem; margin: 0; }
.panel--front dd { margin: 0; }

/* ---- face rail ---------------------------------------------------------- */

.cube-ready .face-rail {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  max-width: calc(100vw - 1.5rem);
  padding: 0.3rem;
  border: 1px solid var(--cube-edge);
  border-radius: 999px;
  background: color-mix(in oklab, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transform: translateX(-50%);
}

.rail-button {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}
.rail-button:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 8%, transparent); }
.rail-button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.rail-button.is-active {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

/* ---- mode switch (cube ⇄ reading document) ------------------------------ */

.mode-switch {
  position: fixed;
  z-index: 14;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--muted);
  border-radius: 999px;
  background: color-mix(in oklab, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.mode-switch:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.mode-switch__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 30px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.82rem;
  transition: background-color 160ms ease, color 160ms ease;
}
/* the active side (keyed on the mode) is filled; clicking anywhere flips it */
body.cube-ready .mode-switch__icon[data-mode="cube"],
body:not(.cube-ready) .mode-switch__icon[data-mode="page"] {
  background: var(--ink);
  color: var(--paper);
}

/* Portrait on the identity face. */
.portrait {
  width: 100%;
  max-height: 260px;
  margin: 0.75rem 0 0.25rem;
  border-radius: 12px;
  object-fit: cover;
  object-position: 52% 20%;
}
.cube-ready .panel--front .portrait { max-height: 180px; }

@media (max-width: 600px) {
  .cube-ready { --cube: min(84vmin, 460px); }
  .cube-ready .panel { border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .cube-ready .rig { transition: none; }
}
