:root {
  --night: #0a0806;
  --night-2: #14100b;
  --ink: #f3e6cf;
  --ink-dim: #b9a68a;
  --ink-faint: #6f604c;
  --resin-hi: #ffd78c;
  --resin: #e2902a;
  --resin-deep: #8f4207;
  --fossil: rgba(58, 22, 0, 0.6);
  --crimson: #ff1f3d;
  --gold: #ffd36b;
  --gold-deep: #f2a900;
  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(60% 55% at 50% 46%, #2a1606 0%, var(--night) 62%) fixed, var(--night);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(14px, 2.4vh, 26px);
  padding: 28px 16px 40px;
}

.counter {
  margin: 0;
  font-size: clamp(11px, 1.05vw, 13px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
}
.counter .n {
  font-family: var(--serif);
  font-size: 2.3em;
  letter-spacing: 0;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 190, 80, 0.45);
  vertical-align: -0.18em;
  font-variant-numeric: tabular-nums;
}

.scene {
  width: min(1040px, 100%);
  perspective: 2200px;
}
.block {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 520;
  transform-style: preserve-3d;
  transition: transform 1.15s cubic-bezier(0.2, 0.7, 0.1, 1);
}
.block.flipped { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  border-radius: clamp(14px, 2.6vw, 28px);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* The resin: layered light, a deep core, an inner rim, and grain. */
.front {
  background:
    radial-gradient(70% 60% at 24% 16%, rgba(255, 228, 170, 0.62), transparent 60%),
    radial-gradient(60% 70% at 86% 96%, rgba(70, 18, 0, 0.62), transparent 62%),
    radial-gradient(40% 40% at 70% 30%, rgba(255, 200, 110, 0.25), transparent 70%),
    linear-gradient(158deg, #f7b950 0%, var(--resin) 36%, #b9600f 66%, var(--resin-deep) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 226, 170, 0.45),
    inset 0 3px 26px rgba(255, 240, 200, 0.4),
    inset 0 -50px 90px rgba(60, 16, 0, 0.55),
    0 60px 140px -30px rgba(255, 140, 20, 0.33),
    0 0 0 1px rgba(0, 0, 0, 0.7);
}
.front::before {
  /* a sheen across the top face */
  content: '';
  position: absolute;
  inset: -20% -10% auto -10%;
  height: 55%;
  background: linear-gradient(176deg, rgba(255, 250, 235, 0.32), rgba(255, 250, 235, 0) 70%);
  transform: rotate(-4deg);
  pointer-events: none;
  z-index: 3;
}
.front::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .14 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  opacity: 0.35;
  pointer-events: none;
  z-index: 2;
}
.bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 252, 240, 0.85), rgba(255, 230, 180, 0.15) 45%, transparent 70%);
  box-shadow: inset 0 0 2px rgba(120, 50, 0, 0.35);
  z-index: 2;
  pointer-events: none;
}

.fossil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
.fossil .wire { fill: none; stroke: var(--fossil); stroke-width: 0.55; vector-effect: non-scaling-stroke; }
.fossil .wire .text { stroke-linecap: round; }
.fossil .wire .heading { stroke-width: 1.4; }
.fossil .wire .button { fill: rgba(58, 22, 0, 0.18); }
.fossil .frame { fill: rgba(255, 236, 200, 0.06); stroke: rgba(80, 30, 0, 0.35); stroke-width: 0.6; }
.fossil .label {
  font-family: var(--mono);
  font-size: 7.2px;
  letter-spacing: 0.08em;
  fill: rgba(60, 22, 0, 0.72);
  text-transform: uppercase;
}
.tile { cursor: pointer; }
.tile:hover .frame, .tile:focus-visible .frame { fill: rgba(255, 244, 220, 0.16); stroke: rgba(90, 30, 0, 0.6); }
.tile:focus { outline: none; }

.core { fill: none; stroke: #2a0204; stroke-width: 1.1; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.tile[data-state='fractured'] .core, .tile[data-state='healed'] .core { opacity: 0.85; }
.crack { fill: none; stroke: #ff1f3d; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; filter: url(#glowRed); opacity: 0; transition: opacity 0.35s; }
.seam { fill: none; stroke: url(#goldGrad); stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; filter: url(#glowGold); opacity: 0; }
.proof { fill: none; stroke: url(#goldGrad); stroke-width: 2.2; stroke-linecap: round; filter: url(#glowGold); opacity: 0; }
.tile[data-state='fractured'] .crack { opacity: 1; }
.tile[data-state='healed'] .seam,
.tile[data-state='proven'] .proof { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .tile[data-state='fractured'] .crack { animation: throb 2.6s ease-in-out infinite; }
  .tile.healing .seam { animation: heal 1.4s cubic-bezier(0.3, 0.6, 0.2, 1) forwards; }
  .tile.healing .crack { opacity: 0; transition: opacity 0.9s 0.3s; }
  .tile.proving .proof { animation: heal 1s ease-out forwards; }
}
@keyframes throb { 50% { opacity: 0.62; } }
@keyframes heal { from { stroke-dashoffset: var(--len); opacity: 1; } to { stroke-dashoffset: 0; opacity: 1; } }

.back {
  transform: rotateY(180deg);
  background: #1b130b;
  box-shadow: inset 0 0 0 1px rgba(255, 200, 120, 0.4), 0 60px 140px -30px rgba(255, 140, 20, 0.33);
  display: grid;
  grid-template-rows: 1fr auto;
}
.back iframe { width: 100%; height: 100%; border: 0; background: #f4f5f7; }
/* A face turned away is invisible but Chrome still gives it the mouse: without this, the hidden front of a
   flipped block swallows every click and scroll meant for the live app on its back. */
.block.flipped .front, .block:not(.flipped) .back { pointer-events: none; }
a.btn { text-decoration: none; display: inline-block; }
a.btn:hover, a.btn:focus-visible { background: rgba(255, 190, 90, 0.16); box-shadow: 0 0 22px rgba(255, 170, 60, 0.25); outline: none; }
.back .bar { display: flex; gap: 10px; justify-content: space-between; align-items: center; padding: 8px 14px; font-size: 11px; color: var(--ink-dim); }

.caption {
  margin: 0;
  max-width: 62ch;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(15px, 1.45vw, 19px);
  color: var(--ink-dim);
  min-height: 1.5em;
}

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
button, .btn {
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 190, 90, 0.06);
  border: 1px solid rgba(255, 196, 110, 0.38);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
}
button:hover, button:focus-visible { background: rgba(255, 190, 90, 0.16); box-shadow: 0 0 22px rgba(255, 170, 60, 0.25); outline: none; }
input[type='range'] { width: min(320px, 70vw); accent-color: var(--gold-deep); }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(460px, 100%);
  background: linear-gradient(180deg, #19120b, #0e0a07);
  border-left: 1px solid rgba(255, 196, 110, 0.25);
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.6);
  padding: 22px 22px 40px;
  overflow-y: auto;
  z-index: 10;
  font-size: 12.5px;
  line-height: 1.55;
}
.drawer h2 { font: 400 26px/1.15 var(--serif); margin: 4px 0 6px; color: var(--ink); }
.drawer .close { float: right; }
.drawer .muted { color: var(--ink-faint); }
.drawer img { width: 100%; border-radius: 8px; border: 1px solid rgba(255, 196, 110, 0.25); margin: 10px 0; display: block; }
.drawer ol { list-style: none; padding: 0; margin: 12px 0; }
.drawer li { padding: 7px 0 7px 14px; border-left: 2px solid rgba(255, 196, 110, 0.2); margin-left: 4px; }
.chip { display: inline-block; font-size: 10px; letter-spacing: 0.12em; padding: 2px 7px; border-radius: 4px; margin-right: 6px; }
.chip.PASS { background: rgba(255, 211, 107, 0.16); color: var(--gold); border: 1px solid rgba(255, 211, 107, 0.4); }
.chip.FAIL { background: rgba(255, 45, 70, 0.14); color: #ff7184; border: 1px solid rgba(255, 45, 70, 0.45); }
.chip.FIX { background: rgba(160, 200, 255, 0.1); color: #b9d4ff; border: 1px solid rgba(160, 200, 255, 0.35); }
code { font-family: var(--mono); color: var(--ink); }
