/* ============================================================
   guess — vintage state lottery ticket, c. 1978
   palette: newsprint cream, navy ink, vermillion red
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --paper: #f1e7d0;
  --paper-shadow: #d8c9a4;
  --ink: #1b2451;
  --ink-soft: #2c3566;
  --red: #b32d1e;
  --red-deep: #851d12;
  --gold: #b58a3a;
  --gold-deep: #7a5a1f;
}

html, body {
  background:
    radial-gradient(ellipse at 30% 20%, #ede1c4 0%, var(--paper) 55%, var(--paper-shadow) 100%);
  color: var(--ink);
  min-height: 100dvh;
  font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', ui-monospace, Menlo, monospace;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(0.5rem, 3vw, 2rem);
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    radial-gradient(rgba(120, 90, 40, 0.06) 1px, transparent 1px),
    radial-gradient(rgba(60, 40, 20, 0.04) 1px, transparent 1px);
  background-size: 3px 3px, 7px 7px;
  background-position: 0 0, 1px 2px;
  mix-blend-mode: multiply;
}

.stage {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1rem 0 3rem;
}

/* ============================================================ TICKET */

.ticket {
  position: relative;
  background: var(--paper);
  border: 3px solid var(--ink);
  padding: 1.5rem 1.25rem 1.25rem;
  box-shadow:
    0 1px 0 var(--paper-shadow),
    0 12px 28px -16px rgba(20, 14, 0, 0.55),
    0 32px 60px -40px rgba(20, 14, 0, 0.4);
}

.ticket::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--ink);
  pointer-events: none;
}

.perf {
  position: relative;
  height: 14px;
  margin: 0.75rem -1.25rem 0.75rem;
  background:
    radial-gradient(circle at 7px 7px, var(--paper-shadow) 2.5px, transparent 3px) repeat-x;
  background-size: 14px 14px;
}
.perf::before, .perf::after {
  content: '';
  position: absolute;
  left: 0; right: 0; height: 1px;
  background: var(--ink);
  opacity: 0.35;
}
.perf::before { top: 0; }
.perf::after { bottom: 0; }

.rail {
  text-align: center;
  border-top: 3px double var(--ink);
  border-bottom: 3px double var(--ink);
  padding: 0.45rem 0;
  margin-bottom: 0.9rem;
}
.rail h1 {
  font-family: 'Anton', 'Oswald', Impact, 'Arial Narrow Bold', sans-serif;
  font-weight: 900;
  font-size: clamp(1.4rem, 5.5vw, 1.85rem);
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--red);
  text-transform: uppercase;
}
.rail .sub {
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  margin-top: 0.3rem;
  text-transform: uppercase;
  color: var(--ink);
}

.serial-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 0.85rem;
  color: var(--ink-soft);
}
.serial-row b { font-weight: 600; color: var(--ink); }

.marquee {
  position: relative;
  text-align: center;
  padding: 1.1rem 0.5rem 1rem;
  border: 2px solid var(--ink);
  background:
    repeating-linear-gradient(
      90deg,
      rgba(179, 45, 30, 0.07) 0 8px,
      transparent 8px 16px
    );
  margin-bottom: 1rem;
}
.marquee .eyebrow {
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink);
}
.marquee .ticket-num {
  font-family: 'Anton', 'Oswald', Impact, 'Arial Narrow Bold', sans-serif;
  font-weight: 900;
  font-size: clamp(2.6rem, 14vw, 4.2rem);
  line-height: 0.95;
  color: var(--red);
  letter-spacing: 0.01em;
  margin: 0.15rem 0 0.3rem;
  text-shadow:
    1px 0 0 rgba(27, 36, 81, 0.6),
   -1px 0 0 rgba(179, 45, 30, 0.6);
}
.marquee .ticket-num::before { content: '№\00a0'; font-size: 0.6em; }

.marquee .counter-line {
  font-size: 0.92rem;
  margin-top: 0.4rem;
  letter-spacing: 0.04em;
}
.marquee .counter-line .n {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  border-bottom: 2px solid var(--red);
  padding: 0 0.18em 1px;
  display: inline-block;
  min-width: 2.5ch;
  transition: transform 0.18s ease;
  font-variant-numeric: tabular-nums;
}
.marquee .counter-line .n.bump { transform: translateY(-2px) scale(1.06); }
.marquee .counter-line small {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.pitch {
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
  margin: 0.5rem 0 1rem;
  color: var(--ink-soft);
}
.pitch em { font-style: italic; color: var(--red); font-weight: 600; }

.guess-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.4rem;
}
.guess-form label {
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink);
}
.guess-form input {
  font: 700 clamp(1.5rem, 7vw, 2rem)/1 'Anton', 'Oswald', Impact, sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  padding: 0.55rem 0.5rem;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  caret-color: var(--red);
  font-variant-numeric: tabular-nums;
}
.guess-form input:focus {
  background: #fff8e6;
  box-shadow: inset 0 0 0 1px var(--red);
}
.guess-form input::placeholder {
  color: rgba(27, 36, 81, 0.35);
  font-weight: 700;
}

.guess-form button {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: 1.1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  padding: 0.85rem 1rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  transition: transform 0.06s ease, background 0.15s ease;
}
.guess-form button:hover:not(:disabled) { background: var(--red); border-color: var(--red); }
.guess-form button:active:not(:disabled) { transform: translateY(1px); }
.guess-form button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--ink-soft);
  border-color: var(--ink-soft);
}

.guess-form .hint {
  font-size: 0.7rem;
  text-align: center;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  min-height: 1.1em;
}
.guess-form .hint.error { color: var(--red); font-weight: 600; }

.footer-rail {
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink-soft);
  padding-top: 0.2rem;
}
.footer-rail .seal {
  display: inline-block;
  border: 1.5px solid var(--ink);
  padding: 0.18rem 0.55rem;
  margin: 0 0.3rem;
  border-radius: 50%;
  font-weight: 700;
}

/* ============================================================ REJECTION SLIP */

.slip {
  background: #faf3df;
  padding: 0;
  font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--ink);
  position: relative;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent 0 17px,
      rgba(27, 36, 81, 0.06) 17px 18px
    );
  box-shadow:
    0 8px 18px -12px rgba(0,0,0,0.4);
  border-top: 1.5px dashed var(--ink);
  border-bottom: 1.5px dashed var(--ink);
}
.slip::before, .slip::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; width: 14px;
  background:
    radial-gradient(circle at 7px 8px, var(--paper) 2px, transparent 2.5px) repeat-y;
  background-size: 14px 16px;
  pointer-events: none;
}
.slip::before { left: 0; }
.slip::after { right: 0; }
.slip .slip-inner {
  padding: 1rem 22px;
  position: relative;
  z-index: 1;
}
.slip h2 {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--red);
  text-align: center;
  margin-bottom: 0.5rem;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 0.3rem 0;
}
.slip pre {
  font: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}
.slip .caret {
  display: inline-block;
  width: 0.55ch;
  background: var(--ink);
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.slip .stamp {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.25rem 0.55rem;
  border: 2.5px solid var(--red);
  color: var(--red);
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  transform: rotate(-6deg);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.slip .stamp.show { opacity: 1; }

.slip-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}
.slip-actions button {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  padding: 0.5rem 0.85rem;
  cursor: pointer;
}
.slip-actions button:hover { background: var(--ink); color: var(--paper); }

/* ============================================================ CERTIFICATE */

.cert-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 0, 0.78);
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  animation: fadein 0.4s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.cert-wrap {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin: auto 0;
}

.cert {
  position: relative;
  width: 100%;
  /* Height grows with content — fixed aspect ratios were clipping the latin
     and seal row. PNG export reads the rendered bounds, so dynamic height
     is fine. */
  background:
    radial-gradient(ellipse at 50% 30%, #fbf5dc 0%, var(--paper) 55%, var(--paper-shadow) 100%);
  border: 6px double var(--ink);
  color: var(--ink);
  padding: clamp(1.25rem, 5%, 2.4rem);
  font-family: 'IBM Plex Mono', monospace;
  box-shadow: 0 30px 70px -30px rgba(0,0,0,0.7);
}
.cert::before {
  content: '';
  position: absolute;
  inset: 10px;
  border: 1.5px solid var(--ink);
  pointer-events: none;
}
.cert::after {
  content: '';
  position: absolute;
  inset: 18px;
  border: 1px dashed var(--gold-deep);
  pointer-events: none;
}
.cert-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  height: 100%;
}
.cert .crest {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: clamp(0.7rem, 2.4vw, 0.95rem);
  letter-spacing: 0.34em;
  color: var(--red);
  text-transform: uppercase;
  margin-top: 0.2rem;
}
.cert .crest::before, .cert .crest::after {
  content: '✦';
  margin: 0 0.5em;
  color: var(--gold-deep);
}
.cert h2 {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 7.5vw, 2.6rem);
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-transform: uppercase;
  margin: 0.45rem 0 0.1rem;
}
.cert h2 .of {
  display: block;
  font-size: 0.45em;
  letter-spacing: 0.4em;
  color: var(--red);
  margin: 0.35em 0;
}
.cert h2 .eyebrow {
  display: block;
  font-family: 'Pinyon Script', 'Allura', 'Snell Roundhand', 'Brush Script MT', cursive;
  font-weight: 400;
  text-transform: none;
  font-style: italic;
  font-size: 0.6em;
  letter-spacing: 0;
  color: var(--red);
  margin-bottom: -0.05em;
  line-height: 1;
}
.cert h2 em { font-style: italic; color: var(--red); }
.cert .preamble {
  font-size: clamp(0.6rem, 2.2vw, 0.78rem);
  line-height: 1.6;
  letter-spacing: 0.04em;
  margin: 0.8rem 0 0.45rem;
  max-width: 36ch;
}
.cert .preamble b { font-weight: 700; color: var(--red); }

.cert .name-line {
  width: 80%;
  margin: 0.4rem 0 0.1rem;
  border-bottom: 1.5px solid var(--ink);
}
.cert .name {
  font-family: 'Pinyon Script', 'Allura', 'Snell Roundhand', 'Brush Script MT', cursive;
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  line-height: 1.05;
  color: var(--ink);
  padding: 0.1rem 0;
  font-weight: 400;
}
.cert .name-caption {
  font-size: 0.55rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
}

.cert .stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin: 0.5rem 0 0.4rem;
  gap: 0.5rem;
}
.cert .stat { flex: 1; }
.cert .stat .num {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  line-height: 1;
  color: var(--red);
}
.cert .stat .lbl {
  font-size: 0.52rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 0.18rem;
}

.cert .latin {
  font-style: italic;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-top: 1rem;
  padding-top: 0.5rem;
  max-width: 32ch;
}

.cert .seal-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.cert .sig {
  flex: 1;
  border-top: 1px solid var(--ink);
  padding-top: 0.15rem;
  margin: 0 0.4rem;
  color: var(--ink-soft);
}
.cert .sig .scrawl {
  font-family: 'Pinyon Script', 'Allura', 'Snell Roundhand', 'Brush Script MT', cursive;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  display: block;
  margin-bottom: -0.1rem;
}
.cert .seal {
  width: clamp(48px, 14%, 76px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f0d27a 0%, var(--gold) 45%, var(--gold-deep) 100%);
  border: 2.5px solid var(--gold-deep);
  display: grid;
  place-items: center;
  color: #3a2a0a;
  font-family: 'Anton', sans-serif;
  font-size: 0.5rem;
  letter-spacing: 0.12em;
  text-align: center;
  line-height: 1.05;
  box-shadow:
    inset 0 0 0 1.5px #f5e3a8,
    inset 0 0 6px rgba(0,0,0,0.25),
    0 1px 2px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.cert .seal span { transform: rotate(-8deg); }

.cert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.cert-actions button {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 0.75rem 1rem;
  border: 2px solid var(--paper);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.cert-actions button:hover { background: var(--red); color: var(--paper); border-color: var(--paper); }
.cert-actions button.ghost { background: transparent; color: var(--paper); }
.cert-actions button.ghost:hover { background: var(--paper); color: var(--ink); }

/* Name-entry prompt */
.name-prompt {
  background: var(--paper);
  border: 3px solid var(--ink);
  padding: 1.25rem;
  text-align: center;
}
.name-prompt h3 {
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 0.4rem;
}
.name-prompt p {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin-bottom: 0.9rem;
}
.name-prompt input {
  font: 400 1.6rem/1 'Pinyon Script', 'Allura', 'Snell Roundhand', 'Brush Script MT', cursive;
  text-align: center;
  background: var(--paper);
  color: var(--ink);
  border: 0;
  border-bottom: 2px solid var(--ink);
  padding: 0.3rem 0.5rem;
  width: 100%;
  outline: none;
}
.name-prompt button {
  margin-top: 0.9rem;
  font-family: 'Anton', 'Oswald', Impact, sans-serif;
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  padding: 0.7rem 1.2rem;
  cursor: pointer;
}
.name-prompt button:hover { background: var(--red); border-color: var(--red); }

/* Confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 14px; height: 28px;
  background: var(--paper);
  border: 1px solid var(--ink);
  animation: fall linear forwards;
  transform-origin: center;
}
.confetti i:nth-child(3n) { background: var(--red); border-color: var(--red-deep); }
.confetti i:nth-child(5n) { background: var(--ink); border-color: var(--paper); }
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.6; }
}

.skel {
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 3rem 0;
}
.skel .dot { display: inline-block; animation: dotpulse 1.4s infinite; }
.skel .dot:nth-child(2) { animation-delay: 0.2s; }
.skel .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotpulse { 0%, 60%, 100% { opacity: 0.2; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .confetti { display: none; }
}

@media (min-width: 760px) {
  .stage { max-width: 480px; padding-top: 2.2rem; }
}
