/* Mobile and tablet layouts.
   The desktop design is unchanged above 900px. The pages use inline styles,
   so these overrides need !important. */

/* Phone menu button (added by js/mobile.js), hidden on desktop */
.nav-toggle{display:none}

/* ---------- Tablet and phone: 900px and narrower ---------- */
@media (max-width: 900px) {
  /* Page gutters */
  #page-top, :is(#hero,#hero-d), :is(#work,#work-d), :is(#contact,#contact-d) { padding-left: 24px !important; padding-right: 24px !important; }
  #page-top { gap: 56px !important; padding-bottom: 48px !important; }

  /* Top navigation becomes a bar with a Menu button */
  nav[aria-label="Main"] { height: 68px !important; padding: 0 24px !important; margin-left: -24px !important; margin-right: -24px !important; }
  :is(#site-nav,#site-nav-d) { margin-left: 0 !important; margin-right: 0 !important; margin-bottom: -68px !important; }
  nav[aria-label="Main"] > span { font-size: 22px !important; }
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
    font: inherit; font-size: 15px; font-weight: 500; border-radius: 999px; cursor: pointer;
    background: transparent; color: inherit; border: 1.5px solid currentColor;
  }
  nav[aria-label="Main"] > div {
    display: none !important;
    position: absolute; top: 68px; left: 0; right: 0;
    flex-direction: column !important; align-items: stretch !important; gap: 0 !important;
    padding: 8px 24px 24px; font-size: 20px !important;
    background: inherit; background-color: inherit;
    box-shadow: 0 18px 30px -18px rgba(0,0,0,0.35);
  }
  nav[aria-label="Main"].nav-open > div { display: flex !important; }
  #site-nav-d > div { background: #141414 !important; }
  nav[aria-label="Main"] > div > a { padding: 14px 0 !important; border-bottom: 1px solid rgba(128,128,128,0.25); }
  nav[aria-label="Main"] > div > a.resume { margin-top: 16px; border-radius: 999px !important; text-align: center; border-bottom: 1.5px solid currentColor; }
  nav[aria-label="Main"] > div > a.theme { width: auto !important; height: auto !important; border-radius: 0 !important; justify-content: flex-start !important; gap: 10px; border-bottom: 0; }
  nav[aria-label="Main"] > div > a.theme::after { content: attr(title); font-size: 16px; }

  /* Every 12-column grid stacks into one column */
  [style*="grid-template-columns: repeat(12"], .case, .idea .meta {
    grid-template-columns: minmax(0, 1fr) !important; row-gap: 24px !important;
  }
  [style*="grid-template-columns: repeat(12"] > *, .case > *, .idea .meta > * { grid-column: 1 / -1 !important; }
  [style*="grid-template-columns: repeat(4"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; row-gap: 24px !important; }

  /* Headers that sit side by side wrap */
  header#top { flex-direction: column !important; align-items: flex-start !important; gap: 20px !important; }
  header#top p { max-width: none !important; }

  /* Type scale */
  [style*="font-size: 220px"] { font-size: clamp(64px, 17vw, 140px) !important; }
  [style*="font-size: 140px"] { font-size: clamp(64px, 16vw, 112px) !important; }
  [style*="font-size: 120px"], [style*="font-size: 112px"] { font-size: clamp(56px, 14vw, 96px) !important; }
  [style*="font-size: 96px"] { font-size: clamp(56px, 13vw, 80px) !important; }
  [style*="font-size: 88px"] { font-size: clamp(44px, 11vw, 72px) !important; }
  [style*="font-size: 76px"] { font-size: clamp(42px, 10.5vw, 64px) !important; }
  [style*="font-size: 72px"] { font-size: clamp(42px, 10vw, 60px) !important; }
  [style*="font-size: 64px"] { font-size: clamp(36px, 9vw, 52px) !important; }
  [style*="font-size: 56px"], .case h2, .case .stat b { font-size: clamp(34px, 8.5vw, 48px) !important; }
  [style*="font-size: 48px"], .idea h2 { font-size: clamp(32px, 8vw, 44px) !important; }
  [style*="font-size: 46px"], [style*="font-size: 44px"] { font-size: clamp(30px, 7.5vw, 40px) !important; }
  [style*="font-size: 40px"] { font-size: clamp(30px, 7.5vw, 36px) !important; }

  /* Home hero */
  :is(#hero,#hero-d) { height: auto !important; min-height: 0 !important; padding-top: 108px !important; padding-bottom: 48px !important; }
  :is(#hero,#hero-d) [style*="grid-column: span 4"] { order: -1; align-items: center; }
  :is(#hero,#hero-d) [style*="width: 340px"] { width: 220px !important; height: 220px !important; }
  :is(#hero,#hero-d) [style*="width: 361px"] { width: auto !important; }

  /* Home bento tiles */
  :is(#work,#work-d) { padding-top: 56px !important; padding-bottom: 56px !important; }
  :is(#work,#work-d) [style*="grid-template-rows"] { grid-template-rows: none !important; }
  :is(#work,#work-d) a.tile { padding: 24px !important; gap: 20px !important; border-radius: 22px !important; }
  :is(#work,#work-d) a.tile:has(> [style*="width: 200px"]) { flex-direction: column-reverse !important; }
  :is(#work,#work-d) a.tile > [style*="width: 200px"] { width: 100% !important; height: 200px !important; }
  :is(#work,#work-d) a.tile > div:first-child { gap: 18px; }

  /* Career timeline: narrower label column */
  :is(#contact,#contact-d) { padding-top: 56px !important; }
  :is(#career,#career-d) { padding-bottom: 24px !important; }
  .tl-row, :is(#career,#career-d) [style*="grid-template-columns: 300px"] { grid-template-columns: 128px minmax(0, 1fr) !important; column-gap: 12px !important; }
  :is(#career,#career-d) [style*="left: 324px"] { left: 140px !important; }
  .tl-lbl strong { font-size: 16px !important; }
  .tl-lbl span { font-size: 11px !important; }
  .tl-row { min-height: 56px !important; }
  :is(#career,#career-d) [style*="height: 18px"][style*="IBM Plex Mono"] span:nth-child(even) { display: none; }
  :is(#career,#career-d) [style*="height: 18px"][style*="IBM Plex Mono"] { font-size: 10px !important; }
  :is(#career,#career-d) [style*="gap: 40px"] { gap: 24px !important; }
  :is(#career,#career-d) input[type=range] { width: 100% !important; max-width: 320px; }
  :is(#contact,#contact-d) button.copy { font-size: 17px !important; padding: 18px 22px !important; max-width: 100%; }
  :is(#contact,#contact-d) button.copy span { overflow-wrap: anywhere; }
  footer { flex-direction: column !important; gap: 8px; }

  /* About hero photo */
  figure[aria-label="Hero image"] { margin: 0 -24px !important; width: calc(100% + 48px) !important; }
  figure[aria-label="Hero image"] img { height: 62vw !important; max-height: 640px; }

  /* Work list */
  .case { padding-top: 28px !important; }
  .case .img { height: auto !important; aspect-ratio: 4 / 3; }

  /* Case studies: section menu turns into a scrolling row of chips */
  div:has(> aside) { flex-direction: column !important; gap: 32px !important; }
  aside { width: auto !important; position: static !important; gap: 20px !important; align-self: stretch !important; min-width: 0; }
  aside nav[aria-label="On this page"] {
    flex-direction: row !important; overflow-x: auto; gap: 8px !important;
    margin: 0 -24px; padding: 0 24px 4px; scrollbar-width: none;
  }
  aside nav[aria-label="On this page"] a { flex: 0 0 auto; gap: 10px; border: 1px solid rgba(128,128,128,0.35); border-radius: 999px !important; }
  main figure[style*="padding: 32px"] { padding: 12px !important; }
  [style*="padding: 44px"] { padding: 28px !important; border-radius: 22px !important; }

  /* Closing "Continue reading" lines */
  p[style*="text-align: right"][style*="font-size: 48px"] { text-align: left !important; }
}

/* ---------- Small phones: 480px and narrower ---------- */
@media (max-width: 480px) {
  #page-top, :is(#hero,#hero-d), :is(#work,#work-d), :is(#contact,#contact-d) { padding-left: 20px !important; padding-right: 20px !important; }
  nav[aria-label="Main"] { padding: 0 20px !important; margin-left: -20px !important; margin-right: -20px !important; }
  :is(#site-nav,#site-nav-d) { margin-left: 0 !important; margin-right: 0 !important; }
  figure[aria-label="Hero image"] { margin: 0 -20px !important; width: calc(100% + 40px) !important; }
  [style*="grid-template-columns: repeat(4"] { grid-template-columns: minmax(0, 1fr) !important; }
  .tl-row, :is(#career,#career-d) [style*="grid-template-columns: 300px"] { grid-template-columns: 112px minmax(0, 1fr) !important; }
  :is(#career,#career-d) [style*="left: 324px"] { left: 124px !important; }
}
