@font-face {
  font-family: 'Marcellus';
  src: url('../assets/fonts/marcellus-latin.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Outfit';
  src: url('../assets/fonts/outfit-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --bg: #050b16;
  --ink: #eaf6ff;
  --muted: #9fb6cc;
  --cyan: #5fd4ff;
  --cyan-soft: rgba(95, 212, 255, 0.35);
  --violet: #9a92e0;
  --red: #f0192e;
  --glass: rgba(120, 200, 255, 0.10);
  --glass-line: rgba(160, 225, 255, 0.45);
  --pad: clamp(14px, 2.4vmin, 28px);
  --gap: clamp(8px, 1.6vmin, 18px);
  --vh: 1vh;
  --chrome: calc(var(--pad) * 2 + 92px + env(safe-area-inset-top) + env(safe-area-inset-bottom));
  --cols: 4;
  --rows: 3;
  --card: min(
    calc((100vw - var(--pad) * 2 - env(safe-area-inset-left) - env(safe-area-inset-right) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    calc((100 * var(--vh) - var(--chrome) - (var(--rows) - 1) * var(--gap)) / var(--rows))
  );
  --ease-pop: cubic-bezier(0.25, 1.4, 0.5, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@supports (height: 1dvh) {
  :root { --vh: 1dvh; }
}

@media (orientation: portrait) {
  :root { --cols: 3; --rows: 4; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

img { display: block; -webkit-user-drag: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Cenário */
.sky {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(60% 50% at 50% 38%, rgba(40, 140, 255, 0.16), transparent 70%),
    radial-gradient(40% 40% at 85% 10%, rgba(154, 146, 224, 0.10), transparent 70%),
    linear-gradient(180deg, #040812 0%, #06101f 60%, #07131f 100%);
}
.forest {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 0;
  height: 42dvh;
  background: url('../assets/bg/floresta.webp') center bottom / cover no-repeat;
  opacity: 0.85;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 55%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 55%);
}
.fireflies { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.fireflies i {
  position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: #8ff0ff; box-shadow: 0 0 10px 2px rgba(120, 240, 255, 0.7);
  opacity: 0; animation: firefly var(--d, 9s) ease-in-out var(--delay, 0s) infinite;
}
.fireflies i:nth-child(3n) { background: #c9b8ff; box-shadow: 0 0 10px 2px rgba(180, 160, 255, 0.6); }
@keyframes firefly {
  0%, 100% { opacity: 0; transform: translate(0, 0); }
  30% { opacity: 0.9; }
  60% { opacity: 0.4; transform: translate(var(--dx, 20px), var(--dy, -30px)); }
}

/* Telas */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: none;
  padding: max(var(--pad), env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right))
           max(var(--pad), env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
}
.screen.is-active { display: flex; animation: screen-in 0.45s var(--ease-out); }
@keyframes screen-in { from { opacity: 0; transform: scale(0.98); } }

.kicker {
  margin: 0; font-size: clamp(14px, 1.9vmin, 20px); letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--cyan); font-weight: 600;
}
.pitch { margin: 0; font-size: clamp(18px, 2.8vmin, 30px); line-height: 1.35; color: var(--ink); }
.pitch strong { color: var(--cyan); font-weight: 700; }
.muted { margin: 0; color: var(--muted); font-size: clamp(15px, 2vmin, 20px); }
.big {
  margin: 0; font-family: 'Marcellus', serif; font-weight: 400;
  font-size: clamp(54px, 10vmin, 110px); line-height: 1;
  background: linear-gradient(180deg, #ffffff 10%, #8fe3ff 60%, #3aa8ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(80, 190, 255, 0.45));
}

.cta {
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: clamp(14px, 2.2vmin, 22px) clamp(30px, 5vmin, 56px);
  min-height: 64px;
  font-weight: 700; font-size: clamp(20px, 3vmin, 30px); letter-spacing: 0.02em;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, rgba(70, 170, 255, 0.55), rgba(30, 90, 210, 0.55));
  box-shadow: 0 0 0 1px rgba(95, 212, 255, 0.15), 0 10px 40px rgba(40, 150, 255, 0.35),
              inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.15s var(--ease-out), box-shadow 0.2s;
}
.cta:active { transform: scale(0.95); }
.cta.ghost { background: var(--glass); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.cta.breathe { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe {
  50% { box-shadow: 0 0 0 1px rgba(95, 212, 255, 0.3), 0 10px 60px rgba(60, 180, 255, 0.6),
                    inset 0 1px 0 rgba(255, 255, 255, 0.5); }
}

/* Abertura */
#start { align-items: center; justify-content: center; }
.logo-hold {
  position: absolute; top: max(var(--pad), env(safe-area-inset-top)); left: max(var(--pad), env(safe-area-inset-left));
  width: 72px; height: 72px; padding: 4px; border: 0; border-radius: 50%; background: none;
  touch-action: none;
}
.logo-hold img { width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 0 10px rgba(80, 190, 255, 0.55)); }
.hold-ring { position: absolute; inset: 0; width: 72px; height: 72px; transform: rotate(-90deg); pointer-events: none; }
.hold-ring circle {
  fill: none; stroke: var(--cyan); stroke-width: 2.5; stroke-linecap: round;
  stroke-dasharray: 113.1; stroke-dashoffset: 113.1;
}
.logo-hold.is-holding .hold-ring circle { stroke-dashoffset: 0; transition: stroke-dashoffset 3s linear; }

.start-body {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: clamp(10px, 2vmin, 20px);
  margin-top: -6dvh;
}
.lettering {
  width: min(62vw, 58dvh * 1.6); height: auto;
  filter: drop-shadow(0 0 30px rgba(60, 170, 255, 0.35));
  animation: float 6s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-8px); } }
#play { margin-top: clamp(6px, 1.4vmin, 14px); }

.prize-strip {
  list-style: none; margin: clamp(8px, 2vmin, 22px) 0 0; padding: 0;
  display: flex; gap: clamp(10px, 2vmin, 22px); justify-content: center; flex-wrap: wrap;
}
.prize-strip li { display: flex; flex-direction: column; align-items: center; gap: 6px; width: clamp(64px, 10vmin, 96px); }
.prize-strip img, .prize-strip .no-art {
  width: 100%; aspect-ratio: 1; border-radius: 16px; object-fit: cover;
  border: 1px solid var(--glass-line); box-shadow: 0 0 18px rgba(60, 170, 255, 0.25);
}
.prize-strip span { font-size: clamp(12px, 1.6vmin, 15px); color: var(--muted); line-height: 1.15; }
.prize-strip .no-art { font-size: 11px; padding: 4px; }

/* Jogo */
#game { flex-direction: column; align-items: center; gap: 10px; }
.hud {
  width: 100%; height: 64px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
}
.hud-logo { width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 0 10px rgba(80, 190, 255, 0.55)); }
.hud-pairs {
  justify-self: center; display: flex; align-items: baseline; gap: 8px;
  padding: 8px 20px; border-radius: 999px; background: var(--glass); border: 1px solid rgba(160, 225, 255, 0.25);
}
.hud-pairs span { font-size: 34px; font-weight: 800; color: var(--cyan); font-variant-numeric: tabular-nums; }
.hud-pairs small { font-size: 18px; color: var(--muted); }
.hud-pairs.bump span { animation: bump 0.4s var(--ease-pop); }
@keyframes bump { 40% { transform: scale(1.5); } }
.hud-timer {
  justify-self: end; font-family: 'Outfit', sans-serif; font-weight: 800;
  font-size: 48px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
  text-shadow: 0 0 18px rgba(95, 212, 255, 0.5);
}
.hud-timer.is-urgent { color: var(--red); text-shadow: 0 0 20px rgba(240, 25, 46, 0.6); }
.hud-timer.pulse { animation: pulse 0.5s var(--ease-pop); }
@keyframes pulse { 30% { transform: scale(1.18); } }

.timebar { width: 100%; height: 6px; border-radius: 6px; background: rgba(160, 225, 255, 0.12); overflow: hidden; }
.timebar i {
  display: block; height: 100%; width: 100%; transform-origin: left; border-radius: 6px;
  background: linear-gradient(90deg, #3aa8ff, var(--cyan));
  box-shadow: 0 0 12px rgba(95, 212, 255, 0.7);
}
.timebar i.is-urgent { background: linear-gradient(90deg, #ff4d5e, var(--red)); box-shadow: 0 0 12px rgba(240, 25, 46, 0.7); }

.grid {
  flex: 1; display: grid; align-content: center; justify-content: center;
  grid-template-columns: repeat(var(--cols), var(--card));
  grid-auto-rows: var(--card);
  gap: var(--gap);
  perspective: 1400px;
}

.card {
  position: relative; width: var(--card); height: var(--card);
  padding: 0; border: 0; background: none; border-radius: 18px;
  touch-action: manipulation;
  animation: deal 0.55s var(--ease-pop) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes deal { from { opacity: 0; transform: translateY(30px) scale(0.7) rotate(-4deg); } }
.card-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform 0.48s var(--ease-pop);
}
.card.is-up .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }
.card:active:not(.is-up):not(.is-matched) .card-inner { transform: scale(0.95); transition-duration: 0.12s; }

.face {
  position: absolute; inset: 0; border-radius: 18px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1.5px solid rgba(160, 225, 255, 0.38);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  background: #071222;
}
.face img { width: 100%; height: 100%; object-fit: cover; }
.face.back::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 35%);
}
.face.front { transform: rotateY(180deg); }
.face .label {
  position: absolute; left: 8%; right: 8%; bottom: 7%;
  padding: 0.35em 0.6em; border-radius: 999px; text-align: center;
  font-weight: 700; font-size: clamp(12px, calc(var(--card) * 0.085), 22px); line-height: 1.1;
  background: rgba(4, 12, 26, 0.62); border: 1px solid rgba(160, 225, 255, 0.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.no-art {
  display: grid; place-items: center; width: 100%; height: 100%;
  background: radial-gradient(circle at 50% 40%, rgba(95, 212, 255, 0.35), rgba(7, 18, 34, 1) 70%);
  font-family: 'Marcellus', serif; font-size: clamp(14px, calc(var(--card) * 0.12), 30px);
  text-align: center; padding: 10%; color: #dff6ff;
}

.card.is-matched .face.front {
  border-color: rgba(140, 240, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(95, 212, 255, 0.55), 0 0 34px rgba(80, 200, 255, 0.55);
}
.card.pop { animation: card-pop 0.5s var(--ease-pop); }
@keyframes card-pop { 35% { transform: scale(1.12); } }
.card.shake { animation: shake 0.42s ease-in-out; }
@keyframes shake {
  20% { transform: translateX(-9px) rotate(-1.5deg); }
  40% { transform: translateX(8px) rotate(1.2deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}
.grid.is-locked { pointer-events: none; }

.spark {
  position: fixed; z-index: 5; width: 8px; height: 8px; border-radius: 50%; pointer-events: none;
  background: #bff6ff; box-shadow: 0 0 12px 3px rgba(110, 230, 255, 0.85);
  animation: spark 0.7s var(--ease-out) forwards;
}
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }

.countdown {
  position: fixed; inset: 0; z-index: 4; display: none; place-items: center; pointer-events: none;
  font-family: 'Marcellus', serif; font-size: clamp(120px, 26vmin, 260px); color: #fff;
  text-shadow: 0 0 40px rgba(80, 200, 255, 0.9);
}
.countdown.is-on { display: grid; background: radial-gradient(circle, rgba(5, 11, 22, 0.35), rgba(5, 11, 22, 0.75)); }
.countdown span { animation: count 0.62s var(--ease-pop) both; }
@keyframes count { from { transform: scale(2.2); opacity: 0; } 70% { opacity: 1; } to { transform: scale(0.9); opacity: 0.2; } }

/* Vitória */
#win { align-items: center; justify-content: center; text-align: center; overflow: hidden; }
.win-body { position: relative; display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.4vmin, 14px); }
.stage {
  --reel: min(30dvh, 40vw);
  position: relative; width: calc(var(--reel) * 1.7); aspect-ratio: 1;
  display: grid; place-items: center;
}
.win-portal {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.95;
  filter: drop-shadow(0 0 50px rgba(60, 170, 255, 0.5));
  animation: portal-open 1.1s var(--ease-pop) both, portal-spin 24s linear 1.1s infinite;
}
@keyframes portal-open { from { transform: scale(0.15) rotate(-140deg); opacity: 0; } }
@keyframes portal-spin { to { transform: rotate(360deg); } }
.reel {
  position: relative; width: var(--reel); aspect-ratio: 1; border-radius: 24px; overflow: hidden;
  border: 2px solid rgba(160, 230, 255, 0.85);
  box-shadow: 0 0 0 6px rgba(95, 212, 255, 0.12), 0 0 70px rgba(80, 200, 255, 0.6);
  background: #071222;
  animation: reel-in 0.7s var(--ease-pop) 0.5s both;
}
@keyframes reel-in { from { transform: scale(0.3); opacity: 0; } }
.reel img { width: 100%; height: 100%; object-fit: cover; }
.reel .no-art { position: absolute; inset: 0; }
.reel span {
  position: absolute; left: 10%; right: 10%; bottom: 7%; padding: 0.35em 0.6em; border-radius: 999px;
  background: rgba(4, 12, 26, 0.62); border: 1px solid rgba(160, 225, 255, 0.35);
  font-weight: 700; font-size: clamp(16px, 2.6vmin, 26px);
}
.reel.is-landed { animation: landed 0.6s var(--ease-pop); }
@keyframes landed { 40% { transform: scale(1.12); } }
.win-title {
  margin: 0; font-family: 'Marcellus', serif; font-weight: 400; font-size: clamp(30px, 5.6vmin, 64px); line-height: 1.05;
  text-shadow: 0 0 24px rgba(80, 200, 255, 0.55);
}
.win-sub { margin: 0; font-size: clamp(17px, 2.6vmin, 26px); color: var(--muted); }

/* Derrota e sem estoque */
#lose, #soldout { align-items: center; justify-content: center; }
.center-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  padding: clamp(26px, 5vmin, 56px) clamp(28px, 7vmin, 80px); border-radius: 32px;
  background: rgba(8, 20, 38, 0.55); border: 1px solid rgba(160, 225, 255, 0.25);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  margin-top: -6dvh;
}
.center-card .cta { margin-top: 8px; }

/* Painel */
.panel { align-items: center; justify-content: center; background: rgba(3, 7, 15, 0.82); z-index: 6; }
.panel-card {
  width: min(680px, 100%); max-height: 100%; overflow: auto;
  padding: 26px 28px; border-radius: 24px; background: #0a1729; border: 1px solid rgba(160, 225, 255, 0.25);
  user-select: auto; -webkit-user-select: auto;
}
.panel-card h2 { margin: 0 0 4px; font-size: 26px; }
.panel-card h3 { margin: 22px 0 8px; font-size: 16px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--cyan); }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-time { margin-top: 18px; font-size: 19px; }
.panel-stock { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.panel-stock li {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 14px;
  padding: 8px 10px; border-radius: 14px; background: rgba(120, 200, 255, 0.06);
}
.panel-stock img, .panel-stock .no-art { width: 52px; height: 52px; border-radius: 10px; font-size: 10px; padding: 4px; }
.panel-stock .name { font-size: 18px; font-weight: 600; }
.panel-stock li.is-empty .name::after { content: ' · esgotado'; color: var(--red); font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 52px; height: 52px; border-radius: 14px; border: 1px solid rgba(160, 225, 255, 0.35);
  background: rgba(120, 200, 255, 0.10); font-size: 26px; font-weight: 700;
}
.stepper button:active { transform: scale(0.92); }
.stepper input {
  width: 76px; height: 52px; border-radius: 12px; text-align: center;
  border: 1px solid rgba(160, 225, 255, 0.25); background: rgba(0, 0, 0, 0.25);
  color: var(--ink); font: 700 22px 'Outfit', sans-serif; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper output { min-width: 64px; text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel-total { margin-top: 12px; }
.panel-card footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; }
.panel-card footer .cta { min-height: 56px; font-size: 20px; padding: 12px 30px; }

/* ---------- iPhone e celulares ---------- */

/* Celular em pé */
@media (max-width: 560px) and (orientation: portrait) {
  :root { --pad: 12px; --gap: 8px; --chrome: calc(24px + 76px + env(safe-area-inset-top) + env(safe-area-inset-bottom)); }
  .hud { height: 52px; }
  .hud-logo { width: 40px; height: 40px; }
  .hud-pairs { padding: 6px 14px; gap: 6px; }
  .hud-pairs span { font-size: 26px; }
  .hud-pairs small { font-size: 14px; }
  .hud-timer { font-size: 36px; }
  .face { border-radius: 14px; }
  .card { border-radius: 14px; }
  .face .label { font-size: 11px; bottom: 6%; left: 5%; right: 5%; }
  .lettering { width: 88vw; }
  .start-body { margin-top: 0; }
  .prize-strip { gap: 8px; }
  .prize-strip li { width: 50px; }
  .prize-strip img, .prize-strip .no-art { border-radius: 12px; }
  .prize-strip span { font-size: 10.5px; }
  .cta { min-height: 56px; }
  .stage { --reel: min(28dvh, 52vw); }
  .panel-card { padding: 20px 16px; }
  .panel-stock li { grid-template-columns: 40px 1fr auto; gap: 10px; padding: 8px; }
  .panel-stock img, .panel-stock .no-art { width: 40px; height: 40px; }
  .panel-stock .name { font-size: 15px; }
  .stepper button { width: 44px; height: 44px; font-size: 22px; }
  .stepper input { width: 54px; height: 44px; font-size: 19px; }
}

/* Celular deitado: 6 colunas x 2 linhas e telas lado a lado */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --cols: 6; --rows: 2; --pad: 10px; --gap: 8px;
          --chrome: calc(20px + 62px + env(safe-area-inset-top) + env(safe-area-inset-bottom)); }
  #game { gap: 6px; }
  .hud { height: 44px; }
  .hud-logo { width: 36px; height: 36px; }
  .hud-pairs { padding: 4px 12px; }
  .hud-pairs span { font-size: 24px; }
  .hud-pairs small { font-size: 13px; }
  .hud-timer { font-size: 32px; }
  .face .label { font-size: 11px; }
  .logo-hold { width: 56px; height: 56px; }
  .logo-hold img { width: 48px; height: 48px; }
  .hold-ring { width: 56px; height: 56px; }

  .start-body {
    display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 28px; row-gap: 8px;
    grid-template-areas: 'art kicker' 'art pitch' 'art cta' 'art strip';
    margin-top: 0; text-align: left; justify-items: start;
  }
  .lettering { grid-area: art; width: auto; height: min(62dvh, 260px); }
  .start-body .kicker { grid-area: kicker; }
  .start-body .pitch { grid-area: pitch; font-size: 17px; max-width: 34ch; }
  #play { grid-area: cta; margin-top: 2px; }
  .prize-strip { grid-area: strip; justify-content: flex-start; margin-top: 4px; gap: 8px; }
  .prize-strip li { width: 46px; }
  .prize-strip span { display: none; }
  .cta { min-height: 50px; font-size: 19px; padding: 10px 28px; }

  .win-body {
    display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 28px; row-gap: 6px;
    grid-template-areas: 'stage kicker' 'stage title' 'stage sub' 'stage btn';
    justify-items: start; text-align: left;
  }
  .win-body .kicker { grid-area: kicker; align-self: end; }
  .stage { grid-area: stage; --reel: 50dvh; width: calc(var(--reel) * 1.6); }
  .win-title { grid-area: title; font-size: 38px; }
  .win-sub { grid-area: sub; font-size: 16px; max-width: 26ch; }
  #again { grid-area: btn; align-self: start; }
  .center-card { margin-top: 0; padding: 20px 36px; gap: 8px; }
  .big { font-size: 56px; }
  .forest { height: 50dvh; }
}

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