/* Night mode: a neon shopfront after dark. The truth is the only thing lit. */

@font-face {
  font-family: "Caveat";
  src: url("/static/fonts/Caveat-Bold.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Patrick Hand";
  src: url("/static/fonts/PatrickHand-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --night: #0f1118;
  --panel: #171a24;
  --line: #262b3a;
  --amber: #ffb45e;
  --amberglow: #ff8c2e;
  --teal: #7ef0d4;
  --tealglow: #17c9a0;
  --red: #ff6b7a;
  --redglow: #e0394f;
  --gold: #ffd77a;
  --slipw: #fff6e6;
  --slipglow: #ffd9a0;
  --dim: #8a93a8;
  --faint: #5d6579;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --marker: "Caveat", "Comic Sans MS", cursive;
  --cjk: "Kaiti SC", "KaiTi", "STKaiti", "Noto Serif CJK SC", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 30%, #1a1e2c 0%, var(--night) 65%);
  color: #cfd6e4;
  font-family: var(--hand);
  display: flex;
  justify-content: center;
}

.stage {
  max-width: 620px;
  padding: 40px 24px 80px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── the marquee ───────────────────────────────────────────────── */
.marquee {
  display: flex;
  align-items: center;
  gap: 26px;
  justify-content: center;
}
.title {
  font-family: var(--marker);
  font-weight: 700;
  font-size: 2.5rem;
  letter-spacing: 0.06em;
  margin: 0;
  color: #e2fff6;
  text-shadow: 0 0 4px var(--teal), 0 0 12px var(--teal), 0 0 30px var(--tealglow);
}
.title .flick { color: #ffedcf; text-shadow: 0 0 4px var(--amber), 0 0 12px var(--amber), 0 0 26px var(--amberglow); }
.tagline {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.78rem;
  letter-spacing: 0.42em;
  color: var(--red);
  text-shadow: 0 0 8px var(--redglow);
  margin: 10px 0 0;
}
.sign-cn {
  font-family: var(--cjk);
  font-size: 2.4rem;
  line-height: 1.15;
  writing-mode: vertical-rl;
  color: #ffc3ca;
  text-shadow: 0 0 4px var(--red), 0 0 12px var(--red), 0 0 30px var(--redglow);
  user-select: none; /* the secret triple-click shouldn't highlight text */
}

/* neon behaviors */
@keyframes flick {
  0%, 84%, 88%, 92%, 100% { opacity: 1; }
  86%, 90% { opacity: 0.2; }
}
.flick { animation: flick 3.4s infinite; }
@keyframes buzz {
  0%, 96%, 100% { opacity: 1; }
  97.5% { opacity: 0.84; }
  98.5% { opacity: 1; }
}
.buzz { animation: buzz 4.2s infinite; }

/* one chip's tube is dying. it adds character. nobody fix it.
   6.7s period, deliberately out of sync with buzz (4.2s) and flick (3.4s) */
.chip-dying { animation: chip-sputter 6.7s infinite; }
@keyframes chip-sputter {
  0%, 86%, 100% { opacity: 1; }
  88% { opacity: 0.12; }
  89.5% { opacity: 0.9; }
  91% { opacity: 0.15; }
  93% { opacity: 1; }
  94.5% { opacity: 0.3; }
  96% { opacity: 1; }
}

/* real neon: a white-hot core, the colour lives in the halo. The filter
   lives on the <svg> ELEMENT, not inner groups — Safari ignores CSS
   filters on SVG children but honours them on the svg box itself. blur()
   first melts the stroke edge, then the halos bloom. */
.tube-amber { stroke: #ffe3b8; }
#cookie-svg {
  overflow: visible;
  filter: drop-shadow(0 0 6px rgba(255, 140, 46, 0.6)) drop-shadow(0 0 18px rgba(255, 140, 46, 0.35));
}

/* ── speech bubble: the shopkeeper's voice, in cold teal ───────── */
.bubble {
  background: var(--panel);
  color: var(--teal);
  text-shadow: 0 0 6px rgba(126, 240, 212, 0.55);
  border: 1.5px solid var(--tealglow);
  box-shadow: 0 0 12px rgba(23, 201, 160, 0.25), inset 0 0 18px rgba(23, 201, 160, 0.07);
  border-radius: 14px;
  padding: 10px 18px;
  font-family: var(--marker);
  font-size: 1.35rem;
  max-width: 440px;
  position: relative;
  margin: 30px 0 26px;
  animation: bubble-in 0.25s ease-out;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  width: 13px;
  height: 13px;
  background: var(--panel);
  border-right: 1.5px solid var(--tealglow);
  border-bottom: 1.5px solid var(--tealglow);
  transform: translateX(-50%) rotate(45deg);
}
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px); } }

/* ── the cookie ────────────────────────────────────────────────── */
.cookie-button {
  background: none; border: none; padding: 0; cursor: pointer;
  margin-top: 12px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.25s ease;
}
/* light spill on the wall behind the sign */
.cookie-button::before {
  content: "";
  position: absolute;
  inset: -44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 140, 46, 0.14), rgba(255, 140, 46, 0.05) 45%, transparent 70%);
  pointer-events: none;
}
.cookie-button:hover { transform: scale(1.03); }
.cookie-button:hover #cookie-svg {
  filter: drop-shadow(0 0 8px rgba(255, 140, 46, 0.7)) drop-shadow(0 0 24px rgba(255, 140, 46, 0.45));
}
.cookie-button:focus-visible { outline: 2px dashed var(--faint); outline-offset: 10px; }

/* SVG elements ignore the HTML `hidden` attribute — enforce it, or the whole
   cookie stays visible behind the cracked halves (the cookie-inside-a-cookie bug) */
#cookie-svg g[hidden] { display: none; }

/* (overflow: visible on #cookie-svg above also lets the parted halves
   travel beyond the viewBox without clipping) */

/* crumbs: scatter once on the snap, then they're gone. like dignity */
.crumb { opacity: 0; }
.cracked .crumb { animation: crumb-fall 0.9s ease-out 0.12s forwards; }
@keyframes crumb-fall {
  0% { opacity: 1; transform: translate(0, 0); }
  100% { opacity: 0; transform: translate(var(--dx, 0), 62px) rotate(50deg); }
}

/* cracking: the tubes protest before they give */
@keyframes hardflick {
  0%, 100% { opacity: 1; }
  20% { opacity: 0.25; }
  35% { opacity: 1; }
  55% { opacity: 0.15; }
  70% { opacity: 0.9; }
  85% { opacity: 0.4; }
}
.cracking #whole { animation: hardflick 0.3s linear infinite; }

/* cracked: the biscuit snaps, the truth drops */
#half-l, #half-r { transition: transform 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.cracked #half-l { transform: translate(-30px, 4px) rotate(-8deg); }
.cracked #half-r { transform: translate(34px, -6px) rotate(10deg); }
#half-l { transform-origin: 60px 160px; }
#half-r { transform-origin: 160px 160px; }

/* closed: the tubes go cold; one red sign stays lit */
.closed-state .cookie-button { cursor: not-allowed; transform: none; }
.closed-state #cookie-svg { opacity: 0.15; filter: none; }
.closed-state .cookie-button .tube-amber { animation: none; }
.closed-state .cookie-button::before { display: none; }
.closed-sign {
  display: none;
  font-family: var(--marker);
  font-size: 1.7rem;
  letter-spacing: 0.18em;
  color: var(--red);
  text-shadow: 0 0 8px var(--red), 0 0 26px var(--redglow);
  margin: 22px 0 0;
}
.closed-state .closed-sign { display: block; }

/* the affordance */
.hint {
  color: var(--faint);
  font-family: var(--marker);
  font-size: 1.2rem;
  margin: 12px 0 0;
  transform: rotate(-1deg);
}

/* ── the receipt: the one physical object in a room of light ───── */
.slot {
  width: 280px;
  height: 9px;
  border-radius: 5px;
  background: #05070c;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.9), 0 1px 0 rgba(255, 180, 94, 0.14);
  margin-top: 22px;
}
.slip { max-width: 470px; width: 100%; margin-top: 0; }
.slip.wiggle { animation: slip-wiggle 0.4s ease; }
@keyframes slip-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(1.6deg); }
  60% { transform: rotate(-2.2deg); }
}

/* the feed: prints out of the slot top-to-bottom in mechanical jerks.
   Speech pops whole above; the document PRINTS below — that contrast is the point. */
.slip.ignite { animation: paper-feed 1.5s steps(9, end) 0.25s both; }
@keyframes paper-feed {
  from { clip-path: inset(-5% -5% 100% -5%); }
  to { clip-path: inset(-5% -5% -12% -5%); }
}

.paper {
  background: linear-gradient(#fbf7ec, #f3edd8);
  color: #2b2620;
  font-family: "Courier New", Courier, monospace;
  text-align: center;
  padding: 24px 26px 30px;
  margin: 0 14px;
  transform: rotate(-0.7deg);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.55);
  clip-path: polygon(0 0, 100% 0, 100% 96%, 94% 100%, 88% 96%, 82% 100%, 76% 96%,
    70% 100%, 64% 96%, 58% 100%, 52% 96%, 46% 100%, 40% 96%, 34% 100%, 28% 96%,
    22% 100%, 16% 96%, 10% 100%, 4% 96%, 0 100%);
}
.slip-text {
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.55;
  margin: 0;
}
.slip-number {
  color: #a63125;
  font-size: 0.92rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 14px 0 0;
}
.slip-extras {
  color: #6f6552;
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  margin: 8px 0 0;
}
.slip-extras:first-of-type {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(43, 38, 32, 0.35);
}
.slip-brand {
  color: #6f6552;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  margin: 12px 0 0;
}
.slip-brand .chop {
  font-family: var(--cjk);
  color: #f6ecd8;
  background: #a63125;
  border-radius: 3px;
  padding: 1px 4px;
  margin-right: 6px;
  font-size: 0.8rem;
}
.slip.tier-good .paper { background: linear-gradient(#fdf8e2, #f7efc7); }
.slip.tier-good .slip-number { color: #a07c1f; }

/* ── share row ─────────────────────────────────────────────────── */
.share-row {
  margin-top: 26px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  animation: bubble-in 0.4s ease-out 0.2s both;
}
.share-btn {
  font-family: var(--hand); font-size: 1rem;
  background: var(--panel); color: #cfd6e4;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  padding: 7px 16px; cursor: pointer; text-decoration: none;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.share-btn:hover {
  border-color: var(--tealglow);
  color: var(--teal);
  box-shadow: 0 0 10px rgba(23, 201, 160, 0.3);
  transform: translateY(-1px);
}
.share-btn.primary {
  border-color: var(--redglow); color: var(--red);
}
.share-btn.primary:hover {
  box-shadow: 0 0 12px rgba(224, 57, 79, 0.4);
  color: var(--red); border-color: var(--red);
}

.counter { color: var(--faint); font-size: 0.95rem; margin-top: 26px; min-height: 1em; }

/* ── permalink page ────────────────────────────────────────────── */
.permalink { align-items: center; }
.perma-wrap { max-width: 620px; padding: 80px 24px; text-align: center; }
.perma-label { color: var(--dim); font-style: italic; font-size: 1.1rem; }
.perma-paper { margin: 26px auto; max-width: 500px; }
.perma-fortune {
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.55;
  margin: 0;
  padding: 0;
}
.perma-cta {
  color: var(--teal);
  text-shadow: 0 0 8px rgba(23, 201, 160, 0.5);
  font-style: italic;
}

@media (max-width: 480px) {
  .marquee { gap: 16px; }
  .title { font-size: 1.9rem; }
  .sign-cn { font-size: 1.8rem; }
}
