/* =========================================
   1. FIXES & PERFORMANCE (CLS & BUGS)
   ========================================= */

/* Fix the broken fade-in effect (Blank screen bug) | 7734906-zen tcrv */ 
.js body {
    opacity: 1 !important;
}

/* Fix main article image layout shift (CLS: 0.634) */
.entry-image img.attachment-rebalance-archive { 
    aspect-ratio: 350 / 257; 
    height: auto; 
    width: 100%; 
}

/* Reserve space for sidebar to stop jumping (CLS: 0.092) */
#secondary.widget-area { 
    min-height: 268px; 
} 

/* Reserve space for Older Posts button (CLS: 0.035) */
#infinite-handle span { 
    min-height: 72px; 
    display: block; 
}

/* Force all images to stay within screen limits */
img {
    max-width: 100%;
    height: auto;
}

/* =========================================
   2. MODERN UX & READABILITY UPGRADES
   ========================================= */

/* Enable smooth scrolling for page anchor links */
html {
    scroll-behavior: smooth;
}

/* Custom Text Highlight (Navy Blue for Naval History) */
::selection {
    background-color: #1a365d; 
    color: #ffffff; 
}

/* Modern Button Hover Effect (Slight lift and shadow) */
button, 
.button, 
.wp-block-button__link {
    transition: all 0.3s ease-in-out !important;
}
button:hover, 
.button:hover, 
.wp-block-button__link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* Improve paragraph spacing for long academic reading */
p {
    line-height: 1.6;
    margin-bottom: 1.5em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Soften sharp image corners slightly */
img {
    border-radius: 4px;
}

/* =========================================
   3. CUSTOM ACADEMIC STYLING
   ========================================= */

/* Elegant Historical Blockquotes */
blockquote {
    border-left: 4px solid #1a365d !important; /* Navy blue accent */
    background-color: #f8f9fa !important; /* Very soft gray/white background */
    padding: 15px 25px !important;
    margin: 25px 0 !important;
    font-style: italic;
    color: #333333;
    border-radius: 0 4px 4px 0;
}
blockquote p {
    margin-bottom: 0 !important;
}
/* ------------------------------------------------------------------------- *
 * CORE WEB VITALS - LAYOUT SHIFT (CLS) FIXES
 * ------------------------------------------------------------------------- */

/* Reserve space for the secondary widget area to prevent the 0.478 layout shift */
@media (max-width: 768px) {
    #secondary.widget-area {
        min-height: 400px; /* Adjust this value if your widget block is substantially taller or shorter */
        display: block; 
    }
}

/* Enforce native aspect ratio scaling so Jetpack images don't collapse */
img {
    max-width: 100%;
    height: auto;
}
/* Fix Cookie Consent Button Contrast (Accessibility) */
.cky-btn-accept, .cky-btn-reject {
    background-color: #0b4aab !important; /* Darker blue for higher contrast */
    color: #ffffff !important; /* Pure white text */
    font-size: 16px !important; /* Fixes the 'Unsupported CSS Property: font-size' error */
}
/* Force text to display immediately while web fonts load */
body, h1, h2, h3, h4, h5, h6, p, a, span {
    font-display: swap !important;
}
/* Tell the browser the aspect ratio of your thumbnails */
.attachment-rebalance-archive {
    aspect-ratio: 16 / 9; /* Change this to match the ratio of your site images */
    width: 100%;
    height: auto;
}

/* ==========================================
   4. SYSTEM FONTS - stop font-swap layout shift (PageSpeed CLS 1.667, sidebar 0.935+0.469)
   Added 2026-12-01. To undo: delete this block. Lora stays selected in Fonts.
   ========================================== */
body,
body *:not(.genericon):not([class*="genericon"]):not([class*="dashicons"]):not([class*="fa-"]):not([class*="icon"]) {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}
body :is(h1, h2, h3, h4, h5, h6, .site-title, .site-title *, .entry-title, .entry-title *, .widget-title, blockquote, blockquote *):not(.genericon):not([class*="genericon"]):not([class*="dashicons"]):not([class*="fa-"]):not([class*="icon"]) {
    font-family: Georgia, "Times New Roman", serif !important;
}
.site-title { font-size: clamp(2.2rem, 11vw, 4.8rem) !important; overflow-wrap: normal !important; }


/* ==========================================
   5. STABLE POST GRID - replaces Masonry's late JS positioning (main cause of layout shift)
   Added 2026-12-01. To undo: delete this block.
   ========================================== */
#infinite-wrap { height: auto !important; }
#infinite-wrap > article { position: static !important; left: auto !important; top: auto !important; }
#infinite-wrap > .infinite-wrap { display: contents; }
#infinite-wrap > #infinite-handle { position: static !important; left: auto !important; top: auto !important; grid-column: 1 / -1; }
#infinite-wrap > .grid-sizer, #infinite-wrap > .grid-item:empty { display: none !important; }
@media (min-width: 600px) {
  #infinite-wrap { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 2%; align-items: start; }
  #infinite-wrap > article, #infinite-wrap > .infinite-wrap > article { width: auto !important; }
}

/* 6. REBALANCE DESKTOP MENU FIRST PAINT */
/* Match Rebalance's three five-item columns while its script initializes. */
@media screen and (min-width: 881px) {
  .js #site-navigation > div > #header-menu:has(> li:nth-child(15):last-child) {
    width: 99%;
    columns: 3;
    column-gap: 0;
  }

  .js #site-navigation > div > #header-menu:has(> li:nth-child(15):last-child) > li {
    break-inside: avoid-column;
  }

  .js #site-navigation > div > #header-menu:has(> li:nth-child(15):last-child) > :is(li:nth-child(6), li:nth-child(11)) {
    break-before: column;
  }
}

/* 7. REBALANCE MENU KEYBOARD AND SIXTEEN-LINK LAYOUT */
@media screen and (max-width: 880px) {
  .js #site-navigation:not(.toggled-on) > div {
    visibility: hidden;
  }
}

@media screen and (min-width: 881px) {
  .js #site-navigation > div > #header-menu:has(> li:nth-child(16):last-child) {
    width: 99%;
    columns: 3;
    column-gap: 0;
  }

  .js #site-navigation > div > #header-menu:has(> li:nth-child(16):last-child) > li {
    break-inside: avoid-column;
  }

  .js #site-navigation > div > #header-menu:has(> li:nth-child(16):last-child) > :is(li:nth-child(7), li:nth-child(13)) {
    break-before: column;
  }
}

/* 8. SEARCH FIELD TEXT CONTRAST */
input[type="search"].search-field,
input[type="search"].search-field::placeholder {
  color: #005a9c;
}

input[type="search"].search-field::placeholder {
  opacity: 1;
}

/* 9. CATEGORY PAGINATION SPACE */
/* Keep the archive footer below the reading area while Jetpack fetches more cards. */
.category #infinite-wrap > .infinite-loader {
    clear: both;
    grid-column: 1 / -1;
}
.category #infinite-wrap:has(> .infinite-loader)::after {
    content: "";
    display: block;
    clear: both;
    grid-column: 1 / -1;
    min-height: 100vh;
}
