:root {
  --bg: #080c16;
  --panel: rgba(15, 23, 42, 0.94);
  --panel-2: rgba(30, 41, 59, 0.95);
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.18);
  --accent: #fbbf24;
  --accent-dark: #d97706;
  --danger: #fb7185;
  --success: #34d399;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, 0.18), transparent 26rem),
    radial-gradient(circle at 85% 12%, rgba(251, 191, 36, 0.12), transparent 24rem),
    linear-gradient(160deg, #080c16, #111827 55%, #060914);
  overflow-x: hidden;
}

button {
  font: inherit;
  touch-action: manipulation;
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  color: #111827;
  background: var(--accent);
  font-weight: 800;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 26px;
}

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

.brand h1 {
  margin: 0;
  font-size: clamp(15px, 3.7vw, 20px);
  letter-spacing: -0.02em;
}

.brand p {
  margin: 3px 0 0;
  max-width: 270px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-row {
  display: flex;
  gap: 6px;
}

.topbar-actions {
  display: flex;
  gap: 7px;
  align-items: stretch;
}

.icon-button,
.hud-control {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
}

.icon-button {
  width: 42px;
  border-radius: 12px;
  font-size: 17px;
}

.stat {
  min-width: 62px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  text-align: center;
}

.stat span,
.hud-pill span,
.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.game-card {
  position: relative;
  width: min(100%, calc((100dvh - 116px) * 0.5625), 540px);
  min-width: min(100%, 280px);
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 24px;
  background: #172033;
  box-shadow: var(--shadow);
  aspect-ratio: 9 / 16;
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, rgba(3, 7, 18, 0.45), rgba(3, 7, 18, 0.82));
  backdrop-filter: blur(5px);
}

.panel {
  width: min(100%, 480px);
  max-height: 92%;
  overflow-y: auto;
  padding: clamp(20px, 5vw, 32px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.overlay,
.panel {
  touch-action: pan-y;
}

.intro-panel,
.result-panel {
  text-align: center;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.panel h2 {
  margin-bottom: 12px;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.panel p {
  color: #cbd5e1;
  font-size: 14px;
  line-height: 1.55;
}

.controls-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 18px 0;
}

.controls-note span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-size: 10px;
}

.legend {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 15px 0 17px;
}

.legend > div {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.legend > div.danger {
  border-color: rgba(251, 113, 133, 0.2);
}

.legend > div.reward {
  border-color: rgba(52, 211, 153, 0.2);
}

.legend span {
  font-size: 22px;
}

.legend strong {
  font-size: 9px;
}

.legend small {
  color: var(--muted);
  font-size: 7px;
}

.primary-button,
.secondary-button,
.ghost-button {
  width: 100%;
  min-height: 48px;
  margin-top: 9px;
  border-radius: 14px;
  font-weight: 900;
  letter-spacing: 0.045em;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, border-color 140ms ease;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-row.compact {
  gap: 4px;
}

.button-row > button {
  min-width: 0;
}

.shop-button {
  border-color: rgba(52, 211, 153, 0.28);
  color: #a7f3d0;
  background: rgba(6, 78, 59, 0.66);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active {
  transform: translateY(1px) scale(0.995);
}

button:focus-visible,
canvas:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid #fef3c7;
  outline-offset: 3px;
}

.primary-button {
  border: 1px solid #fde68a;
  color: #111827;
  background: linear-gradient(180deg, #fde68a, var(--accent));
}

.secondary-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  background: #1e293b;
}

.ghost-button {
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
}

.hud {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  pointer-events: none;
}

.hud-pill {
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(3, 7, 18, 0.74);
  backdrop-filter: blur(8px);
}

.hud-pill strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.hud-pill.power {
  margin-left: auto;
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(6, 78, 59, 0.8);
}

.hud-control {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  margin-left: auto;
  border-color: rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(3, 7, 18, 0.82);
  font-size: 14px;
  font-weight: 900;
  pointer-events: auto;
}

.hud-pill.power + .hud-control {
  margin-left: 0;
}

.pause-panel {
  max-width: 390px;
  text-align: center;
}

.pause-panel h2 {
  margin-bottom: 8px;
}

.result-score {
  display: grid;
  margin: 18px auto;
}

.result-score strong {
  color: var(--accent);
  font-size: clamp(58px, 15vw, 88px);
  line-height: 0.9;
  letter-spacing: -0.06em;
}

.result-score span {
  margin-top: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.15em;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 6px;
}

.result-grid > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}

.result-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.unlock-progress {
  display: grid;
  gap: 6px;
  margin: 13px 0 5px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.025);
  font-size: 10px;
  text-align: left;
}

.unlock-progress-bar {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.17);
}

.unlock-progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
}

.panel-heading {
  display: flex;
  gap: 16px;
  align-items: start;
  justify-content: space-between;
}

.panel-heading h2 {
  margin-bottom: 0;
  font-size: 31px;
}

.close-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  font-size: 24px;
  cursor: pointer;
}

.locker-copy {
  margin: 12px 0 16px;
}

.shop-copy {
  margin: 12px 0 16px;
}

.coin-pack-grid {
  display: grid;
  gap: 9px;
}

.coin-pack-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
}

.coin-pack-card.popular {
  border-color: rgba(251, 191, 36, 0.43);
  background: rgba(251, 191, 36, 0.065);
}

.coin-pack-meta {
  min-width: 0;
}

.coin-pack-meta span,
.coin-pack-meta strong,
.coin-pack-meta small {
  display: block;
}

.coin-pack-meta span {
  color: var(--accent);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.coin-pack-meta strong {
  margin-top: 4px;
  font-size: 15px;
}

.coin-pack-meta small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.buy-button {
  min-width: 82px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: 11px;
  color: #111827;
  background: linear-gradient(180deg, #fde68a, var(--accent));
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.buy-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.checkout-note {
  margin: 13px 2px 0 !important;
  color: var(--muted) !important;
  font-size: 9px !important;
  text-align: center;
}

.payment-notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 12px;
  color: #fde68a;
  background: rgba(120, 53, 15, 0.2);
  font-size: 10px;
  line-height: 1.45;
}

.payment-notice.success {
  border-color: rgba(52, 211, 153, 0.34);
  color: #a7f3d0;
  background: rgba(6, 95, 70, 0.22);
}

.character-grid {
  display: grid;
  gap: 9px;
}

.character-card {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
}

.character-card.selected {
  border-color: rgba(251, 191, 36, 0.52);
  background: rgba(251, 191, 36, 0.07);
}

.character-avatar {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 14px;
  background: #0f172a;
  font-size: 29px;
}

.character-meta strong,
.character-meta span {
  display: block;
}

.character-meta strong {
  font-size: 13px;
}

.character-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.character-action {
  min-width: 74px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: #1e293b;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.character-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.toast {
  position: absolute;
  z-index: 30;
  right: 14px;
  bottom: 14px;
  left: 14px;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 13px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  text-align: center;
}

footer {
  padding: 13px 4px 0;
  text-align: center;
}

footer p {
  margin: 0;
  color: #64748b;
  font-size: 10px;
}

.is-hidden {
  display: none !important;
}

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

@media (max-width: 440px) {
  .app-shell {
    padding-right: 8px;
    padding-left: 8px;
  }

  .topbar {
    padding: 0 2px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .stat {
    min-width: 52px;
    padding: 6px;
  }

  .icon-button {
    width: 38px;
  }

  .overlay {
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

.challenge-card {
  display: grid;
  gap: 4px;
  margin: 17px 0 4px;
  padding: 13px 15px;
  border: 1px solid rgba(251, 191, 36, 0.26);
  border-radius: 15px;
  background: rgba(251, 191, 36, 0.07);
  text-align: left;
}

.challenge-card span,
.challenge-card small {
  color: var(--muted);
}

.challenge-card span {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.challenge-card strong {
  color: #fde68a;
  font-size: 15px;
}

.challenge-card small {
  font-size: 10px;
  line-height: 1.4;
}

.hud-pill.combo {
  border-color: rgba(251, 191, 36, 0.38);
  background: rgba(120, 53, 15, 0.82);
}

.result-reason {
  display: inline-block;
  margin: 0 auto 4px !important;
  padding: 6px 10px;
  border: 1px solid rgba(251, 113, 133, 0.24);
  border-radius: 999px;
  color: #fecdd3 !important;
  background: rgba(136, 19, 55, 0.18);
  font-size: 10px !important;
  font-weight: 800;
}

.challenge-result {
  margin: 12px 0 2px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.challenge-result.win {
  border: 1px solid rgba(52, 211, 153, 0.34);
  color: #a7f3d0;
  background: rgba(6, 95, 70, 0.22);
}

.challenge-result.lose {
  border: 1px solid rgba(251, 191, 36, 0.28);
  color: #fde68a;
  background: rgba(120, 53, 15, 0.2);
}

.result-grid {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 390px) {
  .hud {
    gap: 5px;
  }

  .hud-pill {
    padding: 7px 8px;
  }

  .hud-pill span {
    font-size: 7px;
  }

  .hud-pill strong {
    font-size: 11px;
  }

  .brand p {
    max-width: 150px;
  }

  .legend {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-height: 700px) and (min-width: 560px) {
  footer {
    display: none;
  }
}
