:root {
  --bg: #f6f6f3;
  --ink: #111110;
  --muted: #8a8a84;
  --line: rgba(17, 17, 16, 0.12);
  --chip: rgba(17, 17, 16, 0.06);
  --acid: #c8ff3d;
  --sans: "Instrument Sans", system-ui, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --edge: clamp(16px, 4vw, 48px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.js body { overflow: hidden; }
::selection { background: var(--acid); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.serif { font-family: var(--serif); font-weight: 400; }
sup { font-size: 0.62em; margin-left: 2px; vertical-align: 0.6em; line-height: 0; }

/* Loader */
.loader {
  position: fixed; inset: 0; z-index: 90;
  background: var(--bg);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 18px;
  transition: opacity 0.8s ease, visibility 0.8s;
}
.loader-note { position: absolute; top: calc(50% - 34px); left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 10px; letter-spacing: 0.04em; }
.counter { font-size: 15px; font-variant-numeric: tabular-nums; }
.loaded .loader { opacity: 0; visibility: hidden; }
.no-js .loader { display: none; }

/* Pill nav */
.pill {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: stretch; gap: 3px;
  font-size: 12px; white-space: nowrap;
}
.pill > * {
  display: flex; align-items: center; padding: 3px 9px;
  background: var(--chip); backdrop-filter: blur(12px);
  transition: background 0.2s, color 0.2s;
}
.pill-brand { font-weight: 500; letter-spacing: 0.02em; background: transparent; backdrop-filter: none; font-size: 11px; }
.pill-item { font-size: 13.5px; color: var(--muted); }
.pill-item:hover { color: var(--ink); }
.pill-item[aria-current="true"] { color: var(--ink); background: rgba(17, 17, 16, 0.1); }

/* Sound toggle */
.sound {
  position: fixed; top: 10px; right: var(--edge); z-index: 60;
  display: flex; align-items: center; gap: 8px; padding: 4px 8px;
  background: var(--chip); font-size: 11px; color: var(--muted);
}
.sound:hover { color: var(--ink); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 10px; }
.bars i { width: 2px; height: 2px; background: currentColor; transition: height 0.2s; }
.sound[aria-pressed="true"] { color: var(--ink); }
.sound[aria-pressed="true"] .bars i { animation: eq 0.9s ease-in-out infinite alternate; }
.sound[aria-pressed="true"] .bars i:nth-child(2) { animation-delay: -0.3s; }
.sound[aria-pressed="true"] .bars i:nth-child(3) { animation-delay: -0.6s; }
.sound[aria-pressed="true"] .bars i:nth-child(4) { animation-delay: -0.15s; }
@keyframes eq { from { height: 2px; } to { height: 10px; } }

/* Midline title */
.midline {
  position: fixed; left: var(--edge); right: var(--edge); top: 50%; transform: translateY(-50%);
  z-index: 1; display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 500; pointer-events: none;
}
.mid-r { font-size: 15px; }
.split .ch { display: inline-block; opacity: 0; transform: translateY(40%); filter: blur(4px); transition: opacity 0.5s, transform 0.6s cubic-bezier(.2, .8, .2, 1), filter 0.5s; white-space: pre; }
.loaded .split .ch { opacity: 1; transform: none; filter: none; }

/* Stage */
.stage {
  position: fixed; inset: 0; z-index: 2;
  cursor: grab; touch-action: none;
  transition: opacity 0.6s ease, transform 0.8s cubic-bezier(.2, .8, .2, 1);
}
.stage.dragging { cursor: grabbing; }
.tile {
  position: absolute; left: 0; top: 0;
  will-change: transform, opacity;
  transform-origin: 0 0;
}
.tile canvas { display: block; width: 100%; height: 100%; transition: outline-color 0.15s; outline: 1px solid transparent; outline-offset: 3px; }
.tile:hover canvas { outline-color: var(--ink); }
.no-js .stage { display: none; }

.cursor-label {
  position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none;
  padding: 2px 6px; background: var(--ink); color: var(--bg);
  font-size: 11px; white-space: nowrap;
  opacity: 0; transition: opacity 0.15s;
}
.cursor-label.on { opacity: 1; }
.cursor-label b { font-family: var(--serif); font-weight: 400; font-size: 13px; color: var(--acid); margin-right: 6px; }

/* HUD */
.hud {
  position: fixed; left: var(--edge); right: var(--edge); bottom: 14px; z-index: 60;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline;
  color: var(--muted); font-size: 11px; pointer-events: none;
}
.hud-c { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.hud-r { text-align: right; }

/* Panels (Index, Contact) */
.panel {
  position: fixed; inset: 0; z-index: 40;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 64px var(--edge) 64px;
  background: rgba(246, 246, 243, 0.8);
  backdrop-filter: blur(18px) saturate(1.1);
  opacity: 0; visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s;
}
body[data-view="index"] #panel-index,
body[data-view="contact"] #panel-contact { opacity: 1; visibility: visible; }
body[data-view="index"] .stage,
body[data-view="contact"] .stage { transform: scale(0.92); }
body:not([data-view="specimens"]) .midline,
body:not([data-view="specimens"]) .hud-l { opacity: 0; }
.midline, .hud-l { transition: opacity 0.4s; }

.panel-inner > * { opacity: 0; transform: translateY(10px); transition: opacity 0.6s, transform 0.6s cubic-bezier(.2, .8, .2, 1); }
body[data-view="index"] #panel-index .panel-inner > *,
body[data-view="contact"] #panel-contact .panel-inner > * { opacity: 1; transform: none; }
.panel-inner > *:nth-child(2) { transition-delay: 0.06s; }
.panel-inner > *:nth-child(3) { transition-delay: 0.12s; }
.panel-inner > *:nth-child(4) { transition-delay: 0.18s; }
.panel-inner > *:nth-child(5) { transition-delay: 0.24s; }

.kicker { color: var(--muted); font-size: 11px; margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.big { font-size: clamp(22px, 2.4vw, 32px); line-height: 1.1; margin-bottom: 18px; letter-spacing: -0.005em; }
.small { color: var(--muted); max-width: 30em; }

.index-grid {
  display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 28px;
  max-width: 1440px; margin: 0 auto; padding-top: 6vh;
}
.list { list-style: none; }
.list li {
  display: grid; grid-template-columns: 34px 1fr auto; column-gap: 6px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.list .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.list .title { font-weight: 500; }
.list .title.serif { font-size: 17px; line-height: 1; font-weight: 400; }
.list p { grid-column: 2 / -1; color: var(--muted); margin-top: 4px; }
.st { font-size: 10px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.st::before { content: ""; width: 5px; height: 5px; border-radius: 50%; border: 1px solid currentColor; }
.st.run { color: var(--ink); }
.st.run::before { background: #7aa800; border-color: #7aa800; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.contact {
  min-height: calc(100% - 20px); display: flex; flex-direction: column; justify-content: center;
  max-width: 1100px; margin: 0 auto;
}
.contact .kicker { max-width: 240px; }
.contact h2 { font-size: clamp(48px, 10vw, 150px); line-height: 0.9; letter-spacing: -0.02em; margin-bottom: 28px; }
.contact h2 em { font-style: italic; }
.mail {
  font-size: clamp(18px, 3vw, 34px); align-self: flex-start;
  border-bottom: 1px solid var(--ink); margin-bottom: 18px; word-break: break-all;
  transition: background 0.15s;
}
.mail:hover { background: var(--acid); }
.links { margin-top: 10px; }
.links a { color: var(--ink); border-bottom: 1px solid var(--line); }

/* Specimen viewer */
.viewer {
  position: fixed; inset: 0; z-index: 80;
  display: grid; grid-template-columns: 1fr 300px; gap: 32px; align-items: center;
  padding: 64px var(--edge) 48px;
  background: rgba(246, 246, 243, 0.94);
  backdrop-filter: blur(10px);
  animation: fade 0.35s ease;
}
.viewer[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.viewer-art { display: flex; justify-content: center; align-items: center; height: 100%; min-height: 0; }
.viewer-art canvas { max-width: 100%; max-height: calc(100vh - 140px); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.35); animation: rise 0.5s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { transform: translateY(16px) scale(0.98); opacity: 0; } }
.v-id { font-size: 15px; color: var(--muted); }
.viewer-meta h2 { font-size: 34px; font-family: var(--serif); font-weight: 400; line-height: 1; margin: 6px 0 14px; }
.v-note { color: var(--muted); margin-bottom: 18px; }
.viewer-meta dl { display: grid; grid-template-columns: auto 1fr; border-top: 1px solid var(--line); margin-bottom: 18px; }
.viewer-meta dt, .viewer-meta dd { padding: 6px 0; border-bottom: 1px solid var(--line); }
.viewer-meta dt { color: var(--muted); padding-right: 24px; }
.viewer-meta dd { font-variant-numeric: tabular-nums; }
.v-actions { display: flex; gap: 6px; }
.v-actions button { padding: 6px 12px; background: var(--chip); }
.v-actions button:hover { background: var(--ink); color: var(--bg); }
#vMutate { background: var(--ink); color: var(--bg); }
#vMutate:hover { background: var(--acid); color: var(--ink); }

/* Without JS: show the content as a plain page */
.no-js .panel { position: static; opacity: 1; visibility: visible; background: none; backdrop-filter: none; }
.no-js .panel-inner > * { opacity: 1; transform: none; }
.no-js .midline { position: static; transform: none; padding: 64px var(--edge) 0; }
.no-js .hud, .no-js .sound, .no-js .viewer { display: none; }

@media (max-width: 1000px) {
  .index-grid { grid-template-columns: 1fr 1fr; }
  .col-about { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .pill-brand { display: none !important; }
  .pill-item { font-size: 12.5px; padding: 3px 7px; }
  .sound-label { display: none; }
  .sound { right: 10px; padding: 6px; }
  .midline { flex-direction: column; align-items: flex-start; gap: 2px; top: auto; bottom: 44px; transform: none; }
  .hud-l { display: none; }
  body:not([data-view="specimens"]) .hud { opacity: 0; }
  .hud { transition: opacity 0.4s; }
  .hud { grid-template-columns: 1fr auto; }
  .hud-c { order: 2; }
  .hud-r { order: 1; text-align: left; }
  .index-grid { grid-template-columns: 1fr; gap: 36px; padding-top: 0; }
  .viewer { grid-template-columns: 1fr; align-content: start; overflow-y: auto; gap: 20px; }
  .viewer-art canvas { max-height: 52vh; }
}

@media (prefers-reduced-motion: reduce) {
  .split .ch, .panel-inner > *, .stage { transition: none; }
  .sound[aria-pressed="true"] .bars i, .st.run::before { animation: none; }
}
