:root {
  color-scheme: dark;
  --ink: #051a31;
  --ink-soft: rgba(5, 26, 49, 0.9);
  --blue: #078dd1;
  --blue-deep: #03446f;
  --gold: #ffc72c;
  --gold-deep: #d58a00;
  --cream: #fff8df;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #087bc1;
  font-family: Inter, ui-rounded, "Segoe UI", Arial, Helvetica, sans-serif;
  color: #fff;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 4px;
}

#app-shell,
#game-stage,
#game-stage canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-stage {
  background: linear-gradient(#0b91da, #d7f5ff);
  cursor: pointer;
}

#game-stage canvas {
  display: block;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
}

.screen.active {
  display: flex;
}

#loading-screen {
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 30%, rgba(28, 181, 239, 0.8), transparent 36%),
    linear-gradient(160deg, #0765a0, #04213c 70%);
}

#loading-screen p {
  margin: 0;
  color: var(--cream);
  font-size: clamp(16px, 2.5vw, 22px);
  font-weight: 800;
}

.loading-mark {
  width: 60px;
  aspect-ratio: 1;
  border: 6px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-track {
  width: min(300px, 72vw);
  height: 9px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.22);
}

.loading-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff9f0a, var(--gold), #fff3a0);
  transition: width 120ms ease;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.menu-screen {
  z-index: 40;
  overflow: hidden;
  align-items: stretch;
  justify-content: stretch;
  background: #05213c;
}

.menu-screen::before {
  content: none;
}

.menu-art,
.menu-art img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.menu-art {
  z-index: 1;
  background: #05213c;
}

.menu-art img {
  object-fit: contain;
}

.full-screen-button {
  position: absolute;
  inset: 0;
  z-index: 3;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: clamp(11px, 1.4vw, 14px);
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

#hud {
  position: fixed;
  z-index: 20;
  top: calc(var(--safe-top) + 62px);
  left: var(--safe-left);
  display: none;
  pointer-events: none;
}

#hud.active {
  display: block;
}

.score-card {
  width: clamp(320px, 29vw, 420px);
  padding: clamp(14px, 1.5vw, 20px);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(2, 32, 65, 0.88), rgba(2, 57, 87, 0.78));
  box-shadow: 0 12px 30px rgba(1, 13, 30, 0.24);
  backdrop-filter: blur(8px);
}

.score-row,
.collect-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.score-row {
  font-size: clamp(18px, 1.8vw, 24px);
  font-weight: 800;
}

.score-row strong {
  color: var(--gold);
  font-size: 1.08em;
}

.progress-track {
  height: 12px;
  margin: 10px 0 9px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.2);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff9a00, var(--gold), #fff1a3);
  box-shadow: 0 0 12px rgba(255, 199, 44, 0.8);
  transition: width 90ms linear;
}

.collect-row {
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(13px, 1.15vw, 16px);
  white-space: nowrap;
}

.collect-row strong {
  color: #fff;
}

.currency-note {
  margin: 7px 0 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: clamp(9px, 0.85vw, 11px);
  font-weight: 650;
  line-height: 1.25;
  text-align: left;
}

.currency-note--result {
  margin-top: 8px;
  text-align: center;
}

.game-reward {
  margin: 0.8rem 0 0.35rem;
  padding: 0.85rem;
  border: 1px solid rgba(255, 196, 61, 0.55);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255, 196, 61, 0.18), rgba(5, 47, 78, 0.75));
  text-align: left;
}

.game-reward > strong { color: #ffd65a; display: block; text-align: center; }
.game-reward p { margin: 0.35rem 0 0.65rem; font-size: 0.82rem; text-align: center; }
.reward-fields { display: flex; gap: 0.4rem; align-items: center; }
.reward-fields input { min-width: 0; width: 100%; padding: 0.65rem; border: 1px solid rgba(255,255,255,.3); border-radius: 9px; background: rgba(0,25,43,.75); color: #fff; }
.reward-fields span { font-size: 0.72rem; opacity: .75; }
.reward-consent { display: flex; gap: 0.4rem; align-items: flex-start; margin: 0.55rem 0; font-size: 0.72rem; }
.reward-form .button { width: 100%; }
.reward-message { display: block; min-height: 1.1em; margin-top: 0.35rem; color: #ffe194; text-align: center; }
.game-reward > .button { display: block; text-align: center; text-decoration: none; }

@media (max-width: 520px) {
  .reward-fields { flex-direction: column; }
  .reward-fields span { display: none; }
}

.pause-button {
  position: fixed;
  z-index: 25;
  top: var(--safe-top);
  right: var(--safe-right);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: clamp(48px, 6vw, 60px);
  height: clamp(48px, 6vw, 60px);
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(2, 34, 69, 0.82);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.pause-button.active {
  display: flex;
}

.pause-button span {
  display: block;
  width: 5px;
  height: 20px;
  border-radius: 3px;
  background: #fff;
}

.share-button {
  position: fixed;
  z-index: 70;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 12px);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 999px;
  background: rgba(2, 30, 58, 0.82);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  color: #fff;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 900;
  letter-spacing: 0.01em;
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.share-button.active {
  display: inline-flex;
}

.catalogue-button {
  position: fixed;
  z-index: 72;
  top: calc(var(--safe-top) + 12px);
  left: var(--safe-left);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 199, 44, 0.96), rgba(238, 142, 18, 0.96));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  color: #10213a;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 950;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
}

.catalogue-button:hover,
.catalogue-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

.input-hint {
  position: fixed;
  z-index: 22;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 12px);
  max-width: min(90vw, 520px);
  padding: 10px 18px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 99px;
  background: rgba(2, 30, 58, 0.78);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  font-size: clamp(12px, 1.3vw, 16px);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 18px);
  transition: opacity 220ms ease, transform 220ms ease;
  backdrop-filter: blur(8px);
}

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

.panel-screen {
  z-index: 60;
  align-items: center;
  justify-content: center;
  padding:
    calc(var(--safe-top) + 18px)
    calc(var(--safe-right) + 18px)
    calc(var(--safe-bottom) + 18px)
    calc(var(--safe-left) + 18px);
  background: rgba(0, 16, 35, 0.64);
  backdrop-filter: blur(8px) saturate(0.85);
}

.panel {
  width: min(430px, 92vw);
  max-height: 92dvh;
  overflow: auto;
  padding: clamp(24px, 4.5vw, 38px);
  border: 2px solid rgba(255, 199, 44, 0.66);
  border-radius: 26px;
  background:
    linear-gradient(150deg, rgba(3, 54, 91, 0.98), rgba(2, 23, 49, 0.98));
  box-shadow:
    0 0 0 5px rgba(2, 20, 43, 0.48),
    0 24px 70px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.panel h1 {
  margin: 0 0 12px;
  color: #fff;
  font-size: clamp(30px, 6vw, 48px);
  line-height: 0.98;
}

.panel > p:not(.eyebrow, .claim-note) {
  margin: 0 auto;
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(14px, 2.2vw, 17px);
  line-height: 1.45;
}

.result-score {
  margin: 18px 0 6px;
  color: var(--gold);
  font-size: clamp(25px, 5vw, 36px);
  font-weight: 950;
}

.result-breakdown {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: clamp(12px, 2vw, 15px);
}

.result-breakdown strong {
  color: #fff;
}

.claim-note {
  margin: 8px auto 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 199, 44, 0.13);
  color: var(--cream);
  font-size: clamp(12px, 2vw, 15px);
  line-height: 1.4;
}

.prize-icon {
  margin-bottom: 5px;
  font-size: clamp(48px, 10vw, 72px);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.26));
}

.button-stack {
  display: grid;
  gap: 11px;
  margin-top: 22px;
}

.button {
  min-height: 52px;
  padding: 12px 24px;
  border: 0;
  border-radius: 999px;
  font-size: clamp(14px, 2.2vw, 17px);
  font-weight: 900;
  cursor: pointer;
  transition: transform 100ms ease, filter 100ms ease;
}

.button:active {
  transform: translateY(3px);
  filter: brightness(0.94);
}

.button-primary {
  color: #221500;
  background: linear-gradient(#ffe36f, var(--gold));
  box-shadow: 0 5px 0 var(--gold-deep);
}

.button-secondary {
  color: #fff;
  background: linear-gradient(#149ee0, #0678bb);
  box-shadow: 0 5px 0 #034d80;
}

.button-quiet {
  border: 2px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

#flash {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: #fff;
  pointer-events: none;
  opacity: 0;
}

#flash.hit {
  animation: hit-flash 240ms ease-out;
}

@keyframes hit-flash {
  0% { opacity: 0.72; }
  100% { opacity: 0; }
}

.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 (orientation: portrait) {
  .score-card {
    width: min(calc(100vw - 86px), 330px);
    padding: 12px 14px;
    border-radius: 17px;
  }

  .score-row {
    font-size: clamp(17px, 4.6vw, 21px);
  }

  .collect-row {
    gap: 7px;
    font-size: clamp(11px, 3vw, 13px);
  }

  .currency-note {
    font-size: clamp(8px, 2.35vw, 10px);
  }

  .share-button {
    bottom: calc(var(--safe-bottom) + 10px);
    padding: 10px 14px;
  }

  .progress-track {
    height: 10px;
    margin-block: 8px;
  }

  .input-hint {
    bottom: calc(var(--safe-bottom) + 8px);
    width: max-content;
    padding: 9px 15px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .panel {
    padding: 18px 26px;
  }

  .panel h1 {
    font-size: 31px;
  }

  .button-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
  }

  .button {
    min-height: 45px;
    padding: 8px 14px;
  }
}

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