/* Phone and tablet layout for the static site.
   The pages are styled inline, so these rules match on the inline style text
   and need !important to win. Linked from every page by _src/postprocess.py. */

img { max-width: 100%; }

/* menu button, added by site.js; only shown at phone and tablet widths */
.nav-toggle {
  display: none; flex: none; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; background: none; cursor: pointer;
  border: 1px solid #2B5275; border-radius: 2px; color: #EDEEEA;
}
.nav-toggle:focus-visible { outline: 2px solid #B8A64A; outline-offset: 2px; }
.nav-toggle svg { display: block; }
.nav-toggle .x, .menu-open .nav-toggle .bars { display: none; }
.menu-open .nav-toggle .x { display: block; }

@media (max-width: 900px) {
  /* ---- page gutters and vertical rhythm ---- */
  [style*="px 40px"] { padding-left: 20px !important; padding-right: 20px !important; }
  [style*="padding: 112px"], [style*="padding: 104px"], [style*="padding: 96px"],
  [style*="padding: 88px"], [style*="padding: 80px"], [style*="padding: 72px"] {
    padding-top: 48px !important; padding-bottom: 48px !important;
  }
  [style*="padding: 64px"], [style*="padding: 56px"] { padding-top: 40px !important; padding-bottom: 40px !important; }

  /* ---- header with JavaScript: title + menu button; links open in a panel ---- */
  .js-nav header { display: flex; flex-direction: column; max-height: 100vh; overflow-y: auto; }
  .js-nav header > div:first-child { order: 2; display: none; border-bottom: none !important; }
  .js-nav header > div:last-child { border-bottom-color: transparent !important; }
  .js-nav header > div:last-child > div { min-height: 60px !important; gap: 0 12px !important; flex-wrap: wrap !important; }
  .js-nav header > div:last-child > div > a:first-child { flex: 1 1 0; min-width: 0; font-size: 17px !important; }
  .js-nav header > div:last-child nav,
  .js-nav header > div:last-child > div > a:last-child { display: none !important; }
  .js-nav .nav-toggle { display: inline-flex; }

  .js-nav header.menu-open > div:first-child { display: block; }
  .js-nav header.menu-open > div:last-child nav {
    display: flex !important; flex-direction: column; align-items: stretch !important;
    order: 3; flex: 1 1 100%; border-top: 1px solid #1D3D5C; margin-top: 4px;
  }
  .js-nav header.menu-open > div:last-child nav a {
    min-height: 52px !important; padding: 0 !important; font-size: 18px !important;
    border-bottom: 1px solid #1B3A57;
  }
  .js-nav header.menu-open > div:last-child nav a > span { right: auto !important; width: 28px; }
  .js-nav header.menu-open > div:last-child > div > a:last-child {
    display: block !important; order: 4; flex: 1 1 100% !important; text-align: center; margin: 18px 0 6px;
  }
  .js-nav header.menu-open > div:first-child > div { display: block !important; padding-top: 4px !important; padding-bottom: 20px !important; }
  .js-nav header.menu-open > div:first-child nav { flex-direction: column; align-items: stretch !important; gap: 0 !important; }
  .js-nav header.menu-open > div:first-child a { display: block; padding: 11px 0 !important; font-size: 15px !important; }

  /* ---- header without JavaScript: not sticky, one scrolling row of links ---- */
  html:not(.js-nav) header[style*="position: sticky"] { position: static !important; }
  html:not(.js-nav) header nav { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100%; }
  html:not(.js-nav) header nav::-webkit-scrollbar { display: none; }
  html:not(.js-nav) header nav a { white-space: nowrap; flex: none; }
  html:not(.js-nav) header > div:first-child a[href^="mailto:"] { display: none !important; }
  html:not(.js-nav) header > div:first-child nav { gap: 20px !important; }
  html:not(.js-nav) header > div:last-child > div { gap: 0 16px !important; padding-top: 14px !important; min-height: 0 !important; }
  html:not(.js-nav) header > div:last-child nav { order: 3; flex: 1 1 100%; margin: 6px -20px 0; padding: 0 8px; }
  html:not(.js-nav) header > div:last-child nav a { min-height: 48px !important; padding: 0 12px !important; }
  html:not(.js-nav) header > div:last-child > div > a:first-child { flex: 1 1 0; min-width: 0; font-size: 17px !important; }
  html:not(.js-nav) header > div:last-child > div > a:last-child { padding: 10px 14px !important; font-size: 14px !important; }

  /* ---- multi-column grids collapse to one column ---- */
  [style*="repeat(12,"],
  [style*="minmax(0px, 1.55fr)"],
  [style*="minmax(200px, 250px)"],
  [style*="minmax(220px, 300px)"],
  [style*="minmax(0px, 150px)"] {
    grid-template-columns: minmax(0, 1fr) !important; gap: 20px !important;
  }
  [style*="grid-column:"] { grid-column: 1 / -1 !important; }
  [style*="position: sticky; top: 120px"] { position: static !important; }

  /* ---- type scale ---- */
  [style*="font-size: 76px"] { font-size: 44px !important; }
  [style*="font-size: 66px"] { font-size: 48px !important; }
  [style*="font-size: 52px"], [style*="font-size: 48px"], [style*="font-size: 46px"], [style*="font-size: 44px"] { font-size: 32px !important; }
  [style*="font-size: 40px"], [style*="font-size: 36px"], [style*="font-size: 34px"] { font-size: 28px !important; }
  [style*="font-size: 32px"], [style*="font-size: 30px"] { font-size: 25px !important; }
  [style*="font-size: 28px"], [style*="font-size: 27px"], [style*="font-size: 26px"] { font-size: 22px !important; }
  [style*="font-size: 22px"], [style*="font-size: 21px"] { font-size: 19px !important; }

  /* ---- home hero: text first, cover centred underneath, sitting on the edge ---- */
  .hero-copy { padding: 48px 0 36px !important; }
  .hero-cover { justify-self: center; width: min(62vw, 260px); }
}

@media (max-width: 640px) {
  /* card grids: one card per row, and never wider than the screen */
  [style*="repeat(auto-fit, minmax(2"], [style*="repeat(auto-fit, minmax(3"],
  [style*="repeat(auto-fill, minmax(2"], [style*="repeat(auto-fill, minmax(3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  /* inner card padding */
  [style*="px 34px"], [style*="px 36px"], [style*="px 32px"], [style*="px 30px"],
  [style*="padding: 44px 56px"], [style*="padding: 40px 44px"],
  [style*="padding: 48px;"], [style*="padding: 40px;"] {
    padding-left: 20px !important; padding-right: 20px !important;
  }
  /* columns divided by a rule on desktop: stack, drop the side padding and rule */
  [style*="padding: 28px 44px"], [style*="padding: 28px 0px 0px 44px"],
  [style*="padding: 0px 48px 0px 0px"], [style*="padding: 0px 0px 0px 48px"],
  [style*="padding: 0px 40px 0px 0px"], [style*="padding: 4px 30px 4px 0px"], [style*="padding: 4px 0px 4px 30px"] {
    padding-left: 0 !important; padding-right: 0 !important; border-left: none !important; border-right: none !important;
  }
  /* comparison table on the Chapter Anatomy page */
  table { font-size: 13px !important; }
  th, td { padding: 8px 6px !important; overflow-wrap: break-word; hyphens: auto; }
  th { letter-spacing: 0.04em !important; font-size: 11px !important; }
  /* chapter cards on the book page: numeral above the title, not beside it */
  [style*="padding: 32px 34px 26px"] { flex-direction: column; gap: 14px !important; }
  [style*="white-space: nowrap"] { white-space: normal !important; }
  header a[style*="white-space"], header nav a { white-space: nowrap !important; }
  /* buttons in a row go full width */
  .hero-actions > a { flex: 1 1 100%; text-align: center; }
}

/* ---- Visitor details pop-up (built by site.js) ---- */
html.vg-open, html.vg-open body { overflow: hidden; }
.vg {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(9, 22, 35, 0.78); overflow-y: auto;
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.vg-card {
  width: 100%; max-width: 460px; margin: auto; background: #fff; color: #1C1F1D;
  border-top: 4px solid #C9BE7E; padding: 34px 36px 28px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.vg-eyebrow { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: #5A5F59; font-weight: 600; margin-bottom: 10px; }
.vg-card h2 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 28px; line-height: 1.15; letter-spacing: -0.01em; color: #10263B; margin: 0 0 12px; }
.vg-card p { font-size: 16px; line-height: 1.55; color: #54574F; margin: 0 0 20px; }
.vg-card label { display: block; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: #10263B; margin: 0 0 6px; }
.vg-card input[type="text"], .vg-card input[type="email"] {
  display: block; width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; color: #1C1F1D;
  background: #fff; border: 1px solid #B9BDB6; border-radius: 0; padding: 11px 12px; margin: 0 0 16px;
}
.vg-card input:focus { outline: 2px solid #10263B; outline-offset: 1px; border-color: #10263B; }
.vg-card .vg-hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.vg-card .vg-error { font-size: 14px; color: #A3261B; margin: 0 0 14px; }
.vg-actions { display: flex; gap: 12px; align-items: stretch; margin-top: 4px; }
.vg-actions button { font: inherit; font-size: 16px; font-weight: 600; padding: 13px 18px; cursor: pointer; border-radius: 0; }
.vg-submit { flex: 1 1 auto; background: #10263B; color: #fff; border: 1px solid #10263B; }
.vg-submit:hover { background: #1B3A57; }
.vg-submit:disabled { opacity: 0.65; cursor: default; }
.vg-skip { flex: 0 0 auto; background: #fff; color: #10263B; border: 1px solid #10263B; }
.vg-skip:hover { background: #F1F2EF; }
.vg-actions button:focus-visible { outline: 2px solid #C9BE7E; outline-offset: 2px; }
.vg-card .vg-note { font-size: 13px; line-height: 1.5; color: #6A6E68; margin: 16px 0 0; }
@media (max-width: 480px) {
  .vg { padding: 12px; align-items: flex-start; }
  .vg-card { padding: 26px 22px 22px; }
  .vg-card h2 { font-size: 24px; }
}
