:root {
  --cream: #efe4d0;
  --paper: #f4ecd9;
  --paper-2: #eadfc9;
  --ink: #2b2722;
  --ink-soft: #4b443a;
  --avocado: #7c8b54;
  --gold: #d8a83e;
  --teal: #4e7a75;
  --tomato: #c4453a;
  --rose: #c9a6a0;
  --oat: #b8b0a0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --edge: rgba(43, 39, 34, 0.9);
  --soft-shadow: 4px 5px 0 rgba(43, 39, 34, 0.2);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Archivo', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
button:focus-visible, a:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--cream);
}

#stage canvas {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  transform-origin: 50% 64%;
  will-change: transform;
}

/* One printed sheet over the whole scene. */
.print-grain {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.16;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(43, 39, 34, 0.34) 0.42px, rgba(43, 39, 34, 0) 0.8px),
    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='0.72' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.38'/%3E%3C/svg%3E");
  background-size: 2.4px 2.2px, 220px 220px;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 48%, rgba(43, 39, 34, 0) 46%, rgba(43, 39, 34, 0.26) 100%),
    linear-gradient(to bottom, rgba(43, 39, 34, 0.14), rgba(43, 39, 34, 0) 13%, rgba(43, 39, 34, 0) 84%, rgba(43, 39, 34, 0.22));
}

.hidden { display: none !important; }

/* ---------------- Start, pause and end screens ------------------ */

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(var(--safe-top) + 10px) 12px calc(var(--safe-bottom) + 12px);
  overflow-y: auto;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 50% 6%, rgba(255, 250, 236, 0.72), rgba(250, 240, 220, 0) 46%),
    radial-gradient(ellipse at 50% 42%, rgba(239, 228, 208, 0.78), rgba(239, 228, 208, 0.42) 62%, rgba(231, 218, 194, 0.66)),
    repeating-linear-gradient(0deg, rgba(43, 39, 34, 0.028) 0 1px, rgba(43, 39, 34, 0) 1px 3px),
    repeating-linear-gradient(90deg, rgba(43, 39, 34, 0.022) 0 1px, rgba(43, 39, 34, 0) 1px 3px),
    linear-gradient(#efe4d0, #e9dcc2);
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }

.menu-inner {
  width: min(100%, 470px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  margin: auto 0;
  padding-bottom: 4px;
}

.logo-wrap {
  width: min(84vw, 500px);
  transform: rotate(-1.4deg);
  filter: drop-shadow(5px 7px 0 rgba(43, 39, 34, 0.16)) drop-shadow(0 16px 22px rgba(43, 39, 34, 0.12));
  margin-bottom: 1px;
}

.logo {
  position: relative;
  width: 100%;
  padding: clamp(7px, 2vw, 12px) clamp(6px, 2vw, 12px) 0;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 24% 26%, rgba(43, 39, 34, 0.07) 0 1px, transparent 1.3px),
    radial-gradient(circle at 68% 74%, rgba(43, 39, 34, 0.05) 0 1px, transparent 1.3px),
    linear-gradient(110deg, rgba(255, 255, 255, 0.26), rgba(43, 39, 34, 0.03));
  background-size: 12px 15px, 17px 13px, 100% 100%;
  border: 3px solid var(--ink);
  border-radius: 2px 4px 3px 5px;
  box-shadow: 5px 6px 0 rgba(43, 39, 34, 0.2);
  overflow: hidden;
  container-type: inline-size;
}
.logo::before {
  content: "";
  position: absolute;
  left: -8%;
  top: -40%;
  width: 40%;
  height: 90%;
  background: linear-gradient(to bottom, rgba(43, 39, 34, 0.04), rgba(43, 39, 34, 0));
  transform: rotate(18deg);
  pointer-events: none;
}
.logo-slash {
  position: absolute;
  right: 9%;
  top: 7%;
  width: 19%;
  height: clamp(3px, 0.9cqw, 7px);
  background: var(--tomato);
  transform: rotate(34deg);
  opacity: 0.92;
}

.logo-top {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: baseline;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(26px, 8.2vw, 58px);
  font-size: 10.2cqw;
  line-height: 0.96;
  letter-spacing: -0.012em;
  color: var(--ink);
  white-space: nowrap;
}
.logo-top span,
.logo-bottom span {
  display: inline-block;
  transform: translateY(var(--y, 0)) rotate(var(--r, 0deg));
}
.logo-top span {
  text-shadow:
    0.055em 0.07em 0 var(--tomato),
    0.11em 0.14em 0 rgba(43, 39, 34, 0.2);
}
.logo-band {
  position: relative;
  z-index: 1;
  margin: clamp(4px, 1.2cqw, 7px) calc(-1 * clamp(6px, 2vw, 12px)) 0;
  padding: clamp(1px, 0.6cqw, 4px) 0 clamp(4px, 1.6cqw, 10px);
  background: var(--tomato);
  border-top: 2.5px solid var(--ink);
}
.logo-bottom {
  display: flex;
  justify-content: center;
  align-items: baseline;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(38px, 12.5vw, 88px);
  font-size: 15.8cqw;
  line-height: 0.9;
  letter-spacing: 0.01em;
  color: var(--ink);
  white-space: nowrap;
}
.logo-bottom span {
  text-shadow:
    0.05em 0.065em 0 var(--paper),
    0.1em 0.13em 0 rgba(43, 39, 34, 0.24);
}

@supports not (font-size: 1cqw) {
  .logo-top { font-size: 8.2vw; }
  .logo-bottom { font-size: 12.5vw; }
}

.tagline {
  margin: 0;
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: clamp(9px, 2.7vw, 12px);
  letter-spacing: 0.18em;
  text-align: center;
  color: var(--ink);
}

.dot { color: var(--tomato); font-weight: 900; }

.big-btn {
  position: relative;
  display: block;
  width: min(78vw, 330px);
  padding: 12px 20px 13px;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(18px, 4.9vw, 25px);
  line-height: 1;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--paper);
  background-color: var(--tomato);
  background-image:
    radial-gradient(ellipse at 34% 16%, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 58%),
    repeating-linear-gradient(118deg, rgba(255, 255, 255, 0.06) 0 2px, rgba(255, 255, 255, 0) 2px 5px),
    linear-gradient(180deg, #d0544a, #ba382f);
  border: 3px solid var(--ink);
  border-radius: 4px 6px 4px 7px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.24),
    inset 0 -4px 0 rgba(43, 39, 34, 0.16),
    4px 5px 0 rgba(43, 39, 34, 0.92);
  text-shadow: 0 1.5px 0 rgba(43, 39, 34, 0.35);
  transform: rotate(-0.5deg);
  transition: transform 90ms ease, box-shadow 90ms ease, filter 120ms ease;
  pointer-events: auto;
}

.big-btn:hover { filter: brightness(1.05); }
.big-btn:active, .big-btn.pressed {
  transform: translate(2px, 3px) rotate(-0.5deg);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.18),
    inset 0 -3px 0 rgba(43, 39, 34, 0.2),
    1px 1px 0 rgba(43, 39, 34, 0.92);
}

.paper {
  position: relative;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(43, 39, 34, 0.05) 0 1px, transparent 1.2px),
    radial-gradient(circle at 70% 80%, rgba(43, 39, 34, 0.04) 0 1px, transparent 1.2px),
    linear-gradient(105deg, rgba(255, 255, 255, 0.28), rgba(43, 39, 34, 0.03));
  background-size: 13px 17px, 19px 15px, 100% 100%;
  border: 2.5px solid var(--ink);
  border-radius: 4px 7px 3px 8px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -1px 0 rgba(43, 39, 34, 0.08),
    4px 5px 0 rgba(43, 39, 34, 0.22);
}

.how-to, .howto {
  width: min(100%, 430px);
  padding: 7px 11px 8px 13px;
  font-size: clamp(9.5px, 2.6vw, 11.5px);
  line-height: 1.5;
  letter-spacing: 0.01em;
  transform: rotate(0.25deg);
  box-shadow:
    inset 3.5px 0 0 rgba(196, 69, 58, 0.82),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    4px 5px 0 rgba(43, 39, 34, 0.2);
}
.howto > div + div {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px dashed rgba(43, 39, 34, 0.22);
}
.howto b {
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 0.88em;
  color: var(--tomato);
  margin-right: 5px;
}

.board {
  width: min(100%, 420px);
  padding: 0 0 2px;
  overflow: hidden;
}
.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--tomato);
  background-image:
    repeating-linear-gradient(100deg, rgba(255, 255, 255, 0.055) 0 2px, rgba(255, 255, 255, 0) 2px 5px),
    linear-gradient(180deg, #cd5147, #b93a30);
  color: #f7efdf;
  padding: 5px 9px 6px;
  font-family: 'Alfa Assault', 'Alfa Slab', serif;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(11px, 3.2vw, 14px);
  letter-spacing: 0.14em;
  border-bottom: 2px solid var(--ink);
}
.board-head .over-kicker,
.board-head span { line-height: 1; }
.board-head .board-kicker {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.18em;
  opacity: 0.9;
}
.board-cols {
  display: grid;
  grid-template-columns: 2.9em 1fr auto;
  gap: 10px;
  padding: 3px 10px 2px;
  font-family: 'DM Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: rgba(43, 39, 34, 0.65);
  border-bottom: 1px solid rgba(43, 39, 34, 0.22);
}
.board-rows { padding: 2px 0 2px; }
.row {
  display: grid;
  grid-template-columns: 2.9em minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  padding: 3px 10px;
  font-size: 13px;
  line-height: 1.28;
  border-bottom: 1px solid rgba(43, 195, 190, 0);
}
.row + .row { border-top: 1px dashed rgba(43, 39, 34, 0.16); }
.row .rank {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: rgba(43, 39, 34, 0.55);
}
.row:first-child .rank { color: var(--tomato); }
.row .who {
  font-family: 'Archivo', sans-serif;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.row .who:hover { border-bottom-color: var(--tomato); }
.row .pts {
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.row.mine {
  background: rgba(216, 168, 62, 0.22);
  box-shadow: inset 3px 0 0 var(--tomato);
}
.row.mine .who { font-weight: 800; }
.board-empty {
  padding: 9px 12px 10px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(43, 39, 34, 0.62);
  text-align: center;
}
.board-wrap { width: 100%; display: flex; justify-content: center; }

/* ---------------- HUD ------------------ */

#hud {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

#hudTop {
  position: absolute;
  top: calc(var(--safe-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 14px);
  max-width: 780px;
  display: flex;
  gap: 7px;
  align-items: stretch;
}

.receipt-tab {
  position: relative;
  width: clamp(62px, 21vw, 92px);
  flex: none;
  transform: rotate(-4deg);
  transform-origin: 50% 0%;
  filter: drop-shadow(2px 3px 0 rgba(43, 39, 34, 0.22));
}
.receipt-tab img { display: block; width: 100%; height: auto; }
.lvl-patch {
  position: absolute;
  left: 21%;
  top: 11%;
  width: 46%;
  height: 21%;
  display: grid;
  place-items: center;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(20px, 6.4vw, 32px);
  line-height: 1;
  color: var(--ink);
  background:
    radial-gradient(circle at 34% 22%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 62%),
    #f1e6d2;
  border: 1.6px solid rgba(43, 39, 34, 0.6);
  border-radius: 2px 4px 3px 3px;
  box-shadow: 1.5px 2px 0 rgba(43, 39, 34, 0.22);
  text-shadow: 1px 1.5px 0 rgba(43, 39, 34, 0.22);
  transform: rotate(-1.2deg);
}

.ticket {
  position: relative;
  flex: 1;
  min-width: 0;
  max-height: 112px;
  padding: 5px 9px 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 25% 30%, rgba(43, 39, 34, 0.06) 0 1px, transparent 1.2px),
    linear-gradient(102deg, rgba(255, 255, 255, 0.3), rgba(43, 39, 34, 0.03));
  background-size: 11px 13px, 100% 100%;
  border: 2.5px solid var(--ink);
  border-radius: 3px 6px 4px 7px;
  box-shadow: 3px 4px 0 rgba(43, 39, 34, 0.24);
  transform: rotate(0.5deg);
}
.ticket::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -5px;
  height: 7px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-top: 0;
  clip-path: polygon(0 0, 100% 0, 96% 100%, 90% 28%, 84% 100%, 77% 24%, 70% 100%, 62% 26%, 55% 100%, 47% 25%, 40% 100%, 32% 27%, 25% 100%, 17% 24%, 10% 100%, 4% 30%);
  opacity: 0.95;
}
.ticket-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ticket-row.head { align-items: flex-end; }
.mark {
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: 7.5px;
  letter-spacing: 0.12em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-soft);
  padding-bottom: 2px;
}
.score {
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  font-size: clamp(15px, 4.8vw, 21px);
  letter-spacing: 0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  flex: none;
  border-bottom: 1.5px solid rgba(196, 69, 58, 0.45);
  padding: 0 1px 1px;
}
.score.bump { animation: scorebump 220ms ease-out; }
@keyframes scorebump {
  0% { transform: translateY(0); }
  40% { transform: translateY(-3px); color: var(--tomato); }
  100% { transform: translateY(0); }
}
.ticket-line {
  border-top: 1.5px dashed rgba(43, 39, 34, 0.38);
  margin: 4px 0 3px;
}
.goal-label {
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.mono { font-family: 'DM Mono', monospace; font-size: 10px; }
.ticket-row .mono { font-variant-numeric: tabular-nums; }
.goal-remaining { font-size: 10px; letter-spacing: 0.02em; color: var(--ink); }
.ticket-row .goal-num { font-size: 15px; font-weight: 500; line-height: 1; color: var(--ink); }
.ticket-row .goal-num.zero { color: #c4453a; }

.pips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 12px;
  margin: 3px 0 2px;
}
.pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.2px solid rgba(43, 39, 34, 0.7);
  background: rgba(43, 39, 34, 0.04);
  flex: none;
}
.pip.on {
  border-color: var(--ink);
  background-color: var(--ink);
  background-image:
    radial-gradient(circle at 32% 30%, rgba(244, 236, 217, 0.75) 0 18%, transparent 22%),
    radial-gradient(circle, rgba(43, 39, 34, 0.9) 0.9px, transparent 1.1px);
  background-size: 100% 100%, 2.2px 2.2px;
  box-shadow: 0.6px 0.8px 0 rgba(196, 69, 58, 0.55);
}
.ticket-row.foot {
  font-family: 'Archivo', sans-serif;
  font-weight: 700;
  font-size: 7.5px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  align-items: center;
}
.ticket-row.foot .mono { font-size: 10px; color: var(--ink); }
.foot-speed { font-family: 'DM Mono', monospace; font-size: 8px; letter-spacing: 0.02em; color: var(--ink-soft); white-space: nowrap; }
.foot-speed b { font-weight: 500; color: var(--ink); font-size: 9.5px; }

.hud-tools {
  display: flex;
  gap: 3px;
  pointer-events: auto;
  flex: none;
}
.tool-btn {
  width: 30px;
  height: 23px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  background-color: rgba(244, 236, 217, 0.86);
  background-image: radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0) 70%);
  border: 1.6px solid var(--ink);
  border-radius: 3px 4px 3px 4px;
  box-shadow: 1.5px 2px 0 rgba(43, 39, 34, 0.22);
  line-height: 1;
}
.tool-btn svg { width: 13px; height: 13px; display: block; fill: currentColor; }
.tool-btn svg .wave { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.tool-btn svg .slash { display: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.tool-btn:active { transform: translate(1px, 1.5px); box-shadow: 0.5px 0.5px 0 rgba(43, 39, 34, 0.25); }
.tool-btn.off { color: rgba(43, 39, 34, 0.45); }
.tool-btn.off svg .wave { opacity: 0; }
.tool-btn.off svg .slash { display: block; }

#playHint {
  position: absolute;
  top: auto;
  bottom: calc(var(--safe-bottom) + 3px);
  left: 50%;
  transform: translateX(-50%) rotate(-0.4deg);
  padding: 2px 8px 3px;
  font-family: 'Archivo', sans-serif;
  font-weight: 700;
  font-size: clamp(6px, 1.8vw, 7.4px);
  line-height: 1.3;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--ink-soft);
  background-color: rgba(244, 236, 217, 0.92);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(43, 39, 34, 0.02));
  border: 1.2px solid rgba(43, 39, 34, 0.7);
  border-radius: 3px 5px 3px 5px;
  box-shadow: 1.5px 2px 0 rgba(43, 39, 34, 0.16);
  white-space: normal;
  width: max-content;
  max-width: calc(100% - 176px);
}
#playHint .dot { padding: 0 2px; }
#playHint .legend {
  display: block;
  margin-top: 2px;
  letter-spacing: 0.07em;
  color: #8a5a12;
}

.dash-btn {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 12px);
  width: clamp(56px, 16vw, 78px);
  height: clamp(52px, 14.5vw, 72px);
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 32% 18%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 62%),
    repeating-linear-gradient(45deg, rgba(43, 39, 34, 0.035) 0 1px, rgba(43, 39, 34, 0) 1px 4px);
  border: 2.5px solid var(--ink);
  border-radius: 9px 5px 10px 4px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 -5px 0 rgba(196, 69, 58, 0.14),
    3px 4px 0 rgba(43, 39, 34, 0.28);
  pointer-events: auto;
  touch-action: manipulation;
}
.dash-btn.left { left: 10px; transform: rotate(-2.5deg); }
.dash-btn.right { right: 10px; transform: rotate(2deg); }
.dash-btn svg { width: 46%; height: auto; display: block; color: var(--ink); filter: drop-shadow(2px 2px 0 rgba(196, 69, 58, 0.55)); transition: transform 90ms ease; }
.dash-btn.left:hover svg { transform: translateX(-1.5px); }
.dash-btn.right:hover svg { transform: translateX(1.5px); }
.dash-btn:active, .dash-btn.pressed {
  transform: translate(1px, 2px) rotate(-1deg);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    inset 0 -5px 0 rgba(196, 69, 58, 0.2),
    1px 1px 0 rgba(43, 39, 34, 0.3);
  background-color: #eadfc9;
}
.dash-btn.hot {
  background-color: #f0b1a8;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -5px 0 rgba(150, 42, 33, 0.2),
    0 0 0 3px rgba(196, 69, 58, 0.28),
    3px 4px 0 rgba(43, 39, 34, 0.28);
}

.turn-hint {
  position: absolute;
  top: max(calc(var(--safe-top) + 118px), 15%);
  bottom: max(calc(var(--safe-bottom) + 120px), 17%);
  width: clamp(106px, 29vw, 168px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 14px 8px 15px;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 50% 16%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 62%),
    repeating-linear-gradient(45deg, rgba(43, 39, 34, 0.035) 0 1px, rgba(43, 39, 34, 0) 1px 4px);
  border: 3px solid var(--ink);
  border-radius: 5px 10px 6px 9px;
  box-shadow: 5px 7px 0 rgba(43, 39, 34, 0.3);
  pointer-events: auto;
  touch-action: manipulation;
  overflow: hidden;
  z-index: 16;
  transform: rotate(-2deg);
  transition: background-color 120ms ease;
}
.turn-hint.right { right: 10px; }
.turn-hint.left { left: 10px; transform: rotate(2deg); }
.turn-hint::before,
.turn-hint::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(45deg, var(--tomato) 0 7px, #f4ecd9 7px 14px);
  opacity: 0.9;
}
.turn-hint::before { top: 0; }
.turn-hint::after { bottom: 0; }

.turn-hint .turn-word {
  margin-top: 3px;
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: clamp(9px, 2.4vw, 12px);
  line-height: 1.1;
  letter-spacing: 0.13em;
  text-align: center;
  color: var(--ink-soft);
}
.turn-hint .tap-prompt {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 3px;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(26px, 7.6vw, 38px);
  line-height: 0.9;
  letter-spacing: 0.01em;
  color: var(--tomato);
  text-shadow: 2px 2px 0 rgba(43, 39, 34, 0.2);
  animation: tapPulse 620ms ease-in-out infinite;
  transform-origin: 50% 55%;
}
.turn-hint .tap-count {
  font-family: 'Alfa Slab One', serif;
  font-size: 0.5em;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink);
}
.turn-hint .turn-sub {
  font-family: 'DM Mono', monospace;
  font-size: clamp(6.6px, 1.9vw, 8px);
  letter-spacing: 0.08em;
  text-align: center;
  color: rgba(43, 39, 34, 0.66);
}
.turn-hint .turn-arrow {
  flex: 1 1 auto;
  width: 90%;
  min-height: 34px;
  display: grid;
  place-items: center;
  margin: 2px 0;
  color: var(--tomato);
}
.turn-hint .turn-arrow svg {
  width: 100%;
  max-height: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(2px 3px 0 rgba(43, 39, 34, 0.3));
}
.turn-hint.turn-left .turn-arrow svg { transform: scaleX(-1); }
.turn-hint.armed .turn-arrow { color: #3c5d2c; }

.tap-meter {
  flex: 1 1 auto;
  width: clamp(44px, 12vw, 60px);
  min-height: 78px;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  margin: 4px 0 2px;
  padding: 5px;
  background: rgba(248, 241, 226, 0.75);
  border: 2px solid var(--ink);
  border-radius: 5px;
}
.turn-hint .tap-meter i {
  flex: 1 1 0;
  min-height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(43, 39, 34, 0.42);
  border-radius: 3px;
  background-color: rgba(255, 250, 240, 0.9);
  font-style: normal;
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: clamp(15px, 4.6vw, 24px);
  line-height: 1;
  color: rgba(43, 39, 34, 0.4);
  transition: background-color 90ms ease, transform 90ms ease, color 90ms ease;
}
.turn-hint .tap-meter i.on {
  background-color: var(--tomato);
  background-image: radial-gradient(circle, rgba(43, 39, 34, 0.32) 0.8px, transparent 1.1px);
  background-size: 4px 4px;
  border-color: var(--ink);
  color: var(--paper);
  transform: scale(1.04);
}
.turn-hint.long .tap-prompt { font-size: clamp(23px, 6.6vw, 34px); }
.tap-meter.multi {
  display: grid;
  width: clamp(70px, 20vw, 104px);
  gap: 4px;
  padding: 4px;
}
.turn-hint .tap-meter.multi i {
  min-height: 0;
  min-width: 0;
  font-size: clamp(11px, 3.2vw, 16px);
}
.turn-hint .tap-meter.cols3 i { font-size: clamp(9px, 2.6vw, 13px); border-width: 1.5px; }
.turn-hint .tap-read {
  font-family: 'DM Mono', monospace;
  font-size: clamp(8px, 2.4vw, 10px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  white-space: nowrap;
}

.turn-hint.hit { background-color: #f2c4b9; }
.turn-hint.hit .tap-prompt { animation-duration: 180ms; }
.turn-hint.armed {
  background-color: #d8e6c4;
  box-shadow: 5px 7px 0 rgba(43, 39, 34, 0.3), 0 0 0 4px rgba(94, 132, 70, 0.35);
}
.turn-hint.armed .turn-word { color: #3c5d2c; }
.turn-hint.armed .tap-prompt {
  font-size: clamp(21px, 5.8vw, 28px);
  color: #3c5d2c;
  text-shadow: 2px 2px 0 rgba(43, 39, 34, 0.14);
  animation: setPulse 420ms ease-in-out infinite;
}
@keyframes tapPulse {
  0%, 100% { transform: scale(0.9) rotate(-3deg); color: var(--tomato); }
  50% { transform: scale(1.12) rotate(2deg); color: #df5a3c; }
}
@keyframes setPulse {
  0%, 100% { transform: scale(0.94) rotate(-2deg); }
  50% { transform: scale(1.06) rotate(1deg); }
}
.turn-hint.armed .tap-meter i {
  background-color: #5e8446;
  border-color: var(--ink);
}
.turn-hint.armed .tap-meter i.on { background-color: #4b7135; }
.turn-hint.armed .tap-count { display: none; }
.turn-hint.armed .tap-read { color: #3c5d2c; }

.turn-hint.urgent {
  background-color: #f0b4a6;
  border-color: #7e1b12;
  box-shadow: 5px 7px 0 rgba(43, 39, 34, 0.34), 0 0 0 5px rgba(196, 69, 58, 0.62);
}
.turn-hint.urgent .tap-prompt { animation-duration: 240ms; color: #7e1b12; }
.turn-hint.urgent .turn-word { color: #7e1b12; }
.turn-hint.urgent .turn-sub { color: #7e1b12; font-weight: 700; }
.turn-hint.urgent .tap-read { color: #7e1b12; font-weight: 700; }
.turn-hint.missed {
  background-color: #e8a99e;
  box-shadow: 5px 7px 0 rgba(43, 39, 34, 0.34), 0 0 0 5px rgba(140, 36, 27, 0.55);
}
.turn-hint.missed .turn-word { color: #6d1d15; }
.turn-hint.missed .tap-prompt {
  font-size: clamp(17px, 4.6vw, 24px);
  color: #6d1d15;
  animation: none;
  transform: none;
}
.turn-hint.missed .tap-count { display: none; }
.turn-hint.missed .turn-arrow { color: #6d1d15; opacity: 0.5; }
.turn-hint.missed .tap-meter i { border-color: rgba(43, 39, 34, 0.3); }

/* ---------------- End and pause cards ------------------ */

.over-card {
  width: min(92vw, 400px);
  margin: auto 0;
  padding: 16px 15px 14px;
  transform: rotate(0.25deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.over-kicker {
  margin: 0;
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--tomato);
  transform: rotate(-1deg);
}
.over-title {
  margin: -2px 0 0;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(30px, 9.5vw, 46px);
  line-height: 0.96;
  letter-spacing: 0.01em;
  text-align: center;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(196, 69, 58, 0.5);
}
.over-reason {
  margin: 0;
  font-size: clamp(10px, 2.8vw, 12px);
  text-align: center;
  color: var(--ink-soft);
  min-height: 1.2em;
}
.stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  margin: 3px 0 2px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border-top: 1.5px solid rgba(43, 39, 34, 0.4);
  border-bottom: 1.5px solid rgba(43, 39, 34, 0.4);
  padding: 4px 2px 3px;
}
.stat span {
  font-family: 'Archivo', sans-serif;
  font-weight: 800;
  font-size: 7px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.stat b { font-family: 'DM Mono', monospace; font-size: clamp(13px, 4vw, 17px); font-weight: 500; }
.over-card .board { margin-top: 2px; }
.over-card .big-btn { width: min(88%, 310px); margin-top: 2px; }
.link-btn {
  background: none;
  border: 0;
  padding: 1px 6px 2px;
  font-family: 'Archivo', sans-serif;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(43, 39, 34, 0.35);
}

.pause-card {
  width: min(88vw, 340px);
  margin: auto;
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transform: rotate(-0.4deg);
}
.pause-title {
  margin: 0;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(30px, 9vw, 42px);
  line-height: 1;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(196, 69, 58, 0.45);
}
.pause-card p { margin: 0; font-size: 11px; text-align: center; color: var(--ink-soft); }
.pause-card .big-btn { width: min(88%, 280px); }

/* ---------------- Flash and toast ------------------ */

#flash {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  opacity: 0;
  background: var(--cream);
  transition: opacity 90ms linear;
}
#flash.on { opacity: 0.92; }
#flash.turn-flash {
  background:
    repeating-linear-gradient(115deg, rgba(236, 236, 236, 0.96) 0 14px, rgba(210, 210, 210, 0.96) 14px 28px);
}

#crash-stamp {
  position: fixed;
  left: 50%;
  top: 46%;
  z-index: 60;
  transform: translate(-50%, -50%) rotate(-9deg) scale(0.4);
  padding: 6px 18px 10px;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(34px, 13vw, 74px);
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--paper);
  background: var(--tomato);
  border: 4px solid var(--ink);
  border-radius: 6px 10px 5px 9px;
  box-shadow: 7px 9px 0 rgba(43, 39, 34, 0.32);
  opacity: 0;
  pointer-events: none;
}
#crash-stamp.show {
  opacity: 1;
  animation: crashstamp 620ms cubic-bezier(0.15, 0.9, 0.2, 1) forwards;
}
@keyframes crashstamp {
  0% { transform: translate(-50%, -50%) rotate(-13deg) scale(0.3); opacity: 0; }
  34% { transform: translate(-50%, -50%) rotate(-6deg) scale(1.12); opacity: 1; }
  62% { transform: translate(-50%, -50%) rotate(-9deg) scale(0.98); opacity: 1; }
  100% { transform: translate(-50%, -54%) rotate(-9deg) scale(1); opacity: 0; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 92px);
  z-index: 50;
  transform: translateX(-50%) rotate(-1deg) translateY(10px);
  padding: 7px 14px;
  max-width: 86vw;
  font-family: 'Alfa Slab One', serif;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--paper);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-left: 6px solid var(--tomato);
  border-radius: 3px 6px 4px 5px;
  box-shadow: 3px 4px 0 rgba(196, 69, 58, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) rotate(-1deg) translateY(0); }

/* ---------------- Level stamp and receipt tear ------------------ */

.level-stamp {
  position: fixed;
  left: 50%;
  top: 46%;
  z-index: 18;
  width: clamp(150px, 46vw, 228px);
  transform: translate(-50%, -50%) rotate(-8deg) scale(0.2);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(5px 6px 0 rgba(43, 39, 34, 0.22));
}
.level-stamp img { display: block; width: 100%; height: auto; }
.level-stamp span {
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%) rotate(1.5deg);
  padding: 2px 8px 3px;
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(11px, 3.4vw, 15px);
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  white-space: nowrap;
}
.level-stamp.show { animation: stampthunk 1150ms cubic-bezier(0.2, 0.8, 0.25, 1) forwards; }
@keyframes stampthunk {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-20deg) scale(2.25); }
  22% { opacity: 1; transform: translate(-50%, -50%) rotate(-9deg) scale(0.9); }
  33% { transform: translate(-50%, -50%) rotate(-7deg) scale(1.05); }
  44% { transform: translate(-50%, -50%) rotate(-8deg) scale(0.99); }
  76% { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -46%) rotate(-6deg) scale(1.02); }
}

.receipt-tab.tearing { animation: tearaway 420ms cubic-bezier(0.4, 0, 0.9, 0.5) forwards; }
@keyframes tearaway {
  0% { transform: rotate(-4deg) translate(0, 0); opacity: 1; }
  25% { transform: rotate(-8deg) translate(-5px, -10px); }
  100% { transform: rotate(-30deg) translate(-26px, -150px); opacity: 0; }
}
.receipt-tab.feeding { animation: feedin 380ms cubic-bezier(0.2, 0.9, 0.3, 1.1); }
@keyframes feedin {
  0% { transform: rotate(7deg) translateY(-95px); opacity: 0; }
  100% { transform: rotate(-4deg) translateY(0); opacity: 1; }
}
.lvl-patch.pop { animation: lvlpop 240ms ease-out; }
@keyframes lvlpop {
  0% { transform: scale(1); }
  45% { transform: scale(1.45) rotate(-5deg); }
  100% { transform: scale(1); }
}

#flash.red { background: rgba(196, 69, 58, 0.72); }

/* ---------------- Short and wide layouts ------------------ */

@media (max-height: 720px) {
  .menu-inner { gap: 6px; }
  .logo-wrap { width: min(64vw, 380px); }
  .board-row, .row { padding-top: 2px; padding-bottom: 2px; }
  .screen { align-items: center; }
}

@media (min-width: 700px) {
  .menu-inner { width: min(92vw, 760px); display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr); grid-template-rows: auto auto auto 1fr; align-items: center; gap: 12px 26px; }
  .logo-wrap { grid-column: 1; width: 100%; margin: 0; align-self: end; }
  .tagline { grid-column: 1; }
  .big-btn { grid-column: 1; width: min(38vw, 360px); }
  .howto { grid-column: 1; width: 100%; }
  .board-wrap { grid-column: 2; grid-row: 1 / span 4; align-self: center; }
  .board { width: 100%; }
  .over-card { width: min(90vw, 430px); }
}

@media (max-width: 380px) {
  .mark { display: none; }
  #playHint { font-size: 6.6px; letter-spacing: 0.05em; max-width: calc(100% - 174px); }
  .ticket { padding-left: 7px; padding-right: 7px; }
  .tool-btn { width: 27px; height: 21px; }
}

@media (max-height: 640px) {
  .turn-hint {
    top: max(calc(var(--safe-top) + 112px), 14%);
    bottom: calc(var(--safe-bottom) + 80px);
    gap: 3px;
    padding: 12px 8px 13px;
  }
  .turn-hint .turn-sub { display: none; }
  .turn-hint .tap-prompt { font-size: 24px; }
  .turn-hint .turn-arrow { width: 52%; }
  .tap-meter { min-height: 54px; }
  .turn-hint .tap-meter i { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .turn-hint, .turn-hint .tap-prompt, .big-btn, #toast, #flash { animation: none !important; transition: none !important; }
}
