@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
}

:root {
  --sea: #f3f9fb;
  --foam: #1b2421;
  --paper: #ffffff;
  --ink: #16303a;
  --ocean: #168fbe;
  --ocean-deep: #0c678c;
  --ocean-ink: #0a5f80;
  --stamp: #c5162c;
  --muted: #3d4a50;
  --line: rgba(22, 48, 58, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--sea);
}

body.lock { overflow: hidden; }

button, input { font: inherit; color: inherit; }

button { touch-action: manipulation; cursor: pointer; }

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--ocean);
  outline-offset: 2px;
}

h1, h2, .nick, .eyebrow, .ball strong, .brand, .stamp, .ticket-head h2 {
  font-family: "Fredoka", "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 650;
}

.wrap {
  width: min(1120px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 0.85rem 0 calc(1.5rem + env(safe-area-inset-bottom));
}

.narrow {
  width: min(38rem, 100%);
  margin-left: auto;
  margin-right: auto;
  display: grid;
  gap: 1.6rem;
}

.home {
  width: min(40rem, calc(100% - 2rem));
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.2rem 0 calc(2rem + env(safe-area-inset-bottom));
}

.home h1 {
  font-size: clamp(2.7rem, 9vw, 4.4rem);
  font-weight: 600;
  line-height: 0.92;
  margin: 0.15rem 0 0.4rem;
}

.eyebrow {
  margin: 0.8rem 0 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: var(--ocean-ink);
}

.rule {
  width: 4.2rem;
  height: 3px;
  margin: 0.85rem auto 0.9rem;
  border: 0;
  background: var(--ocean);
}

.lede, .fine {
  margin: 0.4rem 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.fine { font-size: 0.92rem; max-width: 28rem; }

.home-actions {
  width: min(22rem, 100%);
  margin-top: 1.3rem;
  display: grid;
  gap: 0.7rem;
}

.secondary {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1.1rem;
  margin-top: 0.9rem;
}

.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.brand {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.page-title {
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 600;
  margin: 0.2rem 0 0.8rem;
}

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  background: var(--ocean);
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.92rem 1.2rem;
  box-shadow: 0 6px 0 var(--ocean-deep);
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--ocean-deep);
}

.btn:disabled {
  opacity: 0.45;
  box-shadow: none;
  cursor: default;
}

.text-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.4rem 0.15rem;
  text-decoration: underline;
  text-underline-offset: 0.22em;
}

.chip {
  appearance: none;
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0;
}

.ball {
  width: 6.6rem;
  height: 6.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background:
    radial-gradient(circle at 34% 30%, #fff 0 9%, #fffaf3 10% 48%, #e4d3b4 78%, #cbb892 100%);
  box-shadow:
    inset -10px -14px 18px rgba(120, 80, 20, 0.2),
    0 12px 24px rgba(0, 0, 0, 0.28);
}

.poster-ball { width: 7.6rem; height: 7.6rem; }

.ball strong {
  color: var(--stamp);
  font-size: 2.55rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.poster-ball strong { font-size: 2.8rem; }

.ball.pop { animation: land 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes land {
  from { transform: translateY(-16px) scale(0.9); }
}

.machine {
  display: grid;
  gap: 1.35rem;
}

#controls {
  display: grid;
  gap: 0.95rem;
}

.live-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.15rem;
  align-items: center;
}

.nick {
  margin: 0;
  font-size: clamp(1.45rem, 4.5vw, 2.1rem);
  font-weight: 600;
  line-height: 1.25;
}

.reply {
  margin: 0.55rem 0 0;
  color: var(--ocean-ink);
  font-family: "Fredoka", "Avenir Next", "Segoe UI", sans-serif;
  font-style: italic;
  font-size: 1.12rem;
  line-height: 1.35;
}

.trail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.85rem 0 0;
}

.trail span {
  min-width: 2rem;
  text-align: center;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #c5d6df;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.hint {
  min-height: 1.3em;
  margin: 0.55rem 0 0.2rem;
  color: #f3e2b8;
}

.table-grid { display: grid; gap: 0.4rem; }

.prizes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.2rem 0 0.7rem;
}

.prize {
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.86rem;
}

.prize b { font-weight: 700; }

.prize.won {
  background: var(--foam);
  color: var(--ink);
}

.tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.55rem;
}

.tabs button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid rgba(244, 239, 228, 0.2);
  background: transparent;
  color: var(--foam);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  white-space: nowrap;
}

.tabs button[aria-selected="true"] {
  background: var(--foam);
  color: var(--ink);
  border-color: transparent;
}

.swatch {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--dab, var(--ocean));
  display: inline-block;
  flex: none;
}

.need {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--ocean);
}

.c0 { --dab: #c81d25; }
.c1 { --dab: #1d4e89; }
.c2 { --dab: #157a42; }
.c3 { --dab: #9a3412; }
.c4 { --dab: #7c3a6e; }
.c5 { --dab: #0f6e78; }

.stage { display: grid; gap: 0.75rem; }

.ticket-wrap {
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.62rem 0.8rem;
  border-left: 8px solid var(--dab, var(--stamp));
}

.ticket-head h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.ticket-head p {
  margin: 0;
  font-size: 0.85rem;
  color: #5e5648;
}

.ticket {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  background: var(--ink);
  user-select: none;
}

.cell {
  display: grid;
  place-items: center;
  min-height: 2.85rem;
  min-width: 0;
  border: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Fredoka", "Avenir Next", "Segoe UI", sans-serif;
  font-size: clamp(0.95rem, 3.5vw, 1.35rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cell.blank { background: #f3ecdf; }

.cell:disabled {
  opacity: 1;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}

.cell:not(:disabled) { cursor: pointer; }

.cell.hot {
  background: #e5f6fc;
  box-shadow: inset 0 0 0 3px var(--ocean);
  animation: glow 1.1s ease-in-out infinite;
}

@keyframes glow {
  50% { background: #b7e4f5; }
}

.cell.dabbed {
  color: #fff;
  -webkit-text-fill-color: #fff;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.55), transparent 26%),
    radial-gradient(circle closest-side at 50% 52%, var(--dab, var(--stamp)) 0 70%, transparent 71%),
    var(--paper);
}

.cell.lined { box-shadow: inset 0 -3px 0 var(--ocean-deep); }

.readout {
  margin: 0.15rem 0 0.2rem;
  color: var(--foam);
}

.readout p { margin: 0.15rem 0; }

.board-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.85rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0.45rem 0.3rem;
  margin-top: 0;
}

.board span {
  text-align: center;
  font-size: 0.95rem;
  padding: 0.5rem 0;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c5d6df;
  font-variant-numeric: tabular-nums;
}

.board span.on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  font-weight: 700;
}

.board span.now {
  background: var(--ocean);
  color: #fff;
  border-color: var(--ocean);
  font-weight: 700;
}

.player-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.65rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.player-row .swatch { align-self: center; }

.player-tools {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

input[type="text"] {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
}

input::placeholder { color: rgba(244, 239, 228, 0.45); }

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.2rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #c5d6df;
}

.stepper button {
  width: 2.3rem;
  height: 2.3rem;
  border: 0;
  border-radius: 50%;
  background: #e5f6fc;
  color: var(--ink);
}

.stepper span { min-width: 4.4rem; text-align: center; font-size: 0.92rem; }

.choice-label {
  margin: 1rem 0 0.45rem;
  font-size: 1.15rem;
}

.seg { display: grid; gap: 0.45rem; }

.seg .chip { text-align: left; }

#prize-note { min-height: 2.6em; }

.stack-gap { display: grid; gap: 0.8rem; margin-top: 0.8rem; }

.rules {
  margin-top: 1.6rem;
  text-align: left;
  color: var(--muted);
  max-width: 32rem;
}

.rules summary { cursor: pointer; color: var(--ink); }

.rules ol { padding-left: 1.2rem; }

.rules li { margin: 0.6rem 0; }

.modal, .celebrate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 20, 18, 0.76);
}

.celebrate { z-index: 35; overflow: hidden; }

.modal-card, .celebrate-card {
  width: min(26rem, 100%);
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 1.25rem 1.2rem 1.1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.modal-card h2, .celebrate-card h2 {
  margin: 0.2rem 0;
  font-size: 2rem;
  line-height: 1;
}

.modal-card p, .celebrate-card p { line-height: 1.4; }

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions .btn { width: auto; flex: 1; }

.modal-actions .chip {
  color: var(--ink);
  border-color: rgba(27, 36, 33, 0.28);
}

.stamp {
  display: inline-block;
  margin: 0 0 0.35rem;
  padding: 0.12em 0.4em;
  border: 4px solid var(--stamp);
  color: var(--stamp);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  transform: rotate(-6deg);
}

.bit {
  position: absolute;
  top: 0;
  width: 8px;
  height: 14px;
  animation: fall 1.35s ease-in forwards;
}

@keyframes fall {
  to { transform: translateY(75vh) rotate(200deg); opacity: 0; }
}

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(28rem, calc(100% - 2rem));
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: var(--foam);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

@media (max-width: 899px) {
  .machine {
    position: sticky;
    top: 0;
    z-index: 4;
    padding-bottom: 1.1rem;
    background: linear-gradient(180deg, var(--sea) 0%, var(--sea) 82%, rgba(243, 249, 251, 0));
  }
}

@media (min-width: 900px) {
  .table-grid {
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 1.4rem;
    align-items: start;
  }

  .machine {
    position: sticky;
    top: 1rem;
  }

  .live-row {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .ball { width: 10.5rem; height: 10.5rem; }
  .ball strong { font-size: 4rem; }
  .trail { justify-content: center; }
  .cell { min-height: 3.4rem; font-size: 1.35rem; }
}

.btn.ghost {
  background: #fff;
  color: var(--ink);
  box-shadow: none;
  border: 2px solid var(--ink);
}

.print-intro {
  width: min(40rem, 100%);
  margin: 0 auto 1.25rem;
  display: grid;
  justify-items: start;
  gap: 1rem;
}

.print-intro h1,
.print-intro .lede,
.print-intro .btn { margin: 0; }

.sheet-wrap {
  width: min(210mm, 100%);
  margin: 0 auto 1.25rem;
}

.sheet {
  aspect-ratio: 210 / 297;
  background: #fff;
  color: #000;
  padding: 8mm;
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 6mm;
}

.sheet-spacer { display: none; }

.paper-ticket {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #000;
  background: #fff;
  color: #000;
}

.paper-name {
  flex: 0 0 auto;
  margin: 0;
  padding: 2mm 3mm 1.5mm;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11pt;
  line-height: 1.2;
  color: #000;
}

.paper-name span {
  display: inline-block;
  width: 42mm;
  border-bottom: 1px solid #000;
  transform: translateY(-1px);
}

.paper-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  border-top: 1px solid #000;
}

.paper-grid span {
  display: grid;
  place-items: center;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  color: #000;
  background: #fff;
}

.paper-grid span:nth-child(9n) { border-right: 0; }
.paper-grid span:nth-last-child(-n + 9) { border-bottom: 0; }

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html, body, #app, .wrap, #sheets, .sheet-wrap {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    height: auto !important;
    box-shadow: none !important;
  }

  .wrap > *:not(#sheets),
  .no-print,
  #modal,
  #toast { display: none !important; }

  .sheet-wrap { width: auto; margin: 0; }

  .sheet {
    box-sizing: border-box;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    width: 210mm;
    height: auto;
    margin: 0;
    padding: 0 8mm 6mm;
    gap: 4mm;
    background: #fff;
    box-shadow: none;
    overflow: visible;
    break-after: page;
    page-break-after: always;
  }

  .sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .sheet-spacer {
    display: block;
    flex: none;
    height: 20mm;
  }

  .paper-ticket {
    flex: none;
    height: 60mm;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .paper-grid span { font-size: 16pt; }
}

@media (prefers-reduced-motion: reduce) {
  .ball.pop, .cell.hot, .bit { animation: none; }
  .cell.hot { background: #e5f6fc; }
}
