/* Final mobile layout guard. Loaded after the legacy stylesheet on purpose. */
.utility-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 64px;
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 18px;
  background: rgba(244, 255, 238, 0.76);
  box-shadow: 0 12px 28px rgba(25, 105, 44, 0.14);
}

.utility-bar .help-button {
  position: static !important;
  right: auto !important;
  bottom: auto !important;
}

.utility-bar .treasure-button {
  position: relative !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 0;
  isolation: isolate;
  width: 72px;
  min-width: 72px;
  height: 56px;
}

.utility-bar .treasure-button::before {
  inset: 4px 7px 8px !important;
  width: auto !important;
  height: auto !important;
}

.utility-bar .treasure-glyph {
  width: 68px;
  height: 52px;
}

@media (max-width: 620px) {
  html {
    scroll-padding-top: 82px;
  }

  body {
    position: relative;
    isolation: isolate;
    background: linear-gradient(180deg, #73dcff 0%, #c9f7ef 48%, #62c95b 100%) !important;
    background-attachment: scroll !important;
    overscroll-behavior-x: none;
  }

  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    display: block;
    pointer-events: none;
    background:
      linear-gradient(180deg, rgba(25, 151, 207, 0.16) 0%, rgba(61, 195, 180, 0.4) 44%, rgba(24, 137, 72, 0.56) 100%),
      var(--game-bg-image) center center / cover no-repeat;
    transform: translateZ(0);
  }

  body::after {
    display: none;
  }

  body.has-open-overlay {
    overflow: hidden;
  }

  .world-decor {
    display: none;
  }

  .game-shell {
    width: 100%;
    padding: 8px max(8px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow: clip;
  }

  .topbar {
    top: max(6px, env(safe-area-inset-top));
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 4px;
    min-height: 58px;
    padding: 6px;
    border-radius: 18px;
    backdrop-filter: none;
  }

  .brand-button {
    min-width: 0;
    min-height: 44px;
    gap: 6px;
    overflow: hidden;
  }

  .brand-mark {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .brand-tree-icon {
    width: 31px;
    height: 31px;
  }

  .brand-button > span:last-child {
    min-width: 0;
  }

  .brand-button strong {
    overflow: hidden;
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-button small {
    font-size: 0.58rem;
    white-space: nowrap;
  }

  .coin-wallet {
    min-width: 76px;
    min-height: 44px;
    padding: 6px 8px;
  }

  .coin-icon {
    width: 25px;
    height: 25px;
  }

  .wallet-copy small {
    font-size: 0.55rem;
  }

  .wallet-copy strong {
    font-size: 0.78rem;
  }

  .topbar .affiliate-button,
  .topbar .account-button {
    display: grid !important;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    place-items: center;
    padding: 0;
    border-radius: 14px;
  }

  .affiliate-glyph,
  .account-glyph {
    width: 29px;
    height: 29px;
  }

  .affiliate-button-copy,
  .account-button-copy {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
  }

  button,
  input,
  textarea {
    touch-action: manipulation;
  }

  .utility-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-height: 48px;
    margin-top: 6px;
    padding: 4px 6px;
    border: 1px solid rgba(255, 255, 255, 0.58);
    border-radius: 16px;
    background:
      linear-gradient(90deg, rgba(232, 255, 239, 0.9), rgba(210, 251, 255, 0.88) 52%, rgba(240, 255, 218, 0.9));
    box-shadow:
      0 10px 24px rgba(19, 94, 67, 0.16),
      inset 0 1px 0 rgba(255, 255, 255, 0.86);
  }

  main {
    padding-top: 14px;
  }

  .home-view {
    gap: 18px;
    padding-top: 6px;
  }

  .hero-scene {
    min-height: clamp(340px, 105vw, 470px);
    border: 2px solid rgba(238, 255, 225, 0.88);
    border-radius: 28px;
    box-shadow:
      0 18px 38px rgba(15, 89, 60, 0.22),
      0 0 0 1px rgba(46, 161, 80, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
  }

  .home-copy {
    width: calc(100% + 16px);
    margin: -2px -8px 0;
    padding: 10px 14px 14px;
    background:
      linear-gradient(
        90deg,
        transparent,
        rgba(229, 255, 244, 0.92) 15%,
        rgba(220, 250, 255, 0.96) 50%,
        rgba(229, 255, 244, 0.92) 85%,
        transparent
      );
  }

  #mainTitle {
    max-width: 440px;
    font-size: clamp(2.75rem, 13vw, 4rem);
    line-height: 0.94;
    text-shadow:
      0 2px 0 rgba(244, 255, 250, 0.94),
      0 5px 0 rgba(48, 137, 78, 0.4),
      0 10px 20px rgba(12, 74, 45, 0.26);
  }

  .home-copy p {
    max-width: 390px;
    margin-inline: auto;
    color: #28583b;
    font-weight: 700;
    line-height: 1.4;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.78);
  }

  .bank-panel {
    background:
      linear-gradient(150deg, rgba(250, 255, 252, 0.99), rgba(214, 249, 241, 0.98)),
      #effff7;
    box-shadow:
      0 18px 38px rgba(18, 94, 64, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
  }

  .bank-panel input {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(51, 165, 102, 0.3);
    box-shadow: inset 0 3px 8px rgba(30, 111, 73, 0.07);
  }

  .modal-backdrop {
    align-items: start;
    justify-items: center;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain;
    backdrop-filter: none;
  }

  .modal,
  .auth-modal,
  .checkout-modal,
  .tutorial-modal,
  .chest-modal,
  .affiliate-modal,
  .help-modal,
  .seed-hint-modal {
    width: min(100%, 430px) !important;
    max-height: none !important;
    margin: 0 auto !important;
    padding: 16px;
    overflow: visible !important;
    border-radius: 22px;
    backdrop-filter: none;
  }

  .auth-hero {
    min-height: 180px;
    margin: -2px -2px 14px;
    border-radius: 19px;
  }

  .modal-actions,
  .checkout-actions,
  .tutorial-actions,
  .chest-actions {
    grid-template-columns: 1fr !important;
  }

  .modal input,
  .modal textarea,
  .support-widget input {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }

  .section-heading,
  .seed-card,
  .garden-panel,
  .bank-panel,
  .access-panel {
    backdrop-filter: none;
  }

  .reveal,
  .reveal.is-visible {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  .seed-grid {
    gap: 12px;
  }

  .seed-card {
    content-visibility: auto;
    contain: layout paint style;
    contain-intrinsic-size: 570px;
    animation: none !important;
  }

  .seed-card .seed-cta {
    width: 100%;
    min-width: 0;
  }

  .garden-layout,
  .garden-stage,
  .garden-panel,
  .tree-title-row,
  .seed-content {
    min-width: 0;
  }

  .garden-stage {
    height: clamp(420px, 132vw, 560px);
    min-height: 0;
    border-radius: 24px;
  }

  .garden-panel {
    padding: 14px;
    border-radius: 22px;
  }

  .tree-render.is-empty::before {
    display: none;
  }

  .tree-title-row {
    gap: 8px;
  }

  .help-button,
  .treasure-button {
    position: static !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s step-end;
  }

  .help-button {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 4px !important;
    border-radius: 14px !important;
    animation: none !important;
  }

  .help-button > span:last-child {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
  }

  .help-glyph {
    width: 29px;
    height: 29px;
  }

  .treasure-button {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    animation: none !important;
  }

  .treasure-button::before,
  .treasure-button::after {
    animation: none !important;
  }

  .treasure-glyph {
    width: 38px !important;
    height: 34px !important;
    filter: drop-shadow(0 5px 5px rgba(82, 47, 8, 0.24)) !important;
  }

  body.has-open-overlay .help-button,
  body.has-open-overlay .treasure-button {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(12px) scale(0.86) !important;
  }

  .support-widget {
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: auto;
    max-height: none;
    border-radius: 22px;
    animation: none;
  }

  .support-header {
    padding: 10px;
  }

  .support-avatar {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .support-messages {
    min-height: 0;
    max-height: none;
    padding: 12px;
  }

  .support-form {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    padding: 10px;
  }

  .support-form .button {
    min-width: 72px;
    padding-inline: 12px;
  }

  .preview-tree,
  .cloud,
  .mini-cloud,
  .seed-cta,
  .deposit-chip,
  .view {
    animation: none !important;
  }

  .toast-host {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
  }
}

@media (max-width: 350px) {
  .game-shell {
    padding-inline: 6px;
  }

  .topbar {
    gap: 3px;
    padding: 5px;
  }

  .brand-mark {
    flex-basis: 33px;
    width: 33px;
    height: 33px;
  }

  .brand-tree-icon {
    width: 29px;
    height: 29px;
  }

  .brand-button strong {
    font-size: 0.75rem;
  }

  .brand-button small {
    display: none;
  }

  .coin-wallet {
    min-width: 70px;
    padding-inline: 6px;
  }

  .topbar .affiliate-button,
  .topbar .account-button,
  .utility-bar .help-button,
  .utility-bar .treasure-button {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }

  .brand-button > span:last-child {
    display: none;
  }

  .modal,
  .auth-modal,
  .checkout-modal,
  .tutorial-modal,
  .chest-modal,
  .affiliate-modal,
  .help-modal,
  .seed-hint-modal {
    padding: 14px;
  }

  .deposit-grid,
  .checkout-grid {
    gap: 8px;
  }
}

@media (max-height: 500px) and (orientation: landscape) and (max-width: 900px) {
  .modal-backdrop {
    padding-block: 6px;
  }

  .modal {
    width: min(620px, 100%) !important;
  }

  .game-shell {
    padding-bottom: 20px;
  }

  .topbar {
    top: 4px;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 5px;
    min-height: 58px;
    padding: 6px;
    backdrop-filter: none;
  }

  .topbar .affiliate-button,
  .topbar .account-button,
  .utility-bar .help-button,
  .utility-bar .treasure-button {
    position: static !important;
    right: auto !important;
    bottom: auto !important;
    display: grid !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    place-items: center;
    padding: 0 !important;
    border-radius: 14px !important;
  }

  .utility-bar {
    display: flex;
    min-height: 46px;
    margin-top: 4px;
    padding: 3px 6px;
  }

  .help-button {
    grid-template-columns: 1fr !important;
    animation: none !important;
  }

  .help-button > span:last-child,
  .treasure-copy,
  .affiliate-button-copy,
  .account-button-copy {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
  }

  .help-glyph,
  .affiliate-glyph,
  .account-glyph {
    width: 30px;
    height: 30px;
  }

  .treasure-glyph {
    width: 40px !important;
    height: 36px !important;
    filter: drop-shadow(0 5px 5px rgba(82, 47, 8, 0.24)) !important;
  }

  .reveal,
  .reveal.is-visible {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  .preview-tree,
  .seed-card,
  .seed-cta,
  .deposit-chip,
  .view,
  .treasure-button,
  .treasure-button::before,
  .treasure-button::after {
    animation: none !important;
  }

  .seed-benefit-row {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }

  .seed-benefit-row span:last-child {
    width: 100%;
    margin-left: 0;
  }
}
