/* V39: desktop treehouse shares the detailed mobile visual language. */
@media (min-width: 641px) {
  body:not(.needs-entry) .treehouse-card {
    right: 0;
    bottom: 4px;
    grid-template-columns: 66px minmax(96px, 1fr);
    width: 208px;
    min-height: 124px;
    gap: 9px;
    padding: 11px 10px 10px;
    overflow: visible;
    border: 0;
    border-radius: 8px;
    background: #f7f4e9;
    box-shadow: 0 12px 28px rgba(23, 50, 40, .14);
  }

  body:not(.needs-entry) .treehouse-art {
    position: relative;
    width: 64px;
    height: 58px;
  }

  body:not(.needs-entry) .treehouse-roof {
    top: 2px;
    left: 5px;
    width: 54px;
    height: 29px;
    border: 0;
    border-radius: 5px 5px 2px 2px;
    background: #2d6b50;
    clip-path: polygon(50% 0, 100% 72%, 91% 100%, 9% 100%, 0 72%);
    filter: drop-shadow(0 2px 0 #173228);
  }

  body:not(.needs-entry) .treehouse-roof::before {
    content: "";
    position: absolute;
    top: 6px;
    right: 9px;
    width: 8px;
    height: 13px;
    border-radius: 5px 5px 1px 1px;
    background: #f2cb59;
  }

  body:not(.needs-entry) .treehouse-roof::after {
    content: "";
    position: absolute;
    left: 10px;
    top: 13px;
    width: 30px;
    height: 4px;
    border-radius: 999px;
    background: rgba(247, 244, 233, .72);
    transform: rotate(-8deg);
  }

  body:not(.needs-entry) .treehouse-wall {
    left: 12px;
    bottom: 4px;
    width: 41px;
    height: 34px;
    border: 0;
    border-radius: 4px;
    background: #d6a85b;
    box-shadow: inset 0 -4px 0 rgba(111, 84, 58, .18), 0 2px 0 #173228;
  }

  body:not(.needs-entry) .treehouse-wall::before {
    content: "";
    position: absolute;
    top: 9px;
    left: 7px;
    width: 9px;
    height: 9px;
    border: 2px solid #173228;
    border-radius: 50%;
    background: #d8e8df;
    box-shadow: inset 0 0 0 2px rgba(247, 244, 233, .72);
  }

  body:not(.needs-entry) .treehouse-wall i {
    left: 23px;
    width: 12px;
    height: 20px;
    border: 0;
    border-radius: 7px 7px 1px 1px;
    background: #173228;
  }

  body:not(.needs-entry) .treehouse-wall i::after {
    content: "";
    position: absolute;
    top: 11px;
    right: 3px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #f2cb59;
  }

  body:not(.needs-entry) .treehouse-branch {
    right: -1px;
    bottom: 0;
    width: 66px;
    height: 5px;
    border-radius: 999px;
    background: #74523a;
    transform: rotate(-3deg);
    box-shadow: 0 2px 0 rgba(23, 50, 40, .14);
  }

  body:not(.needs-entry) .treehouse-branch::after {
    content: "";
    position: absolute;
    right: 7px;
    top: 1px;
    width: 11px;
    height: 3px;
    border-radius: 999px;
    background: rgba(247, 244, 233, .28);
  }

  body:not(.needs-entry) .treehouse-copy {
    align-self: center;
    gap: 4px;
  }

  body:not(.needs-entry) .treehouse-copy strong {
    font-size: .73rem;
    line-height: 1.15;
  }

  body:not(.needs-entry) .treehouse-copy small {
    color: #5f675f;
    font-size: .66rem;
    font-weight: 700;
  }

  body:not(.needs-entry) .treehouse-upgrade {
    min-height: 31px;
    padding: 6px 10px;
    border-radius: 5px;
    background: #174a37;
    font-size: .66rem;
  }

  body:not(.needs-entry) .treehouse-upgrade b {
    font-size: .63rem;
  }

  body:not(.needs-entry) .treehouse-card:hover {
    box-shadow: 0 15px 32px rgba(23, 50, 40, .17);
  }
}

/* Weekly reward callout: prominent without adding a new layout block. */
.league-rule {
  position: relative;
  margin: 7px 0 10px;
  padding: 9px 11px 9px 27px;
  border-radius: 6px;
  color: #173228;
  background: #f4e7ad;
  box-shadow: inset 4px 0 0 #d4ad39;
  font-size: .68rem;
  font-weight: 800;
  line-height: 1.45;
}

.league-rule::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: #d4ad39;
  box-shadow: 0 0 0 3px rgba(212, 173, 57, .18);
  transform: translateY(-50%) rotate(45deg);
}

@media (max-width: 640px) {
  body:not(.needs-entry) .league-rule {
    margin: 5px 0 8px;
    padding: 7px 8px 7px 23px;
    border-radius: 5px;
    font-size: .59rem;
    line-height: 1.4;
  }

  body:not(.needs-entry) .league-rule::before {
    left: 9px;
    width: 7px;
    height: 7px;
  }
}

/* Stable top toolbar: one visual line, four clear desktop zones. */
@media (min-width: 721px) {
  body:not(.needs-entry) .topbar {
    grid-template-columns: minmax(230px, 1fr) auto minmax(520px, 1fr);
    gap: 14px;
    width: 100%;
    min-height: 72px;
    padding: 11px 16px;
  }

  body:not(.needs-entry) .brand {
    justify-self: start;
    padding-left: 2px;
  }

  body:not(.needs-entry) .track-switch {
    justify-self: center;
  }

  body:not(.needs-entry) .topbar-tools {
    display: grid;
    grid-template-columns: auto auto auto minmax(250px, auto);
    align-items: center;
    justify-content: end;
    gap: 7px;
    width: 100%;
    min-width: 0;
  }

  body:not(.needs-entry) .support-link,
  body:not(.needs-entry) .hungry-notes-link,
  body:not(.needs-entry) .canopy-inbox-button {
    min-height: 44px;
  }

  body:not(.needs-entry) .wallet {
    min-width: 250px;
    min-height: 44px;
    padding: 7px 9px;
    white-space: nowrap;
  }

  body:not(.needs-entry) .wallet.has-annual-pass .leaf-icon { order: 0; }
  body:not(.needs-entry) .wallet.has-annual-pass small { order: 1; }
  body:not(.needs-entry) .wallet.has-annual-pass #leafCount { order: 2; }
  body:not(.needs-entry) .wallet.has-annual-pass .wallet-redeem { order: 3; }
  body:not(.needs-entry) .wallet.has-annual-pass .wallet-help { order: 4; }
}

@media (min-width: 721px) and (max-width: 1180px) {
  body:not(.needs-entry) .topbar {
    grid-template-columns: 48px auto minmax(480px, 1fr);
    gap: 9px;
  }

  body:not(.needs-entry) .brand {
    display: grid;
    place-items: center;
    padding-left: 0;
  }

  body:not(.needs-entry) .brand > span {
    display: none;
  }

  body:not(.needs-entry) .topbar-tools {
    grid-template-columns: auto auto auto minmax(220px, 1fr);
  }

  body:not(.needs-entry) .support-link span,
  body:not(.needs-entry) .canopy-inbox-button span {
    display: none;
  }
}

/* Phone toolbar: every item shares one baseline and fixed, non-overlapping tracks. */
@media (max-width: 720px) and (orientation: portrait) {
  body:not(.needs-entry) .topbar {
    display: grid;
    grid-template-columns: 34px 82px minmax(0, 1fr) !important;
    grid-template-rows: 48px;
    align-items: center;
    gap: 4px !important;
    width: 100%;
    min-height: 58px;
    margin: 0 0 4px;
    padding: 5px 6px;
  }

  body:not(.needs-entry) .brand {
    grid-column: 1;
    grid-row: 1;
    width: 34px;
    height: 34px;
    padding: 0;
  }

  body:not(.needs-entry) .brand .brand-mark {
    width: 34px;
    height: 34px;
  }

  body:not(.needs-entry) .track-switch {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 82px;
    min-width: 82px;
    height: 40px;
    gap: 2px;
    padding: 2px;
  }

  body:not(.needs-entry) .track-button {
    min-width: 0;
    min-height: 36px;
    justify-content: center;
    padding: 2px;
  }

  body:not(.needs-entry) .track-button span {
    width: 27px;
    height: 27px;
    font-size: .72rem;
  }

  body:not(.needs-entry) .track-button small {
    display: none;
  }

  body:not(.needs-entry) .topbar-tools {
    grid-column: 3;
    grid-row: 1;
    display: grid !important;
    grid-template-columns: 48px 48px minmax(0, 1fr) !important;
    align-items: center;
    justify-content: stretch;
    gap: 3px !important;
    width: 100%;
    min-width: 0;
  }

  body:not(.needs-entry) .support-link {
    display: none;
  }

  body:not(.needs-entry) .hungry-notes-link,
  body:not(.needs-entry) .canopy-inbox-button {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    height: 44px;
    min-height: 44px;
    gap: 1px !important;
    padding: 2px !important;
    border-radius: 5px;
  }

  body:not(.needs-entry) .hungry-notes-link svg,
  body:not(.needs-entry) .canopy-inbox-button svg {
    width: 21px !important;
    height: 21px !important;
    flex: 0 0 21px;
  }

  body:not(.needs-entry) #hungryNotesTopLabel,
  body:not(.needs-entry) .canopy-inbox-button span {
    display: block !important;
    width: 44px !important;
    max-width: 44px !important;
    overflow: hidden !important;
    color: #173228;
    font-size: .45rem !important;
    line-height: 1.05;
    text-align: center;
    text-overflow: clip;
    white-space: nowrap !important;
  }

  body:not(.needs-entry) .wallet {
    display: flex;
    width: 100%;
    min-width: 0 !important;
    max-width: none !important;
    height: 44px;
    min-height: 44px;
    gap: 4px;
    justify-content: center;
    padding: 4px 5px;
    overflow: visible;
    border: 0;
    border-radius: 5px;
    box-shadow: none;
  }

  body:not(.needs-entry) .wallet .leaf-icon {
    width: 12px;
    height: 16px;
    flex: 0 0 12px;
  }

  body:not(.needs-entry) .wallet #leafCount {
    min-width: 0;
    font-size: .69rem;
    text-align: center;
  }

  body:not(.needs-entry) .wallet small {
    display: none;
  }

  body:not(.needs-entry) .wallet-redeem {
    min-width: 36px;
    min-height: 27px;
    padding: 2px 4px;
    font-size: .52rem;
  }

  body:not(.needs-entry) .wallet-help {
    display: none;
  }

  body:not(.needs-entry) .wallet.has-annual-pass {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) 38px;
    grid-template-rows: 13px 17px;
    grid-template-areas:
      "leaf expiry redeem"
      "leaf date redeem";
    align-content: center;
    column-gap: 4px;
    row-gap: 0;
  }

  body:not(.needs-entry) .wallet.has-annual-pass .leaf-icon {
    grid-area: leaf;
    align-self: center;
  }

  body:not(.needs-entry) .wallet.has-annual-pass small {
    grid-area: expiry;
    display: block;
    align-self: end;
    color: #607168;
    font-size: .43rem;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }

  body:not(.needs-entry) .wallet.has-annual-pass #leafCount {
    grid-area: date;
    align-self: start;
    font-size: .59rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  body:not(.needs-entry) .wallet.has-annual-pass .wallet-redeem {
    grid-area: redeem;
    align-self: center;
  }
}

@media (max-width: 349px) and (orientation: portrait) {
  body:not(.needs-entry) .topbar {
    grid-template-columns: 32px 78px minmax(0, 1fr) !important;
    gap: 3px !important;
    padding-inline: 4px;
  }

  body:not(.needs-entry) .topbar-tools {
    grid-template-columns: 42px 42px minmax(0, 1fr) !important;
    gap: 2px !important;
  }

  body:not(.needs-entry) .hungry-notes-link,
  body:not(.needs-entry) .canopy-inbox-button {
    width: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
  }

  body:not(.needs-entry) #hungryNotesTopLabel,
  body:not(.needs-entry) .canopy-inbox-button span {
    width: 40px !important;
    max-width: 40px !important;
  }
}
