:root {
  --bg-top: #ffb55a;
  --bg-bottom: #b75a18;
  --panel: #fff6ea;
  --panel-border: #000;
  --accent: #2ecc71;
  --accent-dark: #1b9e50;
  --text: #1b140b;
  --muted: #6b5b4b;
  --coin: #ffcc00;
  --shadow: rgba(0, 0, 0, .25);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --scroll-fade: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  color: var(--text);
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-bottom: var(--safe-bottom);
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='256' height='256' viewBox='0 0 256 256' fill='none'><path d='M0 0H256V256H0V0Z' fill='%23B97222' fill-opacity='0.97'/><mask id='mask0_1245_5442' style='mask-type:alpha' maskUnits='userSpaceOnUse' x='0' y='0' width='256' height='256'><path d='M0 0H256V256H0V0Z' fill='url(%23paint0_radial_1245_5442)'/></mask><g mask='url(%23mask0_1245_5442)'><path d='M-0.314453 0H256.001V256H-0.314453V0Z' fill='url(%23pattern0_1245_5442)'/></g><defs><radialGradient id='paint0_radial_1245_5442' cx='0' cy='0' r='1' gradientUnits='userSpaceOnUse' gradientTransform='translate(128 128) rotate(90) scale(128)'><stop offset='0.531912' stop-color='%23801EAF' stop-opacity='0'/><stop offset='1' stop-color='%23F5C4E1' stop-opacity='0.33'/></radialGradient><pattern id='pattern0_1245_5442' patternUnits='userSpaceOnUse' viewBox='337 -323 24 24' width='0.79704794037080162%25' height='0.79802954569458961%25' x='127.136' y='126.979' patternContentUnits='objectBoundingBox'><path d='M344 -311C344 -313.761 346.239 -316 349 -316C351.761 -316 354 -313.761 354 -311C354 -308.239 351.761 -306 349 -306C346.239 -306 344 -308.239 344 -311Z' fill='%23510D72'/></pattern></defs></svg>") center / cover no-repeat;
}

/* Title */
#title-bar {
  padding: 8px 12px 0;
  text-align: center;
}

.title-text {
  color: #FFE57A;
  text-shadow: 0 4px 0 #0006;
  -webkit-text-stroke: 6px #000;
  font-family: 'Jersey 20', sans-serif;
  font-size: 40px;
  line-height: 1;
  margin: 4px 0 0;
}

.title-text.huge {
  font-size: clamp(28px, 4vw + 16px, 56px);
}

/* Game title with outline/fill (custom colors and metrics) */
.game-title {
  position: relative;
  text-align: center;
  margin: 4px 0 0;
  font-family: "Avenir Next World", 'AvenirNextWorld-Bold', Arial, sans-serif;
  font-size: 29.796px;
  font-style: normal;
  font-weight: 950;
  line-height: 100%;
}

.title-outline {
  text-shadow: 0 3px 0 #000;
}

.game-title .title-outline {
  position: absolute;
  inset: 0;
  z-index: 0;
  color: transparent;
  -webkit-text-stroke-width: 3px;
  -webkit-text-stroke-color: #000;
}

.game-title .title-fill {
  position: relative;
  z-index: 1;
  display: block;
  color: #F6D74B;
  text-shadow: 0 0.931px 0 #000;
}

/* Inner highlight layer (white) clipped to the text */
.game-title .title-inner {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  color: transparent;
  /* White highlight at the top, fading out */
  background: linear-gradient(to bottom,
      rgba(255, 255, 255, 1) 0%,
      rgba(255, 255, 255, 1) 25%,
      rgba(255, 255, 255, 0) 26%,
      rgba(255, 255, 255, 0.00) 75%);
  -webkit-background-clip: text;
  background-clip: text;
}

/* Top gameplay area */
#top-area {
  position: relative;
  flex: 1 0 52vh;
  /* occupies roughly the top half */
  min-height: 320px;
  display: grid;
  place-items: center;
  padding: 8px 12px;
}

/* Decorative image overlay behind the clickable object (above background) */
#top-area::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("https://firebasestorage.googleapis.com/v0/b/sticky-20bca.appspot.com/o/sgm-asset%2Ff296cb32-cf57-4851-a819-849132b2e87b%2F79029efd-ff22-4c70-8848-34ccb8ecd594.png?alt=media&token=8536fe0f-e0d3-4e64-9101-6b61481a38b1") center / contain no-repeat;
  mix-blend-mode: plus-lighter;
  pointer-events: none;
  z-index: 0;
  scale: 300%;
}

#game {
  width: 100%;
  height: auto;
  max-height: 50vh;
  aspect-ratio: 1 / 1;
  display: block;
  outline: none;
  position: relative;
  z-index: 1;
  /* ensure clickable object stays above the overlay */
}

/* Overlay inside top-area (coins) */
#top-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding-bottom: 14px;
  pointer-events: none;
  z-index: 2;
  /* keep coins/overlay UI above the clickable object */
}

#coin-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: clamp(18px, 3.5vw + 6px, 28px);
}

.coin-icon {
  width: 1.2em;
  height: 1.2em;
  display: inline-block;
  object-fit: contain;
  vertical-align: middle;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .25));
}

/* Bottom upgrades section */
#upgrade-section {
  flex: 0 0 48vh;
  min-height: 320px;
  display: grid;
  grid-template-rows: 1fr;
  padding-bottom: var(--safe-bottom);
}

#upgrade-header {
  position: relative;
  text-align: center;
  margin: 8px 0 6px;
  padding: 6px 0 0;
  font-family: 'Jersey 20', sans-serif;
  font-size: 28px;
  color: #15a158;
  text-shadow: 0 3px 0 #0003;
}

#upgrade-list {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 12px 16px;
  display: flex;
  flex-direction: column;
  /* Drag-scroll UX */
  cursor: grab;
  overscroll-behavior: contain;
  touch-action: pan-y;

  /* Hide scrollbar cross-browser */
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE/Edge */
  scrollbar-color: transparent transparent;
  /* Firefox (extra safety) */

  /* Fade mask at top and bottom for smooth transition */
  -webkit-mask-image: linear-gradient(to bottom,
      rgba(0, 0, 0, 0) 0,
      rgba(0, 0, 0, 1) var(--scroll-fade),
      rgba(0, 0, 0, 1) calc(100% - var(--scroll-fade)),
      rgba(0, 0, 0, 0) 100%);
  mask-image: linear-gradient(to bottom,
      rgba(0, 0, 0, 0) 0,
      rgba(0, 0, 0, 1) var(--scroll-fade),
      rgba(0, 0, 0, 1) calc(100% - var(--scroll-fade)),
      rgba(0, 0, 0, 0) 100%);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  mask-mode: alpha;
}

/* Drag scroll helpers */
body.drag-scroll {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

#upgrade-list.dragging {
  cursor: grabbing;
}

/* Upgrade card */
.upgrade-card {
  border-radius: 8px;
  border: 3px solid #000;
  background: #F9F4D7;
  box-shadow: 0 -5px 0 0 rgba(0, 0, 0, 0.25) inset, 0 6px 0 0 #FFF inset, 0 2px 0 0 #000;
  padding: 10px;
  min-height: 130px;
  display: grid;
  grid-template-columns: 112px 1fr auto;
  /* icon | content | level */
  grid-template-rows: auto auto auto;
  /* title | desc | actions */
  gap: 6px 10px;
  align-items: center;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease;
}

.upgrade-card:not(.disabled):active,
.upgrade-card.pressed {
  transform: translateY(2px);
  box-shadow: 0 -3px 0 0 rgba(0, 0, 0, 0.2) inset, 0 3px 0 0 #FFF inset, 0 1px 0 0 #000;
}

.upgrade-card.disabled {
  opacity: .7;
  filter: saturate(60%);
  cursor: not-allowed;
}

/* Left icon inside card */
.upgrade-icon {
  grid-column: 1;
  grid-row: 1 / 4;
  /* span all rows */
  display: grid;
  place-items: center;
  width: 100px;
  height: 100px;
}

.upgrade-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: auto;
}

.upgrade-title {
  position: relative;
  margin: 0;
  text-align: center;
  line-height: 100%;
  font-family: 'AvenirNextWorld-Bold', 'Avenir Next World', Arial, sans-serif;
  font-size: 24px;
  font-style: normal;
  font-weight: 950;
}

/* Center the title across the whole card, reserving space for icon (left) and level (right) */
.upgrade-card .upgrade-title {
  grid-column: 1 / -1;
  /* span all card columns */
  grid-row: 1;
  padding-left: calc(112px + 10px);
  /* icon column (112px) + grid gap (10px) */
  padding-right: 80px;
  /* reserve space for the level column */
  left: -30px;
}

.upgrade-title .title-outline {
  position: absolute;
  inset: 0;
  z-index: 0;
  color: transparent;
  -webkit-text-stroke-width: 4px;
  -webkit-text-stroke-color: #000;
  display: block;
  box-sizing: border-box;
  padding-left: inherit;
  padding-right: inherit;
  text-align: inherit;
}

.upgrade-title .title-fill {
  position: relative;
  z-index: 1;
  display: block;
  color: #FFF;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

/* Coin count styled like upgrade-title */
#coin-count.title-like {
  position: relative;
  display: inline-block;
  line-height: 1;
  font-family: 'AvenirNextWorld-Bold', 'Avenir Next World', Arial, sans-serif;
}

#coin-count.title-like .title-outline {
  position: absolute;
  inset: 0;
  z-index: 0;
  color: transparent;
  -webkit-text-stroke-width: 4px;
  -webkit-text-stroke-color: #000;
}

#coin-count.title-like .title-fill {
  position: relative;
  z-index: 1;
  display: block;
  color: #FFF;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.upgrade-level {
  justify-self: end;
  font-weight: 800;
  color: #444;
  font-size: 14px;
  align-self: center;
  grid-column: 3;
  grid-row: 1;
  min-width: 80px;
  /* keeps a consistent right column so the centered title stays visually centered */
}

.upgrade-desc {
  grid-column: 2 / 4;
  margin: 0;
  color: #684712;
  font-family: 'AvenirNextWorld-Bold', 'Avenir Next World', Arial, sans-serif;
  font-size: 18x;
  font-style: normal;
  font-weight: 700;
  line-height: 100%;
}

.upgrade-actions {
  grid-column: 2 / 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Prestige progress bar */
.upgrade-actions .progress {
  flex: 1 1 auto;
  height: 14px;
  background: rgba(104, 71, 18, 0.15);
  border-radius: 6px;
  border: 3px solid #000;
  box-shadow: 0 -2px 0 0 rgba(0, 0, 0, 0.2) inset, 0 2px 0 0 #FFF inset, 0 1px 0 0 #000;
  overflow: hidden;
  min-width: 140px;
}

.upgrade-actions .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(#F6D74B, #E4BE1F);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
  transition: width .1s linear;
}

.upgrade-actions .ready-count {
  margin-left: 8px;
  padding: 4px 8px;
  color: #684712;
  font-family: 'AvenirNextWorld-Bold', 'Avenir Next World', Arial, sans-serif;
  font-weight: 900;
  line-height: 1;
  min-width: 36px;
  text-align: center;
}

.cost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(104, 71, 18, 0.15);
  border-radius: 5px;
  padding: 4px 8px;
  color: #684712;
  text-align: center;
  font-family: 'AvenirNextWorld-Bold', 'Avenir Next World', Arial, sans-serif;
  font-size: 18px;
  font-style: normal;
  font-weight: 700;
  line-height: 100%;
}

.cost .coin {
  width: 20px;
  height: 20px;
  background-image: url("https://firebasestorage.googleapis.com/v0/b/sticky-20bca.appspot.com/o/sgm-asset%2Ffab98d7c-f44b-41d2-88e0-658d79584880%2F9b023df0-5288-4724-a640-7d28d93fe6c7.png?alt=media&token=35ab5496-6e75-4b78-8ec5-fa0bc192a836");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  image-rendering: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.buy-btn {
  cursor: pointer;
  user-select: none;
  padding: 8px 14px;
  border-radius: 10px;
  border: 3px solid #000;
  background: linear-gradient(#38d07a, #19b35d);
  color: #083b21;
  font-weight: 900;
  font-size: 16px;
  box-shadow:
    0 4px 0 #0004,
    0 4px 0 #78e5aa inset,
    0 -4px 0 #12884a inset;
  transition: transform .06s ease;
}

.buy-btn:active {
  transform: translateY(-2px);
}

.buy-btn.disabled {
  background: linear-gradient(#c9c9c9, #a5a5a5);
  color: #555;
  box-shadow:
    0 4px 0 #0002,
    0 4px 0 #e8e8e8 inset,
    0 -4px 0 #777 inset;
  cursor: not-allowed;
}

/* Scrollbar hidden */
#upgrade-list::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none;
  background: transparent;
}

/* Upgrades list header (scrolls with list) */
.upgrade-list-header {
  position: relative;
  width: 100%;
  bottom: -2px;
}

.upgrade-list-header-svg {
  display: block;
  margin: 0 auto;
  width: clamp(160px, 60%, 280px);
  height: auto;
  pointer-events: none;
}

.upgrade-list-header-title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  z-index: 1;
  font-family: 'Jersey 20', sans-serif;
  font-size: 28px;
  color: #FFF;
  text-shadow: 0 3px 0 #0003;
  line-height: 1;
}

/* Small screens adjustments */
@media (max-width: 420px) {
  .upgrade-title {
    font-size: 20px;
  }

  .upgrade-desc {
    font-size: 13px;
  }

  .buy-btn {
    font-size: 15px;
  }
}

/* Avenir Next World font faces (shared CDN) */
@font-face {
  font-family: 'AvenirNextWorld-Medium';
  src: url('https://firebasestorage.googleapis.com/v0/b/sticky-20bca.appspot.com/o/fonts%2FAvenirNextWorld-Medium.otf?alt=media&token=6d0c0700-529c-45a3-bfd7-dc79b07030cd') format('opentype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'AvenirNextWorld-Bold';
  src: url('https://firebasestorage.googleapis.com/v0/b/sticky-20bca.appspot.com/o/fonts%2FAvenirNextWorld-Bold.otf?alt=media&token=8d06a955-d494-4533-b00f-f419be3a1781') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* Loading screen (reference: merge-drop) */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 1);
  z-index: 2000;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  width: min(70vw, 420px);
}

.loading-bar {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  width: 0%;
  background: #22d3ee;
  transition: width 0.4s ease;
}

.loading-text {
  color: #fff;
  text-align: center;
  margin-top: 8px;
  font-weight: 800;
  text-shadow: 0 2px 0 #000;
}

/* Reset-save button (top-right) */
.hud-reset-btn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 2500;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  width: auto;
  height: auto;
  display: block;
  line-height: 0;
  cursor: pointer;
}

.hud-reset-btn:active {
  transform: none;
}

.hud-reset-btn img {
  width: 44px;
  height: 44px;
  display: block;
  pointer-events: none;
  image-rendering: auto;
  transition: transform .06s ease, filter .06s ease;
}

.hud-reset-btn:active img {
  transform: scale(0.92);
  filter: brightness(0.92);
}

/* Confirm reset overlay */
.confirm-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2100;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.confirm-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.confirm-dialog {
  background: #F9F4D7;
  border: 3px solid #000;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 -5px 0 rgba(0, 0, 0, 0.2) inset, 0 6px 0 #FFF inset, 0 2px 0 #000;
  padding: 16px;
  width: min(90vw, 360px);
  max-width: 420px;
}

.confirm-title {
  margin: 0 0 6px 0;
  font-family: 'AvenirNextWorld-Bold', Arial, sans-serif;
  font-weight: 950;
  font-size: 22px;
  text-align: center;
}

.confirm-text {
  margin: 0 0 12px 0;
  color: #684712;
  font-family: 'AvenirNextWorld-Bold', Arial, sans-serif;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.confirm-btn {
  appearance: none;
  border-radius: 10px;
  border: 3px solid #000;
  padding: 10px 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 #0004, 0 2px 0 #FFF inset, 0 -4px 0 #000 inset;
}

.confirm-btn.cancel {
  background: linear-gradient(#c9c9c9, #a5a5a5);
  color: #333;
}

.confirm-btn.danger {
  background: linear-gradient(#ff6b6b, #e03e3e);
  color: #2b0000;
}

.confirm-btn:active {
  transform: translateY(1px);
  box-shadow: 0 3px 0 #0003, 0 3px 0 #FFF inset, 0 -3px 0 #000 inset;
}
