/* 2026-11-23: final Growth Orchard responsive contract.
   This terminal layer deliberately owns phone portrait geometry so the
   orchard does not inherit contradictory full-screen and footer rules from
   earlier iterations. */

@media (max-width: 580px) and (orientation: portrait) {
  html,
  body.orchard-active,
  body.orchard-active #studyView,
  body.orchard-active #growthView {
    min-height: 100%;
    background: #f6f6ea !important;
  }

  body.orchard-active #growthView {
    padding-bottom: calc(58px + env(safe-area-inset-bottom)) !important;
  }

  body.orchard-active .growth-scroll {
    padding-bottom: 26px !important;
  }

  /* One—and only one—fixed footer at the physical screen edge. */
  body.orchard-active .growth-orchard-footer {
    position: fixed !important;
    z-index: 54 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(58px + env(safe-area-inset-bottom)) !important;
    min-height: calc(58px + env(safe-area-inset-bottom)) !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 16px env(safe-area-inset-bottom) 46vw !important;
    border: 0 !important;
    border-radius: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    background: #194e73 !important;
    box-shadow: 0 -1px 0 rgba(255,255,255,.08) !important;
    color: #f5f2ea !important;
  }
  body.orchard-active .growth-orchard-footer > span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
  }
  body.orchard-active .growth-orchard-footer::after {
    content: "成长果园  by TIGABABA™" !important;
    position: absolute !important;
    top: calc(50% - env(safe-area-inset-bottom) / 2) !important;
    right: 16px !important;
    transform: translateY(-50%) !important;
    color: #f5f2ea !important;
    font-size: 11px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    letter-spacing: .01em !important;
    white-space: nowrap !important;
  }
  body.orchard-active .growth-orchard-footer small {
    color: rgba(245,242,234,.74) !important;
    font-size: 10px !important;
    font-weight: 430 !important;
  }

  body.orchard-active #accountMenuButton,
  body.orchard-active .study-view:not(.keyboard-open) > #accountMenuButton,
  body.orchard-active .study-view.compact-practice-footer:not(.keyboard-open) > #accountMenuButton,
  body.orchard-active .study-view.inspection-active:not(.keyboard-open) > #accountMenuButton {
    position: fixed !important;
    z-index: 55 !important;
    left: 14px !important;
    right: auto !important;
    bottom: env(safe-area-inset-bottom) !important;
    width: min(44vw, 174px) !important;
    max-width: min(44vw, 174px) !important;
    height: 58px !important;
    min-height: 58px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    color: #f5f2ea !important;
    background: transparent !important;
    box-shadow: none !important;
  }
  body.orchard-active #accountMenuButton::before,
  body.orchard-active #accountMenuButton::after {
    content: none !important;
    display: none !important;
  }
  body.orchard-active #accountMenuButton > .main-account-avatar:not([hidden]) {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
    border-radius: 50% !important;
  }
  body.orchard-active #accountMenuButton > #accountMenuGlyph {
    width: 20px !important;
    height: 20px !important;
    color: rgba(245,242,234,.86) !important;
  }
  body.orchard-active #accountMenuButton .main-account-name {
    color: rgba(245,242,234,.92) !important;
    font-size: 11px !important;
    font-weight: 500 !important;
  }
  body.orchard-active #accountMenuButton .main-account-plan {
    color: rgba(245,242,234,.56) !important;
    font-size: 8px !important;
    font-weight: 400 !important;
  }

  /* The hero is a compact, stable scene. Its geometry must not change while
     planting choices replace the tree and copy. */
  body.orchard-active .growth-current-activities,
  body.orchard-active .growth-current-activity,
  body.orchard-active .growth-current-activity.is-planting-open,
  body.orchard-active .growth-view.has-current-tree .growth-current-activity {
    height: 430px !important;
    min-height: 430px !important;
    max-height: 430px !important;
  }
  body.orchard-active .growth-current-activity,
  body.orchard-active .growth-view.has-current-tree .growth-current-activity {
    position: relative !important;
    box-sizing: border-box !important;
    padding: 0 16px 18px !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 266px 130px !important;
    align-content: start !important;
    gap: 4px !important;
    overflow: hidden !important;
  }
  body.orchard-active .growth-current-activity.is-planting-open {
    overflow: visible !important;
  }
  body.orchard-active .growth-view.has-current-tree .growth-current-tree-label {
    top: 16px !important;
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
    max-width: none !important;
    min-height: 82px !important;
    align-content: start !important;
  }
  body.orchard-active .growth-current-tree-label > .growth-plant-card {
    margin-top: 12px !important;
  }
  body.orchard-active .growth-tree-stage {
    grid-column: 1 !important;
    grid-row: 1 !important;
    width: 100% !important;
    height: 220px !important;
    margin: 34px 0 0 !important;
    align-self: start !important;
    transform: none !important;
  }
  body.orchard-active .growth-view.has-current-tree .growth-tree-stage .growth-tree {
    width: min(76vw, 300px) !important;
    height: 210px !important;
    max-height: 210px !important;
    transform: scale(1.13) !important;
    transform-origin: 50% 100% !important;
  }
  body.orchard-active .growth-hero-copy {
    grid-column: 1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    align-self: start !important;
    justify-self: stretch !important;
    justify-items: center !important;
    row-gap: 7px !important;
    transform: none !important;
    text-align: center !important;
  }
  body.orchard-active .growth-hero-copy > #growthHeroMessage {
    margin: 0 !important;
    font-size: clamp(1.04rem, 5.2vw, 1.24rem) !important;
    line-height: 1.28 !important;
  }
  body.orchard-active .growth-hero-copy #growthHeroDetail {
    margin: 0 !important;
  }
  body.orchard-active .growth-current-activity.is-planting-open > .growth-tree-stage,
  body.orchard-active .growth-current-activity.is-planting-open > .growth-hero-copy {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* All planting stages open below the question, on one left guide. */
  body.orchard-active .growth-view.has-current-tree .growth-current-activity
    > .growth-plant-species,
  body.orchard-active .growth-view.has-current-tree .growth-current-activity
    > .growth-plant-categories,
  body.orchard-active .growth-view.has-current-tree .growth-current-activity
    > .growth-plant-targets,
  body.orchard-active .growth-current-activity > .growth-plant-intent {
    position: absolute !important;
    z-index: 8 !important;
    top: var(--plant-menu-top, 126px) !important;
    left: var(--plant-menu-left, 16px) !important;
    right: var(--plant-menu-right, 16px) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    transform: none !important;
  }
  body.orchard-active .growth-current-activity > .growth-plant-species
    .growth-plant-species-grid {
    width: 100% !important;
    justify-content: flex-start !important;
    gap: 5px !important;
    padding: 4px 0 8px !important;
    overflow-x: auto !important;
  }
  body.orchard-active .growth-current-activity > .growth-plant-species
    .growth-plant-species-grid button {
    flex: 0 0 48px !important;
    width: 48px !important;
  }

  /* Revert the experimental 2/4-column phone orchard. Full cards use one
     calm column; compact cards use the established two-column layout. */
  html body.orchard-active #growthForest.growth-forest:not(.is-compact-display) {
    grid-template-columns: 1fr !important;
  }
  html body.orchard-active #growthForest.growth-forest.is-compact-display {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* A visible two-rail fence separates the living tree from the orchard. */
  body.orchard-active .growth-forest-section::before {
    top: 4px !important;
    left: 16px !important;
    right: 16px !important;
    height: 30px !important;
    opacity: 1 !important;
    background:
      repeating-linear-gradient(90deg,
        transparent 0 42px,
        rgba(133,116,78,.34) 42px 45px,
        transparent 45px 82px),
      linear-gradient(180deg,
        transparent 7px,
        rgba(133,116,78,.28) 7px 10px,
        transparent 10px 19px,
        rgba(133,116,78,.22) 19px 22px,
        transparent 22px) !important;
    border: 0 !important;
  }
  body.orchard-active .growth-forest-section > header {
    margin-top: 34px !important;
  }
}

/* The footer remains a single strip in phone landscape as well. */
@media (max-height: 580px) and (orientation: landscape) {
  body.orchard-active,
  body.orchard-active #studyView,
  body.orchard-active #growthView {
    background: #f6f6ea !important;
  }
}
