/* Top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 10; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}
@media (min-width: 761px) { .topbar { padding-inline: 32px; } }
html:not(.js) .topbar { position: absolute; }   /* plain page: the bar scrolls away instead of covering the text */
.mark { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); font-weight: 600; letter-spacing: 0.08em; font-size: 14px; }
.mark img { width: 28px; height: 28px; }
.topnav { display: flex; align-items: center; gap: 24px; }
.topnav a { color: var(--text-secondary); text-decoration: none; font-size: 14px; }
.topnav a:hover { color: var(--text-primary); }
@media (max-width: 480px) { .topnav a.hide-narrow { display: none; } }

.theme-toggle {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid var(--border-light); color: var(--text-secondary);
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--accent-signature); }
.theme-toggle svg { width: 16px; height: 16px; }
:root[data-theme="light"] .icon-moon, :root:not([data-theme]) .icon-moon, :root[data-theme="dark"] .icon-sun { display: none; }

/* Stage: hero text and the 12 cells, over the 3D scene when it runs */
.stage {
  position: relative; min-height: 100svh;
  display: grid; align-content: center; justify-items: center; gap: 40px;
  padding: calc(var(--topbar-h) + 32px) max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px));
}
@media (min-width: 761px) {
  .stage { grid-template-columns: 1fr 1fr; align-items: center; padding-inline: 6vw; }
  .stage .cells { order: -1; }
}

#scene { display: none; }
.has-scene #scene { display: block; position: fixed; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.6s var(--ease-in-out); }
.scene-ready #scene { opacity: 1; }

.hero { max-width: 30rem; display: grid; gap: 16px; position: relative; z-index: 2; }
.hero > p:first-of-type { font-size: 18px; color: var(--text-secondary); max-width: 26rem; }
.hero-actions { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
.hero-actions a:not(.btn) { font-size: 14px; text-decoration: none; }
.hero-meta { margin-top: 4px; }

/* With the scene: the hero sits in the empty space right of the panel (desktop) or above it (phone). */
/* .booting: the scene is still loading; the title already takes its 3D-layout place and the flat panel stays hidden. */
.has-scene .stage, .booting .stage { display: block; }
.has-scene .hero, .booting .hero { position: absolute; z-index: 2; }
.booting .cells { visibility: hidden; }
@media (min-width: 761px) { .has-scene .hero, .booting .hero { left: 58%; top: 30%; right: 32px; } }
@media (max-width: 760px) { .has-scene .hero, .booting .hero { left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); top: calc(var(--topbar-h) + 16px); } }
/* While a section is open the hero steps aside; the panel is the navigation. */
.hero { transition: opacity 0.3s var(--ease-in-out), visibility 0s linear 0s; }
.reading .hero { opacity: 0; visibility: hidden; transition: opacity 0.2s var(--ease-in-out), visibility 0s linear 0.2s; }
@media (max-width: 760px) { html:not(.has-scene).reading .hero { display: none; } }   /* no WebGL: lift the cells out from under the sheet */

/* Page entry: one short staggered rise, finished within 800 ms. */
@keyframes rise { from { opacity: 0; transform: translateY(var(--rise)); filter: blur(6px); } }
.js .topbar { animation: rise 0.6s var(--ease-out) both; }
.js .hero > * { animation: rise 0.7s var(--ease-out) both; }
.js .hero > :nth-child(1) { animation-delay: 80ms; }
.js .hero > :nth-child(2) { animation-delay: 160ms; }
.js .hero > :nth-child(3) { animation-delay: 240ms; }
.js .hero > :nth-child(4) { animation-delay: 320ms; }

/* Cells: a CSS-drawn 3 x 4 panel by default (no JS, no WebGL); placed over the 3D cells when the scene runs. */
.cells {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 16px; width: min(360px, 86vw);
  background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 18px;
}
.cell {
  aspect-ratio: 1; border-radius: var(--radius-md); background: var(--cell); color: var(--cell-label);
  display: flex; align-items: flex-end; padding: 8px; text-decoration: none;
  font: 500 10px/1.25 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase;
}
.cell span { max-width: 9ch; }
.cell-primary { box-shadow: inset 0 0 0 2px var(--accent-cta); }
.cell:hover { outline: 1px solid var(--accent-signature); outline-offset: 0; }
/* With the scene, hover, the open section and the Download mark are drawn in 3D; flat rectangles would not follow the perspective. */
.has-scene .cell, .has-scene .cell:hover, .has-scene .cell[aria-current="true"] { outline: none; box-shadow: none; }
.has-scene .cell:focus-visible { outline: 1px solid var(--accent-signature); }   /* keyboard focus stays visible */

.has-scene .cells { position: fixed; inset: 0; z-index: 1; width: auto; padding: 0; background: none; border: 0; display: block; pointer-events: none; }
.has-scene .cell { position: absolute; pointer-events: auto; aspect-ratio: auto; background: none; padding: 7px; border-radius: var(--radius-sm); overflow: hidden; transition: color 0.2s var(--ease-snap); }
@media (max-width: 760px) { .has-scene .cell { font-size: 8.5px; } }
@media (max-width: 760px) { .has-scene.reading .cell { font-size: 7px; letter-spacing: 0; padding: 4px; } }   /* small panel above the sheet: fits 8 letters per line */
.cell[aria-current="true"] { outline: 1px solid var(--accent-signature); outline-offset: 0; color: #FFFFFF; }
.has-scene .cell[aria-current="true"] { outline: none; }

/* Sheet: a plain page without JS; with JS a non-modal sheet beside the panel, below the top bar. */
html:not(.js) .sheet { display: block; position: static; inset: auto; border: 0; width: auto; max-width: none; height: auto; background: none; color: inherit; }
html:not(.js) .sheet-head { display: none; }
html:not(.js) .sheet-body { max-width: 72ch; margin: 0 auto; padding: 48px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }

.js .sheet {
  position: fixed; inset: var(--topbar-h) 0 0 auto; z-index: 5; margin: 0; padding: 0;
  width: var(--sheet-w); max-width: 100%; height: auto; max-height: none;
  border: 0; border-left: 1px solid var(--border-color); border-top-left-radius: var(--radius-lg);
  background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-lg);
  display: none; flex-direction: column;
  opacity: 0; translate: 24px 0; transition: opacity 0.24s var(--ease-out), translate 0.24s var(--ease-out);
}
.js .sheet[open] { display: flex; }
.js .sheet.in { opacity: 1; translate: 0 0; }
@media (max-width: 760px) {
  .js .sheet { inset: auto 0 0 0; width: 100%; height: 62svh; border-left: 0; border-top: 1px solid var(--border-color); border-radius: 16px 16px 0 0; translate: 0 32px; }
}

.sheet-head {
  display: flex; align-items: center; gap: 16px; flex: none;
  padding: 16px 24px; padding-top: max(16px, env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--border-color);
}
.sheet-path { flex: 1; min-width: 0; margin: 0; }
.sheet-path span:first-child { color: var(--text-muted); }
.sheet-close {
  width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--border-light);
  background: transparent; color: var(--text-secondary); font-size: 18px; line-height: 1; cursor: pointer;
}
.sheet-close:hover { color: var(--text-primary); border-color: var(--accent-signature); }
.js .sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 32px max(24px, env(safe-area-inset-right, 0px)) 64px 32px; transition: opacity 0.15s var(--ease-in-out), filter 0.15s var(--ease-in-out); }
.js .sheet-body.leaving { opacity: 0; filter: blur(2px); }
@media (max-width: 760px) { .js .sheet-body { padding-inline: 16px; } .sheet-head { padding: 12px 16px; } }

/* Section entry: heading, lead and the first blocks rise in, 80 ms apart. */
.sheet-body section.rise > * { animation: rise 0.6s var(--ease-out) both; }
.sheet-body section.rise > :nth-child(2) { animation-delay: 80ms; }
.sheet-body section.rise > :nth-child(3) { animation-delay: 160ms; }
.sheet-body section.rise > :nth-child(4) { animation-delay: 240ms; }
.sheet-body section.rise > :nth-child(5) { animation-delay: 320ms; }
.sheet-body section.rise > :nth-child(n+6) { animation-delay: 400ms; }

/* Footer: plain, below the stage; hidden behind the scene when it runs */
.footer {
  display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; align-items: center;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  border-top: 1px solid var(--border-color); font-size: 13px; color: var(--text-muted);
}
.footer nav { display: flex; gap: 20px; flex-wrap: wrap; }
.footer a { color: var(--text-secondary); text-decoration: none; }
.has-scene .footer { position: fixed; inset: auto 0 0 0; z-index: 2; border: 0; background: none; padding-block: 12px calc(12px + env(safe-area-inset-bottom, 0px)); pointer-events: none; }
.has-scene .footer * { pointer-events: auto; }
.footer { transition: opacity 0.3s var(--ease-in-out); }
.reading .footer { opacity: 0; visibility: hidden; }
@media (max-width: 760px) { .has-scene .footer { display: none; } }   /* on a phone it would sit on the garden; its links are in Citation and About me */

/* Image viewer */
.viewer { margin: auto; max-width: min(1200px, 94vw); max-height: 92vh; border: 0; border-radius: var(--radius-lg); background: var(--bg-card); color: var(--text-primary); padding: 12px; cursor: zoom-out; }
.viewer::backdrop { background: rgba(10, 13, 12, 0.8); }
.viewer img { max-height: 78vh; width: auto; margin: 0 auto; border-radius: var(--radius-md); }
.viewer p { font-size: 14px; padding: 10px 6px 2px; max-width: 80ch; }
