@tailwind base;
@tailwind components;
@tailwind utilities;

@view-transition {
    navigation: auto;
}

/* Self-hosted Figtree font */
@font-face {
    font-family: 'Figtree';
    src: url('../fonts/figtree-400.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Figtree';
    src: url('../fonts/figtree-500.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Figtree';
    src: url('../fonts/figtree-600.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Figtree';
    src: url('../fonts/figtree-700.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* Fallback font with adjusted metrics to match Figtree — prevents CLS on font swap */
@font-face {
    font-family: 'Figtree Fallback';
    src: local('Segoe UI'), local('Arial'), local('Helvetica');
    size-adjust: 100.3%;
    ascent-override: 103%;
    descent-override: 28%;
    line-gap-override: 0%;
}

@layer base {
    html {
        scroll-behavior: smooth;
    }

    *,
    *::before,
    *::after {
        transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    }
}

[x-cloak] {
    display: none !important;
}

/* Hide scrollbar but keep scrolling */
.scrollbar-none {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.scrollbar-none::-webkit-scrollbar {
    display: none;
}

/* Blockquotes - tertiary accent with rounded style */
.prose blockquote {
    border-radius: 0.5rem;
    border-left-width: 8px;
    border-color: #2dd4bf; /* tertiary */
    background-color: rgba(45, 212, 191, 0.1);
    padding: 0.75rem 0.75rem 0.75rem 1em;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    font-weight: 400;
    font-style: italic;
}

.dark .prose blockquote {
    background-color: rgb(8, 47, 73); /* tertiary-dark */
}

[dir="rtl"] .prose blockquote {
    border-left-width: 0;
    border-right-width: 8px;
    padding-left: 0.75rem;
    padding-right: 1em;
}

.prose blockquote p  {
    margin-top: 0.7em;
    margin-bottom: 0em;
}

/* Table of Contents */
.toc-container {
    margin-bottom: 1.25rem;
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
    border-radius: 0.5rem;
    border-width: 1px 1px 1px 8px;
    border-color: #2dd4bf; /* tertiary */
    background-color: rgba(45, 212, 191, 0.1);
    padding: 1rem 1rem 1rem 0.5rem;
    font-size: 1rem;
    line-height: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.dark .toc-container {
    background-color: rgb(8, 47, 73); /* tertiary-dark */
}

[dir="rtl"] .toc-container {
    border-left-width: 1px;
    border-right-width: 8px;
    padding-right: 0.5rem;
    padding-left: 1rem;
}

.toc-container ul {
    margin: 0.25rem 0;
    padding: 0 0 0 1.5rem;
}

[dir="rtl"] .toc-container ul {
    padding-right: 1.5rem;
    padding-left: 0;
}

.toc-container li {
    margin: 0;
    padding: 0;
    line-height: 1.25rem;
}

.toc-container a {
    color: rgb(55, 65, 81);
    text-decoration: none;
}

.dark .toc-container a {
    color: rgb(209, 213, 219);
}

.toc-container a:hover {
    text-decoration: underline;
}

/* First level: bold, disc bullets */
.toc-container > ul > li {
    margin: 0.25rem 0;
    list-style-type: disc;
}

.toc-container > ul > li::marker {
    color: #2dd4bf; /* tertiary */
}

.toc-container > ul > li > a {
    font-weight: 600;
}

/* Second level: disc bullets */
.toc-container ul li ul li {
    list-style-type: circle;
}

.toc-container ul li ul li::marker {
    color: #2dd4bf; /* tertiary */
}

/* Third level: italic */
.toc-container ul li ul li ul li {
    list-style-type: "- ";
    font-style: italic;
}

.toc-container ul li ul li ul li::marker {
    color: #2dd4bf; /* tertiary */
}

/* Post/Page title - centered gradient text */
.entry-title {
    margin: auto auto;
    max-width: 40rem;
    text-align: center;
    font-size: clamp(1.5rem, 6vw, 2.25rem);
    line-height: 1.2;
    font-weight: 800;
    overflow-wrap: break-word;
    background-image: linear-gradient(to top right, #047857, #10b981);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.dark .entry-title {
    background-image: linear-gradient(to top right, #6ee7b7, #059669);
}

/* Content body - justified, optimal reading width */
.prose {
    max-width: 40rem; /* ~640px - optimal reading width (50-75 chars/line) */
    margin-left: auto;
    margin-right: auto;
    text-align: justify;
}

/* Content images */
.prose img {
    margin: 0 auto;
    border-radius: 0.5rem;
}

.prose img.fullimg {
    max-width: 100%;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.prose .illustration {
    border-radius: 0.5rem;
    text-align: center;
    font-style: italic;
    margin-left: auto;
    margin-right: auto;
}

.prose table.illustration td {
    text-align: center;
}

.prose table.illustration tbody tr {
    border-bottom: none;
}

.prose .illustration br {
    display: none;
}

/* Content lists */
.prose ul,
.prose ol {
    padding-left: 1.25rem;
}

[dir="rtl"] .prose ul,
[dir="rtl"] .prose ol {
    padding-left: 0;
    padding-right: 1.25rem;
}

.prose ul li {
    list-style-type: disc;
}

.prose ul li::marker {
    color: #2dd4bf; /* tertiary */
}

.prose ol li::marker {
    color: #2dd4bf; /* tertiary */
    font-weight: 700;
}

[dir="rtl"] .prose ul li,
[dir="rtl"] .prose ol li {
    padding-left: 0;
    padding-right: 0.5rem;
}

/* Content headings - colored per level (shifted: raw h1→h2, h2→h3, h3→h4, h4→h5) */
.prose h2 {
    margin-top: 1.5rem;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 800;
    color: #047857; /* primary */
}

.dark .prose h2 {
    color: #6ee7b7; /* primary-dark */
}

.prose h3 {
    margin-top: 1rem;
    padding-left: 1.25rem;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    color: #10b981; /* secondary */
}

.dark .prose h3 {
    color: #059669; /* secondary-dark */
}

[dir="rtl"] .prose h3 {
    padding-left: 0;
    padding-right: 1.25rem;
}

.prose h4 {
    padding-left: 2.5rem;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 700;
    color: #2dd4bf; /* tertiary */
}

[dir="rtl"] .prose h4 {
    padding-left: 0;
    padding-right: 2.5rem;
}

.prose h5 {
    padding-left: 4rem;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    text-decoration: underline;
    text-underline-offset: 4px;
    color: #2dd4bf; /* tertiary */
}

[dir="rtl"] .prose h5 {
    padding-left: 0;
    padding-right: 4rem;
}

/* Global TOC (multi-page navigation) */
.global-toc-container {
    position: relative;
    margin-bottom: 1.25rem;
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
    border-radius: 0.75rem;
    border: 1px solid rgba(101, 163, 13, 0.2);
    border-left: 6px solid #65a30d;
    background: linear-gradient(135deg, rgba(163, 230, 53, 0.06), rgba(101, 163, 13, 0.03));
    padding: 1.25rem 1.25rem 1.25rem 1rem;
    font-size: 1rem;
    line-height: 1.5rem;
    box-shadow: 0 4px 12px -2px rgba(101, 163, 13, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
}

.dark .global-toc-container {
    border-color: rgba(163, 230, 53, 0.25);
    border-left-color: #a3e635;
    background: linear-gradient(135deg, rgba(54, 83, 20, 0.3), rgba(63, 98, 18, 0.15));
    box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.3);
}

[dir="rtl"] .global-toc-container {
    border-left: 1px solid rgba(101, 163, 13, 0.2);
    border-right: 6px solid #65a30d;
    padding-right: 1rem;
    padding-left: 1.25rem;
}

[dir="rtl"] .dark .global-toc-container {
    border-right-color: #a3e635;
}

.global-toc-container .global-toc-intro {
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    color: #4d7c0f; /* lime-700 */
}

.dark .global-toc-container .global-toc-intro {
    color: #bef264; /* lime-300 */
}

.global-toc-container ol {
    margin: 0;
    padding: 0 0 0 1.5rem;
    list-style-type: decimal;
}

[dir="rtl"] .global-toc-container ol {
    padding-right: 1.5rem;
    padding-left: 0;
}

.global-toc-container li {
    margin: 0.3rem 0;
    padding: 0.1rem 0;
}

.global-toc-container li::marker {
    color: #4d7c0f; /* lime-700 */
    font-weight: 700;
}

.dark .global-toc-container li::marker {
    color: #bef264; /* lime-300 */
}

.global-toc-container a {
    color: rgb(55, 65, 81);
    text-decoration: none;
    transition: color 0.15s ease;
}

.dark .global-toc-container a {
    color: rgb(209, 213, 219);
}

.global-toc-container a:hover {
    color: #4d7c0f; /* lime-700 */
    text-decoration: underline;
}

.dark .global-toc-container a:hover {
    color: #bef264; /* lime-300 */
}

.global-toc-container strong {
    color: #4d7c0f; /* lime-700 */
    background: linear-gradient(120deg, rgba(163, 230, 53, 0.12), rgba(101, 163, 13, 0.08));
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
}

.dark .global-toc-container strong {
    color: #bef264; /* lime-300 */
    background: linear-gradient(120deg, rgba(163, 230, 53, 0.15), rgba(101, 163, 13, 0.1));
}

/* Page Navigation */
.page-navigation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid #047857;
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
    flex-wrap: wrap;
}

.page-nav-number {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.375rem;
    font-weight: 600;
    text-decoration: none;
    color: rgb(55, 65, 81);
    background-color: rgba(4, 120, 87, 0.1);
    transition: all 0.15s ease;
}

.dark .page-nav-number {
    color: rgb(209, 213, 219);
    background-color: rgba(6, 78, 59, 0.3);
}

.page-nav-number:hover {
    background-color: rgba(4, 120, 87, 0.25);
}

.page-nav-number.active {
    background-color: #047857;
    color: white;
}

.dark .page-nav-number.active {
    background-color: #059669;
}

.page-nav-arrow {
    font-weight: 600;
    text-decoration: none;
    color: #047857;
    padding: 0.25rem 0.5rem;
}

.dark .page-nav-arrow {
    color: #6ee7b7;
}

.page-nav-arrow:hover {
    text-decoration: underline;
}

/* Flipbook Thumbnail Wrapper */
.flipbook-thumbnail-wrapper {
    display: block;
    margin: 1rem auto;
    max-width: 32rem;
}

/* Flipbook Modal Overlay */
.flipbook-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
}

.flipbook-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
}

.flipbook-modal-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.flipbook-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem;
    color: #fff;
}

.flipbook-modal-title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flipbook-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flipbook-post-btn,
.flipbook-download-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.3rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.15s, background 0.15s;
}

.flipbook-post-btn:hover,
.flipbook-download-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
}

.flipbook-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.flipbook-close-btn:hover {
    opacity: 1;
}

/* Flipbook Container */
.flipbook-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.flipbook-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: pan-x pan-y pinch-zoom;
}

.flipbook-page {
    position: absolute;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.flipbook-page.active {
    position: relative;
    opacity: 1;
    pointer-events: auto;
}

/* Flipbook Controls */
.flipbook-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    color: #fff;
}

.flipbook-nav-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.15s;
}

.flipbook-nav-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.flipbook-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.flipbook-page-info {
    font-size: 0.875rem;
    min-width: 5rem;
    text-align: center;
}

/* Loading spinner */
.flipbook-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: #fff;
}

.flipbook-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: flipbook-spin 0.8s linear infinite;
}

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