:root {
  --ink: #17201d;
  --paper: #fff8e8;
  --sun: #ffd447;
  --tomato: #ef553f;
  --leaf: #2f7d5c;
  --sky: #b9e7ef;
  --plum: #663c67;
  --shadow: rgba(23, 32, 29, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: transparent;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  background: transparent;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.game-embed {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 0;
}

.game-card {
  position: relative;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 20px 14px 24px 16px;
  background: var(--paper);
}

.game-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 52px;
  padding: 3px 8px 10px;
}

.hud-label {
  display: block;
  margin-bottom: 1px;
  color: rgba(23, 32, 29, 0.52);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.15em;
}

.game-hud strong {
  font-family: "Cooper Black", Georgia, serif;
  font-size: 1rem;
}

.hud-score {
  text-align: right;
}

.round-pips {
  display: flex;
  gap: 7px;
}

.round-pips span {
  width: 11px;
  height: 11px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  transition: background-color 180ms ease, transform 180ms ease;
}

.round-pips span.is-done {
  background: var(--tomato);
  transform: scale(1.14);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 18px 12px 22px 14px;
  background: var(--sky);
  isolation: isolate;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  cursor: crosshair;
  touch-action: manipulation;
}

#game-canvas:focus-visible {
  outline: 5px solid var(--sun);
  outline-offset: -6px;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(18px, 6vw, 40px);
  background: rgba(255, 248, 232, 0.24);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 10;
}

.game-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  position: relative;
  width: min(100%, 390px);
  padding: clamp(25px, 7vw, 42px) clamp(20px, 6vw, 36px) 24px;
  border: 3px solid var(--ink);
  border-radius: 18px 13px 22px 14px;
  text-align: center;
  background: var(--paper);
  box-shadow: 7px 8px 0 var(--ink);
  transform: translateY(12px) rotate(-0.6deg);
  transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.is-visible .overlay-card {
  transform: translateY(0) rotate(-0.6deg);
}

.sticker {
  position: absolute;
  top: -30px;
  left: 50%;
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50% 46% 50% 44%;
  background: var(--sun);
  box-shadow: 3px 4px 0 var(--ink);
  font-size: 1.8rem;
  transform: translateX(-50%) rotate(-8deg);
}

.overlay-kicker {
  margin: 0 0 9px;
  color: var(--tomato);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.overlay-card h2 {
  margin: 0;
  font-family: "Cooper Black", "Bookman Old Style", Georgia, serif;
  font-size: clamp(1.7rem, 7vw, 2.55rem);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.overlay-card p:not(.overlay-kicker) {
  margin: 15px auto 20px;
  color: rgba(23, 32, 29, 0.72);
  font-family: Georgia, serif;
  font-size: clamp(0.83rem, 2.6vw, 0.96rem);
  line-height: 1.5;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 0 22px;
  color: white;
  background: var(--tomato);
  box-shadow: 4px 5px 0 var(--ink);
}

.primary-button span:last-child {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--sun);
}

.secondary-button {
  margin-top: 12px;
  color: var(--ink);
  background: transparent;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: #dd412e;
  transform: translate(-1px, -1px);
  box-shadow: 6px 7px 0 var(--ink);
}

.primary-button:active {
  transform: translate(3px, 4px);
  box-shadow: 1px 1px 0 var(--ink);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  background: var(--sun);
}

/* Compact final result; intro and per-round feedback keep their original card. */
.game-overlay.is-final {
  overflow: hidden;
  padding: 6%;
  background: rgba(13, 20, 30, .8);
  backdrop-filter: blur(4px);
}

.game-overlay.is-final::before,
.game-overlay.is-final::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 135%;
  aspect-ratio: 1;
  content: "";
  pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.08) 0deg 7deg, transparent 7deg 18deg);
  transform: translate(-50%, -50%);
  animation: final-rays 20s linear infinite;
}

.game-overlay.is-final::after {
  width: 78%;
  border: 3px dashed rgba(255,255,255,.2);
  border-radius: 50%;
  background: none;
  animation-direction: reverse;
  animation-duration: 13s;
}

.game-overlay.is-final.is-loss::before {
  background: repeating-conic-gradient(from 0deg, rgba(239,85,63,.17) 0deg 7deg, transparent 7deg 18deg);
}

.overlay-card.is-final {
  width: min(88%, 350px);
  padding: clamp(51px, 12vw, 64px) clamp(20px, 5vw, 27px) clamp(20px, 5vw, 26px);
  border: 4px solid var(--ink);
  border-radius: 25px;
  background: linear-gradient(160deg, #fff173 0 18%, #ffd52d 19% 100%);
  box-shadow: 8px 10px 0 var(--ink), 0 20px 60px rgba(0,0,0,.42);
  transform: rotate(-1deg) scale(.86);
  z-index: 3;
}

.is-visible .overlay-card.is-final {
  animation: final-card-in 520ms cubic-bezier(.18,.9,.23,1.35) forwards;
}

.overlay-card.is-final::before {
  position: absolute;
  inset: 9px;
  border: 2px dashed rgba(23,32,29,.25);
  border-radius: 17px;
  content: "";
  pointer-events: none;
}

.overlay-card.is-final.is-loss {
  width: min(74%, 285px);
  padding: 43px 17px 18px;
  background: linear-gradient(#fff, #edf2f8);
  box-shadow: 7px 8px 0 var(--ink), 0 18px 55px rgba(0,0,0,.42);
}

.overlay-card.is-final.is-loss::before {
  border-color: rgba(23,32,29,.18);
  border-style: solid;
}

.overlay-card.is-final .sticker {
  top: -35px;
  width: clamp(64px, 17vw, 78px);
  height: clamp(64px, 17vw, 78px);
  border-radius: 50% 44% 51% 46%;
  color: white;
  background: var(--leaf);
  box-shadow: 4px 5px 0 var(--ink);
  font-family: "Trebuchet MS", sans-serif;
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  transform: translateX(-50%) rotate(7deg);
  z-index: 4;
}

.overlay-card.is-final.is-loss .sticker {
  top: -29px;
  width: 60px;
  height: 60px;
  background: var(--tomato);
  font-size: 2rem;
}

.overlay-card.is-final .overlay-kicker,
.overlay-card.is-final > p:not(.overlay-kicker) {
  display: none;
}

.overlay-card.is-final h2 {
  position: relative;
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(3rem, 12vw, 4.35rem);
  line-height: .88;
  letter-spacing: .015em;
  text-shadow: 3px 3px 0 rgba(255,255,255,.68);
  z-index: 2;
}

.overlay-card.is-final.is-loss h2 {
  color: #34435d;
  font-size: clamp(2.15rem, 9vw, 3rem);
  text-shadow: none;
}

.final-score {
  display: block;
  margin: 15px 0 18px;
  font-family: "Cooper Black", "Bookman Old Style", Georgia, serif;
  font-size: clamp(2rem, 9vw, 3.15rem);
  line-height: 1;
  letter-spacing: -.04em;
}

.is-loss .final-score {
  margin: 10px 0 13px;
  color: var(--tomato);
  font-size: clamp(1.55rem, 7vw, 2.2rem);
}

.overlay-card.is-final .primary-button {
  position: relative;
  min-height: 50px;
  color: white;
  background: var(--leaf);
  letter-spacing: .07em;
  z-index: 2;
}

.overlay-card.is-final.is-loss .primary-button {
  min-height: 46px;
  padding-left: 18px;
  background: var(--tomato);
  box-shadow: 3px 4px 0 var(--ink);
  font-size: .78rem;
}

.overlay-card.is-final.is-loss .primary-button span:last-child {
  width: 27px;
  height: 27px;
}

.result-confetti {
  display: none;
}

.game-overlay.is-final .result-confetti {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
  z-index: 2;
}

.game-overlay.is-final.is-loss .result-confetti {
  display: none;
}

.result-confetti i {
  position: absolute;
  top: -12%;
  left: calc(var(--x, 50) * 1%);
  width: 9px;
  height: 20px;
  border: 2px solid var(--ink);
  background: var(--confetti, #ffd447);
  opacity: 0;
  transform: rotate(var(--r, 15deg));
}

.is-visible .result-confetti i { animation: final-confetti-fall 1.9s ease-out forwards; }
.result-confetti i:nth-child(1) { --x: 7; --r: 20deg; --confetti: #ef553f; animation-delay: .05s; }
.result-confetti i:nth-child(2) { --x: 15; --r: -40deg; --confetti: #2f7d5c; animation-delay: .28s; }
.result-confetti i:nth-child(3) { --x: 24; --r: 70deg; --confetti: #ffd447; animation-delay: .12s; }
.result-confetti i:nth-child(4) { --x: 34; --r: -15deg; --confetti: #fff; animation-delay: .4s; }
.result-confetti i:nth-child(5) { --x: 43; --r: 33deg; --confetti: #ef553f; animation-delay: .2s; }
.result-confetti i:nth-child(6) { --x: 52; --r: -62deg; --confetti: #2f7d5c; animation-delay: .5s; }
.result-confetti i:nth-child(7) { --x: 61; --r: 10deg; --confetti: #ffd447; animation-delay: .08s; }
.result-confetti i:nth-child(8) { --x: 69; --r: 48deg; --confetti: #fff; animation-delay: .35s; }
.result-confetti i:nth-child(9) { --x: 76; --r: -28deg; --confetti: #ef553f; animation-delay: .18s; }
.result-confetti i:nth-child(10) { --x: 83; --r: 66deg; --confetti: #2f7d5c; animation-delay: .45s; }
.result-confetti i:nth-child(11) { --x: 90; --r: -12deg; --confetti: #ffd447; animation-delay: .1s; }
.result-confetti i:nth-child(12) { --x: 96; --r: 37deg; --confetti: #fff; animation-delay: .31s; }

.is-hidden {
  display: none !important;
}

@keyframes final-card-in {
  0% { opacity: 0; transform: translateY(35px) rotate(-4deg) scale(.72); }
  70% { opacity: 1; transform: translateY(-5px) rotate(1deg) scale(1.03); }
  100% { opacity: 1; transform: translateY(0) rotate(-1deg) scale(1); }
}

@keyframes final-rays {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes final-confetti-fall {
  0% { opacity: 0; transform: translateY(-10px) rotate(var(--r)); }
  12% { opacity: 1; }
  100% { opacity: .9; transform: translateY(700px) rotate(calc(var(--r) + 480deg)); }
}

.tap-hint {
  position: absolute;
  bottom: 7.5%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: var(--sun);
  box-shadow: 3px 4px 0 var(--ink);
  font-size: clamp(0.6rem, 2.5vw, 0.72rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 4;
}

.tap-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tap-icon {
  width: 13px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 8px 8px 6px 6px;
  animation: tap-bob 1.2s ease-in-out infinite;
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes tap-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

@media (max-width: 520px) {
  .game-card {
    padding: 6px;
    border-radius: 14px 10px 17px 12px;
  }

  .game-hud {
    min-height: 45px;
    padding: 1px 7px 7px;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Iframe sizing: fit both the available width and height without clipping. */
html,
body {
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

body {
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  background: var(--paper);
}

.ambient-scene-copy {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  z-index: 0 !important;
  margin: 0 !important;
  border-color: transparent !important;
  box-shadow: none !important;
  filter: blur(12px) saturate(.88) brightness(.94);
  opacity: .38;
  pointer-events: none !important;
  transform-origin: center;
  user-select: none;
}

.ambient-scene-copy--left { left: 12% !important; transform: translate(-50%, -50%) scale(1.12) rotate(-3deg); }
.ambient-scene-copy--right { left: 88% !important; transform: translate(-50%, -50%) scale(1.12) rotate(3deg); }

.ambient-scene-copy *,
.ambient-scene-copy *::before,
.ambient-scene-copy *::after { animation-play-state: paused !important; }

@media (max-width: 700px) {
  .ambient-scene-copy--left { left: 50% !important; transform: translate(-50%, -50%) scale(1.9); }
  .ambient-scene-copy--right { display: none !important; }
}

.game-embed {
  position: relative;
  z-index: 1;
  width: min(100vw, 620px, calc((100vh - 72px) * .8));
  margin: 0;
}

@supports (height: 100dvh) {
  .game-embed {
    width: min(100vw, 620px, calc((100dvh - 72px) * .8));
  }
}

@media (max-height: 560px) {
  .game-card { padding: 6px; border-radius: 12px; }
  .game-hud { min-height: 44px; padding-bottom: 6px; }
}

@media (max-height: 560px) and (min-width: 560px) {
  .game-overlay { padding: 10px; }

  .overlay-card:not(.is-final) {
    width: min(100%, 238px);
    padding: 20px 12px 12px;
    border-width: 2px;
    border-radius: 12px;
    box-shadow: 4px 5px 0 var(--ink);
  }

  .overlay-card:not(.is-final) .sticker {
    top: -19px;
    width: 40px;
    height: 40px;
    border-width: 2px;
    font-size: 1.05rem;
  }

  .overlay-card:not(.is-final) .overlay-kicker {
    margin-bottom: 4px;
    font-size: .47rem;
  }

  .overlay-card:not(.is-final) h2 {
    font-size: 1.22rem;
    line-height: 1;
  }

  .overlay-card:not(.is-final) > p:not(.overlay-kicker) { display: none; }

  .overlay-card:not(.is-final) .primary-button {
    min-height: 36px;
    margin-top: 10px;
    padding: 0 8px 0 13px;
    font-size: .68rem;
    box-shadow: 3px 3px 0 var(--ink);
  }

  .overlay-card:not(.is-final) .primary-button span:last-child {
    width: 22px;
    height: 22px;
  }

  .overlay-card.is-final {
    width: min(88%, 220px);
    padding: 35px 12px 12px;
    border-width: 3px;
    box-shadow: 5px 6px 0 var(--ink);
  }

  .overlay-card.is-final .sticker {
    top: -24px;
    width: 48px;
    height: 48px;
    font-size: 1.45rem;
  }

  .overlay-card.is-final h2 { font-size: 2rem; }
  .overlay-card.is-final.is-loss h2 { font-size: 1.7rem; }
  .final-score { margin: 8px 0 10px; font-size: 1.6rem; }
  .overlay-card.is-final .primary-button { min-height: 36px; font-size: .68rem; }
}
