/* CSS Variables for theming */
:root {
    --bg: #ffffff;
    --fg: #000000;
    --underline: #e74c3c;
    --card: #eaf4fb;
    --border: rgba(127,127,127,0.3);
    --shadow: rgba(0,0,0,0.07);
    --resume-accent: #d78d4c;
}

/* Ensure hidden attribute reliably hides elements (e.g., controls on detail pages) */
[hidden] { display: none !important; }

.dark-theme {
    --bg: #111111;
    --fg: #eeeeee;
    --underline: #ff7675;
    --card: #1e2730;
    --border: rgba(255,255,255,0.18);
    --shadow: rgba(0,0,0,0.35);
    --resume-accent: #d78d4c; /* keep same accent in dark mode */
}

/* Social icons */
.social-icons {
    display: flex;
    align-items: center;
    gap: 10px;
    position: absolute;
    top: 18px;
    right: 60px;
}
.social-icons a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent; /* no circular chip */
    color: var(--fg);
    transition: opacity 0.2s, transform 0.1s;
}
.social-icons a:hover {
    background: transparent; /* remove blue hover */
    box-shadow: none; /* remove glow */
    opacity: 0.85;
}
.social-icons a:active { transform: scale(0.96); }
.social-icons a:focus-visible {
    outline: 2px solid var(--underline);
    outline-offset: 2px;
}
.social-icons img { display: block; width: 20px; height: 20px; }
.social-icons .li-icon { position: absolute; }
.social-icons .li-dark { display: none; }
/* ---------- Base Styles ---------- */
body {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    margin: 24px;
    background-color: var(--bg);
    color: var(--fg);
    transition: background 0.3s, color 0.3s;
    overflow-x: hidden; /* guard against accidental horizontal scroll */
}

/* Header */
h1 {
    font-size: clamp(22px, 3.5vw, 32px);
    font-weight: 900;
    margin: 0 0 16px 0;
}

@media (max-width: 700px) {
    header h1 { margin: 0; }
    body { margin: 12px; }
    .social-icons { right: 12px; top: 12px; }
    nav a { margin-right: 12px; font-size: 1rem; }
    .markdown-body { max-width: 100%; }
    /* About page: revert to left-aligned, narrower feel on mobile */
    .page-about .markdown-body { max-width: 68ch; hyphens: auto; }
    .page-about .fullwidth.markdown-body { max-width: 68ch; }
    /* Override inline-centered blocks inside markdown for mobile */
    .page-about .markdown-body [style*="text-align: center"] { text-align: left !important; }
    /* Left-align hero SVGs on About (we previously centered them on mobile) */
    .page-about .markdown-body img[src*="light_mode.svg"],
    .page-about .markdown-body img[src*="dark_mode.svg"] {
        width: min(420px, 82vw);
        max-width: 100%;
        height: auto;
        display: block;
        margin: 0; /* left aligned */
    }
}

/* Very small phones */
@media (max-width: 480px) {
    body { margin: 10px; }
    /* Prevent horizontal scroll from wide grids */
    .cards.grid { grid-template-columns: 1fr; }
}

/* Navigation */
nav {
    margin-bottom: 16px;
}

nav a {
    text-decoration: none;
    color: inherit; /* inherit from body */
    margin-right: 20px;
    font-weight: 500;
    position: relative;
    font-size: 1.12rem; /* bigger nav items */
}

nav a::after {
    content: "";
    display: block;
    width: 100%;
    height: 2px;
    background: var(--underline); /* underline */
    position: absolute;
    bottom: -4px;
    left: 0;
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

nav a:hover::after {
    transform: scaleX(1);
}

/* Dotted separator */
hr {
    border: none;
    border-top: 2px dotted currentColor;
    margin: 20px 0;
}

/* Sections */
section {
    margin-top: 20px;
}

section h2 {
    font-size: clamp(18px, 2.2vw, 22px);
    font-weight: bold;
    margin-bottom: 10px;
    color: inherit;
}

/* List styling */
ul {
    list-style-type: circle;
    margin-left: 30px;
}

/* ---------- Markdown content ---------- */
.markdown-body {
    line-height: 1.6;
    max-width: 75ch;
    padding: 0.5rem 0;
    /* Prevent horizontal overflow from long words/URLs */
    overflow-wrap: anywhere;
    word-break: break-word;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1.2em 0 0.6em; }
/* Responsive markdown heading sizes */
.markdown-body h1 { font-size: clamp(1.5rem, 5vw, 2.1rem); }
.markdown-body h2 { font-size: clamp(1.25rem, 4vw, 1.7rem); }
.markdown-body h3 { font-size: clamp(1.05rem, 3.4vw, 1.35rem); }
.markdown-body pre {
    overflow: auto;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    background: rgba(0,0,0,0.045);
    border: 1px solid rgba(0,0,0,0.08);
}
.dark-theme .markdown-body pre {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.12);
}
.markdown-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; }
.markdown-body img { max-width: 100%; height: auto; }
.markdown-body a { color: inherit; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 2px; }
.markdown-body blockquote { border-left: 3px solid var(--border); padding-left: 10px; color: inherit; }

/* Theme-aware SVGs embedded via Markdown by filename */
/* Default: show light, hide dark */
.markdown-body img[src*="light_mode.svg"] { display: inline-block !important; }
.markdown-body img[src*="dark_mode.svg"] { display: none !important; }
/* Explicit dark theme: show dark, hide light */
.dark-theme .markdown-body img[src*="light_mode.svg"] { display: none !important; }
.dark-theme .markdown-body img[src*="dark_mode.svg"] { display: inline-block !important; }
/* Explicit light theme: show light, hide dark */
.light-theme .markdown-body img[src*="light_mode.svg"] { display: inline-block !important; }
.light-theme .markdown-body img[src*="dark_mode.svg"] { display: none !important; }
/* System dark when no explicit theme */
@media (prefers-color-scheme: dark) {
        :root:not(.dark-theme):not(.light-theme) .markdown-body img[src*="light_mode.svg"] { display: none !important; }
        :root:not(.dark-theme):not(.light-theme) .markdown-body img[src*="dark_mode.svg"] { display: inline-block !important; }
}

/* Responsive embeds */
.embed-responsive { position: relative; width: 100%; max-width: 720px; aspect-ratio: 16 / 9; margin: 1rem 0; }
.embed-responsive iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Responsive markdown tables */
.markdown-body table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown-body table th, .markdown-body table td { padding: 0.4rem 0.6rem; }

/* Tweets embed */
.tweets-embed {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(0,0,0,0.04);
    padding: 8px;
    overflow: hidden;
}
.dark-theme .tweets-embed { background: rgba(255,255,255,0.06); }

/* Quote bar */
.quote-bar {
                display: flex;
                align-items: center;
                gap: 10px;
                padding: 10px 12px;
                border: 1px solid var(--border);
                border-radius: 12px;
                background: var(--card);
                margin-bottom: 16px;
}
.quote-text { flex: 1; min-height: 1.4em; }
/* Big right-aligned quote on laptops */
@media (min-width: 1024px) {
    .side-panel .quote-text { font-size: clamp(1.1rem, 2vw, 1.6rem); text-align: right; }
}
/* Typewriter effect for quote */
.typewriter { overflow: hidden; margin: 0; letter-spacing: .01em; }
/* Explicit caret element for multi-line typing */
.typewriter .caret { display: inline-block; width: .14em; background: var(--underline); animation: caret-blink .85s step-end infinite; margin-inline-start: 0.12em; }
@keyframes caret-blink { from, to { opacity: 0; } 50% { opacity: 1; } }

/* About layout with side sandbox */
.about-layout { display: grid; grid-template-columns: 1fr minmax(420px, 600px); gap: 0; align-items: start; }
/* Right side full-bleed with divider */
.right-side { position: relative; overflow: hidden; display: block; border-left: 1px solid var(--border); }
.right-bg { position: absolute; inset: 0; padding: 10px; }
.right-bg pre { margin: 0; line-height: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono','Courier New', monospace; font-size: clamp(9px, 0.9vw, 14px); color: rgba(0,0,0,0.28); white-space: pre; }
.dark-theme .right-bg pre { color: rgba(255,255,255,0.22); }
.quote-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding: 24px; pointer-events: none; }
.quote-overlay .quote-text { text-align: right; max-width: 100%; white-space: normal; }
.quote-overlay .quote-main { font-weight: 800; line-height: 1.15; }
.quote-overlay .quote-author { margin-top: 8px; opacity: 0.9; font-size: 0.8em; font-weight: 600; }
.quote-overlay .quote-spacer { height: 0.6em; }
@media (min-width: 1024px) {
    .about-layout { grid-template-columns: 3fr 2fr; }
    .quote-overlay .quote-text { font-size: clamp(1.8rem, 2.8vw, 3rem); }
}
@media (min-width: 1280px) {
    .about-layout { grid-template-columns: 1fr 1fr; }
}

/* Hide right panel on smaller screens; let content use full width */
@media (max-width: 1023.98px) {
    .about-layout { grid-template-columns: 1fr; }
    .right-side { display: none; }
}

/* Let content stretch more on large screens */
@media (min-width: 1024px) {
    .markdown-body { max-width: 85ch; }
    /* Make listing pages use full width */
    .page-blogs main, .page-projects main { max-width: none; }
    .page-blogs .cards.grid, .page-projects .cards.grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
    .page-blogs .cards:not(.grid), .page-projects .cards:not(.grid) { grid-template-columns: 1fr; }
}

/* Better grid on small screens: allow two columns when possible */
@media (max-width: 700px) {
    .page-blogs .cards.grid, .page-projects .cards.grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 480px) {
    .page-blogs .cards.grid, .page-projects .cards.grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Mobile adjustments for About and general safety */
@media (max-width: 1023.98px) {
    .markdown-body { max-width: 100%; }
    /* Tighten hero spacing on About mobile */
    .page-about .markdown-body { margin-top: 4px; }
    /* Shrink the top hero SVG on mobile; About has a more specific left-align rule elsewhere */
    .markdown-body img[src*="light_mode.svg"],
    .markdown-body img[src*="dark_mode.svg"] {
        width: min(420px, 82vw);
        max-width: 100%;
        height: auto;
        display: block;
        margin: 0 auto;
    }
    .quote-overlay { display: none !important; }
}

/* ---------- Listings (blogs/projects) ---------- */
.listing-controls { display: flex; flex-direction: column; gap: 10px; align-items: stretch; margin: 10px 0 16px; }
.listing-controls .controls-row { display: flex; gap: 10px; align-items: center; }
.listing-controls .controls-row .search-wrap { flex: 1; }
.listing-controls .controls-row .view-toggle { margin-left: auto; display: inline-flex; gap: 8px; }
.listing-controls .tags-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.listing-controls .tags-label { opacity: 0.8; font-weight: 600; }
.listing-controls .search-wrap { position: relative; flex: 1 1 420px; min-width: 220px; }
.listing-controls input[type="search"] {
    width: 100%;
    padding: 12px 44px 12px 14px; /* room for icon */
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font-size: 1rem;
}
.listing-controls .search-btn {
    position: absolute;
    right: 8px; top: 50%; transform: translateY(-50%);
    width: 32px; height: 32px;
    border: none; background: transparent; color: inherit; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
}
.listing-controls .search-btn:focus-visible { outline: 2px solid var(--underline); outline-offset: 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags button { padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: transparent; color: inherit; cursor: pointer; }
.tags button.active { background: var(--card); }
.view-toggle button {
    padding: 6px 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
    cursor: pointer;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.view-toggle button[aria-pressed="true"] { background: var(--card); }
.view-toggle .icon { width: 16px; height: 16px; display: inline-block; }
.icon-list { background: currentColor; mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="%23000" d="M2 3h12v2H2V3zm0 4h12v2H2V7zm0 4h12v2H2v-2z"/></svg>') no-repeat center / contain; -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path fill=\"%23000\" d=\"M2 3h12v2H2V3zm0 4h12v2H2V7zm0 4h12v2H2v-2z\"/></svg>') no-repeat center / contain; }
.icon-grid { background: currentColor; mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="%23000" d="M2 2h5v5H2V2zm7 0h5v5H9V2zM2 9h5v5H2V9zm7 0h5v5H9V9z"/></svg>') no-repeat center / contain; -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path fill=\"%23000\" d=\"M2 2h5v5H2V2zm7 0h5v5H9V2zM2 9h5v5H2V9zm7 0h5v5H9V9z\"/></svg>') no-repeat center / contain; }

.cards { display: grid; gap: 12px; }
.cards:not(.grid) { grid-template-columns: 1fr; }
.cards.grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.fullwidth { grid-column: 1 / -1; margin-top: 16px; }
.fullwidth.markdown-body { max-width: none; }
.page-projects #content.markdown-body,
.page-blogs #content.markdown-body {
    max-width: none;
    width: 100%;
}
/* Let embeds span full width on detail pages */
.page-projects #content .embed-responsive,
.page-blogs #content .embed-responsive { max-width: none; }
.card { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: rgba(0,0,0,0.04); }
.dark-theme .card { background: rgba(255,255,255,0.06); }
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card .muted { opacity: 0.75; font-size: 0.9rem; margin: 0 0 8px; }
.card-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { opacity: 0.85; }
.btn-secondary { opacity: 0.9; }
.share-row { margin-top: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin: 10px 0 16px; }
.btn i { font-size: 1rem; line-height: 1; }
.card { cursor: pointer; }
.card .btn { cursor: pointer; }

/* View Resume button: centered, terminal-like, orange */
.markdown-body a.btn[aria-label="View Resume PDF"] {
    justify-content: center;
    text-align: center;
    gap: 0;
    color: var(--resume-accent);
    border-color: var(--resume-accent);
    border-width: 1.5px;
    border-radius: 6px; /* more terminal-ish */
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.markdown-body a.btn[aria-label="View Resume PDF"] i { display: none; }
.markdown-body a.btn[aria-label="View Resume PDF"]:hover { opacity: 0.95; }
.markdown-body a.btn[aria-label="View Resume PDF"]:focus-visible {
    outline: 2px solid var(--resume-accent);
    outline-offset: 2px;
}

/* ---------- Mobile Menu ---------- */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: inherit;
}

@media (max-width: 700px) {
    header {
        position: relative;
        padding-top: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: 56px;
    }
    .menu-toggle {
        display: block;
        position: static;
        z-index: 1;
        font-size: 1.8rem;
        line-height: 1;
        order: 1;
    }
    header .theme-toggle {
        position: static;
        right: auto !important;
        top: auto !important;
        left: auto !important;
        margin-left: 8px;
        order: 4;
    }
    .social-icons {
        position: static;
        top: auto;
        right: auto;
        margin-left: 0;
        order: 3;
        gap: 8px;
    }
    header h1 { order: 2; flex: 1; }
    nav {
        display: none;
        flex-direction: column;
        background: var(--bg);
        position: fixed;
        top: 56px;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        box-shadow: 0 2px 12px var(--shadow);
        padding: 8px 0;
        z-index: 99;
        backdrop-filter: saturate(120%) blur(6px);
        -webkit-backdrop-filter: saturate(120%) blur(6px);
        border-top: 1px solid var(--border);
    }
    nav.open {
        display: flex;
    }
    nav a {
        margin: 0;
        padding: 14px 18px;
    border-bottom: none;
        font-size: 1.18rem; /* larger on mobile too */
    }
}

/* ---------- Responsive Typography ---------- */
/* Small phones */
@media (max-width: 480px) {
    body {
        margin: 10px;
        font-size: 0.98rem;
    }
    header h1 {
        font-size: 1.2rem;
        margin-bottom: 6px;
    }
    .theme-toggle { width: 32px; height: 32px; }
    .theme-toggle i { font-size: 18px; }
    .social-icons a { width: 30px; height: 30px; }
    h2 {
        font-size: 1rem;
        margin: 14px 0 7px;
    }
    ul {
        margin-left: 12px;
    }
}

/* Phones to small tablets */
@media (min-width: 481px) and (max-width: 700px) {
    body { margin: 14px; font-size: 1rem; }
    header h1 { font-size: 1.4rem; }
}

/* Tablets */
@media (min-width: 701px) and (max-width: 1024px) {
    body { margin: 24px; font-size: 1.02rem; }
    header h1 { font-size: 1.6rem; }
}

/* ---------- Dark Mode ---------- */
/* Respect system preference when no explicit theme chosen */
@media (prefers-color-scheme: dark) {
    :root:not(.dark-theme):not(.light-theme) body {
        background-color: #111;
        color: #eee;
    }
    :root:not(.dark-theme):not(.light-theme) nav {
        background-color: #111;
    }
    :root:not(.dark-theme):not(.light-theme) nav a::after {
        background: #ff7675;
    }
    :root:not(.dark-theme):not(.light-theme) hr {
        border-top: 2px dotted #666;
    }
    /* If no explicit theme, switch LinkedIn icon by system preference */
    :root:not(.dark-theme):not(.light-theme) .li-light { display: none; }
    :root:not(.dark-theme):not(.light-theme) .li-dark { display: block; }
}

/* Explicit theme classes override */
.dark-theme body { background-color: var(--bg); color: var(--fg); }
.dark-theme nav { background-color: var(--bg); }
.dark-theme hr { border-top: 2px dotted #666; }
/* Explicit icons for explicit themes */
.dark-theme .li-light { display: none; }
.dark-theme .li-dark { display: block; }
.light-theme .li-light { display: block; }
.light-theme .li-dark { display: none; }

/* Theme toggle button */
.theme-toggle {
    position: absolute;
    top: 14px;
    right: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none; /* remove ring */
    background: transparent; /* no chip */
    color: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    z-index: 101;
}
.theme-toggle:hover { background: transparent; opacity: 0.85; }
.theme-toggle:active { transform: scale(0.96); }
.theme-toggle:focus-visible { outline: 2px solid var(--underline); outline-offset: 2px; }
.theme-toggle i { font-size: 20px; line-height: 1; }
