:root {
  --wall: #0c0b0a;
  --wall-2: #141210;
  --ink: #ece7dd;
  --ink-soft: #c8c0b2;
  --muted: #8b8478;
  --faint: #5a554c;
  --brass: #d8b27a;
  --hair: rgba(232, 224, 210, 0.14);
  --hair-soft: rgba(232, 224, 210, 0.08);
  --spot: rgba(216, 178, 122, 0.10);
  --serif: "Fraunces", Georgia, serif;
  --read: "Newsreader", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* beat element display rules (.gallery is flex) */
html, body { height: 100%; }

body {
  background: var(--wall);
  color: var(--ink);
  font-family: var(--read);
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* crossfade when the room (palette) changes */
  transition: background-color 0.9s ease, color 0.9s ease;
}

/* soft museum spotlight from above, plus a floor vignette */
.spotlight {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--spot), transparent 55%),
    radial-gradient(90% 70% at 50% 36%, var(--wall-2), transparent 70%),
    radial-gradient(140% 120% at 50% 120%, rgba(0,0,0,0.55), transparent 60%);
  transition: background 0.9s ease;
}

/* persistent chrome also eases between rooms */
.frame-top, .frame-bottom, .brand, .brand-name, .timer,
.frame-bottom .tagline, kbd, .brand-glyph {
  transition: color 0.9s ease, border-color 0.9s ease,
              box-shadow 0.9s ease, background-color 0.9s ease;
}
body > *:not(.spotlight):not(.modal) { position: relative; z-index: 1; }

/* ---------- top + bottom frame chrome ---------- */
.frame-top, .frame-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px clamp(20px, 5vw, 60px);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-glyph {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--brass);
  box-shadow: 0 0 0 3px rgba(216,178,122,0.08);
}
.brand-name { letter-spacing: 0.22em; font-size: 0.74rem; }
.view-toggle {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease;
}
.view-toggle:hover { color: var(--ink); border-color: var(--brass); }

.frame-bottom .tagline { color: var(--faint); text-transform: none; letter-spacing: 0.04em; font-family: var(--read); font-style: italic; font-size: 0.86rem; }
kbd {
  font-family: var(--mono);
  font-size: 0.66rem;
  border: 1px solid var(--hair);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--muted);
}

/* ---------- the countdown timer (bottom-right) ---------- */
.timer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.timer-ring { width: 15px; height: 15px; transform: rotate(-90deg); overflow: visible; }
.timer-ring circle { fill: none; stroke-width: 2; }
.ring-track { stroke: var(--hair-soft); }
.ring-fill {
  stroke: var(--brass);
  stroke-linecap: round;
  stroke-dasharray: 62.83;        /* 2 * PI * r(10) */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.95s linear;
}

/* ---------- the gallery stage ---------- */
.gallery {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vh, 40px) clamp(16px, 6vw, 90px);
  min-height: 0;
  overflow-y: auto;
}

.work {
  width: min(820px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* crossfade swap */
.work.swap { animation: reveal 0.7s cubic-bezier(0.22, 0.61, 0.36, 1); }
@keyframes reveal {
  from { opacity: 0; transform: translateY(10px); filter: blur(3px); }
  to   { opacity: 1; transform: none; filter: none; }
}

/* --- TEXT / aphorism --- */
.work .prose {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 400;
  font-size: clamp(1.7rem, 1.1rem + 2.8vw, 3.3rem);
  line-height: 1.22;
  letter-spacing: -0.015em;
  color: var(--ink);
  max-width: 18ch;
  text-wrap: balance;
}
.work .prose em { font-style: italic; color: var(--brass); }
.work .prose p + p { margin-top: 0.7em; }

/* --- CODE specimen --- */
.work .specimen {
  width: 100%;
  text-align: left;
  font-family: var(--mono);
  font-size: clamp(0.82rem, 0.7rem + 0.6vw, 1.02rem);
  line-height: 1.85;
  color: var(--ink-soft);
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: clamp(24px, 4vw, 44px);
  box-shadow: 0 40px 90px -50px rgba(0,0,0,0.9);
  overflow-x: auto;
  position: relative;
}
.work .specimen::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 2px; background: var(--brass); opacity: 0.5;
}
.specimen .cmt { color: var(--faint); font-style: italic; }
.specimen .str { color: #cdbb96; }
.specimen .kw  { color: var(--brass); }
.specimen .num { color: #b59ec9; }
.specimen .fn  { color: #d9d2c4; }

/* --- IMAGE --- */
.work .plate {
  max-width: 100%;
  padding: 14px;
  background: #100e0c;
  border: 1px solid var(--hair);
  box-shadow: 0 50px 100px -50px rgba(0,0,0,0.95);
}
.work .plate img, .work .plate svg {
  display: block;
  max-width: 100%;
  max-height: 56vh;
  height: auto;
}

/* --- ARTICLE --- */
.work .article { max-width: 36ch; }
.work .article .dek {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 18px;
}
.work .article h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.8rem, 1.2rem + 2.4vw, 3rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin-bottom: 22px;
}
.work .article .body {
  font-family: var(--read);
  font-size: clamp(0.98rem, 0.92rem + 0.34vw, 1.12rem);
  line-height: 1.55;
  color: var(--ink-soft);
  text-align: left;
  max-width: 34ch;
  margin: 0 auto;
}
.work .article .body em { color: var(--ink); font-style: italic; }
.work .article .body p + p { margin-top: 1em; }
.work .article .read-on {
  display: inline-block;
  margin-top: 26px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
  text-decoration: none;
  border-bottom: 1px solid rgba(216,178,122,0.4);
  padding-bottom: 3px;
}
.work .article .read-on:hover { color: var(--ink); }

/* inline code in prose/body */
code.tick { font-family: var(--mono); font-size: 0.85em; color: var(--brass); background: rgba(216,178,122,0.08); padding: 1px 5px; border-radius: 3px; }

/* --- LINK / web hack --- */
.work .hack { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.work .hack-token {
  font-family: var(--mono);
  font-size: clamp(1.6rem, 1rem + 3vw, 3rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--brass);
  text-decoration: none;
  padding: 14px 26px;
  border: 1px solid var(--hair);
  border-radius: 10px;
  background: rgba(0,0,0,0.22);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.work .hack-token:hover { transform: translateY(-2px); border-color: var(--brass); background: rgba(0,0,0,0.32); }
.work .hack-go { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }

/* --- DOWNLOAD --- */
.work .download { display: flex; flex-direction: column; align-items: center; gap: 22px; width: 100%; }
.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--wall);
  background: var(--brass);
  text-decoration: none;
  padding: 13px 24px;
  border-radius: 999px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.download-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 34px -12px var(--spot); }
/* keep the preview compact so the button + placard never collide */
.work .download .plate img, .work .download .plate svg { max-height: 40vh; }
.modal-work .plate img, .modal-work .plate svg { max-height: 48vh; }

/* ---------- the museum placard ---------- */
.placard {
  max-width: min(560px, 88vw);
  margin: clamp(20px, 4vh, 46px) auto 0;
  padding: 0 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 96px;
}
.placard.swap { animation: reveal 0.7s 0.05s backwards cubic-bezier(0.22, 0.61, 0.36, 1); }
.placard .medium {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--brass);
}
.placard .title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.06rem;
  color: var(--ink);
}
.placard .meta { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em; color: var(--muted); }
.placard .note {
  font-family: var(--read);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
  max-width: 52ch;
  margin: 4px auto 0;
}

/* ---------- edge navigation ---------- */
.edge {
  flex: none;
  background: none;
  border: none;
  color: var(--faint);
  font-family: var(--serif);
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 30px 14px;
  transition: color 0.3s ease, transform 0.3s ease;
  opacity: 0.55;
  align-self: center;
}
.edge:hover { color: var(--brass); opacity: 1; transform: scale(1.15); }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .frame-top { padding: 16px 18px; }
  /* lift the timer above the fixed bottom-corner nav arrows */
  .frame-bottom { padding: 16px 18px 56px; justify-content: flex-end; }
  .frame-bottom .tagline { display: none; }

  .gallery { padding: 6px 16px; }
  .work { width: 100%; }

  /* the back control becomes a fixed thumb-reachable button, bottom-left */
  .edge {
    position: fixed;
    bottom: 14px;
    z-index: 4;
    font-size: 2.1rem;
    padding: 10px 16px;
    opacity: 0.8;
  }
  .edge-prev { left: 2px; }

  .work .specimen { padding: 20px; font-size: 0.82rem; line-height: 1.7; }
  .work .plate img, .work .plate svg { max-height: 46vh; }
  .work .hack-token { font-size: 1.7rem; padding: 12px 18px; }
  .placard { margin-top: 18px; min-height: 78px; }
  .placard .note { font-size: 0.86rem; }
}

@media (max-width: 380px) {
  .work .prose { font-size: 1.55rem; }
  .edge { font-size: 1.8rem; }
}

/* taller-than-wide phones: keep the work from crowding the fixed edges */
@media (max-width: 720px) and (max-height: 760px) {
  .work .plate img, .work .plate svg { max-height: 38vh; }
}

/* ---------- index view (caption list → popup) ---------- */
.index-view {
  overflow-y: auto;
  padding: clamp(16px, 4vh, 48px) clamp(20px, 6vw, 90px);
}
.index-list { list-style: none; max-width: 780px; margin: 0 auto; }
.index-list li:first-child .index-item { border-top: none; }
.index-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: clamp(12px, 3vw, 26px);
  align-items: baseline;
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid var(--hair-soft);
  padding: clamp(14px, 2.2vh, 22px) 4px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.ix-num { font-family: var(--mono); font-size: 0.7rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.ix-title {
  font-family: var(--serif);
  font-size: clamp(1.1rem, 0.9rem + 1vw, 1.7rem);
  letter-spacing: -0.01em;
  line-height: 1.15;
  transition: color 0.25s ease, padding-left 0.25s ease;
}
.ix-medium {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.index-item:hover .ix-title, .index-item:focus-visible .ix-title { color: var(--brass); padding-left: 8px; }
@media (max-width: 560px) {
  .index-item { grid-template-columns: auto 1fr; }
  .ix-medium { display: none; }
}

/* ---------- popup ---------- */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 40px);
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fade 0.3s ease;
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--wall);
  border: 1px solid var(--hair);
  border-radius: 6px;
  box-shadow: 0 60px 140px -40px rgba(0,0,0,0.95);
  padding: clamp(30px, 5vw, 60px);
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  transition: color 0.2s ease;
}
.modal-close:hover { color: var(--ink); }
.modal-placard { margin-top: 26px; display: flex; flex-direction: column; gap: 7px; }
.modal-placard .medium { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--brass); }
.modal-placard .title { font-family: var(--serif); font-style: italic; font-size: 1.06rem; color: var(--ink); }
.modal-placard .meta { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }
.modal-placard .note { font-family: var(--read); font-size: 0.92rem; line-height: 1.5; color: var(--muted); max-width: 52ch; margin: 4px auto 0; }
body.modal-open { overflow: hidden; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* loading / error states */
.state {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .work.swap, .placard.swap { animation: none !important; }
  .modal-card, .modal-backdrop { animation: none !important; }
  .edge { transition: none; }
  body, .spotlight, .frame-top, .frame-bottom, .brand, .brand-name,
  .timer, .frame-bottom .tagline, kbd, .brand-glyph { transition: none !important; }
}
