:root {
  --flag-red: #e30a17;
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, 0.78);
  --accent: #ffffff;
  --accent-2: #ffd23f;
  --line: rgba(255, 255, 255, 0.28);
  --ok: #b8ffd4;
  --font-display: "Syne", sans-serif;
  --font-body: "Manrope", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--flag-red);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: var(--flag-red);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 800'%3E%3Crect width='1200' height='800' fill='%23E30A17'/%3E%3Ccircle cx='430' cy='400' r='200' fill='%23fff'/%3E%3Ccircle cx='490' cy='400' r='160' fill='%23E30A17'/%3E%3Cpolygon fill='%23fff' points='620,400 635,355 655,355 640,325 655,295 620,315 585,295 600,325 585,355 605,355'/%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.side-art {
  position: fixed;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.side-art img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.45));
}

.side-art--left {
  left: max(0px, env(safe-area-inset-left));
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: clamp(110px, 28vw, 220px);
  opacity: 0.92;
}

.side-art--left img {
  transform: scaleX(-1);
}

.side-art--right {
  right: max(0px, env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: clamp(96px, 24vw, 190px);
  opacity: 0.95;
}

.side-art--right img {
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.15);
}

.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;
}

[hidden] {
  display: none !important;
}

/* —— Gate (username) —— */
.gate {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.gate__panel {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
}

.gate__brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  letter-spacing: -0.04em;
  line-height: 0.9;
  background: linear-gradient(120deg, var(--ink), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate__title {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
}

.gate__hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

#username {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #1a1a1a;
  text-shadow: none;
  font: inherit;
  font-size: 1.05rem;
  padding: 16px 16px;
  outline: none;
}

#username:focus {
  border-color: rgba(255, 77, 26, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 77, 26, 0.2);
}

.gate__submit {
  border: 0;
  border-radius: 14px;
  padding: 16px;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  color: #140800;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  cursor: pointer;
}

.gate__submit:active {
  transform: scale(0.98);
}

/* —— Main app —— */
.app {
  position: relative;
  z-index: 1;
  width: min(100%, 440px);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 8vw, 2.35rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

.hello {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.hello span {
  color: var(--ink);
  font-weight: 700;
}

.hero {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 24px;
  text-align: center;
  padding: 8px 0 12px;
}

.counter {
  margin: 0;
  max-width: 18ch;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.35rem, 5.6vw, 1.7rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.counter__num {
  display: inline-block;
  color: var(--accent-2);
  min-width: 2ch;
  transition: transform 0.18s ease;
}

.counter__num.is-bump {
  transform: scale(1.12);
}

.apoya-zone {
  position: relative;
  width: min(78vw, 300px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  z-index: 2;
}

.fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.fx-text {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  overflow: visible;
}

.fly-text {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1001;
  max-width: min(88vw, 320px);
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
  background: rgba(0, 0, 0, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  animation: fly-text 1.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.fly-text--hot {
  background: linear-gradient(135deg, #ff6b00, #ffd23f);
  color: #4a1200;
  text-shadow: none;
  border-color: #fff;
  font-size: clamp(1.1rem, 5vw, 1.4rem);
  box-shadow: 0 10px 32px rgba(255, 120, 0, 0.55);
}

.combo {
  position: absolute;
  top: -6px;
  right: -4px;
  z-index: 5;
  display: grid;
  gap: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff6b00, #ffd23f);
  color: #4a1200;
  text-shadow: none;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transform: scale(0.8);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.combo.is-visible {
  transform: scale(1);
  opacity: 1;
  animation: combo-pop 0.35s ease;
}

.combo__label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.combo__num {
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.apoya {
  position: relative;
  z-index: 2;
  width: min(72vw, 260px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #6b0a00;
  background:
    radial-gradient(circle at 32% 24%, #ffffff 0%, #fff8dc 18%, transparent 42%),
    radial-gradient(circle at 70% 78%, #c41e00 0%, #8b0000 55%, #5c0000 100%),
    linear-gradient(145deg, #ffd23f 0%, #ff8c00 42%, #e30a17 100%);
  box-shadow:
    0 0 0 6px rgba(255, 255, 255, 0.22),
    0 0 0 12px rgba(255, 210, 63, 0.18),
    0 22px 50px rgba(0, 0, 0, 0.42),
    inset 0 10px 20px rgba(255, 255, 255, 0.45),
    inset 0 -14px 28px rgba(0, 0, 0, 0.28);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  isolation: isolate;
  transition: transform 0.08s ease;
  animation: floaty 3.2s ease-in-out infinite;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  will-change: transform;
}

.apoya__glow {
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 63, 0.55) 0%, transparent 68%);
  opacity: 0.45;
  z-index: -1;
}

.apoya__ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  pointer-events: none;
  opacity: 0.7;
}

.apoya__ring--1 {
  animation: none;
}

.apoya__ring--2 {
  inset: -22px;
  border-color: rgba(255, 210, 63, 0.28);
  animation: none;
}

.apoya__shine {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 255, 255, 0) 42%
  );
  pointer-events: none;
}

.apoya__label {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  letter-spacing: 0.08em;
  line-height: 1.05;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.apoya__line {
  display: block;
}

.apoya.is-pressed {
  transform: scale(0.9);
  animation: none;
  filter: brightness(1.08);
}

.apoya.is-hot {
  box-shadow:
    0 0 0 6px rgba(255, 255, 255, 0.28),
    0 0 30px rgba(255, 140, 0, 0.55),
    0 22px 50px rgba(0, 0, 0, 0.42),
    inset 0 10px 20px rgba(255, 255, 255, 0.5),
    inset 0 -14px 28px rgba(0, 0, 0, 0.28);
}

.apoya.is-fire {
  animation: none;
  box-shadow:
    0 0 0 8px rgba(255, 210, 63, 0.35),
    0 0 45px rgba(255, 77, 0, 0.75),
    0 22px 50px rgba(0, 0, 0, 0.42),
    inset 0 10px 20px rgba(255, 255, 255, 0.55),
    inset 0 -14px 28px rgba(0, 0, 0, 0.28);
}

.apoya.is-fire .apoya__glow {
  opacity: 0.85;
}

.apoya:disabled {
  opacity: 0.7;
  cursor: wait;
}

.status {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.is-ok {
  color: var(--ok);
}

.board {
  border-top: 1px solid var(--line);
  padding: 16px 14px 8px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
}

.board__title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.board__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.board__row {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}

.board__row:last-child {
  border-bottom: 0;
}

.board__rank {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--accent-2);
}

.board__name {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board__score {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.board__empty {
  color: var(--muted);
  padding: 8px 0;
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.96);
    opacity: 0.75;
  }
  70% {
    transform: scale(1.12);
    opacity: 0;
  }
  100% {
    transform: scale(1.12);
    opacity: 0;
  }
}

@keyframes glow-pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.96);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.04);
  }
}

@keyframes glow-pulse-fast {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes fly-text {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
  }
  10% {
    transform: translate(-50%, calc(-50% - 20px)) scale(1.15);
    opacity: 1;
  }
  35% {
    transform: translate(calc(-50% + var(--drift, 0px)), calc(-50% - 90px)) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--drift, 0px)), calc(-50% + 130px)) scale(0.85);
    opacity: 0;
  }
}

@keyframes fx-ripple {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(12);
    opacity: 0;
  }
}

@keyframes spark-burst {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--tx, 0px)), calc(-50% + var(--ty, 0px))) scale(0.2);
    opacity: 0;
  }
}

@keyframes bolt-fade {
  0% {
    opacity: 1;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes screen-flash {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes screen-flash-max {
  0% {
    opacity: 1;
  }
  35% {
    opacity: 0.55;
  }
  55% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
  }
}

@keyframes combo-pop {
  0% {
    transform: scale(0.6) rotate(-8deg);
  }
  60% {
    transform: scale(1.12) rotate(4deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateY(-4px) rotate(0deg);
  }
  25% {
    transform: translateY(-6px) rotate(-1.5deg);
  }
  75% {
    transform: translateY(-2px) rotate(1.5deg);
  }
}

@keyframes zone-juice {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 420px) {
  .side-art--left {
    width: clamp(88px, 24vw, 130px);
    opacity: 0.78;
  }

  .side-art--right {
    width: clamp(78px, 22vw, 120px);
    opacity: 0.82;
  }
}

@media (min-width: 720px) {
  .app {
    padding-top: 40px;
  }

  .hero {
    gap: 36px;
  }
}
