/* ==========================================================================
   responsive-fixes.css
   Repairs mobile-layout problems in the khatu.org static archive.
   Loaded last so it wins over the theme without needing !important.
   ========================================================================== */

/* --- 1. Stop horizontal overflow -------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;   /* iOS Safari: no surprise font inflation */
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;               /* kill sideways scroll from stray wide nodes */
}

*,
*::before,
*::after {
  box-sizing: border-box;           /* padding stops blowing out declared widths */
}

/* --- 2. Fluid media ---------------------------------------------------- */
/* Scraped markup carries hardcoded width/height attributes; override them. */
img,
video,
canvas,
svg,
object,
embed {
  max-width: 100%;
  height: auto;
}

/* Preserve intrinsic ratio when only width was authored */
img[width][height] {
  height: auto;
}

/* --- 3. Responsive embeds --------------------------------------------- */
iframe {
  max-width: 100%;
  border: 0;
}

/* Video embeds keep a 16:9 box instead of a fixed 320/600px frame */
iframe[src*="youtube"],
iframe[src*="youtu.be"],
iframe[src*="vimeo"],
iframe[src*="dailymotion"],
iframe[src*="facebook.com/plugins/video"] {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  margin-inline: auto;
}

/* Maps are typically squarer */
iframe[src*="google.com/maps"],
iframe[src*="maps.google"] {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  display: block;
}

/* --- 4. Long strings & code ------------------------------------------- */
p, li, td, th, dd, dt, h1, h2, h3, h4, h5, h6, blockquote, figcaption {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

a {
  overflow-wrap: break-word;        /* bare URLs stop pushing the viewport */
}

pre, code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- 5. Tables -------------------------------------------------------- */
table {
  max-width: 100%;
  display: block;
  overflow-x: auto;                 /* scroll the table, not the page */
  -webkit-overflow-scrolling: touch;
}

/* --- 6. Missing-image degradation ------------------------------------- */
/* Part of this archive's image payload was not captured by the scraper.
   Broken images collapse to nothing rather than showing a torn-page icon
   that breaks surrounding layout. Alt text stays available to screen
   readers and to anyone with images disabled.                            */
img {
  font-size: 0.85rem;
  line-height: 1.3;
  color: #6b6b6b;
}

img:not([src]),
img[src=""],
img[src$="/images/"] {
  display: none;
}

/* --- 7. Touch-target & form sanity ------------------------------------ */
input,
select,
textarea,
button {
  max-width: 100%;
  font-size: max(16px, 1rem);       /* <16px triggers iOS zoom-on-focus */
}

input[type="text"],
input[type="search"],
input[type="email"],
input[type="url"],
input[type="tel"],
textarea,
select {
  width: 100%;
}

/* --- 8. Small-screen refinements -------------------------------------- */
@media (max-width: 768px) {
  /* Neutralise inline pixel widths the theme hardcoded on wrappers */
  [style*="width:"][style*="px"],
  [width] {
    max-width: 100% !important;
  }

  .post-body img,
  .entry-content img {
    display: block;
    margin-inline: auto;
  }

  /* Blogger sidebar/columns stack instead of squeezing */
  #sidebar-wrapper,
  #main-wrapper,
  .sidebar,
  .main-wrapper,
  .column-left-outer,
  .column-right-outer,
  .column-center-outer {
    width: 100% !important;
    float: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 16px;
    line-height: 1.6;
  }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.35rem; }
  h3 { font-size: 1.15rem; }
}

/* --- 9. Accessibility -------------------------------------------------- */
/* Visible keyboard focus — several theme rules removed outlines entirely. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #0049CE;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- 10. Print --------------------------------------------------------- */
@media print {
  nav, .sidebar, .mobile-menu-toggle, iframe, .social-share {
    display: none !important;
  }

  body {
    color: #000;
    background: #fff;
  }
}
