:root {
    --color-primary: #2563eb;
    --color-secondary: #7c3aed;
    --bg-light: #f8fafc;
    --bg-dark: #0f172a;
    --nav-height: 76px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--nav-height) + 16px);
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 0;
    margin: 0;
    font-family: 'Inter', sans-serif;
    overflow-x: clip;
    background-color: var(--bg-light);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.dark body {
    background-color: var(--bg-dark);
}

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

a,
button {
    -webkit-tap-highlight-color: transparent;
}

button,
a {
    touch-action: manipulation;
}

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.55);
    outline-offset: 3px;
}

/* Prevent long labels/text from forcing horizontal overflow. */
p,
li,
h1,
h2,
h3,
h4,
a,
span {
    overflow-wrap: anywhere;
}

/* Loader */
#loader {
    position: fixed;
    inset: 0;
    background: #0f172a;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.45s ease, visibility 0.45s ease;
}

#loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Loader icon (replaces plain spinner) */
.loader-icon {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-glyph {
    position: relative;
    z-index: 2;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: #fff;
    
    box-shadow: 0 0 25px rgba(37, 99, 235, 0.65);
    animation: loader-pulse 1.6s ease-in-out infinite;
}
.loader-glyph img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }

.loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(124, 58, 237, 0.55);
    animation: loader-ring-ping 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loader-ring--delay {
    animation-delay: 0.6s;
    border-color: rgba(37, 99, 235, 0.5);
}

@keyframes loader-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); box-shadow: 0 0 34px rgba(124, 58, 237, 0.75); }
}

@keyframes loader-ring-ping {
    0% { transform: scale(0.75); opacity: 0.9; }
    100% { transform: scale(1.9); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .loader-glyph,
    .loader-ring,
    .loader-ring--delay {
        animation: none;
    }
}

/* Glassmorphism */
.glass {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.32);
}

.dark .glass {
    background: rgba(15, 23, 42, 0.68);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.glass-card {
    background: rgba(255, 255, 255, 0.48);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.52);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
}

.dark .glass-card {
    background: rgba(30, 41, 59, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

@media (hover: hover) and (pointer: fine) {
    .glass-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 30px -10px rgba(124, 58, 237, 0.3);
        border-color: rgba(124, 58, 237, 0.3);
    }
}

/* Gradients */
.text-gradient {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.bg-gradient-custom {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

/* Floating background */
.blob {
    position: absolute;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.4;
    animation: float 10s infinite ease-in-out alternate;
    will-change: transform;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -50px) scale(1.1); }
    100% { transform: translate(-20px, 20px) scale(0.9); }
}

/* Scroll reveal */
.reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.7s cubic-bezier(0.5, 0, 0, 1), transform 0.7s cubic-bezier(0.5, 0, 0, 1);
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

/* Theme toggle switch */
.theme-switch {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}

.theme-switch-track {
    position: relative;
    width: 60px;
    height: 32px;
    border-radius: 999px;
    background: linear-gradient(135deg, #dbeafe, #ede9fe);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 2px 5px rgba(15, 23, 42, 0.12), 0 4px 10px -4px rgba(37, 99, 235, 0.35);
    transition: background 0.4s ease, box-shadow 0.3s ease;
    overflow: hidden;
}

.dark .theme-switch-track {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 14px rgba(124, 58, 237, 0.35);
}

.theme-switch-deco {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    transition: opacity 0.3s ease, color 0.3s ease;
}

.theme-switch-deco--sun {
    left: 7px;
    color: #f59e0b;
    opacity: 1;
}

.theme-switch-deco--moon {
    right: 7px;
    color: #94a3b8;
    opacity: 0.5;
}

.dark .theme-switch-deco--sun { opacity: 0.35; }
.dark .theme-switch-deco--moon { opacity: 1; color: #c4b5fd; }

.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fff, #f1f5f9);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s ease;
    z-index: 2;
}

.dark .theme-switch-thumb {
    transform: translateX(28px);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

.theme-switch-icon {
    position: absolute;
    font-size: 0.7rem;
    transition: opacity 0.25s ease, transform 0.35s ease;
}

.theme-switch-icon--sun { color: #f59e0b; opacity: 1; transform: scale(1) rotate(0deg); }
.theme-switch-icon--moon { color: #fff; opacity: 0; transform: scale(0.5) rotate(-90deg); }

.dark .theme-switch-icon--sun { opacity: 0; transform: scale(0.5) rotate(90deg); }
.dark .theme-switch-icon--moon { opacity: 1; transform: scale(1) rotate(0deg); }

.theme-switch:hover .theme-switch-track {
    box-shadow: inset 0 2px 5px rgba(15, 23, 42, 0.12), 0 4px 14px -3px rgba(124, 58, 237, 0.5);
}

.theme-switch:focus-visible .theme-switch-track {
    outline: 3px solid rgba(37, 99, 235, 0.55);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .theme-switch-thumb,
    .theme-switch-icon {
        transition: none;
    }
}

/* Hub node icon (Peta Integrasi) */
#hub-node {
    position: relative;
}

.hub-node-icon { width: 48%; height: 48%; object-fit: cover; border-radius: 50%; filter: drop-shadow(0 2px 6px rgba(15, 23, 42, 0.25)); }

.hub-node-tag {
    margin-top: 2px;
    font-size: clamp(0.6rem, 1.4vw, 0.75rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    opacity: 0.9;
}

.hub-node-pulse {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid rgba(124, 58, 237, 0.45);
    animation: loader-ring-ping 2.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .hub-node-pulse { animation: none; }
}

/* Social buttons */
.social-btn {
    position: relative;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #64748b;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 8px 20px -8px rgba(15, 23, 42, 0.25);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.35s ease, color 0.3s ease, background 0.3s ease;
    opacity: 0;
    transform: translateY(16px) scale(0.9);
    animation: social-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    animation-delay: var(--d, 0ms);
    animation-play-state: paused;
}

.reveal.active .social-btn {
    animation-play-state: running;
}

@keyframes social-pop {
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.dark .social-btn {
    background: rgba(30, 41, 59, 0.55);
    border-color: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
}

@media (min-width: 768px) {
    .social-btn {
        width: 5rem;
        height: 5rem;
        font-size: 2rem;
    }
}

@media (hover: hover) and (pointer: fine) {
    .social-btn:hover {
        transform: translateY(-8px) scale(1.08) rotate(-4deg);
        color: var(--brand, var(--color-primary));
        background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--brand, var(--color-primary)) 22%, transparent), rgba(255, 255, 255, 0.55));
        box-shadow: 0 16px 28px -10px color-mix(in srgb, var(--brand, var(--color-primary)) 55%, transparent), 0 0 0 1px color-mix(in srgb, var(--brand, var(--color-primary)) 35%, transparent);
    }

    .dark .social-btn:hover {
        background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--brand, var(--color-primary)) 30%, transparent), rgba(30, 41, 59, 0.55));
    }
}

.social-btn:active {
    transform: translateY(-2px) scale(0.96);
}

.social-tip {
    position: absolute;
    bottom: -1.75rem;
    left: 50%;
    transform: translate(-50%, 4px);
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.85);
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.social-btn:hover .social-tip,
.social-btn:focus-visible .social-tip {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
    .social-btn {
        opacity: 1;
        transform: none;
        animation: none;
    }
}

/* Navigation */
#navbar {
    padding-top: env(safe-area-inset-top, 0px);
}

#mobileMenu {
    padding-top: max(5rem, calc(4rem + env(safe-area-inset-top, 0px)));
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
}

/* Interactive ecosystem map */
.ecosystem-map {
    height: clamp(520px, 66vw, 700px);
    isolation: isolate;
}

.map-node {
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    cursor: default;
    will-change: transform;
}

@media (hover: hover) and (pointer: fine) {
    .map-node:hover {
        transform: translate(-50%, -50%) scale(1.12) !important;
        z-index: 30;
        box-shadow: 0 0 20px rgba(124, 58, 237, 0.55);
    }
}

.tooltip-custom {
    visibility: hidden;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.map-node:hover .tooltip-custom,
.map-node:focus-visible .tooltip-custom,
.map-node.is-active .tooltip-custom {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

svg.map-lines line {
    stroke: rgba(124, 58, 237, 0.28);
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke 0.3s;
    stroke-dasharray: 5, 7;
    animation: dash 20s linear infinite;
}

@keyframes dash {
    to { stroke-dashoffset: 1000; }
}

.dark svg.map-lines line {
    stroke: rgba(255, 255, 255, 0.14);
}

/* Responsive refinements */
@media (max-width: 1023.98px) {
    :root { --nav-height: 68px; }

    #navbar .container {
        max-width: 100%;
    }
}

@media (max-width: 639.98px) {
    :root { --nav-height: 64px; }

    .blob {
        filter: blur(64px);
        opacity: 0.28;
    }

    .ecosystem-map {
        height: 540px;
        min-height: 540px;
    }

    #hub-node {
        box-shadow: 0 0 28px rgba(37, 99, 235, 0.48);
    }

    .map-node {
        width: 46px !important;
        height: 46px !important;
    }

    .map-node i {
        font-size: 1rem !important;
    }

    .tooltip-custom {
        font-size: 0.62rem !important;
        padding: 0.25rem 0.45rem !important;
        max-width: 86px;
        white-space: normal !important;
        text-align: center;
        line-height: 1.2;
    }

    #sosial a {
        width: 3.5rem;
        height: 3.5rem;
        font-size: 1.65rem;
    }

    footer .flex.gap-4.text-sm {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (max-width: 374.98px) {
    .ecosystem-map {
        height: 510px;
        min-height: 510px;
    }

    #hub-node {
        width: 84px !important;
        height: 84px !important;
    }

    .map-node {
        width: 42px !important;
        height: 42px !important;
    }

    .tooltip-custom {
        max-width: 72px;
        font-size: 0.58rem !important;
    }
}

/* Reduced motion / accessibility */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }

    .reveal {
        opacity: 1;
        transform: none;
    }
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #7c3aed; }

/* Static utility build compatibility: nodes are centered without Tailwind transform variables. */
.map-node {
    transform: translate(-50%, -50%);
}
