/* Custom styles inspired by Taoist principles - stillness, flow, and natural harmony */

/* ========== Animations ========== */

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes gentle-flow {
    0% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

@keyframes ripple {
    0% { box-shadow: 0 0 0 0 rgba(103, 125, 183, 0); }
    70% { box-shadow: 0 0 0 10px rgba(103, 125, 183, 0); }
    100% { box-shadow: 0 0 0 0 rgba(103, 125, 183, 0); }
}

@keyframes wave {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes pulse-slow {
    0% { opacity: 0.10; transform: scale(1); }
    50% { opacity: 0.20; transform: scale(1.03); }
    100% { opacity: 0.10; transform: scale(1); }
}

@keyframes drift-slow {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-2%, 2%); }
    50% { transform: translate(-1%, 4%); }
    75% { transform: translate(1%, 1%); }
    100% { transform: translate(0, 0); }
}

@keyframes subtleFadeIn {
    from { opacity: 0.8; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes subtleReveal {
    from { opacity: 0.85; letter-spacing: 0.01em; }
    to { opacity: 1; letter-spacing: normal; }
}

/* Animation classes */
.animate-fade-in {
    animation: fadeIn 0.8s ease-out forwards;
    opacity: 0;
}

.delay-1 { animation-delay: 0.2s; }
.delay-2 { animation-delay: 0.4s; }
.delay-3 { animation-delay: 0.6s; }

.animate-pulse-slow {
    animation: pulse-slow 12s infinite ease-in-out;
}

.animate-drift-slow {
    animation: drift-slow 20s infinite ease-in-out;
}

.subtle-fade {
    animation: subtleFadeIn 0.8s ease-out forwards;
}

/* ========== Tao Component Styles ========== */

.tao-heading {
    transition: all 0.5s ease-in-out;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.dark .tao-heading {
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tao-link {
    position: relative;
    display: inline-block;
    transition: all 0.3s ease-in-out;
}

.tao-link:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: #677db7;
    transition: all 0.3s ease-in-out;
}

.dark .tao-link:after {
    background-color: #a5b4fc;
}

.tao-link:hover:after {
    width: 100%;
}

.tao-link:hover {
    animation: gentle-flow 2s ease-in-out infinite;
}

.tao-background {
    background-image:
        radial-gradient(circle at 10% 20%, rgba(103, 125, 183, 0.05) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(132, 169, 140, 0.05) 0%, transparent 20%);
    transition: all 0.5s ease-in-out;
}

.dark .tao-background {
    background-image:
        radial-gradient(circle at 10% 20%, rgba(103, 125, 183, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(132, 169, 140, 0.07) 0%, transparent 20%);
}

.tao-card {
    transition: all 0.3s ease-in-out;
    transform: translateY(0);
}

.tao-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.tao-input:focus {
    animation: ripple 1.5s ease-out;
}

.tao-chapter-link {
    transition: all 0.3s ease-in-out;
}

.tao-chapter-link:hover {
    transform: translateX(4px);
}

.tao-wave-decoration {
    position: relative;
    overflow: hidden;
}

.tao-wave-decoration:before {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, transparent, rgba(103, 125, 183, 0.2), transparent);
    transform: translateX(-100%);
    animation: wave 8s linear infinite;
}

/* ========== Sidebar Styles ========== */

.sidebar-transition {
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 16rem;
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    border-right: 1px solid rgba(229, 231, 235, 0.5);
    display: flex;
    flex-direction: column;
}

.dark .sidebar-transition {
    background-color: rgba(31, 41, 55, 0.5);
    border-right: 1px solid rgba(55, 65, 81, 0.2);
}

@media (min-width: 1024px) {
    .sidebar-transition {
        width: 18rem;
    }
}

.sidebar-collapsed {
    width: 4.5rem;
}

.sidebar-header {
    border-bottom: none;
    height: 4rem;
}

.home-link {
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    width: 100%;
}

.home-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 2.5rem;
    flex-shrink: 0;
    font-size: 1.5rem;
}

.home-text {
    transition: opacity 0.3s ease, max-width 0.4s ease;
    max-width: 200px;
    overflow: hidden;
}

.sidebar-collapsed .home-text {
    max-width: 0;
    opacity: 0;
}

.sidebar-collapsed .home-link {
    justify-content: center;
    padding-left: 0;
}

.toggle-button {
    flex-shrink: 0;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.toggle-button:hover {
    opacity: 1;
}

.toc-transition {
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    transform: translateX(0);
    white-space: nowrap;
    overflow: hidden;
}

.toc-hidden {
    opacity: 0;
    transform: translateX(-100%);
    position: absolute;
    pointer-events: none;
}

.main-content-transition {
    transition: margin-left 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile sidebar */
@media screen and (max-width: 767px) {
    .sidebar-transition {
        position: fixed !important;
        left: 0;
        top: 0;
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        z-index: 50;
        transform: translateX(0);
        transition: transform 0.3s ease-in-out;
        background-color: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(12px);
        display: flex;
        flex-direction: column;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .dark .sidebar-transition {
        background-color: rgba(17, 24, 39, 0.98);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
    }

    .sidebar-transition.mobile-hidden {
        transform: translateX(-100%);
        box-shadow: none;
    }

    /* Override any collapsed state on mobile */
    .sidebar-collapsed {
        transform: translateX(0);
        width: 85vw;
        max-width: 320px;
    }

    .sidebar-collapsed.mobile-hidden {
        transform: translateX(-100%);
    }

    #main-content {
        width: 100% !important;
        margin-left: 0 !important;
    }

    #toc-container {
        height: calc(100vh - 4rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #toc-container nav {
        height: auto;
        overflow: visible;
    }

    /* Allow text wrapping on mobile */
    .toc-transition {
        white-space: normal;
    }

    /* Mobile overlay when sidebar is open - must be below sidebar (z-50) */
    .mobile-sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 40;
        opacity: 1;
        transition: opacity 0.3s ease-in-out;
    }

    .mobile-sidebar-overlay.hidden {
        opacity: 0;
        pointer-events: none;
    }
}

/* Mobile close button in sidebar */
.mobile-close-button {
    transition: all 0.3s ease;
}

/* ========== Prose Overrides ========== */

.prose h1, .prose-lg h1, .prose-xl h1 {
    font-family: 'EB Garamond', serif;
    font-weight: 500;
    margin-bottom: 1.5rem;
}

.prose h1 { font-size: 1.875rem; }
.prose-lg h1 { font-size: 2.25rem; }
.prose-xl h1 { font-size: 2.25rem; }

/* Style for level 4 headings - integrated with horizontal rule */
.prose h4, .prose-lg h4, .prose-xl h4 {
    font-family: 'EB Garamond', serif;
    text-align: center;
    color: #677db7;
    margin-top: 3rem;
    margin-bottom: 3rem;
    font-weight: 500;
    position: relative;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: none;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-size: 0.95em;
}

.dark .prose h4, .dark .prose-lg h4, .dark .prose-xl h4 {
    color: #a5b4fc;
}

.prose h4::before, .prose h4::after {
    content: "";
    height: 1px;
    flex-grow: 1;
    max-width: 16rem;
    background: linear-gradient(to right, transparent, rgba(103, 125, 183, 0.4), rgba(103, 125, 183, 0.4));
}

.prose h4::after {
    background: linear-gradient(to left, transparent, rgba(103, 125, 183, 0.4), rgba(103, 125, 183, 0.4));
}

.dark .prose h4::before, .dark .prose h4::after {
    background: linear-gradient(to right, transparent, rgba(165, 180, 252, 0.3), rgba(165, 180, 252, 0.3));
}

.dark .prose h4::after {
    background: linear-gradient(to left, transparent, rgba(165, 180, 252, 0.3), rgba(165, 180, 252, 0.3));
}

.prose h4 span, .prose-lg h4 span, .prose-xl h4 span {
    padding-left: 1rem;
    padding-right: 1rem;
    z-index: 10;
    position: relative;
}

/* Horizontal rule styling */
.prose hr, .prose-lg hr, .prose-xl hr {
    margin-top: 3rem;
    margin-bottom: 3rem;
    position: relative;
    width: 80%;
    margin-left: auto;
    margin-right: auto;
    height: 1px;
    border: 0;
    max-width: 28rem;
    background: linear-gradient(to right, transparent, rgba(103, 125, 183, 0.4), transparent);
}

.prose hr::before {
    content: "\25C6";
    position: absolute;
    color: rgba(103, 125, 183, 0.8);
    font-size: 0.75rem;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    z-index: 10;
}

.dark .prose hr::before {
    color: rgba(165, 180, 252, 0.8);
    background-color: #1f2937;
}

/* Hide hr when immediately followed by h4 (both have decorative lines) */
.prose hr:has(+ h4),
.prose-lg hr:has(+ h4),
.prose-xl hr:has(+ h4) {
    display: none;
}

/* Blockquote styling */
.prose blockquote, .prose-lg blockquote, .prose-xl blockquote {
    padding-left: 2rem;
    padding-right: 1.5rem;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
    border-left-width: 4px;
    border-left-color: rgba(103, 125, 183, 0.7);
    border-radius: 0.5rem;
    font-style: italic;
    position: relative;
    background: rgba(245, 247, 250, 0.85);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.dark .prose blockquote,
.dark .prose-lg blockquote,
.dark .prose-xl blockquote {
    border-left-color: rgba(129, 140, 248, 0.7);
    background: rgba(40, 50, 70, 0.6);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}

/* Remove Tailwind prose default quotes - content already has quotation marks */
.prose blockquote p:first-of-type::before,
.prose blockquote p:last-of-type::after,
.prose-lg blockquote p:first-of-type::before,
.prose-lg blockquote p:last-of-type::after,
.prose-xl blockquote p:first-of-type::before,
.prose-xl blockquote p:last-of-type::after {
    content: "" !important;
}

.prose blockquote p,
.prose-lg blockquote p,
.prose-xl blockquote p {
    color: #1f2937;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.dark .prose blockquote p,
.dark .prose-lg blockquote p,
.dark .prose-xl blockquote p {
    color: #e5e7eb;
}

/* Links */
.prose a, .prose-lg a, .prose-xl a {
    color: #677db7;
}

.dark .prose a, .dark .prose-lg a, .dark .prose-xl a {
    color: #a5b4fc;
}

.prose a:hover, .prose-lg a:hover, .prose-xl a:hover {
    text-decoration: underline;
}

/* Inline code styling */
.prose code:not(pre code),
.prose-lg code:not(pre code),
.prose-xl code:not(pre code) {
    background-color: rgba(243, 244, 246, 0.95);
    color: #111827;
    padding-left: 0.375rem;
    padding-right: 0.375rem;
    padding-top: 0.125rem;
    padding-bottom: 0.125rem;
    border-radius: 0.25rem;
    font-size: 0.9em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.dark .prose code:not(pre code),
.dark .prose-lg code:not(pre code),
.dark .prose-xl code:not(pre code) {
    background-color: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Remove backticks from rendered inline code */
.prose code:not(pre code)::before,
.prose code:not(pre code)::after,
.prose-lg code:not(pre code)::before,
.prose-lg code:not(pre code)::after,
.prose-xl code:not(pre code)::before,
.prose-xl code:not(pre code)::after {
    content: "" !important;
}

/* Code blocks */
.prose pre, .prose-lg pre, .prose-xl pre {
    background-color: rgba(245, 247, 250, 0.85) !important;
}

.dark .prose pre, .dark .prose-lg pre, .dark .prose-xl pre {
    background-color: rgba(40, 50, 70, 0.6) !important;
}

.hljs {
    background-color: transparent !important;
}

/* Prose content animations */
.prose p, .prose li, .prose h1, .prose h2, .prose h3, .prose h4, .prose blockquote, .prose hr {
    animation: subtleReveal 0.6s ease-out forwards;
}

.prose p:nth-child(2) { animation-delay: 0.05s; }
.prose p:nth-child(3) { animation-delay: 0.1s; }
.prose p:nth-child(4) { animation-delay: 0.15s; }
.prose h2, .prose h3 { animation-delay: 0.03s; }
.prose h4 { animation-delay: 0.04s; }
.prose li:nth-child(1) { animation-delay: 0.05s; }
.prose li:nth-child(2) { animation-delay: 0.07s; }
.prose li:nth-child(3) { animation-delay: 0.09s; }
.prose blockquote { animation-delay: 0.1s; }
.prose hr { animation-delay: 0.12s; }

/* ========== Utilities ========== */

/* Radial gradient utility (not built into Tailwind by default) */
.bg-gradient-radial {
    background: radial-gradient(var(--tw-gradient-stops));
}

/* Safari animation fixes */
@supports (-webkit-touch-callout: none) {
    .animate-pulse-slow, .animate-drift-slow {
        will-change: transform, opacity;
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
    }

    .sidebar-collapsed {
        width: 3.5rem;
    }
}
