@property --fold { syntax: '<length>'; inherits: true; initial-value: 7px; }
@property --glow { syntax: '<number>'; inherits: true; initial-value: 0.35; }

:root {
  --bg: #f3f0e9;
  --paper: #f8f6f0;
  --ink: #1b1a17;
  --muted: #716c62;
  --rule: #ddd7cb;
  --ember: #ffc777;
  --serif: 'Newsreader', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 18px/1.55 var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html.world-open, html.world-open body { overflow: hidden; }
a { color: inherit; }
::selection { background: #ead9b8; }

/* ───────── homepage ───────── */

.page { will-change: auto; }
main { max-width: 740px; margin: 0 auto; padding: clamp(64px, 14vh, 140px) 24px 24px; }

.intro h1 {
  font-weight: 400;
  font-size: clamp(36px, 6vw, 50px);
  letter-spacing: -0.022em;
  line-height: 1.02;
  margin: 0 0 20px;
}
.lede { margin: 0; max-width: 31em; font-size: 20px; line-height: 1.5; color: #2c2a25; }

.sec {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 0 28px;
  margin-top: 64px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}
.label {
  margin: 4px 0 16px;
  font: 500 11px/1.8 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.sec ul, .sec ol { list-style: none; margin: 0; padding: 0; }

.focus li { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 16px; padding: 3px 0; }
.focus strong { font-weight: 500; }
.focus span { color: var(--muted); }

.reading li { padding: 0 0 18px; }
.reading li:last-child { padding-bottom: 0; }
.reading a { text-decoration: none; }
.reading .t {
  font-size: 19px;
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
  transition: background-size .4s var(--ease);
}
.reading a:hover .t, .reading a:focus-visible .t { background-size: 100% 1px; }
.reading .m { margin-left: 10px; font: 400 12px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.reading p { margin: 2px 0 0; color: var(--muted); font-size: 16.5px; font-style: italic; }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile {
  position: relative;
  aspect-ratio: 1 / 0.92;
  border-radius: 9px;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 13px 14px 12px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.tile svg { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 1.15; stroke-linecap: round; stroke-linejoin: round; opacity: .82; }
.tile .n { display: block; margin: 0; font-size: 15.5px; line-height: 1.25; }
.tile .m { display: block; margin: 3px 0 0; font: 400 10.5px/1.3 var(--mono); color: var(--muted); letter-spacing: .02em; }

/* The one tile that isn't flat. A paper face over a warm, dark well. */
.tile--portal {
  padding: 0; border: 0; background: transparent;
  font: inherit; color: inherit; text-align: left;
  cursor: pointer;
  perspective: 420px;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.tile-well {
  position: absolute; inset: 0; border-radius: 9px; overflow: hidden;
  background: radial-gradient(130% 100% at 78% 12%, #7b5532 0%, #3a2819 42%, #17110c 100%);
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, .7), inset 0 -1px 0 rgba(255, 220, 170, .12);
}
.tile-glow {
  position: absolute; inset: -30%;
  background: radial-gradient(40% 35% at 82% 14%, rgba(255, 199, 119, .9), rgba(255, 199, 119, 0) 70%);
  opacity: var(--glow);
  transition: opacity .6s var(--ease);
}
.tile-face {
  position: absolute; inset: 0;
  border-radius: 9px;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 13px 14px 12px;
  display: flex; flex-direction: column; justify-content: space-between;
  transform-origin: 50% 50%;
  transform: translateZ(0);
  clip-path: polygon(0 0, calc(100% - var(--fold)) 0, 100% var(--fold), 100% 100%, 0 100%);
  transition: transform .55s var(--ease), box-shadow .55s var(--ease), --fold .55s var(--ease), background-color .4s;
}
/* the dog-ear: back of the paper, folded down over the corner */
.tile-corner {
  position: absolute; top: -1px; right: -1px;
  width: var(--fold); height: var(--fold);
  background: linear-gradient(225deg, transparent 50%, #e7e1d3 50%, #ddd5c4 100%);
  border-bottom-left-radius: 2px;
  box-shadow: -1px 1px 2px rgba(60, 40, 20, .18);
}
.tile-spark {
  position: absolute; top: 5px; right: 5px; width: 3px; height: 3px; border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 6px 2px rgba(255, 190, 100, .7);
  opacity: 0; pointer-events: none;
  animation: spark 7s 2.5s infinite var(--ease);
}
.tile-spark--2 { animation-delay: 6.3s; animation-duration: 9s; }
@keyframes spark {
  0%, 86% { opacity: 0; transform: translate(0, 0) scale(1); }
  88% { opacity: 1; }
  100% { opacity: 0; transform: translate(11px, -15px) scale(.4); }
}
/* every so often the corner breathes, so touch visitors see it too */
.tile--portal { animation: breathe 7s 2.5s infinite; }
@keyframes breathe { 0%, 82%, 100% { --fold: 7px; --glow: .35; } 88% { --fold: 11px; --glow: .7; } }

@media (hover: hover) {
  .tile--portal:hover { animation: none; --fold: 15px; --glow: .85; }
  .tile--portal:hover .tile-face {
    transform: translateZ(-9px) rotateX(1.2deg) rotateY(-1.4deg);
    box-shadow: 0 1px 0 rgba(0, 0, 0, .04);
  }
  .tile--portal:hover .tile-spark { animation-duration: 2.8s; animation-delay: .2s; }
}
.tile--portal:focus-visible { animation: none; --fold: 15px; --glow: .85; }
.tile--portal:focus-visible .tile-face { transform: translateZ(-9px); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ink); }
.tile--portal:active, .tile--portal.is-pressed { animation: none; --fold: 18px; --glow: 1; }
.tile--portal:active .tile-face, .tile--portal.is-pressed .tile-face {
  transform: translateZ(-46px);
  background-color: #efebe2;
  transition-duration: .22s;
}
.tile--portal.is-pressed .tile-spark { animation: none; }
.tile--portal.is-loading .tile-glow { animation: pulse 1s infinite alternate ease-in-out; }
@keyframes pulse { to { opacity: .45; } }
.tile--portal.is-failed .m::after { content: ' — needs WebGL'; }

.links li { display: inline; }
.links li + li::before { content: '·'; margin: 0 12px; color: var(--muted); }
.links a { text-decoration: none; }
.links a span { display: none; }
.links a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

footer {
  max-width: 740px; margin: 0 auto; padding: 72px 24px 48px;
  font: 400 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: #a8a297;
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  .lede { font-size: 18.5px; }
  .sec { grid-template-columns: minmax(0, 1fr); margin-top: 48px; }
  .focus li { grid-template-columns: 1fr; gap: 0; padding: 0 0 10px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading .m { display: block; margin: 4px 0 0; }
}

/* ───────── the world ───────── */

.world { position: fixed; inset: 0; z-index: 20; background: var(--bg); color: var(--ink); }
.world[hidden] { display: none; }
.w-canvas, .w-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.w-canvas canvas { touch-action: none; cursor: grab; outline: none; }

.w-ui { opacity: 0; transition: opacity .7s var(--ease); }
.world.is-ready .w-ui { opacity: 1; }

.w-back, .w-index-toggle, .w-close, .w-step button {
  font: 500 11px/1 var(--mono); letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink); cursor: pointer;
}
.w-back, .w-index-toggle {
  position: absolute; top: max(16px, env(safe-area-inset-top));
  padding: 10px 14px;
  background: rgba(248, 246, 240, .78);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--rule); border-radius: 999px;
  transition: opacity .7s var(--ease), background-color .2s;
}
.w-back { left: 16px; }
.w-index-toggle { right: 16px; }
.w-back:hover, .w-index-toggle:hover { background: var(--paper); }
.w-title {
  position: absolute; top: max(28px, calc(env(safe-area-inset-top) + 12px)); left: 50%; transform: translateX(-50%);
  margin: 0; font: italic 400 16px/1 var(--serif); color: var(--muted); pointer-events: none;
}

.w-index {
  position: absolute; right: 16px; top: calc(max(16px, env(safe-area-inset-top)) + 46px);
  width: 260px; padding: 8px;
  background: rgba(248, 246, 240, .9);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--rule); border-radius: 12px;
  visibility: hidden; opacity: 0; transform: translateY(-6px);
  transition: opacity .3s var(--ease), transform .3s var(--ease), visibility 0s .3s;
}
.world.index-open .w-index { visibility: visible; opacity: 1; transform: none; transition-delay: 0s; }
.w-index ol { list-style: none; margin: 0; padding: 0; }
.w-index button {
  width: 100%; display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 7px 8px; border: 0; border-radius: 7px; background: none; cursor: pointer;
  font: 400 15px/1.25 var(--serif); color: var(--ink); text-align: left;
}
.w-index button em { font: normal 400 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.w-index button:hover, .w-index button[aria-current] { background: rgba(0, 0, 0, .05); }

.w-hint {
  position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  margin: 0; padding: 9px 14px; border-radius: 999px;
  background: rgba(248, 246, 240, .7); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font: 400 11px/1.4 var(--mono); letter-spacing: .05em; color: var(--muted); white-space: nowrap; max-width: calc(100% - 32px); text-align: center;
  pointer-events: none;
}
.w-hint .touch { display: none; }
@media (hover: none) { .w-hint .desk { display: none; } .w-hint .touch { display: inline; } }
.world.hint-gone .w-hint, .world.has-focus .w-hint { opacity: 0; }

.w-label {
  position: absolute; left: 0; top: 0; pointer-events: none;
  padding: 5px 9px; border-radius: 7px;
  background: var(--paper); border: 1px solid var(--rule);
  font: 400 14px/1.2 var(--serif); white-space: nowrap;
  box-shadow: 0 6px 20px -10px rgba(40, 30, 20, .35);
  opacity: 0; transition: opacity .2s;
}
.w-label.is-on { opacity: 1; }

.w-panel {
  position: absolute; right: 24px; top: 50%;
  width: 360px; max-height: calc(100% - 140px); overflow: auto;
  padding: 18px 22px 16px;
  background: rgba(248, 246, 240, .9);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: 0 30px 60px -30px rgba(40, 30, 20, .35);
  opacity: 0; visibility: hidden; transform: translate(18px, -50%);
  transition: opacity .45s var(--ease), transform .55s var(--ease), visibility 0s .55s;
}
.w-panel.is-open { opacity: 1; visibility: visible; transform: translate(0, -50%); transition-delay: .25s, .25s, 0s; }
.w-close { padding: 6px 0; border: 0; background: none; color: var(--muted); }
.w-close:hover { color: var(--ink); }
.w-kicker { margin: 18px 0 6px; font: 400 10.5px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.w-name { margin: 0; font: 400 27px/1.12 var(--serif); letter-spacing: -.01em; }
.w-by { margin: 6px 0 0; font-style: italic; color: #3b3832; }
.w-why { margin: 14px 0 0; font-size: 16.5px; line-height: 1.55; color: #2c2a25; }
.w-link { display: inline-flex; gap: 4px; margin-top: 14px; font-size: 16px; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.w-link[hidden] { display: none; }
.w-link i { font-style: normal; color: var(--muted); }
.w-step { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--rule); }
.w-step button { width: 34px; height: 30px; border: 1px solid var(--rule); border-radius: 999px; background: transparent; font-size: 14px; }
.w-step button:hover { background: rgba(0, 0, 0, .04); }
.w-count { font: 400 11px/1 var(--mono); color: var(--muted); }

@media (max-width: 759px) {
  .w-title { display: none; }
  .w-panel {
    left: 10px; right: 10px; top: auto; bottom: max(10px, env(safe-area-inset-bottom));
    width: auto; max-height: 46vh; padding: 12px 18px 12px;
    transform: translateY(24px);
  }
  .w-panel.is-open { transform: none; }
  .w-kicker { margin-top: 10px; }
  .w-name { font-size: 23px; }
  .w-why { font-size: 15.5px; margin-top: 10px; }
  .w-index { left: 16px; right: 16px; width: auto; }
  .w-hint { white-space: normal; width: max-content; border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile-spark, .tile--portal { animation: none !important; }
}
