/*
================================================================================
  1. THEME & COLOR VARIABLES
================================================================================
*/

/* Using Times New Roman for consistent serif typography across the site */


:root {
    /* Light Theme Colors */
    --color-bg-primary: #fdedc8;
    --color-bg-secondary: #fff9ec;
    --color-bg-tertiary: #f5e6c8;
    --color-text-primary: #674636;
    --color-text-secondary: #6f7a57;
    --color-text-tertiary: #886806;
    --color-text-accent: #439085;
    --color-border-primary: #674636;
    --color-border-accent: #9c7e59;
    --color-shadow: #3c4451b3;
    --color-selection-bg: #cbb191;
    --color-selection-text: #fff9ec;
    --color-scrollbar-thumb: #bfa07a;
    --color-scrollbar-track: #f5e6c8;

    /* Theme Toggle Button */
    --toggle-bg: #674636;
    --toggle-text: #fff9ec;
    --toggle-shadow: #67463622;
    --toggle-bg-hover: #8a5a3c;
    --toggle-bg-active: #3c4451;
    --toggle-text-active: #ffe7c2;
    --toggle-bg-toggled: #3c4451;
    --toggle-text-toggled: #ffe7c2;
}

[data-theme="dark"] {
    /* Dark Theme Colors */
    --color-bg-primary: #181c1f;
    --color-bg-secondary: #23272b;
    --color-bg-tertiary: #2c3138;
    --color-text-primary: #ffe7c2;
    --color-text-secondary: #b7cfa7;
    --color-text-tertiary: #a7cccf; /* Re-using secondary for consistency */
    --color-text-accent: #6fdad1;
    --color-border-primary: #52617a;
    --color-border-accent: #439085;
    --color-shadow: #000000aa;
    --color-selection-bg: #3c4451;
    --color-selection-text: #ffe7c2;
    --color-scrollbar-thumb: #3c4451;
    --color-scrollbar-track: #23272b;

    /* Theme Toggle Button */
    --toggle-bg: #ffe7c2;
    --toggle-text: #23272b;
    --toggle-shadow: #ffe7c222;
    --toggle-bg-hover: #ffd18a;
    --toggle-bg-active: #439085;
    --toggle-text-active: #fff9ec;
    --toggle-bg-toggled: #439085;
    --toggle-text-toggled: #fff9ec;
}

/*
================================================================================
  2. GENERAL & ROOT STYLES
================================================================================
*/

html {
    overflow-y: scroll;
    scrollbar-width: thin;
    scrollbar-color: var(--color-scrollbar-thumb) var(--color-scrollbar-track);
}

/* For Chrome, Edge, Safari */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: 8px;
}
::-webkit-scrollbar-track {
    background: var(--color-scrollbar-track);
    border-radius: 8px;
}

::selection {
    background: var(--color-selection-bg);
    color: var(--color-selection-text);
}

body {
    background-color: var(--color-bg-primary);
    transition: background-color 0.4s cubic-bezier(.4, 0, .2, 1);
}

/* Use a consistent system font stack site-wide so text appearance matches across elements */
body {
    font-family: 'Times New Roman', Times, serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 400;
}

#content {
    position: relative;
    margin: 0 auto;
    width: 100%;
    max-width: 520px;
    font-size: 18px;
    line-height: 1.8em;
}

/* General transition for all theme-aware elements */
.block, header, h1, h2, h3, p, a, hr, .blog-quote, .blog-caption, .blog-code, .blog-list, .blog-equation, .page_breaker,
#readingTimeDisplay, .time-text, .time-label, .collapsible-trigger, .collapsible-content
 {
    transition: background-color 0.4s cubic-bezier(.4, 0, .2, 1), 
                color 0.4s cubic-bezier(.4, 0, .2, 1), 
                border-color 0.4s cubic-bezier(.4, 0, .2, 1),
                max-height 0.4s cubic-bezier(.4, 0, .2, 1);
}

/* 
================================================================================
  3. TYPOGRAPHY & LAYOUT
================================================================================
*/

header {
    font-size: 32px;
    color: var(--color-text-primary);
}

h1, h2, h3 {
    color: var(--color-text-primary);
}

h1 { font-size: 1.75em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.15em; }

p {
    font-size: 1em;
    color: var(--color-text-secondary);
    margin: 10px 20px auto;
    line-height: 1.5em;
}

a {
    color: var(--color-text-accent);
}

hr {
    border: none;
    border-top: 2px solid var(--color-border-primary);
}

.page-breaker {
    position: relative;
    border: none;
    border-top: 4px dashed var(--color-border-primary);
    margin: 3.5em auto;
    left: -9%;
    width: 118%;
}

.block {
    width: 100%;
    max-width: 520px;
    margin: 40px auto;
    padding: 42px;
    /*padding: 42px;*/
    border: 0.5rem solid var(--color-border-primary);
    border-radius: 36px;
    background-color: var(--color-bg-secondary);
    filter: drop-shadow(0 0 0.8rem var(--color-shadow));
    /*min-height: 300px;*/
    will-change: filter;
}

/*
================================================================================
  4. BLOG-SPECIFIC COMPONENTS
================================================================================
*/

.blog-quote {
    border-left: 4px solid var(--color-border-accent);
    padding-left: 16px;
    margin: 20px 40px;
    font-style: italic;
    font-size: 1em;
    color: var(--color-text-secondary);
}

.blog-quote .author {
    display: block;
    margin-top: 8px;
    font-style: normal;
    font-size: 1em;
    text-align: right;
}

.blog-figure {
    margin: 20px auto;
    text-align: center;
}

.blog-img {
    max-width: 100%;
    border-radius: 16px;
    cursor: pointer;
    filter: none;
    transition: transform 0.4s cubic-bezier(.25,.8,.25,1),
                filter 0.4s cubic-bezier(.25,.8,.25,1);
    will-change: transform, filter;
}

.blog-img:hover {
    transform: scale(1.005);
    filter: drop-shadow(0 0 0.75rem var(--color-shadow));
}

.blog-caption {
    margin-top: 8px;
    font-size: 0.9em;
    color: var(--color-text-tertiary);
    opacity: 0.8;
}

.blog-list {
    margin: 20px 40px;
    padding-left: 20px;
    list-style-type: '->';
    font-size: 1em;
    color: var(--color-text-tertiary);
}

.blog-list li {
    padding-left: 12px;
    margin-bottom: 10px;
}

.blog-code {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 0.95em;
    margin: 20px 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.blog-equation {
    color: var(--color-text-tertiary);
}

.blog-equation .katex-display {
    font-size: 1.3em;
}
/* ===============READING STUFF GOES HERE===================*/

/* --- Progress Bar Container (the radial thingy) --- */
#readingTimeDisplay {
    position: fixed;
    bottom:0;
    right:0;
    /* Sizing and Shape of the floating card */
    width: 100px; 
    height: 100px;
    background: var(--color-bg-secondary);;
    border-radius: 50%; /* Perfect circle background */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 8px solid var(--color-border-primary);
    
    /* Positioning content inside the circle */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    
    /* Hides the indicator if no article content is found */
    visibility: hidden; 
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Show when content is ready */
#readingTimeDisplay.ready {
    visibility: visible;
    opacity: 1;
}

/* --- SVG Styles for Radial Bar --- */
.radial-progress-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Rotate -90deg so the progress starts at the top (12 o'clock) */
    transform: rotate(-90deg); 
}

/* Settings for both the track and the progress bar */
.progress-track, .progress-bar {
    fill: none;
    stroke-width: 5; /* Thickness of the bar */
    cx: 50; /* Center X */
    cy: 50; /* Center Y */
    r: 40;  /* Radius: 40 */
}

.progress-track {
    stroke: var(--color-bg-tertiary); /* Light grey background */
}

.progress-bar {
    stroke: #10b981; /* Vibrant green progress color */
    stroke-linecap: round;
    /* Circumference of r=40 is ~251.3. Set as dash array and initial offset. */
    stroke-dasharray: 251.3; 
    stroke-dashoffset: 251.3; /* 0% progress */
    transition: stroke-dashoffset 0.15s ease-out; /* Smooth animation */
}

/* --- Text Styling (Centered) --- */
.time-text {
    font-size: 1.25rem; /* Larger font for minutes */
    font-weight: 700;
    text-align: center;
    color: var(--color-text-primary); /* Darker text */
    line-height: 1;
}

.time-label {
    font-size: 0.85rem; /* Smaller font for "remaining" */
    color: var(--color-text-secondary);
    font-weight: 500;
    line-height: 1.2;
}

/*
================================================================================
  5. THEME TOGGLE BUTTON
================================================================================
*/

#theme-toggle {
    background: var(--toggle-bg);
    color: var(--toggle-text);
    box-shadow: 0 2px 8px var(--toggle-shadow);
    border: none;
    border-radius: 8px;
    transition: background 0.4s cubic-bezier(.4, 0, .2, 1), 
                color 0.4s cubic-bezier(.4, 0, .2, 1), 
                box-shadow 0.4s cubic-bezier(.4, 0, .2, 1);
}

#theme-toggle:hover {
    background: var(--toggle-bg-hover);
}

#theme-toggle:active {
    background: var(--toggle-bg-active);
    color: var(--toggle-text-active);
}

#theme-toggle.toggled {
    background: var(--toggle-bg-toggled);
    color: var(--toggle-text-toggled);
}

/* ================================================================================
  6. IMAGE ZOOM MODAL
================================================================================
*/

#image-zoom-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    /* Use 'inset' to cover all edges, including safe area */
    inset: 0; 
    /* Modern, device-relative viewport units for full screen */
    width: 100dvw; 
    height: 100dvh; 
    /* Fallback for older browsers or if 'inset' is not enough */
    left: 0;
    top: 0;
    /* Fallback full viewport units */
    /* width: 100%; */ 
    /* height: 100%; */
    
    background-color: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    animation: fade-in 0.3s cubic-bezier(.4, 0, .2, 1);
    will-change: backdrop-filter;
}

#image-zoom-container {
    text-align: center;
}

#image-zoom-content {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 16px;
}

#image-zoom-caption {
    margin-top: 15px;
    color: #ccc;
    font-size: 1.1em;
}

#image-zoom-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

#image-zoom-close:hover {
    color: #ccc;
}

#image-zoom-modal.fade-out {
    animation: fade-out 0.3s cubic-bezier(.4, 0, .2, 1) forwards;
}

/* ================================================================================
  7. KEYFRAME ANIMATIONS
================================================================================
*/

@keyframes fade-in {
    from { opacity: 0; 
    backdrop-filter: blur(0px);}
    to { opacity: 1;
    backdrop-filter: blur(10px); }
}

@keyframes fade-out {
    from { opacity: 1; 
    backdrop-filter: blur(10px);}
    to { opacity: 0; 
    backdrop-filter: blur(0px);}
}

@keyframes slide-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slide {
    from { left: 0%; }
    to { left: -50%; }
}

/* ================================================================================
  8. COLLAPSIBLE ELEMENTS
================================================================================
*/

.collapsible-container {
    margin: 2.2rem 0;
    border-radius: 12px;
    overflow: hidden;
    border: 4px solid var(--color-border-accent);
    /* remove default shadow; show it only on hover for a cleaner default look */
    box-shadow: none;
    width: 100%;
    background: var(--color-bg-secondary);
}


.collapsible-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.6rem 0.8rem; /* similar vertical spacing to blog list items */
    background-color: transparent;
    color: var(--color-text-primary);
    cursor: pointer;
    border: none;
    text-align: left;
    font-size: 1.25rem;
    font-weight: bold;
    transition: background-color 0.18s cubic-bezier(.25,.8,.25,1), color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
    /* remove the divider line between triggers to match request (keep container border) */
    border-bottom: none;
    /* Ensure buttons inherit the page font instead of using the browser's UI font */
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    /* Default: no highlight, use normal text color; highlight will appear on hover */
    background-color: transparent;
    color: var(--color-text-primary);
}

.collapsible-trigger:hover {
    /* Change background & text color on hover instead of shadows or lift */
    background-color: var(--color-selection-bg);
    color: var(--color-selection-text);
}

/* Persisted 'open' state color when the trigger is active (clicked) */
.collapsible-trigger.active {
    background-color: var(--color-selection-bg);
    color: var(--color-selection-text);
}

.collapsible-trigger::after {
    content: '+';
    font-size: 1.25rem;
    font-weight: bold;
    transition: transform 0.25s cubic-bezier(.25,.8,.25,1), color 0.25s ease;
    color: var(--color-text-secondary);
}
.collapsible-trigger.active::after { transform: rotate(45deg); color: var(--color-text-accent); }

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    background-color: var(--color-bg-secondary);
    transition: max-height 0.45s cubic-bezier(.25,.8,.25,1),
                padding 0.35s cubic-bezier(.25,.8,.25,1);
}

.collapsible-content-inner {
    padding: 0.9rem 1rem;
    font-size: 0.95em;
    line-height: 1.6;
    /* keep inner contents using normal site colors */
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
}

.collapsible-content-inner pre.blog-code {
    padding: 1rem;
    overflow-x: auto;
    background-color: var(--color-bg-tertiary);
    border-radius: 6px;
    margin: 0.8rem 0;
    font-size: 0.9em;
}

.collapsible-content-inner h3 { margin: 1rem 0 0.5rem; }
.collapsible-content-inner p { margin: 0.7rem 0; }

/*
================================================================================
  9. CONTEXT HIGHLIGHTS & POPUPS
================================================================================
*/

.context-highlight {
    /* Match collapsible trigger styling: no movement, use selection colors on hover/active */
    background-color: transparent;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease;
    display: inline-block;
    font-family: inherit;
    font-weight: 500;
}

.context-highlight:hover {
    background-color: var(--color-selection-bg);
    color: var(--color-selection-text);
}

.context-highlight.active {
    background-color: var(--color-selection-bg);
    color: var(--color-selection-text);
}

.context-popup {
    position: absolute;
    z-index: 1001;
    background-color: var(--color-bg-secondary);
    border: 4px solid var(--color-border-primary);
    border-radius: 8px;
    width: 320px;
    max-width: 90vw;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s cubic-bezier(.4, 0, .2, 1), transform 0.3s cubic-bezier(.4, 0, .2, 1);
    filter: drop-shadow(0 0 0.8rem var(--color-shadow));
    display: none; /* Initially hidden */
}

.context-popup.visible {
    opacity: 1;
    transform: translateY(0);
}

.context-popup-close {
    position: absolute;
    top: 5px;
    right: 8px;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    line-height: 1;
}

.context-popup-close:hover {
    color: var(--color-text-primary);
}

.context-popup-content {
    padding: 1.2rem;
    font-size: 0.95em;
    line-height: 1.6;
    color: var(--color-text-secondary);
}

/*
================================================================================
  BLOG FILTER STYLING
================================================================================
*/

.filter-section {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap; /* keep on one line when possible */
}

.filter-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.tag-dropdown {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    border: 4px solid var(--color-border-primary);
    padding: 0.6rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    min-width: 160px;
    transition: all 0.3s ease;
    appearance: none; /* Remove default browser styling */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23674636' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.7rem center;
    background-repeat: no-repeat;
    background-size: 1.2em 1.2em;
    padding-right: 2.5rem;
    font-family: inherit;
}

[data-theme="dark"] .tag-dropdown {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23ffe7c2' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
}

.tag-dropdown:hover {
    border-color: var(--color-text-accent);
    background-color: var(--color-bg-secondary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--color-shadow);
}

.tag-dropdown:focus {
    outline: none;
    border-color: var(--color-text-accent);
    box-shadow: 0 0 0 3px var(--color-text-accent)33, 0 4px 8px var(--color-shadow);
    background-color: var(--color-bg-secondary);
}

.tag-dropdown option {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    padding: 0.5rem;
    font-weight: 500;
}

.search-input {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 16px;
    border: 4px solid var(--color-border-primary);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-sizing: border-box;
    transition: all 0.3s ease;
    font-family: inherit;
    flex: 1 1 220px; /* grow to fill remaining space, but allow shrinking */
}

.search-input:hover {
    border-color: var(--color-text-accent);
    background-color: var(--color-bg-secondary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--color-shadow);
}

.search-input:focus {
    outline: none;
    border-color: var(--color-text-accent);
    background-color: var(--color-bg-secondary);
    box-shadow: 0 0 0 3px var(--color-text-accent)33, 0 4px 8px var(--color-shadow);
}

.search-input::placeholder {
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* Small screens: stack dropdown above search so it remains usable */
@media (max-width: 640px) {
    .filter-section {
        flex-wrap: wrap;
    }
    .tag-dropdown {
        width: 100%;
    }
    .search-input {
        width: 100%;
        flex: none;
    }
}

/*
================================================================================
  BLOG ANIMATION STYLES
================================================================================
*/

#blog-listing {
    list-style: none;
    padding: 0;
    margin: 0;
    min-height: 0; /* Ensure no minimum height when empty */
}

#blog-listing li {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 60px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-border-accent);
    position: relative;
}

#blog-listing li:last-child {
    border-bottom: none;
}

#blog-listing li:hover {
    transform: translateX(8px);
    background: linear-gradient(90deg, var(--color-bg-secondary) 0%, transparent 100%);
    padding-left: 1rem;
    border-radius: 8px 0 0 4px;
}

#blog-listing li.hidden {
    opacity: 0;
    transform: translateY(-8px);
    max-height: 0;
    margin-bottom: 0;
    padding: 0;
    border-bottom: none;
    overflow: hidden;
}

#blog-listing li a {
    text-decoration: none;
    color: var(--color-text-primary);
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.2s ease;
    display: block;
    position: relative;
}

#blog-listing li a:hover {
    color: var(--color-text-accent);
}

#blog-listing li a::before {
    content: '→';
    position: absolute;
    left: -1.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    color: var(--color-text-accent);
    font-weight: bold;
}

#blog-listing li:hover a::before {
    opacity: 1;
}

#no-results {
    text-align: center;
    padding: 1.5rem 0;
    color: var(--color-text-secondary);
    font-style: italic;
    margin-top: 1rem;
}