:root {
  --ink: #315b63;
  --pink: #ee2f88;
  --cream: #fffced;
  --card: rgba(255, 255, 247, .96);
  --shadow: rgba(29, 70, 77, .2);
  --visual-viewport-height: 100dvh;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: start center;
  background: linear-gradient(180deg, #63d4f2 0%, #c9f4ef 67%, #fff2a9 100%);
  transition: background .8s ease;
}

body[data-environment="night"] {
  background: linear-gradient(180deg, #071b68 0%, #173b93 58%, #5b8bb4 100%);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid #ffe04e;
  outline-offset: 3px;
}

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

.app {
  width: min(100%, 470px);
  height: var(--visual-viewport-height);
  min-height: 520px;
  padding: max(6px, env(safe-area-inset-top)) 10px max(6px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 55px;
  margin-bottom: 5px;
}

.round-button,
.games-button,
.hud-button {
  display: grid;
  place-items: center;
  color: #356571;
  background: rgba(255,255,255,.94);
  border: 2px solid rgba(255,255,255,.92);
  border-radius: 16px;
  box-shadow: 0 5px 0 rgba(36,87,96,.18), 0 7px 18px rgba(31,79,88,.16);
  text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease;
}

.round-button {
  width: 45px;
  height: 45px;
  font-size: 23px;
  font-weight: 900;
}

.games-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 118px;
  height: 45px;
  padding: 0 10px 0 7px;
  border-radius: 16px;
  color: #356571;
  font-size: 10px;
  font-weight: 1000;
  line-height: 1.05;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .025em;
}

.games-button svg {
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  overflow: visible;
}

.games-button .house-roof,
.games-button .house-body,
.games-button .house-door {
  stroke: #315e68;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.games-button .house-roof {
  fill: none;
  stroke: #315e68;
}

.games-button .house-body { fill: #fff4a8; }
.games-button .house-door { fill: #ff72a9; }
.games-button circle { fill: #315e68; }

body.is-playing .games-button {
  width: 45px;
  padding: 0;
}

body.is-playing .games-button span { display: none; }

.round-button:active,
.games-button:active,
.hud-button:active,
.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(36,87,96,.2);
}

.tony-brand {
  position: absolute;
  left: 50%;
  translate: -50% 0;
  display: grid;
  place-items: center;
  width: 120px;
  height: 54px;
}

.tony-brand img {
  display: block;
  width: auto;
  height: 50px;
  object-fit: contain;
  filter: drop-shadow(0 3px 1px rgba(28,67,74,.16));
}

.screen {
  display: none;
  height: calc(var(--visual-viewport-height) - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 0;
}

.screen.is-active {
  display: flex;
  animation: screen-in .34s ease both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.home-screen {
  align-items: flex-start;
  justify-content: center;
}

.home-art {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 4px solid rgba(255,255,255,.94);
  border-radius: 28px;
  background: #65d1ee;
  box-shadow: 0 8px 0 rgba(38,85,69,.18), 0 18px 35px var(--shadow);
}

.home-art > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.environment-choice {
  position: absolute;
  top: 56.2%;
  width: 38.2%;
  height: 22.8%;
  border-radius: 15%;
  background: transparent;
  transition: transform .18s ease, box-shadow .18s ease;
}

.environment-choice::after {
  content: "TOQUE AQUI";
  position: absolute;
  left: 50%;
  bottom: 5%;
  translate: -50% 0;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: rgba(39,67,66,.72);
  font-size: clamp(9px, 2.5vw, 12px);
  font-weight: 900;
  letter-spacing: .03em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .18s ease;
}

.environment-choice:hover,
.environment-choice:focus-visible {
  transform: scale(1.035);
  box-shadow: 0 0 0 5px rgba(255,238,91,.88), 0 0 28px rgba(255,228,62,.9);
}

.environment-choice:hover::after,
.environment-choice:focus-visible::after {
  opacity: 1;
}

.environment-day { left: 11.7%; }
.environment-night { right: 11.7%; }

.campaign-note {
  position: absolute;
  left: 50%;
  bottom: 3.3%;
  translate: -50% 0;
  width: max-content;
  max-width: 88%;
  padding: 7px 14px;
  border: 2px solid rgba(255,255,255,.92);
  border-radius: 999px;
  color: #fff;
  background: rgba(20,82,55,.78);
  box-shadow: 0 4px 0 rgba(17,60,42,.22);
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  letter-spacing: .025em;
}

.block-screen {
  align-items: flex-start;
  justify-content: center;
}

.selection-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 100%;
  padding: 12px 17px 16px;
  overflow: hidden;
  border: 4px solid rgba(255,255,255,.94);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255,255,249,.98), rgba(255,249,212,.98));
  box-shadow: 0 8px 0 rgba(50,94,72,.16), 0 18px 34px var(--shadow);
}

.back-button {
  align-self: flex-start;
  min-height: 34px;
  padding: 7px 13px;
  border-radius: 999px;
  color: #8b4867;
  background: #ffe2f0;
  font-size: clamp(12px, 3.3vw, 15px);
  font-weight: 900;
}

.eyebrow {
  margin: 2px 0 0;
  color: var(--pink);
  font-size: clamp(13px, 3.5vw, 17px);
  font-weight: 900;
  text-align: center;
  letter-spacing: .04em;
}

.selection-card h1 {
  margin: 2px 0 9px;
  color: #315e68;
  font-size: clamp(23px, 6.5vw, 33px);
  line-height: 1.08;
  text-align: center;
}

.block-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
  min-height: 0;
}

.block-option {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 8px;
  border: 3px solid transparent;
  border-radius: 22px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 6px 0 rgba(58,99,72,.13), 0 8px 18px rgba(41,77,68,.1);
  transition: transform .16s ease, border-color .16s ease;
}

.block-option img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 5px 2px rgba(38,65,57,.12));
}

.block-option span {
  position: absolute;
  top: -7px;
  right: -6px;
  display: none;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 3px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: #f43d99;
  box-shadow: 0 4px 0 #c81f72;
  font-size: 20px;
  font-weight: 900;
}

.block-option.is-selected {
  z-index: 2;
  border-color: #f43d99;
  transform: translateY(-2px) scale(1.025);
}

.block-option.is-selected span { display: grid; }

.same-physics {
  margin: 11px 0 10px;
  color: #5a7774;
  font-size: clamp(13px, 3.7vw, 17px);
  font-weight: 800;
  text-align: center;
}

.primary-button {
  width: 100%;
  min-height: 55px;
  padding: 12px 18px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(180deg, #ff50aa 0%, #ed2a85 100%);
  box-shadow: 0 8px 0 #bd1e68, 0 14px 24px rgba(229,48,126,.23);
  font-size: clamp(17px, 4.8vw, 22px);
  font-weight: 1000;
  line-height: 1.05;
}

.game-screen {
  flex-direction: column;
  gap: 6px;
}

.game-hud {
  display: grid;
  grid-template-columns: .9fr 1.25fr .95fr 46px;
  gap: 5px;
  width: 100%;
  flex: 0 0 54px;
}

.hud-card,
.hud-button {
  min-width: 0;
  height: 52px;
  border-radius: 16px;
  background: rgba(255,255,255,.95);
  box-shadow: 0 5px 0 rgba(41,91,79,.16), 0 8px 16px rgba(29,66,72,.12);
}

.hud-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3px 4px;
}

.hud-card span {
  color: #e63685;
  font-size: clamp(9px, 2.5vw, 12px);
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
}

.hud-card strong {
  margin-top: 3px;
  color: #315d65;
  font-size: clamp(14px, 4vw, 19px);
  line-height: 1;
  white-space: nowrap;
}

.hud-button {
  width: 43px;
  color: #35636b;
  font-size: 24px;
  font-weight: 1000;
}

.stage-wrap {
  position: relative;
  align-self: center;
  width: min(100%, calc((var(--visual-viewport-height) - 135px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .5625));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 4px solid rgba(30,75,68,.92);
  border-radius: 24px;
  background: #8fdf51;
  box-shadow: 0 7px 0 rgba(26,70,63,.2), 0 14px 28px rgba(17,57,66,.2);
}

.stage-background {
  position: absolute;
  z-index: 0;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.aim-instruction {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 1.5%;
  translate: -50% 0;
  width: min(92%, 390px);
  padding: 8px 12px;
  border: 3px solid rgba(255,255,255,.98);
  border-radius: 999px;
  color: #fff;
  background: rgba(24,75,67,.93);
  box-shadow: 0 4px 0 rgba(22,57,50,.24), 0 0 16px rgba(255,234,70,.5);
  font-size: clamp(12px, 3.3vw, 16px);
  font-weight: 900;
  line-height: 1.12;
  text-align: center;
  pointer-events: none;
  transition: opacity .2s ease;
}

.aim-instruction.is-hidden { opacity: 0; }

.phase-overlay {
  position: absolute;
  z-index: 15;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12,50,45,.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

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

.phase-card {
  width: min(100%, 340px);
  padding: 16px 18px 22px;
  border: 4px solid #fff;
  border-radius: 28px;
  color: #3b645b;
  background: linear-gradient(180deg, #fffef3, #fff1a8);
  box-shadow: 0 10px 0 rgba(58,86,57,.2), 0 22px 44px rgba(15,48,42,.3);
  text-align: center;
  transform: translateY(14px) scale(.94);
  transition: transform .3s cubic-bezier(.2,.9,.3,1.25);
}

.phase-overlay.is-visible .phase-card { transform: none; }

.phase-card img {
  display: block;
  width: 132px;
  height: 120px;
  margin: -34px auto -2px;
  object-fit: contain;
  filter: drop-shadow(0 6px 2px rgba(66,77,49,.17));
}

.phase-kicker {
  margin: 0;
  color: #e73886;
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 1000;
  letter-spacing: .04em;
}

.phase-card h2 {
  margin: 3px 0 4px;
  color: #2f615c;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1;
}

.phase-card > p:not(.phase-kicker) {
  margin: 0 0 14px;
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 800;
}

.sky-transition {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #fff;
  background: radial-gradient(circle at 50% 42%, #7066cb, #0a1955);
  opacity: 0;
  pointer-events: none;
  transition: opacity .6s ease;
}

.sky-transition.is-visible { opacity: 1; }
.sky-transition span { font-size: 74px; }
.sky-transition strong { font-size: clamp(22px, 6vw, 32px); }

@media (max-height: 690px) {
  .topbar { height: 48px; margin-bottom: 3px; }
  .tony-brand img { height: 44px; }
  .round-button { width: 41px; height: 41px; }
  .games-button { width: 108px; height: 41px; padding-right: 7px; font-size: 9px; }
  body.is-playing .games-button { width: 41px; }
  .games-button svg { width: 24px; height: 24px; flex-basis: 24px; }
  .screen { height: calc(var(--visual-viewport-height) - 58px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .selection-card { padding: 9px 14px 13px; }
  .selection-card h1 { margin-bottom: 6px; }
  .block-grid { gap: 6px; }
  .block-option { padding: 5px; border-radius: 17px; }
  .same-physics { margin: 7px 0; }
  .primary-button { min-height: 48px; }
  .game-hud { flex-basis: 48px; }
  .hud-card, .hud-button { height: 46px; }
  .stage-wrap { width: min(100%, calc((var(--visual-viewport-height) - 116px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .5625)); }
}

@media (min-width: 700px) and (max-height: 850px) {
  .app { width: 430px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
