/* A Small Fortune: a cassette label on an amber CRT. One dark theme.
   The only external file is the self-hosted pixel face built by scripts/make_font.py. */

@font-face {
  font-family: "Small Fortune Mono";
  src: url("fonts/smallfortune.woff") format("woff"),
       url("fonts/smallfortune.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --screen: #0b0805;
  --screen-2: #191008;
  --bezel: #000;
  --amber: #ffb63d;      /* body text: 11.4:1 on --screen */
  --amber-hi: #ffd27a;   /* fortune, field text: 13.9:1 */
  --amber-dim: #e3a548;  /* secondary text and borders: 9.3:1 on --screen, 8.7:1 on --screen-2, 6.5:1 on a scanline row */
  --amber-low: #7a5218;  /* decorative rules only */
  --amber-ghost: rgba(255, 182, 61, .09); /* unlit segments */
  --orange: #e0661c;
  --brown: #8c4a1a;
  --label-bg: #140c06;
  --field-bg: #0e0904;
  --on-amber: #140b03;   /* text on an amber button: 11:1 */

  --glow: 0 0 1px rgba(255, 196, 100, .45), 0 0 9px rgba(255, 150, 40, .3);
  --glow-soft: 0 0 7px rgba(255, 150, 40, .24);
  --mono: "Small Fortune Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--screen);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 90% 55% at 50% 30%, var(--screen-2) 0%, var(--screen) 72%) no-repeat,
    var(--screen);
  color: var(--amber);
  font: 400 1.125rem/1.55 var(--mono);
  font-synthesis: none;
  text-shadow: var(--glow);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--amber); color: var(--on-amber); text-shadow: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* The tube: scanlines, curved glass corners, vignette                 */
/* ------------------------------------------------------------------ */
.crt {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
.crt-scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom,
    rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, .17) 2px, rgba(0, 0, 0, .17) 3px);
  animation: hum 7s ease-in-out infinite;
}
/* A very slow breath of a few percent: no strobing. */
@keyframes hum {
  0%, 100% { opacity: .8; }
  50% { opacity: 1; }
}
.crt-glass {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: radial-gradient(ellipse 80% 75% at 50% 50%, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, .42) 100%);
  box-shadow:
    0 0 0 40px var(--bezel),                 /* paints the corners outside the curve */
    inset 0 0 70px 4px rgba(0, 0, 0, .5),
    inset 0 0 2px 1px rgba(255, 170, 60, .08);
}

/* ------------------------------------------------------------------ */
/* Page                                                                */
/* ------------------------------------------------------------------ */
.page {
  position: relative;
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

/* ------------------------------------------------------------------ */
/* Header: the cassette label                                          */
/* ------------------------------------------------------------------ */
.label {
  position: relative;
  margin: 0 0 1.4rem;
  padding: .55rem .875rem 0;
  background: var(--label-bg);
  border: 2px solid var(--amber-dim);
  border-radius: 14px;
  box-shadow:
    inset 0 0 0 3px var(--label-bg),
    inset 0 0 0 4px rgba(255, 182, 61, .16),
    0 0 24px -6px rgba(255, 150, 30, .4);
  text-shadow: none;
  overflow: hidden;
}

.title { margin: 0; line-height: 0; font-size: 1rem; }
.wordmark {
  display: block;
  width: calc(100% + 1.75rem);   /* stripes run to the label's edges */
  height: auto;
  margin: 0 -.875rem;
  filter: drop-shadow(0 0 5px rgba(255, 150, 30, .32));
}
.st-1 { fill: var(--amber); }
.st-2 { fill: var(--orange); }
.st-3 { fill: var(--brown); }
.wm-key { fill: var(--label-bg); stroke: var(--label-bg); stroke-width: 14px; stroke-linejoin: round; }
.wm-key-arc { fill: none; stroke: var(--label-bg); stroke-width: 34px; }
.wm-ink { fill: var(--amber-hi); }
.wm-ink-arc { fill: none; stroke: var(--amber-hi); stroke-width: 20px; }

.wm-window { fill: rgba(0, 0, 0, .35); stroke: var(--amber-dim); stroke-width: 3px; }
.wm-pack { fill: var(--brown); opacity: .55; }
.reel { fill: none; stroke: var(--amber); stroke-width: 2.5px; stroke-linecap: round; transform-box: fill-box; transform-origin: 50% 50%; }
[data-phase="loading"] .reel { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }

.tagline {
  margin: .3rem 0 0;
  font-size: clamp(13px, 3.8vw, 15px);
  line-height: 1.35;
  letter-spacing: .01em;
  color: var(--amber);
  text-shadow: var(--glow-soft);
  text-wrap: balance;
}

.label-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .45rem;
  font-size: 11px;
  line-height: 1;
  letter-spacing: .08em;
  color: var(--amber-dim);
}
.label-foot span { padding-bottom: .5rem; white-space: nowrap; }
.shell {
  display: block;
  flex: 0 1 7.5rem;
  min-width: 4rem;
  height: auto;
  margin-bottom: -1px;
  fill: none;
  stroke: var(--amber-dim);
  stroke-width: 1.6px;
}

/* ------------------------------------------------------------------ */
/* Deck: the tape loader, then the name prompt                         */
/* ------------------------------------------------------------------ */
.deck { min-height: 7.75rem; } /* loader and form take the same room, so nothing jumps */

.loader p { margin: 0 0 .1rem; }
.loader p:first-child { color: var(--amber-dim); text-shadow: var(--glow-soft); }
.blk {
  display: inline-block;
  width: .6em;
  height: .9em;
  margin-left: .1em;
  vertical-align: -.2em;
  background: var(--amber);
  box-shadow: 0 0 8px rgba(255, 150, 40, .45);
  animation: blink 1.06s linear infinite;
}
.counter-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .55rem !important;
  font-size: 1rem;
  color: var(--amber-dim);
  text-shadow: var(--glow-soft);
}
.counter { display: inline-flex; gap: 3px; }
.counter b {
  display: inline-block;
  min-width: 1.5em;
  padding: .2em 0 .15em;
  font-weight: 400;
  font-size: 1.125rem;
  line-height: 1.2;
  text-align: center;
  color: var(--amber-hi);
  background: #1c1108;
  border: 1px solid var(--amber-low);
  border-radius: 3px;
  text-shadow: var(--glow);
}

@keyframes blink {
  0%, 49.9% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.ask { margin: 0 0 .5rem; }
.ask label {
  display: block;
  margin: 0 0 .4rem;
  font-size: 1rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--amber-dim);
  text-shadow: var(--glow-soft);
}
.row { display: flex; gap: .6rem; }

.field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--field-bg);
  border: 2px solid var(--amber-dim);   /* well over 3:1 against the field */
  border-radius: 8px;
  overflow: hidden;
}
.field:focus-within {
  border-color: var(--amber);
  outline: 2px solid var(--amber-hi);
  outline-offset: 3px;
  box-shadow: 0 0 16px -2px rgba(255, 150, 30, .4);
}

.field input,
.field .mirror,
.field .prompt,
.field .caret {
  font-family: var(--mono);
  font-size: max(16px, 1.125rem);   /* 16px+ keeps iOS Safari from zooming */
  letter-spacing: 0;
}
.field input {
  display: block;
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: .75rem 1em .75rem 1.9em;
  line-height: 1.3;
  color: var(--amber-hi);
  background: transparent;
  caret-color: transparent;          /* the block below is the caret */
  text-shadow: var(--glow);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field .prompt {
  position: absolute;
  left: .6em;
  top: .75rem;
  line-height: 1.3;
  color: var(--amber-dim);
  pointer-events: none;
}
.field .mirror {
  position: absolute;
  left: 0;
  top: 0;
  white-space: pre;
  visibility: hidden;
  pointer-events: none;
}
/* Block caret: positioned by app.js from the selection; the native caret is hidden. */
.field .caret {
  position: absolute;
  left: 0;
  top: calc(.75rem + .2em);
  width: .6em;                       /* one cell of the monospaced face */
  height: .9em;
  background: var(--amber-hi);
  box-shadow: 0 0 8px rgba(255, 160, 50, .5);
  mix-blend-mode: difference;        /* the letter under the block shows dark */
  pointer-events: none;
  will-change: transform;
}
.field .caret.blink { animation: blink 1.06s linear infinite; }
.field .caret.idle {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--amber-dim);
  mix-blend-mode: normal;
  animation: none;
}
.field .caret.hide { visibility: hidden; }

button {
  flex: 0 0 auto;
  min-height: 44px;
  margin: 0;
  padding: .75rem 1rem;
  font: inherit;
  font-size: max(16px, 1.125rem);
  line-height: 1.3;
  color: var(--on-amber);
  background: var(--amber);
  border: 2px solid var(--amber);
  border-radius: 8px;
  text-shadow: none;
  box-shadow: 0 0 18px -3px rgba(255, 150, 30, .5);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color .12s ease, transform .08s ease;
}
button:active { transform: translateY(1px); background: #eaa233; }
@media (hover: hover) {
  button:hover { background: var(--amber-hi); border-color: var(--amber-hi); }
}

/* Separate rules: Safari before 15.4 drops a whole selector list containing :focus-visible. */
:focus { outline: 2px solid var(--amber-hi); outline-offset: 3px; }
@supports selector(:focus-visible) {
  :focus:not(:focus-visible) { outline: none; }
}
:focus-visible { outline: 2px solid var(--amber-hi); outline-offset: 3px; }
.field input:focus { outline: none; }  /* the field box carries the ring */

.hint {
  min-height: 1.55em;
  margin: .45rem 0 0;
  font-size: 1rem;
  color: var(--amber);
  text-shadow: var(--glow-soft);
}
.hint.error {
  color: var(--amber-hi);
  padding-left: .6em;
  border-left: 3px solid var(--orange);
}

@media (max-width: 359px) {
  .deck { min-height: 11.5rem; } /* the stacked form is taller; reserve its room for the loader too */
  .row { flex-direction: column; }
  button { width: 100%; }
}

/* ------------------------------------------------------------------ */
/* Stage: the wireframe cookie                                          */
/* ------------------------------------------------------------------ */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: .5rem;
}
.cookie-wrap { width: min(13.5rem, 60vw); margin: 0 auto; }
/* A side-on crescent with a slip in one horn. viewBox 0 0 248 170, drawn for about 216px wide
   (0.9 CSS px per unit); stroke widths below are in viewBox units. */
.cookie {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 0 3px rgba(255, 160, 40, .55));
}

.ck path { fill: none; stroke: var(--amber); stroke-linecap: round; stroke-linejoin: round; }
.ck .ck-outline { stroke-width: 2.4px; }
.ck .ck-fold { stroke-width: 1.7px; }
.ck .ck-rim { stroke-width: 1.4px; }
.ck .ck-line { stroke: var(--amber-dim); stroke-width: 1.25px; opacity: .8; }
.ck .ck-slip { fill: var(--screen); stroke: var(--amber-hi); stroke-width: 1.4px; }
.ck .ck-print { stroke: var(--amber-dim); stroke-width: 1.1px; stroke-dasharray: 3 2.5; opacity: .75; }
.ck .ck-edge { stroke-width: 1.5px; opacity: 0; }
.ck-shadow { fill: none; stroke: var(--amber-low); stroke-width: 1px; stroke-dasharray: 3 4; }
.ck-crack {
  fill: none;
  stroke: var(--amber-hi);
  stroke-width: 1.7px;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 79; /* crack path length is 77.9 */
  stroke-dashoffset: 79;
  opacity: 0;
}
.crumb { fill: none; stroke: var(--amber); stroke-width: 1.1px; stroke-linejoin: round; opacity: 0; }

/* Each piece pivots on its own horn tip, as if resting on the table. */
.half {
  transform-box: view-box;
  transition: transform .3s cubic-bezier(.2, .9, .3, 1.1);
}
.half-l { transform-origin: 35px 146px; }
.half-r { transform-origin: 216px 116px; }

.stage.waiting .cookie { animation: sway 1.1s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes sway {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}

/* Cracking: a short wobble while the crack runs down from the top to the pinch, then the pieces part. */
.stage.cracking .cookie { animation: wobble .13s ease-in-out 1; transform-origin: 50% 90%; }
.stage.cracking .ck-crack { opacity: 1; animation: crackline .13s linear forwards; }
@keyframes wobble {
  0% { transform: rotate(0); }
  35% { transform: rotate(-3deg) scale(1.02); }
  70% { transform: rotate(2.5deg) scale(1.02); }
  100% { transform: rotate(0); }
}
@keyframes crackline { to { stroke-dashoffset: 0; } }

.stage[data-state="open"] .half-l { transform: translate(-12px, 0px) rotate(-9deg); }
.stage[data-state="open"] .half-r { transform: translate(12px, 0px) rotate(9deg); }
.stage[data-state="open"] .ck-edge { opacity: .75; transition: opacity .2s ease; }

.stage.animate .crumb { animation: crumb .6s cubic-bezier(.3, .1, .6, 1) both; }
.stage.animate .c1 { --dx: -14px; animation-delay: .13s; }
.stage.animate .c2 { --dx: 10px; animation-delay: .16s; }
.stage.animate .c3 { --dx: -4px; animation-delay: .14s; }
.stage.animate .c4 { --dx: 18px; animation-delay: .18s; }
.stage.animate .c5 { --dx: -22px; animation-delay: .19s; }
@keyframes crumb {
  0% { opacity: 0; transform: translate(0, 0) rotate(0); }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), 26px) rotate(40deg); }
}

/* ------------------------------------------------------------------ */
/* 3D cookie (cookie3d.js). The SVG above stays as the fallback: it is   */
/* hidden only once the canvas has really drawn a frame (.has-3d), and   */
/* keeps its box so nothing on the page moves.                           */
/* ------------------------------------------------------------------ */
.cookie-wrap { position: relative; }
.cookie3d {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  display: block;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity .4s ease-out;
}
/* The two drawings differ in shape, so the switch is a short cross-fade: the canvas fades in
   while the SVG stays, and the SVG goes once the canvas is fully there. Reduced motion turns
   all transitions off, so there it is instant. */
.stage.has-3d .cookie3d { opacity: 1; }
.stage.has-3d .cookie { visibility: hidden; transition: visibility 0s linear .4s; }
/* While the 3D cookie is still loading the SVG is held back (it keeps its box), so one cookie
   is never seen being swapped for the other. cookie3d.js drops this class if the 3D fails,
   takes too long, or a cookie is cracked first. */
.stage.pending-3d .cookie { visibility: hidden; }
/* The loading screen: the SVG is held back from the very first paint, before cookie3d.js has
   had a chance to run. If that script never runs, the SVG appears together with the form. */
[data-phase="loading"] .stage .cookie { visibility: hidden; }
/* High-contrast (forced colours): the canvas cannot follow the forced palette; the SVG can. */
@media (forced-colors: active) {
  .cookie3d { display: none; }
  .stage.has-3d .cookie, .stage.pending-3d .cookie { visibility: visible; }
}

/* ------------------------------------------------------------------ */
/* The printout                                                         */
/* ------------------------------------------------------------------ */
.result { width: 100%; display: flex; justify-content: center; }
.slip {
  width: min(100%, 27rem);
  margin-top: .6rem;
  padding: 1rem 1.1rem .95rem;
  background: rgba(22, 13, 5, .65);
  border: 2px solid var(--amber-dim);
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 3px var(--screen),
    inset 0 0 0 4px rgba(255, 182, 61, .2),
    0 0 20px -6px rgba(255, 150, 30, .4);
}
/* Power-on: the box opens out from a line, like a tube warming up. */
.stage.animate .slip { animation: boot .16s ease-out .14s both; transform-origin: 50% 0; }
@keyframes boot {
  0% { opacity: 0; transform: scaleY(.08); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: none; }
}

.fortune {
  margin: 0;
  min-height: 1.4em;
  font-size: clamp(1.375rem, 5.8vw, 1.75rem);
  line-height: 1.4;
  color: var(--amber-hi);
  text-shadow: 0 0 1px rgba(255, 210, 122, .5), 0 0 12px rgba(255, 160, 40, .38);
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
}
.fortune .w { visibility: hidden; }
.fortune .w.on { visibility: visible; }
.fortune .w.cur { position: relative; }
.fortune .w.cur::after {
  content: "";
  position: absolute;
  left: 100%;
  top: .2em;
  width: .6em;
  height: .9em;
  background: var(--amber-hi);
  box-shadow: 0 0 8px rgba(255, 160, 50, .5);
}

.lucky {
  margin-top: .9rem;
  padding-top: .7rem;
  border-top: 1px dashed var(--amber-low);
}
.lucky-label {
  display: block;
  margin-bottom: .45rem;
  font-size: 1rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--amber-dim);
  text-shadow: var(--glow-soft);
}
.readout {
  display: grid;
  grid-template-columns: repeat(6, auto);
  justify-content: start;
  gap: .5rem .5rem;
  font-size: clamp(15px, 4.6vw, 20px);
}
.pair {
  display: inline-flex;
  gap: 2px;
  padding: 5px 5px 4px;
  background: #130b04;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 182, 61, .16);
}
.digit { display: block; width: .82em; height: 1.17em; overflow: visible; }
.seg { fill: var(--amber-ghost); transition: fill .12s ease; }
.readout.lit .seg.on { fill: var(--amber-hi); }
.readout.lit .digit { filter: drop-shadow(0 0 2.5px rgba(255, 160, 40, .7)); }

@media (max-width: 345px) {
  .readout { grid-template-columns: repeat(3, auto); font-size: 20px; gap: .55rem .7rem; }
}

.again {
  margin: 1rem 0 0;
  font-size: 1rem;
  text-align: center;
  color: var(--amber);
  text-shadow: var(--glow-soft);
  text-wrap: balance;
}
.again.pending { visibility: hidden; }

/* ------------------------------------------------------------------ */
/* Footer                                                               */
/* ------------------------------------------------------------------ */
.foot {
  margin-top: auto;
  padding-top: 2.25rem;
  text-align: center;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--amber);
  text-shadow: var(--glow-soft);
}
.how { margin: 0 auto .75rem; max-width: 28rem; }
.how summary {
  display: inline-block;
  min-height: 44px;
  padding: .65rem .75rem;
  border-radius: 6px;
  color: var(--amber);
  text-decoration: underline;
  text-decoration-color: var(--amber-low);
  text-underline-offset: .25em;
  cursor: pointer;
  list-style: none;
  text-shadow: var(--glow);
}
.how summary::-webkit-details-marker { display: none; }
.how p { margin: .35rem 0 .5rem; color: var(--amber); text-align: left; }
.small { margin: 0 auto .5rem; max-width: 28rem; text-wrap: balance; }
.motto {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: 1rem;
  color: var(--amber);
}
.motto::before,
.motto::after {
  content: "";
  flex: 1 1 0;
  border-top: 1px solid var(--amber-low);
}

@media (min-width: 48rem) {
  .page { padding-top: max(3rem, env(safe-area-inset-top)); }
  .crt-glass { border-radius: 30px; }
  .cookie-wrap { width: 15rem; }
}

/* Reduced motion: no flicker, no blinking, no ticking, no crack; everything simply appears. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ------------------------------------------------------------------ */
/* 404 page                                                             */
/* ------------------------------------------------------------------ */
.lost { justify-content: center; text-align: center; }
.lost p { margin: 0 0 1rem; }
.lost-code { margin: 0 0 .5rem; font-size: clamp(4rem, 28vw, 8rem); line-height: 1; font-weight: 400; color: var(--amber-hi); }
.lost-error { color: var(--amber-hi); }
.lost-home {
  display: inline-block;
  min-height: 44px;
  padding: .65rem .75rem;
  color: var(--amber-hi);
  text-decoration: underline;
  text-decoration-color: var(--amber-dim);
  text-underline-offset: .25em;
}
