:root {
  --ink: #111111;
  --paper: #fffefa;
  --red: #ed1c24;
  --cream: #f8f2df;
  --line: #d7d4cc;
  --green: #1eaf73;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 300px;
  margin: 0;
  background: transparent;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.game {
  position: relative;
  overflow: hidden;
  width: min(100%, 620px);
  aspect-ratio: 4 / 5;
  min-height: 500px;
  margin: 0 auto;
  border: 2px solid #e8e8e8;
  border-radius: 16px;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.98) 0 34%, rgba(250, 250, 247, 0.9) 66%, rgba(239, 239, 235, 0.94) 100%),
    var(--paper);
  box-shadow: inset 0 0 38px rgba(20, 20, 20, 0.05);
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  isolation: isolate;
  user-select: none;
}

.game::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.12;
  background-image: repeating-linear-gradient(0deg, transparent 0 4px, rgba(0, 0, 0, 0.05) 5px);
  z-index: 0;
}

.hud {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 10.5%;
  padding: 0 4.2%;
  border-bottom: 2px solid var(--ink);
  background: rgba(255, 254, 250, 0.94);
  z-index: 8;
}

.hud-block span {
  display: block;
  margin-bottom: 1px;
  color: #77736c;
  font-size: clamp(0.5rem, 1.6vw, 0.68rem);
  font-weight: 900;
  letter-spacing: 0.15em;
}

.hud-block strong {
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(0.92rem, 3vw, 1.22rem);
  letter-spacing: 0.05em;
}

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

.reset-button {
  min-height: 32px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: white;
  font-size: clamp(0.56rem, 1.8vw, 0.7rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.phase-pill {
  min-width: 105px;
  padding: 7px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: white;
  text-align: center;
  background: var(--ink);
  box-shadow: 3px 3px 0 #c9c9c2;
  font-size: clamp(0.62rem, 2vw, 0.78rem);
  font-weight: 900;
  letter-spacing: 0.13em;
}

.stage {
  position: absolute;
  inset: 10.5% 0 0;
  overflow: hidden;
  touch-action: manipulation;
}

.svg-defs {
  position: absolute;
}

.decor-bottle {
  position: absolute;
  top: 5%;
  width: 34%;
  height: auto;
  filter: drop-shadow(5px 8px 1px rgba(0, 0, 0, 0.2));
  pointer-events: none;
  z-index: 1;
}

.decor-bottle-left {
  left: -8.5%;
  transform: rotate(54deg);
  transform-origin: 50% 35%;
}

.decor-bottle-right {
  right: -8.5%;
  transform: rotate(-54deg) scaleX(-1);
  transform-origin: 50% 35%;
}

.bottle-black {
  fill: #090909;
}

.bottle-outline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 8;
  stroke-linejoin: round;
}

.bottle-shine {
  fill: none;
  stroke: white;
  stroke-linecap: round;
  stroke-width: 9;
  opacity: 0.85;
}

.bottle-label,
.bottle-cap {
  fill: var(--red);
  stroke: var(--ink);
  stroke-width: 6;
}

.bottle-word {
  fill: white;
  font-family: Georgia, serif;
  font-size: 22px;
  font-style: italic;
  font-weight: 900;
}

.center-bottle-wrap {
  position: absolute;
  top: 19%;
  left: 50%;
  width: 31%;
  transform: translateX(-50%);
  z-index: 4;
}

.center-bottle {
  display: block;
  width: 100%;
  overflow: visible;
  filter: drop-shadow(0 8px 3px rgba(0, 0, 0, 0.13));
}

.bottle-paper {
  fill: rgba(255, 255, 255, 0.92);
}

.center-outline,
.center-cap-outline {
  fill: none;
  stroke: #babbb7;
  stroke-width: 7;
  stroke-linejoin: round;
}

.center-cap-outline {
  stroke-width: 5;
}

.paint-layer {
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: layer-in 300ms cubic-bezier(0.2, 0.85, 0.25, 1) both;
}

.paint-black {
  fill: #090909;
}

.paint-red {
  fill: var(--red);
  stroke: var(--ink);
  stroke-width: 5;
}

.paint-white path {
  fill: none;
  stroke: white;
  stroke-linecap: round;
  stroke-width: 10;
}

.paint-white text {
  fill: white;
  font-family: Georgia, serif;
  font-size: 31px;
  font-style: italic;
  font-weight: 900;
}

.step-count {
  position: absolute;
  bottom: -6%;
  left: 50%;
  min-width: 92px;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: white;
  text-align: center;
  background: var(--ink);
  font-size: clamp(0.62rem, 2.2vw, 0.8rem);
  font-weight: 900;
  transform: translateX(-50%);
}

.color-control {
  position: absolute;
  display: flex;
  align-items: center;
  gap: clamp(5px, 1.3vw, 8px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 1;
  transition: opacity 160ms ease, transform 120ms ease, filter 160ms ease;
  z-index: 6;
}

.color-control:hover,
.color-control:focus-visible {
  filter: brightness(1.06);
  outline: none;
}

.color-control:active {
  transform: scale(0.92);
}

.color-control:disabled {
  opacity: 0.25;
  filter: grayscale(0.8);
  cursor: default;
  pointer-events: none;
}

.color-red {
  top: 43%;
  left: 16%;
  color: var(--red);
}

.color-white {
  top: 43%;
  right: 15%;
  flex-direction: row;
  color: #d7d1c3;
}

.color-black {
  bottom: 8.5%;
  left: 50%;
  flex-direction: column-reverse;
  color: #171717;
  transform: translateX(-50%);
}

.color-black:active {
  transform: translateX(-50%) scale(0.92);
}

.seal {
  display: grid;
  width: clamp(31px, 8vw, 45px);
  height: clamp(31px, 8vw, 45px);
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: white;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.18);
  font-family: Georgia, serif;
  font-size: clamp(0.88rem, 3vw, 1.2rem);
  font-style: italic;
  font-weight: 900;
}

.color-bar {
  display: block;
  width: clamp(13px, 3.3vw, 20px);
  height: clamp(67px, 17vw, 98px);
  border: 3px solid var(--ink);
  border-radius: 5px;
  background: currentColor;
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.35), 3px 4px 0 rgba(0, 0, 0, 0.16);
}

.color-white .color-bar {
  background: #fffdf5;
}

.color-black .color-bar {
  width: clamp(70px, 18vw, 104px);
  height: clamp(13px, 3.3vw, 20px);
}

.feedback {
  position: absolute;
  top: 17.5%;
  left: 50%;
  min-width: 170px;
  color: var(--ink);
  text-align: center;
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(1rem, 4.5vw, 1.7rem);
  letter-spacing: 0.06em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) rotate(-2deg);
  z-index: 7;
}

.feedback.is-visible {
  animation: feedback-pop 750ms ease both;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 8%;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 20;
}

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

.overlay-card {
  position: relative;
  width: min(100%, 390px);
  padding: clamp(31px, 8vw, 47px) clamp(22px, 6vw, 36px) clamp(22px, 5vw, 31px);
  border: 3px solid var(--ink);
  border-radius: 12px;
  text-align: center;
  background: var(--paper);
  box-shadow: 8px 9px 0 var(--ink);
}

.mini-bottle {
  position: absolute;
  top: 0;
  left: 50%;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--red);
  box-shadow: 3px 4px 0 var(--ink);
  font-size: 1.7rem;
  transform: translate(-50%, -54%);
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--red);
  font-size: clamp(0.62rem, 1.8vw, 0.72rem);
  font-weight: 900;
  letter-spacing: 0.18em;
}

.overlay h1 {
  margin: 0;
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(2rem, 8.5vw, 3.45rem);
  font-weight: 900;
  line-height: 0.93;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.overlay-card > p:not(.overlay-kicker) {
  margin: 16px auto 21px;
  color: #56534e;
  font-family: Georgia, serif;
  font-size: clamp(0.82rem, 2.7vw, 0.98rem);
  line-height: 1.48;
}

.action-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 52px;
  padding: 0 12px 0 21px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  color: white;
  background: var(--red);
  box-shadow: 4px 5px 0 var(--ink);
  font-weight: 900;
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.action-button b {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: white;
}

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

/* Compact casual-game result state */
.overlay {
  overflow: hidden;
  padding: 6%;
  background: rgba(12, 18, 29, 0.8);
  backdrop-filter: blur(4px);
}

.overlay::before,
.overlay::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: result-rays 20s linear infinite;
}

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

.overlay.is-loss::before {
  background: repeating-conic-gradient(from 0deg, rgba(237,28,36,.16) 0deg 7deg, transparent 7deg 18deg);
}

.overlay-card {
  width: min(88%, 350px);
  padding: clamp(52px, 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;
}

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

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

.overlay-card.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-loss::before {
  border-color: rgba(17,17,17,.18);
  border-style: solid;
}

.result-icon {
  position: absolute;
  top: -35px;
  left: 50%;
  display: grid;
  width: clamp(64px, 17vw, 78px);
  height: clamp(64px, 17vw, 78px);
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50% 44% 51% 46%;
  color: white;
  background: var(--green);
  box-shadow: 4px 5px 0 var(--ink);
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  font-weight: 900;
  transform: translateX(-50%) rotate(7deg);
  z-index: 4;
}

.is-loss .result-icon {
  top: -29px;
  width: 60px;
  height: 60px;
  background: var(--red);
  font-size: 2rem;
}

.overlay h1 {
  position: relative;
  font-size: clamp(3.1rem, 13vw, 4.7rem);
  line-height: .88;
  text-shadow: 3px 3px 0 rgba(255,255,255,.68);
  z-index: 2;
}

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

.result-bottle {
  position: relative;
  width: 74px;
  height: 116px;
  margin: 15px auto 18px;
  filter: drop-shadow(4px 5px 0 var(--ink));
}

.result-cap,
.result-neck,
.result-body {
  position: absolute;
  left: 50%;
  display: block;
  transform: translateX(-50%);
}

.result-cap {
  top: 0;
  width: 31px;
  height: 13px;
  border: 3px solid var(--ink);
  border-radius: 4px 4px 2px 2px;
  background: var(--red);
  z-index: 2;
}

.result-neck {
  top: 11px;
  width: 27px;
  height: 27px;
  border: 3px solid var(--ink);
  border-bottom: 0;
  background: #202020;
}

.result-body {
  top: 28px;
  width: 68px;
  height: 86px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 18px 18px 13px 13px / 26px 26px 13px 13px;
  background: linear-gradient(90deg, #101010, #343434 48%, #090909);
}

.result-body b {
  position: absolute;
  top: 32px;
  right: -6px;
  left: -6px;
  padding: 7px 0;
  color: white;
  background: var(--red);
  font-family: Georgia, serif;
  font-size: .62rem;
  font-style: italic;
  transform: rotate(-7deg);
}

.is-loss .result-bottle {
  display: none;
}

.action-button {
  position: relative;
  min-height: 50px;
  padding-left: 22px;
  background: var(--green);
  letter-spacing: .07em;
  z-index: 2;
}

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

.is-loss .action-button b {
  width: 27px;
  height: 27px;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

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

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

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

.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 layer-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes feedback-pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.7) rotate(-2deg); }
  24%, 70% { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%, -12px) scale(1.05) rotate(-2deg); }
}

@keyframes result-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 result-rays {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes 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)); }
}

@media (max-width: 420px) {
  .game {
    min-height: 460px;
    border-radius: 10px;
  }

  .phase-pill {
    min-width: 82px;
    padding-inline: 9px;
  }

  .center-bottle-wrap {
    top: 21%;
    width: 33%;
  }

  .color-red {
    left: 11%;
  }

  .color-white {
    right: 10%;
  }
}

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

/* Iframe sizing: preserve the game ratio while respecting short and narrow frames. */
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 {
  z-index: 1;
  width: min(100vw, 620px, 80vh);
  height: auto;
  min-height: 0;
  max-height: 100vh;
  margin: 0;
}

@supports (height: 100dvh) {
  .game {
    width: min(100vw, 620px, 80dvh);
    max-height: 100dvh;
  }
}
