/* Base page extra UI styles extracted from base.html */

html,
body {
    max-width: 100%;
}

img,
svg,
video,
canvas,
iframe,
table {
    max-width: 100%;
}

.site-footer .footer-links-col {
    row-gap: 0.5rem;
}

.site-footer .footer-links-col a,
.site-footer .footer-page-views {
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .site-footer .footer-links-col {
        gap: 0.5rem 0.75rem !important;
    }

    .site-footer .footer-page-views {
        width: 100%;
        margin-left: 0 !important;
        text-align: center;
    }
}

/* Minimal fixed-position toast container that does not affect page layout */
#global-toast-container {
    position: fixed;
    top: 0; /* will be set at runtime */
    right: 20px;
    z-index: 1080;
    pointer-events: none; /* clicks pass through except on the toast elements themselves */
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-end;
    /* DO NOT set width/padding that may affect page layout */
}
@media (max-width: 576px) {
    #global-toast-container {
        left: 12px;
        right: 12px;
        align-items: center;
    }
    .global-toast { width: 100%; max-width: none; }
}

.global-toast {
    min-width: 280px;
    max-width: 420px;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    padding: 14px 16px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    pointer-events: auto; /* allow interaction with the toast itself */
    opacity: 0;
    transform: translateY(-8px) scale(0.99);
    transition: opacity 260ms cubic-bezier(.2,.9,.3,1), transform 260ms cubic-bezier(.2,.9,.3,1);
    border-left: 4px solid transparent;
}
.global-toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.global-toast .toast-title {
    font-weight: 700;
    margin: 0 0 6px 0;
    font-size: 15px;
}
.global-toast .toast-message {
    margin: 0;
    font-size: 14px;
    line-height: 1.3;
    opacity: .95;
}
.global-toast.success { border-left-color: #28a745; }
.global-toast.partial { border-left-color: #ffc107; }
.global-toast.failed { border-left-color: #dc3545; }
.global-toast .close-btn {
    margin-left: auto;
    background: transparent;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: inherit;
    cursor: pointer;
}

/* Navbar scroll/shrink styles (responsive + theme-aware) */
.portfolio-navbar {
    transition: padding 360ms ease, box-shadow 360ms ease, background-color 360ms ease, transform 360ms ease;
    will-change: padding, box-shadow, background-color, transform;
    padding: 1.3rem 0.75rem; /* increased default padding to amplify shrink */
}
.portfolio-navbar .navbar-brand {
    display: flex;
    align-items: center; /* ensure logo and text are vertically centered */
    gap: 0.5rem;
}
.portfolio-navbar .navbar-brand img {
    display: block;
    vertical-align: middle;
    transition: width 360ms ease, height 360ms ease, transform 360ms ease;
    width: 64px; /* larger default logo to increase the shrink delta */
    height: 64px;
    object-fit: contain;
    margin: 0; /* remove default inline spacing quirks */
}
.portfolio-navbar.navbar-scrolled {
    padding: 0.15rem 0.5rem; /* even smaller when scrolled -> larger animation amplitude */
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    transform: translateZ(0);
    z-index: 1040;
    /* translucent background to improve contrast when scrolled */
    background-color: rgba(255,255,255,0.88);
    backdrop-filter: blur(6px);
}
/* Dark theme variant */
html[data-bs-theme="dark"] .portfolio-navbar.navbar-scrolled {
    background-color: rgba(24,24,24,0.78);
}
/* smaller logo when scrolled */
.portfolio-navbar.navbar-scrolled .navbar-brand img {
    width: 32px; /* reduced more for a stronger effect */
    height: 32px;
    transform: none; /* remove translateY so text stays aligned */
}

/* Make sure collapse menu (mobile) is readable when open: keep backdrop */
@media (max-width: 991px) {
    .portfolio-navbar {
        padding: 0.7rem 0.5rem;
    }
    .portfolio-navbar .navbar-brand img { width:52px; height:52px; }
    .portfolio-navbar.navbar-scrolled { padding: 0.35rem 0.5rem; }
}

/* Active nav-link background */
.portfolio-navbar .nav-link.active,
.portfolio-navbar .nav-link[aria-current="page"] {
    position: relative;
    border-radius: 0.375rem;
    padding: 0.425rem 0.75rem;
    color: inherit;
    transition: background 220ms ease, color 220ms ease, box-shadow 220ms ease;
    background-color: rgba(0, 0, 0, 0.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0,0,0,0.06);
}
html[data-bs-theme="dark"] .portfolio-navbar .nav-link.active,
html[data-bs-theme="dark"] .portfolio-navbar .nav-link[aria-current="page"] {
    background-color: rgba(255, 255, 255, 0.03);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    outline: 1px solid rgba(255,255,255,0.03);
}
.portfolio-navbar.navbar-dark .nav-link.active,
.portfolio-navbar.navbar-dark .nav-link[aria-current="page"] {
    color: #fff;
}

/* THEME SWITCH */
.theme-switcher { }
.theme-switch {
    --active-index: 0;
    --count: 2;
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    align-items: center;
    height: 34px;
    min-width: 132px;
    background: rgb(0,0,0,0);
    border: 1px solid #cfcfcf;
    border-radius: 999px;
    padding: 2px;
    box-shadow: 0 1px 0 rgba(255,255,255,0.7) inset, 0 -1px 0 rgba(0,0,0,0.06) inset, 0 4px 10px rgba(0,0,0,0.08);
    cursor: pointer;
}
html[data-bs-theme="dark"] .theme-switch { --active-index: 1; }
html[data-bs-theme="light"] .theme-switch { --active-index: 0; }
@media (prefers-color-scheme: dark) {
    html[data-bs-theme="auto"] .theme-switch { --active-index: 1; }
}
@media (prefers-color-scheme: light) {
    html[data-bs-theme="auto"] .theme-switch { --active-index: 0; }
}
html[data-bs-theme="dark"] .theme-switch {
    background: rgb(0,0,0,0);
    border-color: #cfcfcf;
}
.theme-switch .theme-option {
    position: relative;
    z-index: 2;
    background: transparent;
    border: 0;
    padding: 0;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #222;
    pointer-events: none;
    border-radius: 999px;
    outline: none;
}
.theme-switch .theme-option svg { width: 18px; height: 18px; opacity: 0.75; transition: opacity 160ms ease; }
.theme-switch .theme-option.active svg { opacity: 1; }
.theme-switch .theme-thumb {
    --bounce-dir: -1;
    position: absolute;
    z-index: 1;
    top: 2px;
    left: calc(2px + var(--active-index) * ((100% - 4px) / var(--count)));
    width: calc((100% - 4px) / var(--count));
    height: calc(100% - 4px);
    background: linear-gradient(180deg, #f7f7f7 0%, #e3e3e3 50%, #f7f7f7 100%);
    border: 1px solid #cfcfcf;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    transition: left 260ms cubic-bezier(.22, 1, .36, 1), background-color 260ms ease;
    will-change: left, transform;
    transform: none;
    pointer-events: none;
}
.theme-switch.no-anim .theme-thumb { transition: none !important; }
html[data-bs-theme="dark"] .theme-switch .theme-thumb { box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.theme-switch .theme-thumb.animate-bounce { animation: theme-thumb-bounce 280ms ease-out; }
@keyframes theme-thumb-bounce {
    0% { transform: translateX(0); }
    60% { transform: translateX(calc(var(--bounce-dir, -1) * 6px)); }
    100% { transform: translateX(0); }
}
@media (max-width: 575.98px) {
    .theme-switch { height: 32px; min-width: 120px; }
    .theme-switch .theme-option svg { width: 16px; height: 16px; }
}

/* Sun/Moon one-shot animations on theme change */
.theme-switch .bi-sun-fill.sun-animate { animation: sun-spin-zoom 520ms cubic-bezier(.22,1,.36,1); transform-origin: 50% 50%; }
@keyframes sun-spin-zoom {
    0% { transform: rotate(0deg) scale(0.9); }
    45% { transform: rotate(180deg) scale(1.15); }
    100% { transform: rotate(360deg) scale(1); }
}
.theme-switch .bi-moon-stars-fill.moon-animate { animation: moon-sway 560ms cubic-bezier(.22,1,.36,1); transform-origin: 50% 50%; }
@keyframes moon-sway {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-12deg); }
    50% { transform: rotate(10deg); }
    75% { transform: rotate(-6deg); }
    100% { transform: rotate(0deg); }
}

/* Loading Animations and Skeleton Screens */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--bs-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

[data-bs-theme="dark"] .loading-overlay {
    background: rgba(0, 0, 0, 0.9);
}

/* Skeleton screens */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

[data-bs-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-title {
    height: 2em;
    width: 60%;
    margin-bottom: 1em;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    border-radius: 8px;
}

/* Lazy loading images */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Button loading state */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Responsive improvements for mobile */
@media (max-width: 768px) {
    .thought-content img {
        max-width: 100%;
        height: auto;
    }
    
    .comment-reply {
        margin-left: 10px;
    }
    
    .card {
        margin-bottom: 1rem;
    }
}

/* Like button jelly animation */
.like-btn-wrapper {
    position: relative;
    display: inline-block;
}

.like-jelly-animate {
    animation: like-jelly 380ms cubic-bezier(.22, 1.1, .36, 1);
    will-change: transform;
}

@keyframes like-jelly {
    0% { transform: scale3d(1, 1, 1); }
    25% { transform: scale3d(1.12, 0.88, 1); }
    50% { transform: scale3d(0.92, 1.08, 1); }
    75% { transform: scale3d(1.04, 0.96, 1); }
    100% { transform: scale3d(1, 1, 1); }
}

/* Floating hearts emitted from like button */
.like-heart {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.4);
    transform-origin: center;
    color: #e25555;
    opacity: 0;
    pointer-events: none;
    font-size: 1.1rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.18));
}

.like-heart-animate {
    animation: like-heart-float 620ms ease-out forwards;
}

@keyframes like-heart-float {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.4);
    }
    8% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--tx, 0px)), calc(-50% + var(--ty, -36px))) scale(0.8);
    }
}

/* Global image viewer / lightbox for content images */
.image-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 2050;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease; /* no transform/position changes */
}

.image-viewer-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.image-viewer-content {
    position: relative;
    max-width: 96vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-viewer-img {
    max-width: 90vw;   /* leave a bit of margin so it never touches edges */
    max-height: 80vh;  /* avoid被顶部关闭按钮/底部文字挤压 */
    object-fit: contain;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    cursor: zoom-in;
    transition: transform 0.2s ease;
}

.image-viewer-img.is-zoomed {
    cursor: zoom-out;
}

.image-viewer-info {
    margin-top: 10px;
    text-align: center;
    color: #f8f9fa;
    font-size: 0.9rem;
}

.image-viewer-counter {
    font-weight: 600;
}

.image-viewer-caption {
    margin-top: 4px;
    opacity: 0.85;
}

.image-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.image-viewer-prev { left: 16px; }
.image-viewer-next { right: 16px; }

.image-viewer-nav:hover {
    background: rgba(0, 0, 0, 0.85);
    transform: translateY(-50%) scale(1.05);
}

.image-viewer-close {
    position: absolute;
    top: 6px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    z-index: 3;
}

.image-viewer-close:hover {
    background: rgba(0, 0, 0, 0.9);
}

body.image-viewer-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .image-viewer-prev { left: 4px; }
    .image-viewer-next { right: 4px; }
    .image-viewer-close { top: 10px; right: 10px; }
}
