/* =============================================
   Ahmed Habib — Custom Overrides (Tailwind + Flowbite)
   Only styles that cannot be done with Tailwind utilities
   ============================================= */

/* --- Gradient Text Effect --- */
.gradient-text {
    background: linear-gradient(135deg, #1a1a2e 0%, #4361ee 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dark .gradient-text {
    background: linear-gradient(135deg, #e8e8f0 0%, #5b7cfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.counter-number {
    background: linear-gradient(135deg, #4361ee, #f72585);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- Prose Content (rendered markdown in blog posts) --- */
.prose {
    line-height: 1.85;
    font-size: 1.05rem;
}

.prose h2 {
    font-size: 1.6rem;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.prose h3 {
    font-size: 1.3rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.prose p {
    margin-bottom: 1.25rem;
}

.prose a {
    color: #4361ee;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.dark .prose a {
    color: #5b7cfa;
}

.prose a:hover {
    opacity: 0.8;
}

.prose ul, .prose ol {
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
}

.prose li {
    margin-bottom: 0.35rem;
}

.prose blockquote {
    border-left: 4px solid #4361ee;
    padding: 1rem 1.5rem;
    margin: 1.5rem 0;
    background: rgba(67, 97, 238, 0.05);
    border-radius: 0 8px 8px 0;
    font-style: italic;
}

.dark .prose blockquote {
    border-left-color: #5b7cfa;
    background: rgba(91, 124, 250, 0.08);
}

.prose pre {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.6;
    background: #1e1e2e;
    color: #e8e8f0;
}

.prose code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
}

.prose p code, .prose li code {
    background: #f4f5f7;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.dark .prose p code, .dark .prose li code {
    background: #222240;
}

.prose img {
    max-width: 100%;
    border-radius: 10px;
    margin: 1.5rem 0;
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.9rem;
}

.prose table th {
    text-align: left;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid #e2e6ea;
}

.dark .prose table th {
    border-bottom-color: #2d2d50;
}

.prose table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e6ea;
}

.dark .prose table td {
    border-bottom-color: #2d2d50;
}

.prose hr {
    margin: 2rem 0;
    border: none;
    border-top: 1px solid #e2e6ea;
}

.dark .prose hr {
    border-top-color: #2d2d50;
}

/* --- Game Canvas Responsive --- */
.game-container canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* --- Navbar entrance animation (avoids forced reflow) --- */
nav.sticky.nav-enter {
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
nav.sticky.nav-enter.nav-entered {
    opacity: 1;
    transform: translateY(0);
}

/* --- Smooth transitions for dark mode --- */
body, .dark body {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* =============================================
   Animation System — Scroll Reveal
   ============================================= */

[data-animate] {
    opacity: 0;
}

[data-animate].is-visible {
    opacity: 1;
}

.anim-delay-0 { animation-delay: 0ms; }
.anim-delay-1 { animation-delay: 60ms; }
.anim-delay-2 { animation-delay: 120ms; }
.anim-delay-3 { animation-delay: 180ms; }
.anim-delay-4 { animation-delay: 240ms; }
.anim-delay-5 { animation-delay: 300ms; }
.anim-delay-6 { animation-delay: 360ms; }
.anim-delay-7 { animation-delay: 420ms; }
.anim-delay-8 { animation-delay: 480ms; }

.no-js [data-animate] {
    opacity: 1 !important;
}

@media (prefers-reduced-motion: reduce) {
    [data-animate] {
        opacity: 1 !important;
        animation: none !important;
        transition: none !important;
    }
}

/* =============================================
   Speed Dial FAB
   ============================================= */

.fab-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 50;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 0.75rem;
}

/* Main trigger button */
.fab-trigger {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    color: #fff;
    font-size: 1.2rem;
    box-shadow: 0 4px 14px rgba(67, 97, 238, 0.35);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                background 0.2s ease,
                box-shadow 0.2s ease;
    position: relative;
    z-index: 2;
}

.fab-trigger:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 6px 20px rgba(67, 97, 238, 0.45);
}

.fab-trigger:active {
    transform: scale(0.93);
}

.fab-trigger .fab-icon-open,
.fab-trigger .fab-icon-close {
    position: absolute;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.fab-trigger .fab-icon-close {
    opacity: 0;
    transform: rotate(-90deg);
}

.fab-container.is-open .fab-trigger {
    transform: rotate(0deg);
}

.fab-container.is-open .fab-trigger .fab-icon-open {
    opacity: 0;
    transform: rotate(90deg);
}

.fab-container.is-open .fab-trigger .fab-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Speed dial action items */
.fab-actions {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 0.625rem;
    pointer-events: none;
}

.fab-container.is-open .fab-actions {
    pointer-events: auto;
}

.fab-action {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.95rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--color-border);
    opacity: 0;
    transform: translateY(8px) scale(0.8);
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                background 0.15s ease,
                box-shadow 0.15s ease;
    position: relative;
}

.fab-container.is-open .fab-action {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Back to top hidden until scrolled */
.fab-action[data-fab="top"] {
    display: none;
}
.fab-action[data-fab="top"].fab-scrolled {
    display: flex;
}

/* Staggered reveal — dynamically re-indexed by visible items */
.fab-container.is-open .fab-action:nth-child(1) { transition-delay: 0ms; }
.fab-container.is-open .fab-action:nth-child(2) { transition-delay: 40ms; }
.fab-container.is-open .fab-action:nth-child(3) { transition-delay: 80ms; }
.fab-container.is-open .fab-action:nth-child(4) { transition-delay: 120ms; }
.fab-container.is-open .fab-action:nth-child(5) { transition-delay: 160ms; }
.fab-container.is-open .fab-action:nth-child(6) { transition-delay: 200ms; }

/* Staggered hide (reverse) */
.fab-action:nth-child(6) { transition-delay: 0ms; }
.fab-action:nth-child(5) { transition-delay: 30ms; }
.fab-action:nth-child(4) { transition-delay: 60ms; }
.fab-action:nth-child(3) { transition-delay: 90ms; }
.fab-action:nth-child(2) { transition-delay: 120ms; }
.fab-action:nth-child(1) { transition-delay: 150ms; }

.fab-action:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    box-shadow: 0 4px 14px rgba(67, 97, 238, 0.3);
    transform: scale(1.1);
}

.fab-action:active {
    transform: scale(0.95);
}

/* Tooltip labels */
.fab-action::before {
    content: attr(data-label);
    position: absolute;
    right: calc(100% + 0.75rem);
    white-space: nowrap;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--color-text);
    color: var(--color-bg);
    opacity: 0;
    transform: translateX(4px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.fab-action:hover::before {
    opacity: 1;
    transform: translateX(0);
}

/* Dark mode */
.dark .fab-trigger {
    box-shadow: 0 4px 14px rgba(91, 124, 250, 0.3);
}
.dark .fab-trigger:hover {
    box-shadow: 0 6px 20px rgba(91, 124, 250, 0.4);
}
.dark .fab-action {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.dark .fab-action:hover {
    box-shadow: 0 4px 14px rgba(91, 124, 250, 0.3);
}

/* Backdrop when open */
.fab-backdrop {
    position: fixed;
    inset: 0;
    z-index: 49;
    display: none;
}
.fab-container.is-open ~ .fab-backdrop {
    display: block;
}

@media (max-width: 640px) {
    .fab-container {
        bottom: 1.25rem;
        right: 1.25rem;
    }
    .fab-trigger {
        width: 48px;
        height: 48px;
    }
    .fab-action {
        width: 40px;
        height: 40px;
    }
    .fab-action::before {
        display: none;
    }
}

/* =============================================
   Micro-interactions
   ============================================= */

input:focus, textarea:focus, select:focus {
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.dark input:focus, .dark textarea:focus, .dark select:focus {
    box-shadow: 0 0 0 3px rgba(91, 124, 250, 0.15);
}

button:active:not(:disabled),
a[class*="bg-primary"]:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
}

.card-hover {
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.25s ease;
}
.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.1),
                0 4px 8px -4px rgba(0, 0, 0, 0.06);
}
.dark .card-hover:hover {
    box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.3),
                0 4px 8px -4px rgba(0, 0, 0, 0.2);
}

/* =============================================
   Overlay Transitions
   ============================================= */

.overlay-animated {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.overlay-animated.is-open {
    opacity: 1;
    visibility: visible;
}
.overlay-animated .overlay-content {
    transform: translateY(-20px) scale(0.98);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.overlay-animated.is-open .overlay-content {
    transform: translateY(0) scale(1);
    opacity: 1;
}

[data-dismiss] {
    animation: fadeDown 0.3s ease-out forwards;
}

/* =============================================
   Plugin Bridge — CSS Custom Properties
   Maps vars used by ecosystem plugins to theme values.
   ============================================= */

:root {
    --color-primary: #4361ee;
    --color-primary-hover: #3a56d4;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #4b5563;
    --color-text-secondary: #4b5563;
    --color-bg: #ffffff;
    --color-bg-card: #ffffff;
    --color-bg-alt: #f1f3f5;
    --color-bg-secondary: #f9fafb;
    --color-surface: #f1f3f5;
    --color-success: #06d6a0;
    --color-success-light: #d1fae5;
    --color-warning: #ffd166;
    --color-warning-light: #fef3c7;
    --color-danger: #ef476f;
    --color-danger-light: #fee2e2;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

.dark {
    --color-primary: #5b7cfa;
    --color-primary-hover: #7b96ff;
    --color-border: #2d2d50;
    --color-text: #e8e8f0;
    --color-text-muted: #a0a0b8;
    --color-text-secondary: #a0a0b8;
    --color-bg: #0f0f1a;
    --color-bg-card: #1a1a2e;
    --color-bg-alt: #222240;
    --color-bg-secondary: #1a1a2e;
    --color-surface: #222240;
    --color-success: #06d6a0;
    --color-success-light: rgba(6, 214, 160, 0.15);
    --color-warning: #ffd166;
    --color-warning-light: rgba(255, 209, 102, 0.15);
    --color-danger: #ef476f;
    --color-danger-light: rgba(239, 71, 111, 0.15);
}

/* =============================================
   Plugin Bridge — Utility Classes
   Shared styles for ecosystem plugins.
   ============================================= */

/* --- Form Controls --- */
.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}
.dark .form-control:focus {
    box-shadow: 0 0 0 3px rgba(91, 124, 250, 0.15);
}
select.form-control {
    appearance: auto;
}

.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

/* --- Typography --- */
.text-small {
    font-size: 0.8rem;
    line-height: 1.4;
}
.text-muted {
    color: var(--color-text-muted);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--color-bg-alt);
    color: var(--color-text);
    transition: all 0.15s ease;
    line-height: 1.4;
    text-decoration: none;
    box-sizing: border-box;
}
.btn:hover {
    opacity: 0.85;
}
.btn:active {
    transform: scale(0.97);
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    opacity: 1;
}

.btn-secondary {
    background: var(--color-bg-alt);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-border);
    opacity: 1;
}

.btn-ghost {
    background: transparent;
    color: var(--color-primary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: rgba(67, 97, 238, 0.08);
    opacity: 1;
}
.dark .btn-ghost:hover {
    background: rgba(91, 124, 250, 0.1);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}
.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* --- Stat Cards --- */
.stat-card {
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    text-align: center;
}
.stat-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 0.15rem;
    font-weight: 600;
}
.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

/* --- Layout Helpers --- */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Admin Card (used in scaffold templates) --- */
.admin-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

/* =============================================
   PWA Standalone Mode
   Loaded in <head> to prevent FOUC of site chrome.
   ============================================= */
@media all and (display-mode: standalone) {
    body > nav, body > footer, #search-overlay { display: none !important; }
    .pwa-hide { display: none !important; }
    #pwa-info-panel { display: none !important; }
    .pwa-standalone-section { padding-top: 1rem; padding-bottom: 1rem; }
    .pwa-standalone-only { display: block !important; }
    #pwa-info-dialog { display: none !important; }
    #pwa-info-dialog.pwa-dialog-open { display: block !important; }
    .pwa-standalone-section .bg-white.rounded-xl { border: none; box-shadow: none; border-radius: 0; padding-left: 1rem; padding-right: 1rem; }
}
