/* Custom styles to improve spacing and layout */

/* Specific styling for article page titles only */
article header h1 {
    margin-top: 0.2rem !important;
    margin-bottom: 0.2rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    line-height: 1.2 !important;
}

/* Section page titles (like AI for Business) - keep them normal */
main > h1:not(article header h1) {
    margin-top: 1rem !important;
    margin-bottom: 0.25rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    line-height: 1.2 !important;
}

/* Reduce space between site header and main content */
body > header {
    margin-bottom: 1rem !important;
    padding: 1rem 0; /* match footer */
}

main {
    padding-top: 0;
    margin-top: -0.5rem;
    min-height: auto !important;
    flex: 1 0 auto;
}

/* Make body a flexbox container for better layout control */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    display: flex !important;
    flex-direction: column !important;
    min-height: 100vh !important;
}

/* Ensure footer stays at bottom and mirrors header spacing*/
footer {
    margin-top: auto;
    padding: 1rem 0; /* match header default padding */
}

/* Improve section page layout */
.container {
    padding-top: 0.25rem;
    padding-bottom: 0.5rem;
}

/* Responsive layout adjustments */
@media (max-height: 800px) {
    /* Reduce margins on shorter screens */
    header {
        margin-bottom: 0.5rem !important;
    }
    
    footer {
        margin-top: 1rem;
        padding: 1rem 0;
    }
}

/* Very compact layout for small screens */
@media (max-height: 600px) {
    header {
        padding: 0.5rem 0;
        margin-bottom: 0.25rem !important;
    }
    
    footer {
        padding: 0.5rem 0;
    }
    
    .container {
        padding-top: 0.1rem;
        padding-bottom: 0.25rem;
    }
}

/* Force very tight spacing between title and content */
main .container h1 + p {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

main .container h1 {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    line-height: 1.1 !important;
}

/* Try different selectors in case the structure is different */
body main h1:first-child {
    margin-bottom: 0 !important;
}

.container > h1:first-child {
    margin-bottom: 0 !important;
}

/* Better spacing for content sections */
main .content {
    margin-top: 0 !important;
}

/* Override any default paragraph margins after titles */
main p:first-of-type {
    margin-top: 0 !important;
}

/* Reduce spacing in single page article headers (About, individual posts) */
main > .container > article {
    margin-top: 0.5rem !important;
    padding-top: 0 !important;
}

/* Reset article headers so they don't inherit the site header styling */
main > .container > article > header {
    background: transparent !important;
    border: none !important;
    margin: 0 0 0.75rem 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* Refined page title */
main > .container > article > header h1,
main > .container > article > header .page-title {
    font-size: clamp(1.6rem, 2vw + 1.2rem, 2.25rem);
    font-weight: 700;
    color: var(--ctp-text);
    letter-spacing: -0.01em;
}

main > .container > article header .post-meta {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Keep normal spacing for post list items */
.post-item {
    margin-bottom: 1rem;
    background-color: var(--ctp-surface0) !important;
    border-radius: 8px !important;
    padding: 1.5rem !important;
    transition: background-color 0.2s ease !important;
}

.post-item:hover {
    background-color: var(--ctp-surface1) !important;
}

.post-item article header {
    margin-bottom: 0.5rem !important;
    padding-left: 0;
    padding-right: 0;
}

/* Ensure post titles are visible */
.post-item .post-title {
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
}

.post-item .post-title a {
    color: var(--ctp-text) !important;
    text-decoration: none !important;
}

.post-item .post-title a:hover {
    color: var(--ctp-blue) !important;
}

/* Make sure post meta and summary are visible */
.post-item .post-meta {
    color: var(--ctp-subtext0) !important;
    font-size: 0.9rem !important;
    margin-bottom: 1rem !important;
}

.post-item .post-summary {
    color: var(--ctp-text) !important;
    line-height: 1.6 !important;
}

/* Improve post meta spacing */
.post-meta {
    margin-bottom: 1rem;
    margin-left: 0;
    padding-left: 0;
}

/* Better spacing for section lists */
.post-list {
    margin-top: 1rem;
}

/* Improve vertical rhythm */
p {
    margin-bottom: 1rem;
}

/* Better spacing for home page sections */
.home-section {
    margin-bottom: 2rem;
}

.home-section:last-child {
    margin-bottom: 1rem;
}

/* Clean, targeted heading spacing overrides */
.container h1 {
    margin-top: 1rem !important;
    margin-bottom: 0.1rem !important;
}

.container h2 {
    margin-top: 1.5rem !important;
    margin-bottom: 0.1rem !important;
}

.container h3 {
    margin-top: 1.25rem !important;
    margin-bottom: 0.1rem !important;
}

/* Force H2 and H3 to match H1 tight spacing with highest specificity */
main .container h2,
body main .container h2,
html body main .container h2 {
    margin-bottom: 0.1rem !important;
    padding-bottom: 0 !important;
}

main .container h3,
body main .container h3,
html body main .container h3 {
    margin-bottom: 0.1rem !important;
    padding-bottom: 0 !important;
}

/* Remove top margin from paragraphs that immediately follow H2 and H3, but NOT in post items */
main .container h2 + p:not(.post-item h2 + p),
body main .container h2 + p:not(.post-item h2 + p),
html body main .container h2 + p:not(.post-item h2 + p) {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

main .container h3 + p:not(.post-item h3 + p),
body main .container h3 + p:not(.post-item h3 + p),
html body main .container h3 + p:not(.post-item h3 + p) {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Ensure post items maintain proper internal spacing */
.post-item h3 {
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
}

.post-item .post-summary {
    margin-top: 0 !important;
}

/* Improved tags/terms display */
.terms-list {
    display: inline-block;
    margin-bottom: 0.5rem;
}

.terms-label {
    font-weight: normal;
    margin-right: 0.5rem;
}

.terms-items {
    display: inline;
}

.terms-items a {
    text-decoration: none;
    opacity: 0.8;
}

.terms-items a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Global heading line-height improvements */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.3 !important;
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    html { font-size: 15px; }
    h1, h2, h3, h4, h5, h6 { line-height: 1.2 !important; }

    /* Header compression */
    body > header { padding: 0.6rem 0 !important; }
    footer { padding: 0.6rem 0 !important; }
    .header-content { gap: 0.6rem !important; }
    .site-title { font-size: 1.25rem !important; }

    /* Keep nav items on one line each, allow horizontal scroll if needed */
    nav ul {
        gap: 0.75rem !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        scrollbar-width: none; /* Firefox */
        /* Subtle edge fade to hint scrollability */
        -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
        mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
    }
    nav ul::-webkit-scrollbar { display: none; }
    nav a {
        font-size: 0.95rem !important;
        padding: 0.3rem 0.5rem !important;
        white-space: nowrap !important; /* Prevent two-line labels like AI for Business */
    }

    /* Headings and section titles scale down */
    .container h1 { font-size: 1.9rem !important; }
    .container h2 { font-size: 1.35rem !important; }

    article header {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    article header h1 {
        margin-top: 0.2rem !important;
        margin-bottom: 0.2rem !important;
        line-height: 1.15 !important;
    }

    /* Mobile image optimization */
    .content img {
        max-width: 100% !important;
        height: auto !important;
        width: auto !important;
        display: block;
        margin: 1rem auto;
    }
    
    /* Ensure images don't overflow on mobile */
    article .content { overflow-x: hidden; }
    
    /* Fix for any embedded content */
    .content iframe,
    .content video,
    .content embed,
    .content object {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* Extra compact breakpoints for narrow phones */
@media (max-width: 600px) {
    .site-title { font-size: 1.15rem !important; }
    nav a { font-size: 0.9rem !important; }
    .container h1 { font-size: 1.75rem !important; }
    .container h2 { font-size: 1.25rem !important; }
}

@media (max-width: 400px) {
    .site-title { font-size: 1.05rem !important; }
    nav a { font-size: 0.85rem !important; }
}

/* ===================== */
/* Modern UI Enhancements */
/* ===================== */

:root {
    --font-sans: 'Inter', 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Typography */
body {
    font-family: var(--font-sans) !important;
    font-feature-settings: "ss01" 1, "ss02" 1, "cv01" 1, "cv02" 1;
    letter-spacing: 0.005em;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Space Grotesk', var(--font-sans) !important;
    letter-spacing: -0.01em;
}

code, pre, kbd, samp {
    font-family: var(--font-mono) !important;
}

/* Container width */
.container {
    max-width: 960px !important;
}

/* Header + nav */
.site-title {
    font-family: 'Space Grotesk', var(--font-sans) !important;
    letter-spacing: -0.01em;
}

nav a {
    padding: 0.35rem 0.65rem;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
}

nav a:hover {
    background-color: color-mix(in oklab, var(--ctp-surface0) 80%, transparent);
    border-color: color-mix(in oklab, var(--ctp-surface1) 70%, transparent);
    text-decoration: none !important;
    transform: translateY(-1px);
}

/* Links */
a {
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
}

a:hover {
    text-decoration-color: var(--ctp-sapphire);
}

/* Cards (post list items) */
.post-item {
    position: relative;
    border: 1px solid var(--ctp-surface1) !important;
    background: linear-gradient(
        180deg,
        color-mix(in oklab, var(--ctp-surface0) 96%, transparent) 0%,
        color-mix(in oklab, var(--ctp-surface0) 92%, transparent) 100%
    ) !important;
    box-shadow:
        0 1px 0 color-mix(in oklab, var(--ctp-surface2) 40%, transparent),
        0 10px 24px rgba(0, 0, 0, 0.25);
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.post-item:hover {
    transform: translateY(-2px);
    border-color: var(--ctp-sapphire) !important;
    box-shadow:
        0 2px 0 color-mix(in oklab, var(--ctp-sapphire) 40%, transparent),
        0 16px 32px rgba(0, 0, 0, 0.35);
}

.post-title a {
    text-decoration: none !important;
}

/* Tag badges */
.tag {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--ctp-surface2);
    color: var(--ctp-subtext1);
    background-color: color-mix(in oklab, var(--ctp-surface0) 85%, transparent);
    transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease;
}

.tag:hover {
    border-color: var(--ctp-blue);
    color: var(--ctp-text);
    background-color: color-mix(in oklab, var(--ctp-surface1) 80%, transparent);
}

/* Code blocks */
pre {
    border-radius: 12px !important;
    border: 1px solid var(--ctp-surface1) !important;
    background:
      radial-gradient(1200px 80px at 10% -10%, color-mix(in oklab, var(--ctp-blue) 12%, transparent), transparent),
      radial-gradient(1200px 80px at 110% 110%, color-mix(in oklab, var(--ctp-mauve) 10%, transparent), transparent),
      var(--ctp-crust) !important;
    box-shadow: inset 0 1px 0 color-mix(in oklab, var(--ctp-surface2) 30%, transparent);
}

code {
    border-radius: 6px !important;
}

/* Blockquotes */
blockquote {
    border-left: 3px solid var(--ctp-sapphire) !important;
    background: linear-gradient(
        90deg,
        color-mix(in oklab, var(--ctp-surface0) 96%, transparent),
        color-mix(in oklab, var(--ctp-surface0) 85%, transparent)
    ) !important;
}

/* Images */
.content img {
    border-radius: 10px;
    border: 1px solid var(--ctp-surface1);
}

/* HR */
hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--ctp-surface2), transparent);
}

/* Focus states */
*:focus-visible {
    outline: 2px solid var(--ctp-blue);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Text selection */
::selection {
    background: color-mix(in oklab, var(--ctp-blue) 30%, transparent);
    color: var(--ctp-text);
}

/* Footer subtle tint */
footer {
    background-image: linear-gradient(180deg, transparent, color-mix(in oklab, var(--ctp-mantle) 70%, transparent));
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--ctp-surface1);
    border-radius: 8px;
    overflow: hidden;
}

thead {
    background: color-mix(in oklab, var(--ctp-surface0) 90%, transparent);
}

th, td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--ctp-surface1);
}

tr:hover td {
    background: color-mix(in oklab, var(--ctp-surface0) 90%, transparent);
}