:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
.mobile-only { display: none; }

/* The phone is a game screen. Navigation, safe areas and the HUD reserve their
   own space; only the garden grows when Safari's visible viewport changes. */
@media (max-width: 700px), (max-width: 950px) and (max-height: 520px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { height: 100vh; height: 100dvh; }
  .mobile-only { display: block; }
  .desktop-label, .intro, .right-rail, .level-strip, footer,
  .rail-heading, .journey-card, .botanical-note { display: none; }
  .site-shell {
    display: flex; flex-direction: column; height: 100%; max-width: 520px;
    padding: var(--safe-top) max(12px, var(--safe-right)) 0 max(12px, var(--safe-left));
  }
  .site-header { flex: 0 0 68px; height: 68px; border: 0; }
  .brand { gap: 7px; }
  .brand > span { font-size: 38px; }
  .brand svg { width: 25px; height: 25px; }
  .header-tools { gap: 4px; }
  .header-tools .icon-button { width: 44px; height: 44px; }
  .header-tools .icon-button svg { width: 19px; height: 19px; }
  nav {
    position: fixed; z-index: 8; bottom: 0; left: 0; right: 0;
    height: calc(62px + var(--safe-bottom));
    padding: 5px max(12px, var(--safe-right)) calc(5px + var(--safe-bottom)) max(12px, var(--safe-left));
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
    border-top: 1px solid #343d2f; background: #101211f5; backdrop-filter: blur(12px);
  }
  nav button, nav button:first-child, nav button.mobile-only {
    height: 52px; min-height: 44px; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 4px; padding: 4px;
    border-radius: 11px; font-size: 10px; color: #9da69c; line-height: 1.2;
  }
  nav button .mobile-only { display: block; }
  nav button svg { width: 22px; height: 22px; }
  nav button.nav-active { background: #d5ec9b0b; color: var(--green); }
  nav button.nav-active::after { display: none; }
  .nav-help { display: grid; place-items: center; width: 21px; height: 21px; border: 1.4px solid currentColor; border-radius: 50%; font: 15px var(--serif); }
  main {
    display: flex; flex-direction: column; flex: 1; min-height: 0;
    padding-bottom: calc(70px + var(--safe-bottom));
  }
  .play-layout { display: flex; flex-direction: column; align-items: stretch; flex: 1; min-height: 0; gap: 8px; }
  .left-rail { flex: 0 0 auto; width: 100%; }
  body.game-active .left-rail { display: none; }
  .mode-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 4px; background: #1b201b; border: 1px solid #30392c; border-radius: 50px; }
  .mode-button { min-width: 0; min-height: 44px; padding: 5px 3px; gap: 5px; border: 1px solid transparent; border-radius: 50px; justify-content: center; }
  .mode-icon { height: 20px; width: 24px; background: none !important; }
  .mode-icon svg { width: 20px; height: 20px; }
  .mode-button strong { font-size: 11px; font-weight: 600; white-space: nowrap; }
  .mode-button small, .mode-arrow, .new-dot { display: none; }
  .game-panel {
    display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%;
    border-radius: 0; padding: 8px 0 0; overflow: hidden; background: none; border: 0; box-shadow: none;
  }
  .game-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px; flex: 0 0 auto; min-height: 48px; margin: 0 0 8px; }
  .game-heading .eyebrow { font-size: 9px; letter-spacing: 1.1px; margin-bottom: 4px; }
  .game-heading h2 { font-size: 28px; line-height: 1.15; }
  .game-controls { gap: 2px; }
  .game-controls .icon-button { width: 44px; height: 44px; border-radius: 10px; }
  .game-controls .icon-button svg { width: 21px; height: 21px; }
  #restart-button { display: none; }
  .mode-status { flex: 0 0 auto; gap: 12px; min-height: 31px; padding: 0 3px 7px; font-size: 12px; }
  .mode-health { font-size: 23px; line-height: 1; }
  .mode-status > span:last-child { display: none; }
  .garden-field { flex: 1; min-height: 0; height: auto; width: 100%; aspect-ratio: auto; border-radius: 18px; }
  canvas { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  .field-tag { display: none; }
  .field-overlay { padding: 16px; justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; }
  .field-overlay > * { flex-shrink: 0; }
  .field-overlay::before, .field-overlay::after { content: ''; flex: 1 0 0; }
  .overlay-motif { width: 48px; height: 48px; margin-bottom: 14px; }
  .overlay-eyebrow { font-size: 9px; letter-spacing: 1.5px; margin-bottom: 10px; }
  .field-overlay h2 { font-size: 38px; line-height: 1.04; letter-spacing: -.8px; margin-bottom: 13px; }
  .field-overlay .overlay-copy { font-size: 13px !important; line-height: 1.65; max-width: 310px; }
  .field-overlay .primary-button, .field-overlay .secondary-button {
    flex-shrink: 0; min-height: 48px; padding: 12px 19px; font-size: 14px; margin-top: 22px; border-radius: 50px;
  }
  .overlay-small { font-size: 10px; line-height: 1.5; margin-top: 13px; }
  .overlay-stars { font-size: 30px; margin-bottom: 13px; }
  .result-stats { gap: 12px; width: 100%; margin-top: 16px; }
  .result-stats > div { flex: 1; min-width: 0; font-size: 11px; line-height: 1.5; }
  .result-stats strong { font-size: 26px; margin-bottom: 4px; }
  .overlay-actions { flex-direction: column; gap: 10px; width: 100%; margin-top: 20px; }
  .field-overlay .overlay-actions .primary-button, .field-overlay .overlay-actions .secondary-button { margin: 0; width: min(100%, 285px); }
  .chain-label { top: 12px; right: 12px; padding: 9px 12px; }
  .chain-label strong { font-size: 30px; }
  .chain-label span { font-size: 10px; }
  .harvest-button { min-height: 48px; bottom: 12px; padding: 11px 15px; width: calc(100% - 24px); max-width: 325px; font-size: 12px; border-radius: 50px; white-space: normal; }
  .touch-hint { position: absolute; bottom: 12px; left: 12px; right: 12px; margin: 0; padding: 9px 7px; text-align: center; font-size: 11px; line-height: 1.4; color: #d5ec9b; background: #1a2519ed; border: 1px solid #4c5e3d; border-radius: 9px; pointer-events: none; }
  .game-bottom { flex: 0 0 auto; margin: 0; padding: 17px 2px 10px; gap: 12px; }
  .flower-progress { min-width: 0; }
  .flower-progress > div { font-size: 11px; margin-bottom: 9px; }
  .flower-progress strong { font-size: 14px; white-space: nowrap; }
  .seed-stock, .score-box { padding-left: 12px; }
  .seed-stock > span, .score-box > span { font-size: 10px; margin-bottom: 6px; }
  .seed-dot { font-size: 24px; line-height: 22px; }
  .seed-stock > div { gap: 3px; }
  .score-box { min-width: 57px; }
  .score-box strong { font-size: 22px; }
  .game-instructions { display: none; }
  .game-panel.expanded {
    inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    max-width: none; height: auto; width: auto; margin: 0; z-index: 12; border-radius: 0; padding: 12px 12px 0;
  }
  .game-panel.expanded .garden-field { width: 100%; height: auto; max-height: none; min-height: 0; aspect-ratio: auto; }
  dialog {
    position: fixed; inset: auto 0 0; width: 100%; max-width: 520px;
    max-height: calc(100dvh - var(--safe-top) - 12px); margin: 0 auto;
    padding: 20px max(20px, var(--safe-right)) calc(22px + var(--safe-bottom)) max(20px, var(--safe-left));
    border-radius: 22px 22px 0 0; overflow-y: auto; overscroll-behavior: contain;
  }
  .modal-heading { position: sticky; top: -20px; background: #191e19; z-index: 1; min-height: 44px; }
  .close-button { width: 44px; height: 44px; flex-shrink: 0; }
  .modal-heading + h2 { font-size: 31px; margin-bottom: 20px; }
  .modal-copy { font-size: 14px; line-height: 1.7; }
  .garden-tabs { gap: 5px; }
  .garden-tab { font-size: 11px; min-height: 72px; padding: 8px 5px; }
  .garden-tab span { font-size: 10px; }
  .map-level { min-height: 105px; }
  .map-level span { font-size: 12px; }
  .section-tabs { gap: 8px; }
  .section-tabs button { flex: 1; min-height: 44px; font-size: 12px; padding: 6px 0; }
  .flower-card p, .achievement p, .boon-card p { font-size: 13px; }
  .achievement h3 { font-size: 14px; }
  .achievement small { font-size: 11px; }
  .boon-card { min-height: 112px; padding: 16px; }
  .boon-card h3 { font-size: 24px; }
  .boon-card small { font-size: 12px; }
  .settings-row strong { font-size: 15px; }
  .settings-row small, .storage-note { font-size: 12px; }
  .backup-actions .primary-button, .backup-actions .secondary-button { min-height: 48px; font-size: 14px; }
  .text-button { min-height: 44px; }
  .help-step p { font-size: 14px; }
  .skin-button { min-height: 116px; }
  .skin-button strong { font-size: 13px; }
  .skin-button small { font-size: 11px; }
  .profile-summary p { font-size: 12px; }
  .toast-region { bottom: calc(76px + var(--safe-bottom)); }
  .toast { font-size: 12px; padding: 12px 16px; }
  .mobile-mode-picker { display: grid; gap: 12px; margin: 10px 0; }
  .mobile-mode-card { display: grid; grid-template-columns: minmax(0, 1fr) 20px; column-gap: 12px; text-align: left; min-height: 88px; padding: 16px; border: 1px solid #43513a; border-radius: 13px; background: #242c1f; }
  .mobile-mode-card strong { font: 24px var(--serif); margin-bottom: 6px; }
  .mobile-mode-card > span:first-of-type { grid-column: 1; font-size: 13px; color: #adb8a2; line-height: 1.5; }
  .mobile-mode-card > span:last-child { grid-column: 2; grid-row: 1/3; align-self: center; }
  .field-overlay[data-screen=intro] {
    padding: 16px 24px 24px; align-items: flex-start; justify-content: flex-end;
  }
  .field-overlay[data-screen=intro]::before, .field-overlay[data-screen=intro]::after { display: none; }
  .field-overlay[data-screen=intro] .intro-art {
    position: relative; top: auto; right: auto; width: calc(100% + 32px); margin: -8px -16px 10px;
    height: 180px; min-height: 60px; max-height: 44%; flex: 1 1 180px; mask-image: none;
  }
  .intro-art img { object-fit: contain; opacity: 1; mask-image: linear-gradient(#000 75%, transparent); }
  .art-caption { right: 0; bottom: 20px; font-size: 6px; letter-spacing: 1.6px; color: #b39ba8; }
  .field-overlay[data-screen=intro] h2 { max-width: 100%; font-size: 53px; line-height: .94; letter-spacing: -1.1px; margin-bottom: 13px; }
  .field-overlay[data-screen=intro] .overlay-eyebrow { font-size: 8px; letter-spacing: 1.8px; margin-bottom: 12px; }
  .field-overlay[data-screen=intro] .overlay-copy { max-width: 100%; font-size: 12px !important; line-height: 1.7; }
  .field-overlay[data-screen=intro] .primary-button { width: 100%; justify-content: space-between; min-height: 50px; margin-top: 20px; padding: 10px 18px 10px 23px; border-radius: 50px; font-size: 13px; }
  .field-overlay[data-screen=intro] .primary-button > span { width: 29px; height: 29px; border: 1px solid #1b28152e; border-radius: 50%; }
  .field-overlay[data-screen=intro] .overlay-small { max-width: 100%; width: 100%; text-align: center; font-size: 9px; margin-top: 11px; }
}

/* Smaller iPhones and Safari with its browser controls expanded. */
@media (max-width: 700px) and (max-height: 740px), (max-width: 950px) and (max-height: 520px) {
  .site-header { flex-basis: 50px; height: 50px; }
  .brand > span { font-size: 33px; }
  .brand svg { width: 25px; height: 25px; }
  .game-heading h2 { font-size: 25px; }
  .game-heading .eyebrow { font-size: 8px; }
  .game-heading { min-height: 44px; margin-bottom: 6px; }
  .mode-button { min-height: 44px; }
  .mode-button strong { font-size: 10px; }
  .game-bottom { padding: 9px 0; gap: 8px; }
  .seed-stock, .score-box { padding-left: 8px; }
  .seed-stock > span, .score-box > span { font-size: 9px; }
  .flower-progress > div { font-size: 10px; }
  .field-overlay { padding: 12px; }
  .overlay-motif, .overlay-small { display: none; }
  .field-overlay h2 { font-size: 26px; margin-bottom: 9px; }
  .overlay-eyebrow { font-size: 8px; margin-bottom: 7px; }
  .field-overlay .overlay-copy { font-size: 12px !important; }
  .overlay-stars { font-size: 24px; margin-bottom: 8px; }
  .result-stats { margin-top: 10px; gap: 8px; }
  .result-stats strong { font-size: 23px; }
  .result-stats > div { font-size: 10px; }
  .overlay-actions { gap: 8px; margin-top: 13px; }
  .field-overlay .primary-button, .field-overlay .secondary-button { margin-top: 15px; }
  .field-overlay[data-screen=intro] { padding: 12px 19px 18px; }
  .field-overlay[data-screen=intro] h2 { font-size: 42px; margin-bottom: 10px; }
  .field-overlay[data-screen=intro] .overlay-copy { font-size: 11px !important; }
  .field-overlay[data-screen=intro] .intro-art { height: 100px; flex-basis: 100px; min-height: 45px; margin-bottom: 4px; }
  .field-overlay[data-screen=intro] .overlay-eyebrow { font-size: 7px; margin-bottom: 9px; letter-spacing: 1.5px; }
  .field-overlay[data-screen=intro] .primary-button { margin-top: 14px; }
}

@media (min-width: 701px) and (max-width: 950px) and (max-height: 520px) {
  .site-shell { max-width: none; }
  .play-layout { flex-direction: row; }
  .left-rail { width: 116px; }
  .mode-list { grid-template-columns: 1fr; }
  .game-panel { display: grid; height: 100%; grid-template-columns: minmax(0, 1fr) 120px; grid-template-rows: auto minmax(0, 1fr); gap: 8px 12px; padding: 8px; }
  .game-heading { grid-column: 1/-1; margin: 0; }
  .garden-field { grid-column: 1; grid-row: 2; height: 100%; }
  .game-bottom { grid-column: 2; grid-row: 2; align-self: end; flex-direction: column; align-items: stretch; gap: 10px; padding: 0; }
  .seed-stock, .score-box { border: 0; padding: 0; text-align: left; }
  .mode-status { grid-column: 2; grid-row: 2; align-self: start; flex-wrap: wrap; gap: 4px; font-size: 10px; }
  .mode-health { font-size: 18px; }
  .game-panel.expanded { display: flex; }
  .overlay-actions { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .field-overlay .overlay-actions .primary-button, .field-overlay .overlay-actions .secondary-button { width: auto; min-height: 44px; padding: 10px 13px; font-size: 12px; }
  .field-overlay[data-screen=intro] { display: flex; justify-content: center; padding: 15px 24px; }
  .field-overlay[data-screen=intro] .intro-art { position: absolute; width: 65%; height: 120%; max-height: none; right: -15%; top: -10%; margin: 0; mask-image: linear-gradient(90deg, transparent, #000 45%); }
  .field-overlay[data-screen=intro] h2 { font-size: 36px; margin-bottom: 7px; }
  .field-overlay[data-screen=intro] .overlay-copy { font-size: 10px !important; }
  .field-overlay[data-screen=intro] .primary-button { width: auto; min-height: 44px; font-size: 12px; margin-top: 12px; }
}
.iphone-install { margin-top: 22px; padding: 17px; border: 1px solid #43513a; border-radius: 12px; background: #252e20; }
.iphone-install strong { display: block; font: 22px var(--serif); margin-bottom: 8px; }
.iphone-install p { color: #adb8a2; font-size: 13px; line-height: 1.75; margin: 0; }

@media (max-width: 700px) and (max-height: 640px) {
  .field-overlay[data-screen=intro] .intro-art { display: none; }
  .field-overlay[data-screen=intro] h2 { font-size: 40px; }
  .field-overlay[data-screen=intro] { justify-content: center; }
}
