:root {
  --bg: #1a140f;
  --surface: #2a2118;
  --surface-2: #3a2e22;
  --ink: #f2e6d4;
  --muted: #b8a38a;
  --primary: #c47a3a;
  --primary-ink: #1a140f;
  --accent: #6b8f4e;
  --demon: #a33c2a;
  --coin: #d4a017;
  --energy: #5aa8c4;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --sticky-bottom: 72px;
  --sticky-right: 0px;
  --font-display: "Russo One", system-ui, sans-serif;
  --font-body: "Manrope", system-ui, sans-serif;
}

@media (min-width: 900px) {
  :root {
    --sticky-bottom: 0px;
    --sticky-right: 120px;
  }
}

@media (max-width: 899px) {
  :root {
    --sticky-bottom: 72px;
    --sticky-right: 0px;
  }
}

@media (max-width: 899px) and (orientation: landscape) {
  :root {
    --sticky-bottom: 56px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: calc(var(--safe-t));
  left: calc(var(--safe-l));
  right: calc(var(--sticky-right) + var(--safe-r));
  bottom: calc(var(--sticky-bottom) + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.hidden[hidden],
.hidden {
  display: none !important;
}

/* Boot */
.screen--boot {
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(ellipse at 50% 30%, #3a2a1a 0%, var(--bg) 70%);
}

.boot__title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  margin: 0;
}

.boot__bar {
  width: min(220px, 60vw);
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
}

.boot__bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--coin));
  transition: width 0.2s ease;
}

/* Menu */
.screen--menu {
  justify-content: flex-end;
  padding: 24px 20px 28px;
  background: #0e0a08;
}

.menu__bg {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat url("../assets/bg/street.png");
  opacity: 0.55;
  filter: saturate(0.85) brightness(0.75);
}

.menu__header,
.menu__actions {
  position: relative;
  z-index: 1;
}

.menu__eyebrow {
  margin: 0 0 6px;
  color: var(--coin);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu__title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  line-height: 1.15;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

.menu__tagline {
  margin: 0 0 22px;
  color: var(--muted);
  max-width: 28ch;
  line-height: 1.4;
}

.menu__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, 100%);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface-2);
}

.btn--primary {
  background: linear-gradient(180deg, #d4893f, var(--primary));
  color: var(--primary-ink);
}

.btn--ghost {
  background: rgba(42, 33, 24, 0.85);
  border: 1px solid rgba(242, 230, 212, 0.18);
}

.btn--ad {
  background: linear-gradient(180deg, #4a6b3a, var(--accent));
  color: #f5f5f0;
}

.btn--iap {
  background: linear-gradient(180deg, #8a5a28, #6a4218);
  color: var(--ink);
}

.btn:active {
  transform: scale(0.98);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(26, 20, 15, 0.65);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.icon-tv,
.icon-currency {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}

.icon-currency--fallback {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 800;
  color: var(--coin);
}

/* Game HUD */
.screen--game {
  background: #0e0a08;
  position: relative;
  height: 100%;
  min-height: 0;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 8px 10px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  background: linear-gradient(180deg, rgba(14, 10, 8, 0.55) 0%, rgba(14, 10, 8, 0.18) 55%, transparent 100%);
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud__stat,
.hud__level {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(42, 33, 24, 0.82);
  border-radius: 999px;
  padding: 4px 10px 4px 6px;
  min-height: 32px;
  backdrop-filter: blur(4px);
}

button.hud__stat {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: help;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
}

.hud-tip {
  position: absolute;
  z-index: 8;
  left: 12px;
  top: calc(100% + 6px);
  max-width: min(280px, calc(100% - 24px));
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(26, 20, 15, 0.96);
  border: 1px solid rgba(242, 230, 212, 0.2);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  button.hud__stat.tip-host:hover,
  button.hud__stat.tip-host:focus-visible {
    outline: 1px solid rgba(212, 160, 23, 0.55);
  }
}

.hud__icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.hud__value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.hud__label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.hud .icon-btn {
  margin-left: auto;
}

.hud #btnHudMenu {
  margin-left: 0;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.stage__bg {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  transition: background-image 0.35s ease;
}

.tap-hero {
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  padding: 0 0 4px;
  cursor: pointer;
  width: min(88vw, 420px);
  max-height: 78%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.tap-hero__img {
  width: 100%;
  max-height: min(62vh, 520px);
  object-fit: contain;
  object-position: bottom center;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55));
  transition: transform 0.08s ease;
}

.tap-hero.is-tap .tap-hero__img {
  transform: scale(0.96);
}

.tap-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.tap-float {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  color: var(--coin);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  animation: floatUp 0.7s ease-out forwards;
  font-size: 0.95rem;
}

.tap-float img {
  width: 18px;
  height: 18px;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-70px) scale(1.1);
  }
}

.boost-banner {
  position: absolute;
  top: auto;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(196, 122, 58, 0.92);
  color: #1a140f;
  font-weight: 800;
  font-size: 0.85rem;
}

.dock {
  z-index: 2;
  padding: 8px 12px 10px;
  background: linear-gradient(0deg, rgba(14, 10, 8, 0.94) 55%, rgba(14, 10, 8, 0.15));
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.upgrades {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: min(28vh, 220px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.upgrade {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 6px 10px;
  align-items: center;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid rgba(242, 230, 212, 0.12);
  border-radius: 12px;
  background: rgba(42, 33, 24, 0.9);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-body);
}

.upgrade.is-affordable {
  border-color: rgba(212, 160, 23, 0.55);
  box-shadow: 0 0 0 1px rgba(212, 160, 23, 0.2);
  animation: affordPulse 1.6s ease-in-out infinite;
}

@keyframes affordPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.015);
  }
}

.upgrade:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  animation: none;
}

.upgrade__icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  padding: 4px;
  border-radius: 12px;
  background: radial-gradient(circle at 40% 30%, #6b5340 0%, #2e241a 75%);
  box-shadow: inset 0 0 0 1px rgba(242, 230, 212, 0.12);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.upgrade__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.upgrade__top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.upgrade__name {
  font-weight: 700;
  font-size: 0.9rem;
}

.upgrade__desc {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.25;
}

.upgrade__meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  color: var(--coin);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.upgrade__meta img {
  width: 16px;
  height: 16px;
}

.upgrade__lvl {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.dock__income {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.ad-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.ad-row .btn {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.btn--ad-secondary {
  background: linear-gradient(180deg, #6a5230, #4a381e);
}

.btn--shop {
  background: linear-gradient(180deg, #d4a017, #a67812);
  color: #1a140f;
  position: relative;
}

.btn.is-pulse {
  animation: adPulse 1.2s ease-in-out infinite;
}

@keyframes adPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(107, 143, 78, 0.55);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(107, 143, 78, 0);
  }
}

.hud__xp {
  flex: 1 1 80px;
  min-width: 64px;
  max-width: 140px;
  height: 8px;
  border-radius: 999px;
  background: rgba(42, 33, 24, 0.9);
  overflow: hidden;
}

.hud__xp-bar {
  width: 100%;
  height: 100%;
}

.hud__xp-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--coin));
  transition: width 0.2s ease;
}

.icon-btn {
  position: relative;
}

.icon-btn__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e24a3b;
  box-shadow: 0 0 0 2px rgba(26, 20, 15, 0.9);
}

.shop-item--hot {
  border: 1px solid rgba(212, 160, 23, 0.55);
  background: linear-gradient(180deg, rgba(90, 60, 20, 0.55), rgba(42, 33, 24, 0.95));
}

.shop-hot {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--demon);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

/* Story */
.screen--story {
  background: #0a0705;
}

.story__bg {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  opacity: 0.7;
}

.story__char-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 38%;
  top: 8%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1;
  pointer-events: none;
}

.story__char {
  max-height: 100%;
  max-width: min(80vw, 420px);
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
}

.story__panel {
  position: relative;
  z-index: 2;
  margin-top: auto;
  padding: 18px 16px 16px;
  background: linear-gradient(180deg, rgba(26, 20, 15, 0.72), rgba(26, 20, 15, 0.96));
  border-top: 1px solid rgba(242, 230, 212, 0.12);
}

.story__title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.story__text {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
}

.story__choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story__choices .btn {
  justify-content: flex-start;
  background: rgba(58, 46, 34, 0.95);
  border: 1px solid rgba(242, 230, 212, 0.14);
}

/* Modals */
.screen--modal {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 6, 4, 0.72);
  z-index: 20;
}

.modal {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid rgba(242, 230, 212, 0.14);
  border-radius: 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 90%;
  overflow: auto;
}

.modal__icon {
  align-self: center;
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.modal__title {
  margin: 0;
  font-family: var(--font-display);
  text-align: center;
  font-size: 1.25rem;
}

.modal__text,
.modal__note {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.4;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-2);
}

.shop-item__icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.shop-item__name {
  margin: 0;
  font-weight: 700;
  font-size: 0.92rem;
}

.shop-item__desc {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.shop-item .btn {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.iap-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sticky-bottom) + var(--safe-b) + 18px);
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(42, 33, 24, 0.95);
  border: 1px solid rgba(242, 230, 212, 0.2);
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}

@media (min-width: 900px) {
  .menu__actions {
    width: 360px;
  }

  .screen--game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(320px, 30vw);
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    align-content: stretch;
  }

  .screen--game .hud {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 10px 14px;
    padding-right: calc(14px + var(--sticky-right));
  }

  .screen--game .stage {
    grid-column: 1;
    grid-row: 1;
    height: 100%;
    min-height: 0;
  }

  .screen--game .dock {
    grid-column: 2;
    grid-row: 1;
    height: 100%;
    align-self: stretch;
    justify-content: flex-end;
    max-width: 320px;
    width: 100%;
    box-sizing: border-box;
    padding: 52px 12px 12px;
    background: linear-gradient(90deg, rgba(14, 10, 8, 0.15), rgba(14, 10, 8, 0.94) 14%);
    gap: 6px;
    overflow: hidden;
  }

  .tap-hero {
    width: auto;
    height: min(92%, 820px);
    max-width: 95%;
    max-height: none;
    margin-bottom: 0;
  }

  .tap-hero__img {
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: none;
  }

  .dock__income {
    font-size: 0.72rem;
  }

  .ad-row {
    grid-template-columns: 1fr;
    max-width: 100%;
    gap: 5px;
  }

  .ad-row .btn {
    min-height: 38px;
    font-size: 0.74rem;
    padding: 6px 8px;
  }

  .upgrades {
    grid-template-columns: 1fr;
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  .upgrade {
    padding: 6px 7px;
    grid-template-columns: 40px 1fr;
  }

  .upgrade__icon {
    width: 36px;
    height: 36px;
  }

  .upgrade__name {
    font-size: 0.8rem;
  }

  .upgrade__desc {
    font-size: 0.66rem;
  }

  .story__char-wrap {
    bottom: 32%;
    justify-content: flex-start;
    padding-left: 8%;
  }

  .story__panel {
    max-width: 480px;
    margin-left: auto;
    margin-right: 4%;
    border-radius: 16px 16px 0 0;
  }
}

@media (max-width: 899px) {
  .screen--game {
    display: flex;
    flex-direction: column;
  }

  .screen--game .stage {
    padding-top: 44px;
    flex: 1 1 auto;
    min-height: 42vh;
  }

  .tap-hero {
    height: min(88%, 420px);
    width: auto;
    max-width: none;
    aspect-ratio: 3 / 4;
    max-height: 88%;
  }

  .tap-hero__img {
    height: 100%;
    width: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
    object-position: center top;
  }

  .dock {
    flex: 0 0 auto;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .dock__income {
    font-size: 0.72rem;
  }

  .ad-row {
    max-width: 100%;
    gap: 6px;
  }

  .ad-row .btn {
    min-height: 38px;
    font-size: 0.72rem;
    padding: 6px 8px;
  }

  .upgrades {
    max-height: min(22vh, 168px);
    gap: 5px;
  }

  .upgrade {
    padding: 6px 8px;
    grid-template-columns: 40px 1fr;
  }

  .upgrade__icon {
    width: 36px;
    height: 36px;
    padding: 2px;
  }

  .upgrade__name {
    font-size: 0.82rem;
  }

  .upgrade__desc {
    font-size: 0.68rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tap-float {
    animation: none;
    opacity: 0;
  }

  .tap-hero__img,
  .boot__bar span {
    transition: none;
  }
}
