/* Phone layout (screens narrower than 900px).
   Wider screens show the 1440px design scaled to fit (fit.js). On phones that made the text tiny, so
   here fit.js leaves the page at its real size and these rules turn each section into a single column.
   The homepage sections carry their design values as inline styles, hence the !important; the "m-"
   classes on them (in designs-src/home/Advanced.dc.html) mark what each rule targets. */

/* All screens: hide the floating "Admissions open" button while the photo viewer is open, so it can't sit
   on top of the viewer's arrows (on inner pages the viewer is inside #main, which stacks below the button). */
body:has(.m-lightbox) .adm-tab { display: none; }

@media (max-width: 899px) {
  html, body { overflow-x: hidden; }
  #root { width: auto !important; height: auto !important; overflow: hidden !important; }
  #root img { max-width: 100%; }
  .m-hide, .d3 .nx .plane, .d3 .nx .stamp { display: none !important; }

  /* ---------- Top strip: cut-off note, phone, email and address, centred on short lines ---------- */
  .m-strip { height: auto !important; padding: 10px 16px !important; flex-direction: column; gap: 6px; text-align: center; font-size: 12.5px !important; line-height: 1.45; }
  .m-strip > div { flex-wrap: wrap; justify-content: center; gap: 4px 14px !important; }
  .m-strip > div:first-child { padding-bottom: 6px; border-bottom: 1px solid rgba(244, 239, 217, .22); width: 100%; }
  .m-strip > div:first-child > svg { display: none; }
  .m-strip > div:last-child > * { gap: 6px !important; }
  .m-strip a { overflow-wrap: anywhere; }

  /* ---------- Header: logo and button, then the menu as an even 3 x 2 grid ---------- */
  .m-header { height: auto !important; padding: 12px 20px 0 !important; flex-wrap: wrap; row-gap: 10px; }
  .m-header > a:first-child img { width: 110px !important; height: auto !important; }
  .m-cta { height: 44px !important; padding: 0 16px !important; font-size: 15px !important; gap: 8px !important; }
  .m-nav {
    order: 3; width: 100%; display: grid !important; grid-template-columns: repeat(3, 1fr);
    gap: 0 !important; font-size: 15px !important; border-top: 1px solid #E4DCC2; border-bottom: 1px solid #E4DCC2;
  }
  .m-nav a { padding: 11px 4px; text-align: center; white-space: nowrap; }
  .m-nav a:nth-child(-n+3) { border-bottom: 1px solid #EFE7D0; }
  .m-nav a:not(:nth-child(3n+1)) { border-left: 1px solid #EFE7D0; }

  /* ---------- Type ---------- */
  #root h1 { font-size: 46px !important; }
  #root section:not(.nx) h2[style] { font-size: 34px !important; }
  #root section:not(.nx) h3[style] { font-size: 26px !important; }
  #root section:not(.nx) [style*="font-family: 'Kalam'"] { font-size: 19px !important; }
  #root section:not(.nx) p[style*="font-size: 20px"], #root section:not(.nx) p[style*="font-size: 19px"] { font-size: 18px !important; }

  /* ---------- Sections: side margins and tighter vertical spacing ---------- */
  #root section:not(.nx):not(.m-marquee) { padding-left: 20px !important; padding-right: 20px !important; }
  .m-grid, .m-programs, .m-moments, #reviews { padding-top: 56px !important; padding-bottom: 56px !important; }
  .m-quest { padding-bottom: 0 !important; }

  /* 12-column grids become one column */
  .m-grid, .m-grid-inner { display: block !important; }
  .m-grid > *, .m-grid-inner > * { grid-column: auto !important; }
  .m-grid > * + *, .m-grid-inner > * + * { margin-top: 32px !important; }
  .m-grid > [style*="padding-top"] { padding-top: 0 !important; }
  .m-headrow { display: block !important; }
  .m-headrow > * { width: auto !important; }
  .m-headrow > * + * { margin-top: 14px !important; }

  /* ---------- Hero ---------- */
  .m-hero { height: auto !important; display: block !important; padding-top: 28px !important; padding-bottom: 8px !important; }
  .m-hero-copy { width: auto !important; padding-top: 0 !important; }
  .m-hero p, .m-hero figure { width: auto !important; }
  .m-believed { margin: 12px 0 0 !important; }
  .m-actions { flex-wrap: wrap; gap: 14px 22px !important; margin-top: 28px !important; }
  .m-hero-copy > figure { margin-top: 32px !important; }
  /* The photo collage keeps its design, drawn at a smaller scale. */
  .m-hero-art { flex: none !important; width: 640px !important; height: 680px !important; margin: 20px auto 0 !important; zoom: .53; }

  /* ---------- Moving class names ---------- */
  .m-marquee { height: 86px !important; }
  .m-marquee > div { top: 18px !important; height: 52px !important; }
  .m-marquee .pr-marquee { font-size: 22px !important; gap: 22px !important; }
  .m-marquee .pr-marquee svg { width: 18px; height: 18px; }

  /* ---------- Numbers: 2 x 2 ---------- */
  .m-numbers { grid-template-columns: 1fr 1fr !important; }
  .m-numbers > div { padding: 22px 0 22px 16px !important; }
  .m-numbers > div:nth-child(odd) { border-left: 0 !important; padding-left: 0 !important; }
  .m-numbers > div:nth-child(n+3) { border-top: 1px solid #E4DCC2; }
  .m-numbers > div > div:first-child { font-size: 40px !important; }
  .m-numbers > div > div:first-child svg { display: none; }
  .m-numbers > div > div + div { font-size: 14px !important; }

  /* ---------- Name story ---------- */
  .m-outline { font-size: 140px !important; left: 10px !important; top: 24px !important; }
  .m-story img { height: 260px !important; }

  /* ---------- Programs by age ---------- */
  .m-tabs { flex-wrap: wrap; }
  .m-tabs button { height: 42px !important; padding: 0 14px !important; font-size: 14px !important; }
  #programs .pr-row { grid-template-columns: 56px minmax(0, 1fr) auto !important; column-gap: 12px !important; padding: 12px 2px !important; }
  #programs .pr-row > img, #programs .pr-row > div:first-child { width: 56px !important; height: 56px !important; font-size: 22px !important; }
  #programs .pr-row > svg { display: none; }
  #programs .pr-row [style*="font-size: 28px"] { font-size: 20px !important; }
  #programs .pr-row > div:last-of-type { font-size: 14px !important; text-align: right; }
  #eligibility { margin-top: 44px !important; }
  #eligibility > div[style*="padding: 30px"] { padding: 22px 18px !important; }

  /* ---------- Principal ---------- */
  .m-principal > div:first-child { max-width: 320px; margin: 0 auto; }
  .m-principal [style*="gap: 22px"] { flex-wrap: wrap; gap: 12px 18px !important; }
  .m-principal [style*="border-left"] { border-left: 0 !important; padding-left: 0 !important; }
  .m-principal img[alt^="Signature"] { width: 180px !important; height: auto !important; }
  .m-principal [style*="font-size: 150px"] { font-size: 110px !important; height: 48px !important; }

  /* ---------- Photo scrapbook ---------- */
  .m-photos { grid-template-columns: 1fr 1fr !important; gap: 22px 14px !important; margin-top: 32px !important; }
  .m-photos > figure { grid-column: auto !important; }
  .m-photos > figure:first-child { grid-column: 1 / -1 !important; }
  .m-photos img { height: 170px !important; }
  .m-photos > figure:first-child img { height: 230px !important; }
  .m-photos figcaption { font-size: 16px !important; }
  /* Photo viewer: photo nearly full width, caption centred under it, arrows in a row at the bottom */
  .m-lightbox { position: fixed !important; z-index: 2000 !important; padding: 72px 12px 110px !important; background: #162014 !important; }
  .m-lightbox img { width: 100% !important; height: auto !important; max-height: 68vh; border-radius: 4px; }
  .m-lightbox > div { flex-wrap: wrap; justify-content: center; text-align: center; gap: 4px 12px !important; margin-top: 14px !important; }
  .m-lightbox > div > span:first-child { font-size: 21px !important; }
  .m-lightbox button[aria-label="Close photo viewer"] { top: 16px !important; right: 16px !important; width: 44px !important; height: 44px !important; }
  .m-lightbox button[aria-label="Previous photo"], .m-lightbox button[aria-label="Next photo"] {
    top: auto !important; bottom: 32px !important; margin-top: 0 !important; width: 52px !important; height: 52px !important;
  }
  .m-lightbox button[aria-label="Previous photo"] { left: calc(50% - 64px) !important; }
  .m-lightbox button[aria-label="Next photo"] { right: calc(50% - 64px) !important; }

  /* ---------- Parents' reviews ---------- */
  .m-quote { height: auto !important; min-height: 280px; }
  #reviews blockquote { font-size: 22px !important; }
  #reviews .m-grid-inner > div:last-child { align-items: flex-start !important; }

  /* ---------- FAQ ---------- */
  #faq button { padding: 18px 0 !important; gap: 14px !important; }
  #faq button > span:first-child { font-size: 19px !important; }
  #faq p[style*="padding: 0 64px"] { padding-right: 0 !important; }

  /* ---------- Visit + form ---------- */
  #visit h2[style] { font-size: 38px !important; }
  .m-findus { flex-wrap: wrap; gap: 20px !important; }
  .m-findus > div:first-child { zoom: .7; }
  .m-card { padding: 24px 18px !important; }
  .m-form { grid-template-columns: 1fr !important; }
  .m-form > label { grid-column: auto !important; }
  .m-card [role="status"] { min-height: 0 !important; padding: 20px 0; }

  /* ---------- Footer ---------- */
  .m-footer { padding: 48px 20px 24px !important; }
  .m-footer-grid { grid-template-columns: 1fr 1fr !important; row-gap: 32px; }
  .m-footer-grid > div:first-child, .m-footer-grid > div:last-child { grid-column: 1 / -1; }
  .m-footer a, .m-findus a { overflow-wrap: anywhere; }
  .m-footer-grid p { width: auto !important; }
  .m-footer > div:last-child { flex-wrap: wrap; gap: 10px; margin-top: 36px !important; }

  /* ================= Inner pages (sections built by designs-src/build.mjs) ================= */
  .nx.section { padding: 56px 20px; }
  .nx.wrap { padding-left: 20px; padding-right: 20px; }
  .nx.phero { padding: 24px 20px 48px; }
  .nx .g12 { display: block; }
  .nx .g12 > * + * { margin-top: 28px; }
  .nx .head-row { display: block; }
  .nx .head-row > p { width: auto; margin-top: 14px; }
  .nx .hand { font-size: 19px; }
  .nx .display, .nx .hl-head .display, .nx .ar-head .display, .nx .ha-copy .display { font-size: 42px; }
  .nx .display.post-title { font-size: 32px; }
  .nx .h2 { font-size: 32px; }
  .nx .club .h2 { font-size: 34px !important; }
  .nx .h3 { font-size: 26px; }
  .nx .h4 { font-size: 21px; }
  .nx .h4[style*="font-size:30px"] { font-size: 22px !important; }
  .nx .lead { font-size: 18px; }
  .nx .copy { font-size: 17px; }
  .nx .panel { padding: 24px; }
  .d3 .nx .wave { top: -20px; height: 21px; }

  /* Generic page hero with a photo */
  .nx .phero-art { height: auto; }
  .nx .phero-art .disc, .nx .phero-art .rays { display: none; }
  .nx .phero-art .shot { position: relative; inset: auto; }
  .nx .phero-art .shot img { height: 260px !important; }

  /* Lists and cards */
  .nx .blocks { grid-template-columns: 1fr; }
  .nx .blocks > div, .nx .blocks > div:not(:nth-child(3n+1)) { padding: 24px 0; border-left: 0; }
  .nx .prog { grid-template-columns: 1fr; row-gap: 16px; padding: 28px 0; }
  .nx .prog img { width: 100%; height: 210px; }
  .nx .chart { font-size: 14px; }
  .nx .chart th, .nx .chart td { padding-right: 10px; }
  .nx .chart td:first-child { font-size: 17px; }
  .nx .yr-pick { flex-wrap: wrap; }
  .nx .club { display: block; padding: 36px 0; }
  .nx .club .txt { margin-top: 26px; }
  .nx .club .pic img { height: 240px !important; }
  .nx .feats { grid-template-columns: 1fr; gap: 22px; }
  .nx .chips span { font-size: 15px; padding: 10px 14px; }
  .nx .bigquote { font-size: 26px; }
  .nx .post-row { grid-template-columns: 1fr; row-gap: 6px; padding: 24px 0; }
  .nx .post-row .go { display: none; }
  .nx .article p { font-size: 17px; }
  .nx .article p:first-child { font-size: 19px; }
  .nx .article h2 { font-size: 25px; margin-top: 34px; }
  .nx .faq-item summary { font-size: 19px; padding: 18px 0; gap: 14px; }
  .nx .faq-item p { padding-right: 0; }
  .nx .faq-static { grid-template-columns: 1fr; row-gap: 8px; }
  .nx .form-card { padding: 24px 18px; }
  .nx .fields { grid-template-columns: 1fr; }
  .nx .form-done { min-height: 0; padding: 20px 0; }
  .nx .map { height: 300px; }

  /* Curriculum hero: the four pegged-up prints sit in a 2 x 2 grid, all visible at once */
  .nx.hero-line { padding: 24px 0 40px; }
  .nx.hero-line .crumbs { padding: 0 20px; }
  .nx .hl-head { padding: 0 20px; margin-top: 20px; }
  .nx .hl-head .actions { flex-direction: column; gap: 18px; }
  .nx .hl-head .actions .btn { order: -1; }
  .nx .hl-line { height: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 34px 16px; padding: 30px 20px 0; margin-top: 36px; }
  .nx .hl-string { display: none; }
  .nx .hl-print { width: auto; margin-top: 0 !important; padding: 8px 8px 10px; }
  .nx .hl-print img { height: 120px; }
  .nx .hl-print figcaption { margin-top: 8px; font-size: 16px; }
  .nx .hl-print .area { font-size: 10px; }
  .nx .hl-print .peg { top: -16px; width: 12px; height: 32px; margin-left: -6px; }

  /* Programs hero: the class staircase becomes a 2-column grid */
  .nx.hero-steps { padding: 24px 20px 44px; }
  .nx .hs-top { grid-template-columns: 1fr; gap: 20px; }
  .nx .hs-stairs { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 32px; }
  .nx .hs-stairs li { padding-top: 0; }
  .nx .hs-stairs a { height: auto; padding: 10px 10px 14px; border-radius: 16px; }
  .nx .hs-stairs img { height: 110px; border-radius: 10px; }
  .nx .hs-name { font-size: 19px; }
  .nx .hs-age { font-size: 16px; margin-top: 10px; }
  .nx .hs-go { display: none; }
  .nx .hs-sun { display: none; }

  /* Afterschool hero */
  .nx.hero-arch { display: block; padding: 24px 20px 48px; }
  .nx .ha-art { height: 300px; margin-bottom: 28px; }
  .nx .ha-disc { display: none; }
  .nx .ha-bell { width: 60px; height: 60px; top: 10px; right: 6px; }
  .nx .ha-tickets { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
  .nx .ha-tickets a { padding: 10px 12px; gap: 10px; }
  .nx .ha-tickets .ic { width: 36px; height: 36px; }
  .nx .ha-tickets strong { font-size: 17px; }

  /* About hero: the rising sun keeps its design, drawn smaller */
  .nx.hero-rise { padding: 24px 20px 0; }
  .nx .ar-stage { zoom: .27; margin-top: 60px; }
}

/* Small tablets: a little more room for the scaled pieces */
@media (min-width: 600px) and (max-width: 899px) {
  .m-hero-art { zoom: .9; }
  .nx .ar-stage { zoom: .55; }
  .m-photos img { height: 260px !important; }
}
