:root {
  color-scheme: light;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", sans-serif;
  --ink: #2c1930;
  --muted: #705b6e;
  --pink: #c92b67;
  --pink-dark: #9c174d;
  --yellow: #f6b82d;
  --teal: #167c67;
  --blue: #6f58b8;
  --paper: #fff;
  --canvas: #fff7f5;
  --line: #ead7df;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: clip;
}

body {
  background: var(--canvas);
  color: var(--ink);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.game-app {
  width: min(100%, 790px);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    14px
    max(18px, env(safe-area-inset-bottom));
}

.app-bar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 10px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 850;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #ed7b2d;
  color: #fff;
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 12px;
  font-weight: 950;
}

.sound-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.sound-button[aria-pressed="true"] {
  border-color: var(--teal);
  color: #086d69;
}

.game-shell {
  position: relative;
  width: min(100%, 720px, calc((100dvh - 86px) * 0.8));
  aspect-ratio: 4 / 5;
  margin: 0 auto;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--canvas);
  box-shadow: 8px 10px 0 rgb(35 23 45 / 12%);
  isolation: isolate;
}

/* Keep the complete login form inside the shell on short laptops.
   This applies only while the start screen is visible; the live game keeps
   its exact 4:5 canvas. */
.game-shell:has(#startScreen:not([hidden])) {
  height: calc(100dvh - 86px);
  min-height: 880px;
  aspect-ratio: auto;
}

.game-mount {
  width: 100%;
  height: 100%;
}

.game-mount {
  position: absolute;
  inset: 0;
  touch-action: none;
  overscroll-behavior: contain;
}

.game-mount canvas {
  display: block;
  /* CSS owns the frame, Phaser owns its proportional canvas dimensions.
     Stale negative auto-center margins must never clip the title or tiles. */
  margin: 0 !important;
}

.screen-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 6vw, 52px);
  background: rgb(255 247 245 / 97%);
  text-align: center;
}

.screen-overlay[hidden] {
  display: none;
}

.start-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding-top: 38px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.start-screen::before,
.result-screen::before {
  content: "";
  position: absolute;
  inset: 24px;
  z-index: -1;
  border: 2px dashed rgb(185 28 92 / 30%);
  border-radius: 8px;
  pointer-events: none;
}

.start-art {
  position: relative;
  width: 264px;
  height: 66px;
  flex: 0 0 66px;
  margin-bottom: 12px;
}

.mini-prize {
  position: absolute;
  bottom: 0;
  width: 64px;
  height: 64px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(3px 5px 2px rgb(35 23 45 / 18%));
}

.mini-prize-pumpkin {
  left: 0;
  background-image: url("/games/prize-match/assets/autumn-pumpkin-v1.png?v=1.0.0");
  transform: rotate(-9deg);
}

.mini-prize-apple {
  left: 40px;
  bottom: 4px;
  background-image: url("/games/prize-match/assets/autumn-caramel-apple-v1.png?v=1.0.0");
  transform: rotate(4deg);
}

.mini-prize-leaf {
  left: 80px;
  background-image: url("/games/prize-match/assets/autumn-maple-leaf-v1.png?v=1.0.0");
  transform: rotate(-3deg);
}

.mini-prize-cider {
  left: 120px;
  bottom: 4px;
  background-image: url("/games/prize-match/assets/autumn-cider-v1.png?v=1.0.0");
  transform: rotate(5deg);
}

.mini-prize-acorn {
  left: 160px;
  background-image: url("/games/prize-match/assets/autumn-acorn-v1.png?v=1.0.0");
  transform: rotate(-5deg);
}

.mini-prize-mitten {
  left: 200px;
  bottom: 3px;
  background-image: url("/games/prize-match/assets/autumn-mitten-v1.png?v=1.0.0");
  transform: rotate(8deg);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--pink-dark);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(42px, 10vw, 76px);
  line-height: 0.95;
  font-weight: 950;
}

.start-screen h1 {
  max-width: 100%;
  font-size: clamp(42px, 9vw, 64px);
  white-space: nowrap;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(34px, 8vw, 58px);
  line-height: 1;
  font-weight: 950;
}

.start-copy {
  max-width: 520px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: clamp(17px, 3vw, 22px);
  font-weight: 750;
  line-height: 1.35;
}

.vault-progress-card,
.vault-result-card {
  width: min(100%, 520px);
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 2px solid #d07121;
  border-radius: 7px;
  background: #fff2d2;
  box-shadow: 3px 4px 0 rgb(120 62 35 / 14%);
  text-align: left;
}

.vault-result-card {
  width: min(100%, 390px);
  margin-bottom: 10px;
}

.vault-progress-card[data-vault-ready],
.vault-result-card[data-vault-ready] {
  border-color: var(--pink-dark);
  background: #ffedbd;
  box-shadow: 0 0 0 5px rgb(255 197 61 / 18%), 4px 5px 0 rgb(35 23 45 / 12%);
}

.vault-progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #8c411a;
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.vault-progress-heading strong {
  color: var(--pink-dark);
  font-size: 11px;
}

.vault-key-row {
  display: flex;
  gap: 17px;
  margin: 9px 0 7px 3px;
}

.vault-key-row > span {
  position: relative;
  width: 30px;
  height: 11px;
  display: block;
  border: 2px solid #8d7d72;
  border-left: 0;
  border-radius: 0 7px 7px 0;
  background: #d9d2cc;
  transform: rotate(-8deg);
}

.vault-key-row > span::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -9px;
  width: 15px;
  height: 15px;
  border: 4px solid #8d7d72;
  border-radius: 50%;
  background: var(--paper);
  transform: translateY(-50%);
}

.vault-key-row > span::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: -7px;
  width: 8px;
  height: 7px;
  border-right: 4px solid #8d7d72;
  border-bottom: 4px solid #8d7d72;
}

.vault-key-row > span.is-filled {
  border-color: #9b5d00;
  background: var(--yellow);
  filter: drop-shadow(0 2px 2px rgb(155 93 0 / 25%));
}

.vault-key-row > span.is-filled::before {
  border-color: #9b5d00;
  background: #fff4b2;
}

.vault-key-row > span.is-filled::after {
  border-color: #9b5d00;
}

.vault-progress-card p,
.vault-result-card p {
  margin: 0;
  color: #664b3f;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
}

.vault-key-row > span.is-ready {
  animation: vault-key-ready 900ms ease-in-out infinite alternate;
}

@keyframes vault-key-ready {
  to {
    filter: drop-shadow(0 0 7px rgb(239 61 147 / 60%));
    transform: rotate(-8deg) translateY(-2px);
  }
}

.how-to-play {
  width: min(100%, 520px);
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 3px 4px 0 rgb(35 23 45 / 12%);
  text-align: left;
}

.how-to-play h2 {
  margin: 0 0 8px;
  color: var(--pink-dark);
  font-size: 15px;
  line-height: 1.2;
}

.how-to-play ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.how-to-play li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
}

.how-to-play li > span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 11px;
  font-weight: 950;
}

.how-to-play li p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.how-to-play li strong {
  color: var(--ink);
}

.power-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.power-preview-item {
  min-width: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border: 1px solid rgb(35 23 45 / 14%);
  border-radius: 6px;
  background: #fff2d2;
}

.power-preview-item:nth-child(2) {
  background: #fff0d0;
}

.power-preview-item:nth-child(3) {
  background: #e8f8f7;
}

.power-preview-item img {
  width: 34px;
  height: 38px;
  flex: 0 0 34px;
  object-fit: contain;
  filter: grayscale(0.18) sepia(1) saturate(3.2) hue-rotate(330deg)
    drop-shadow(2px 3px 1px rgb(35 23 45 / 16%));
}

.power-preview-item span {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.power-preview-item strong,
.power-preview-item small {
  display: block;
  line-height: 1.1;
}

.power-preview-item strong {
  color: var(--ink);
  font-size: 10px;
  font-weight: 950;
}

.power-preview-item small {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
}

.how-to-note {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 11px;
  font-weight: 850;
  line-height: 1.35;
}

.start-form {
  width: min(100%, 460px);
}

.start-form label {
  display: block;
  margin-bottom: 7px;
  text-align: left;
  font-size: 13px;
  font-weight: 900;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.name-row input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  font-weight: 750;
  outline: none;
}

.email-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  font-weight: 750;
  outline: none;
}

.name-row + label {
  margin-top: 12px;
}

.email-input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgb(239 61 147 / 15%);
}

.email-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: left;
}

.name-row input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgb(239 61 147 / 15%);
}

.secondary-button,
.primary-button,
.text-button,
.close-button {
  border: 0;
}

.secondary-button {
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.primary-button {
  width: min(100%, 460px);
  min-height: 52px;
  margin-top: 6px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--pink);
  color: #fff;
  box-shadow: 4px 5px 0 var(--ink);
  font-size: 17px;
  font-weight: 950;
}

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

.primary-button:disabled {
  background: #d9257e;
  color: #fff;
  opacity: 0.78;
}

.text-button {
  margin-top: 22px;
  padding: 8px 12px;
  background: transparent;
  color: var(--pink-dark);
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.field-error {
  min-height: 21px;
  margin: 5px 0 0;
  color: #b42318;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

.result-score {
  min-width: min(100%, 340px);
  margin: 8px 0 16px;
  padding: 18px;
  border-block: 2px solid var(--line);
}

.result-score span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.result-score strong {
  color: var(--pink-dark);
  font-size: clamp(48px, 11vw, 78px);
  line-height: 1;
}

.result-target {
  min-height: 22px;
  margin: -6px 0 10px;
  color: #087c70;
  font-size: 13px;
  font-weight: 900;
}

.result-rank {
  min-height: 25px;
  color: var(--muted);
  font-weight: 800;
}

.save-status {
  min-height: 20px;
  margin: -8px 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 850;
}

.leaderboard-screen {
  align-items: stretch;
  justify-content: flex-start;
  background: #fff;
  text-align: left;
}

.overlay-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--line);
}

.overlay-heading h2 {
  margin: 0;
}

.close-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.leaderboard-list {
  width: 100%;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  overflow: auto;
}

.leaderboard-list li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-weight: 850;
}

.leaderboard-list li::before {
  content: counter(rank);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f7e8f1;
  color: var(--pink-dark);
  font-size: 13px;
}

.leaderboard-list strong {
  color: var(--pink-dark);
}

.empty-leaderboard {
  margin: auto;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

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

@media (max-width: 520px) {
  .game-app {
    padding-inline: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-bar {
    padding-inline: 12px;
  }

  .brand span:last-child {
    font-size: 13px;
  }

  .game-shell {
    width: 100%;
    border-inline: 0;
    border-radius: 0;
    box-shadow: none;
  }

  /* The email opt-in made the start form taller than the 4:5 game canvas.
     Give only the start state enough natural height; gameplay returns to the
     exact 4:5 Phaser canvas as soon as the round begins. */
  .game-shell:has(#startScreen:not([hidden])) {
    height: calc(100dvh - 68px);
    min-height: 0;
    aspect-ratio: auto;
  }

  .screen-overlay {
    padding: 18px 20px;
  }

  .start-screen {
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .start-screen::before,
  .result-screen::before {
    inset: 14px;
  }

  .start-screen > .eyebrow {
    display: none;
  }

  .name-row {
    grid-template-columns: minmax(0, 1fr) 106px;
  }

  .secondary-button {
    min-height: 48px;
    padding-inline: 8px;
    font-size: 11px;
  }

  .start-art {
    display: block;
    width: 250px;
    height: 48px;
    flex-basis: 48px;
    margin: 0 0 3px;
    transform: scale(0.78);
    transform-origin: center bottom;
  }

  .start-copy {
    margin-bottom: 7px;
    font-size: 13px;
    line-height: 1.25;
  }

  .vault-progress-card {
    margin-bottom: 7px;
    padding: 7px 10px;
  }

  .vault-progress-heading {
    font-size: 10px;
  }

  .vault-progress-heading strong,
  .vault-progress-card p,
  .vault-result-card p {
    font-size: 9px;
  }

  .vault-key-row {
    margin-block: 6px 5px;
    transform: scale(0.86);
    transform-origin: left center;
  }

  .how-to-play {
    margin-bottom: 8px;
    padding: 7px 10px;
  }

  .how-to-play h2 {
    margin-bottom: 4px;
    font-size: 13px;
  }

  .how-to-play ol {
    gap: 3px;
  }

  .how-to-play li {
    grid-template-columns: 21px minmax(0, 1fr);
    gap: 6px;
  }

  .how-to-play li > span {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .how-to-play li p {
    font-size: 10px;
    line-height: 1.2;
  }

  .power-preview {
    gap: 4px;
    margin-top: 5px;
  }

  .power-preview-item {
    min-height: 42px;
    gap: 3px;
    padding: 3px 4px;
  }

  .power-preview-item img {
    width: 25px;
    height: 29px;
    flex-basis: 25px;
  }

  .power-preview-item strong {
    font-size: 8px;
  }

  .power-preview-item small {
    font-size: 7px;
  }

  .how-to-note {
    margin-top: 4px;
    padding-top: 4px;
    font-size: 9px;
    line-height: 1.2;
  }

  .start-screen h1 {
    margin-bottom: 5px;
    font-size: 36px;
  }

  .start-form label {
    margin-bottom: 4px;
  }

  .name-row + label {
    margin-top: 8px;
  }

  .name-row input,
  .email-input {
    min-height: 40px;
  }

  .secondary-button {
    min-height: 40px;
  }

  .email-note {
    display: none;
  }

  .field-error:empty {
    display: none;
  }

  .field-error:not(:empty) {
    min-height: 15px;
    margin: 2px 0 0;
  }

  .primary-button {
    min-height: 44px;
  }

  .text-button {
    margin-top: 6px;
  }
}

/* Keep the complete start flow inside short mobile Chrome viewports. */
@media (max-width: 520px) and (max-height: 740px) {
  .game-app {
    padding-top: 4px;
  }

  .app-bar {
    min-height: 48px;
    padding-bottom: 4px;
  }

  .game-shell:has(#startScreen:not([hidden])) {
    height: calc(100dvh - 52px);
  }

  .screen-overlay {
    padding: 10px 20px;
  }

  .start-screen h1 {
    margin-bottom: 3px;
    font-size: 32px;
  }

  .start-copy {
    margin-bottom: 4px;
    font-size: 11px;
  }

  .vault-progress-card {
    margin-bottom: 4px;
  }

  .how-to-play {
    margin-bottom: 6px;
    padding-block: 6px;
  }

  .power-preview,
  .how-to-note {
    display: none;
  }

  .text-button {
    margin-top: 0;
  }
}

@media (max-height: 690px) and (orientation: landscape) {
  .game-app {
    width: min(100%, 620px);
  }

  .app-bar {
    min-height: 44px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .game-shell {
    width: min(100%, calc((100dvh - 58px) * 0.8));
  }

  .start-art {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .vault-key-row > span.is-ready {
    animation: none;
  }
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Halloween Trail v1: clear tile art and readable start/replay copy. */
.halloween-trail .start-art{display:flex;align-items:center;justify-content:center;gap:5px;width:min(100%,380px);height:64px;margin-inline:auto}
.halloween-trail .mini-prize{position:static;flex:1 1 0;max-width:58px;aspect-ratio:1;height:auto;background-image:url('/games/prize-match/assets/halloween-pieces-v1.webp');background-size:600% 400%;border-radius:8px;filter:none;transform:none}
.halloween-trail .mini-prize-pumpkin{background-position:0 0}
.halloween-trail .mini-prize-apple{background-position:20% 0}
.halloween-trail .mini-prize-leaf{background-position:40% 0}
.halloween-trail .mini-prize-cider{background-position:60% 0}
.halloween-trail .mini-prize-acorn{background-position:80% 0}
.halloween-trail .mini-prize-mitten{background-position:100% 0}
.halloween-trail .vault-progress-card{background:#fff6e3;color:#362036;border:2px solid #bd681e}
.halloween-trail .vault-progress-card p,.halloween-trail .vault-progress-heading{color:#362036}
.halloween-trail .vault-progress-card[data-vault-ready]{background:#31213d;color:#fff8ea;border-color:#ffcf70}
.halloween-trail .vault-progress-card[data-vault-ready] p,.halloween-trail .vault-progress-card[data-vault-ready] .vault-progress-heading{color:#fff8ea}
.halloween-trail .vault-progress-card[data-vault-ready] strong{color:#ffdb77}
.halloween-trail .eyebrow{color:#7d2a16}
.halloween-trail .start-copy{color:#473343}
@media(min-width:701px) and (pointer:fine){.halloween-trail .game-shell:not(:has(#startScreen:not([hidden]))){width:min(100%,720px,calc((100dvh - 200px)*.8))}}
@media(prefers-reduced-motion:reduce){.halloween-trail .vault-key-row span,.halloween-trail .vault-progress-card{animation:none!important;transition:none!important}}
