/* ========================================
   ADVANCED ANIMATIONS & EFFECTS
   เพิ่มลูกเล่นและ animations ที่ทำให้เว็บดู WOW
   ======================================== */

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* ========================================
   KEYFRAME ANIMATIONS
   ======================================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-20px);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }

    100% {
        background-position: 1000px 0;
    }
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes borderGlow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(25, 184, 166, 0.3),
            0 0 10px rgba(25, 184, 166, 0.2),
            0 0 15px rgba(25, 184, 166, 0.1);
    }

    50% {
        box-shadow: 0 0 10px rgba(25, 184, 166, 0.5),
            0 0 20px rgba(25, 184, 166, 0.3),
            0 0 30px rgba(25, 184, 166, 0.2);
    }
}

@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(50px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-10deg) scale(0.9);
    }

    to {
        opacity: 1;
        transform: rotate(0) scale(1);
    }
}

/* ========================================
   SCROLL ANIMATIONS
   ======================================== */

.animate-on-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.animate-on-scroll.animated {
    opacity: 1;
    transform: translateY(0);
}

.animate-fade-in {
    animation: fadeInUp 0.8s ease-out forwards;
}

.animate-delay-1 {
    animation-delay: 0.1s;
}

.animate-delay-2 {
    animation-delay: 0.2s;
}

.animate-delay-3 {
    animation-delay: 0.3s;
}

.animate-delay-4 {
    animation-delay: 0.4s;
}

/* ========================================
   ENHANCED HERO SECTION
   ======================================== */

.hero-overlay {
    background:
        linear-gradient(90deg, rgba(8, 11, 15, 0.96) 0%, rgba(8, 11, 15, 0.78) 42%, rgba(8, 11, 15, 0.24) 100%),
        linear-gradient(0deg, #080b0f 0%, rgba(8, 11, 15, 0.04) 42%),
        radial-gradient(circle at 18% 32%, rgba(25, 184, 166, 0.24), transparent 28%);
    animation: gradientShift 15s ease infinite;
    background-size: 200% 200%;
}

.hero-name {
    animation: fadeInLeft 1s ease-out;
}

.thai-name {
    animation: fadeInLeft 1.2s ease-out;
}

.role {
    animation: fadeInLeft 1.4s ease-out;
}

.intro {
    animation: fadeInLeft 1.6s ease-out;
}

.hero-actions {
    animation: fadeInUp 1.8s ease-out;
}

.portrait-card {
    animation: fadeInRight 1.2s ease-out;
}

/* Floating animation for portrait */
.portrait-card:hover {
    animation: float 3s ease-in-out infinite;
}

/* ========================================
   ENHANCED BUTTONS & LINKS
   ======================================== */

.primary-link,
.secondary-link,
button {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.primary-link::before,
.secondary-link::before,
button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.primary-link:hover::before,
.secondary-link:hover::before,
button:hover::before {
    width: 300px;
    height: 300px;
}

.primary-link:hover,
.secondary-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(25, 184, 166, 0.3);
}

.primary-link:active,
.secondary-link:active {
    transform: translateY(0);
}

/* ========================================
   ENHANCED CARDS
   ======================================== */

.devops-card,
.infra-grid article,
.alignment-grid article,
.expertise-grid article,
.project-card,
.webapp-card,
.client-logo-card,
.skill-groups article,
.education-list article {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.devops-card::after,
.project-card::after,
.webapp-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(25, 184, 166, 0.1), rgba(109, 169, 255, 0.1));
}

.devops-card:hover,
.project-card:hover,
.expertise-grid article:hover,
.skill-groups article:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border-color: rgba(25, 184, 166, 0.5);
}

.devops-card:hover::after,
.project-card:hover::after {
    opacity: 1;
}

/* 3D Tilt Effect for Cards */
.webapp-card {
    transform-style: preserve-3d;
    perspective: 1000px;
}

.webapp-card:hover {
    transform: translateY(-5px) rotateX(2deg) rotateY(2deg);
    box-shadow: 0 25px 70px rgba(25, 184, 166, 0.2);
}

/* ========================================
   GLASSMORPHISM EFFECTS
   ======================================== */

.signal-panel,
.portrait-card {
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    transition: all 0.4s ease;
}

.signal-panel:hover {
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.4);
}

/* ========================================
   GRADIENT TEXT EFFECTS
   ======================================== */

.hero-name,
h2 {
    background: linear-gradient(135deg, #f7f4ee 0%, #19b8a6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    background-size: 200% 200%;
    animation: gradientShift 8s ease infinite;
}

.section-kicker,
.eyebrow {
    position: relative;
    display: inline-block;
}

.section-kicker::after,
.eyebrow::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--teal), var(--blue));
    transition: width 0.4s ease;
}

.section-kicker:hover::after,
.eyebrow:hover::after {
    width: 100%;
}

/* ========================================
   ENHANCED NAVIGATION
   ======================================== */

.topbar {
    transition: all 0.3s ease;
}

.topbar.scrolled {
    background: rgba(8, 11, 15, 0.95);
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.nav a {
    position: relative;
    transition: all 0.3s ease;
}

.nav a::before {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--teal), var(--blue));
    transition: width 0.3s ease;
}

.nav a:hover::before,
.nav a.active::before {
    width: 100%;
}

.nav a:hover {
    color: white;
    transform: translateY(-2px);
}

/* ========================================
   SKILL TAGS ANIMATION
   ======================================== */

.devops-stack span,
.infra-stack span,
.developer-stack span {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.devops-stack span:hover,
.infra-stack span:hover,
.developer-stack span:hover {
    transform: translateY(-3px) scale(1.05);
    background: rgba(25, 184, 166, 0.2);
    border-color: rgba(25, 184, 166, 0.5);
    box-shadow: 0 8px 20px rgba(25, 184, 166, 0.3);
}

/* ========================================
   TIMELINE ENHANCEMENTS
   ======================================== */

.timeline-item {
    position: relative;
    transition: all 0.3s ease;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 3px;
    height: 0;
    background: linear-gradient(180deg, var(--teal), var(--amber));
    transition: height 0.6s ease;
}

.timeline-item:hover::before {
    height: 100%;
}

.timeline-item:hover {
    padding-left: 20px;
    background: rgba(25, 184, 166, 0.03);
}

/* ========================================
   METRIC COUNTERS ANIMATION
   ======================================== */

.metric-grid strong {
    display: inline-block;
    transition: all 0.3s ease;
}

.metric-grid article:hover strong {
    transform: scale(1.1);
    color: var(--teal);
}

/* ========================================
   CLIENT LOGOS EFFECTS
   ======================================== */

.client-logo-card {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.client-logo-card:hover {
    transform: translateY(-8px) scale(1.05);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.client-logo-card img {
    transition: all 0.3s ease;
    filter: grayscale(0%);
}

.client-logo-card:hover img {
    filter: grayscale(0%) brightness(1.1);
}

/* ========================================
   LOADING ANIMATION
   ======================================== */

.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(25, 184, 166, 0.1);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========================================
   SCROLL PROGRESS BAR
   ======================================== */

.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--teal), var(--blue), var(--amber));
    z-index: 9999;
    transition: width 0.1s ease;
}

/* ========================================
   PARTICLE BACKGROUND (Optional)
   ======================================== */

.particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(25, 184, 166, 0.3);
    border-radius: 50%;
    animation: particleFloat 20s infinite;
}

@keyframes particleFloat {
    0% {
        transform: translateY(100vh) translateX(0);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        transform: translateY(-100vh) translateX(100px);
        opacity: 0;
    }
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 960px) {

    .devops-card:hover,
    .project-card:hover,
    .webapp-card:hover {
        transform: translateY(-4px) scale(1.01);
    }
}

@media (max-width: 640px) {

    .hero-name,
    h2 {
        background: #f7f4ee;
        -webkit-text-fill-color: #f7f4ee;
    }

    .devops-card:hover,
    .project-card:hover {
        transform: none;
    }
}

/* ========================================
   CUSTOM CURSOR GLOW
   ======================================== */

.custom-cursor {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(25, 184, 166, 0.25) 0%, rgba(109, 169, 255, 0.08) 40%, transparent 70%);
    transform: translate(-25px, -25px);
    transition: width 0.4s ease, height 0.4s ease, background 0.4s ease;
    will-change: transform;
    mix-blend-mode: screen;
}

.custom-cursor.cursor-hover {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle at center, rgba(25, 184, 166, 0.15) 0%, rgba(109, 169, 255, 0.05) 40%, transparent 70%);
}

@media (max-width: 768px), (hover: none) {
    .custom-cursor {
        display: none;
    }
}

/* ========================================
   MAGNETIC HOVER
   ======================================== */

@media (hover: hover) {
    .primary-link,
    .secondary-link,
    .language-button,
    .download-button,
    button[data-pdf-lang] {
        transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1);
        will-change: transform;
    }
}

/* ========================================
   BACK TO TOP BUTTON
   ======================================== */

.back-to-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 100;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid rgba(25, 184, 166, 0.5);
    background: rgba(8, 11, 15, 0.88);
    backdrop-filter: blur(12px);
    color: var(--teal);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.2, 0, 0, 1), background 0.3s, border-color 0.3s;
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.back-to-top:hover {
    background: var(--teal);
    color: #071014;
    border-color: var(--teal);
    transform: translateY(-3px) scale(1.08);
    box-shadow: 0 8px 30px rgba(25, 184, 166, 0.35);
}

.back-to-top:active {
    transform: translateY(0) scale(0.95);
}

.back-to-top svg {
    display: block;
}

/* ========================================
   HAMBURGER MENU
   ======================================== */

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    padding: 8px;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.3s;
    z-index: 25;
}

.hamburger:hover {
    border-color: var(--teal);
}

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s, background 0.3s;
    transform-origin: center;
}

.hamburger.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
    background: var(--teal);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
    background: var(--teal);
}

/* Mobile Navigation Overlay */
@media (max-width: 960px) {
    .hamburger {
        display: flex;
    }

    .nav {
        position: fixed;
        top: 72px;
        left: 0;
        width: 100%;
        height: calc(100vh - 72px);
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 0;
        padding: 24px 24px 40px;
        background: rgba(8, 11, 15, 0.97);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        transform: translateX(100%);
        transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 24;
        overflow-y: auto;
    }

    .nav.nav-open {
        transform: translateX(0);
    }

    .nav a {
        display: block;
        width: 100%;
        padding: 16px 0;
        font-size: 1.25rem;
        font-weight: 800;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        opacity: 0;
        transform: translateX(20px);
        transition: opacity 0.4s ease, transform 0.4s ease;
    }

    .nav.nav-open a {
        opacity: 1;
        transform: translateX(0);
    }

    .nav.nav-open a:nth-child(1) { transition-delay: 0.05s; }
    .nav.nav-open a:nth-child(2) { transition-delay: 0.1s; }
    .nav.nav-open a:nth-child(3) { transition-delay: 0.15s; }
    .nav.nav-open a:nth-child(4) { transition-delay: 0.2s; }
    .nav.nav-open a:nth-child(5) { transition-delay: 0.25s; }
    .nav.nav-open a:nth-child(6) { transition-delay: 0.3s; }
    .nav.nav-open a:nth-child(7) { transition-delay: 0.35s; }

    body.menu-open {
        overflow: hidden;
    }
}

/* ========================================
   SCROLL INDICATOR
   ======================================== */

.scroll-indicator {
    position: absolute;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    opacity: 1;
    transition: opacity 0.6s ease;
    pointer-events: none;
}

.scroll-indicator.hidden {
    opacity: 0;
}

.scroll-text {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.35);
    font-weight: 800;
}

.scroll-icon {
    color: rgba(25, 184, 166, 0.6);
    animation: scrollBounce 2.4s ease-in-out infinite;
}

.scroll-dot {
    animation: scrollDot 2.4s ease-in-out infinite;
}

@keyframes scrollBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

@keyframes scrollDot {
    0%, 100% { opacity: 1; transform: translateY(0); }
    50% { opacity: 0.2; transform: translateY(8px); }
}

@media (max-width: 640px) {
    .scroll-indicator {
        display: none;
    }
}

/* ========================================
   ENHANCED STAGGER REVEAL
   ======================================== */

.animate-on-scroll {
    transition: opacity 0.7s cubic-bezier(0.2, 0, 0, 1),
                transform 0.7s cubic-bezier(0.2, 0, 0, 1) !important;
}

.devops-grid .animate-on-scroll,
.infra-grid .animate-on-scroll,
.alignment-grid .animate-on-scroll,
.expertise-grid .animate-on-scroll,
.project-grid .animate-on-scroll,
.developer-grid .animate-on-scroll,
.webapp-grid .animate-on-scroll {
    transform: translateY(40px) scale(0.97);
    opacity: 0;
}

.devops-grid .animate-on-scroll.animated,
.infra-grid .animate-on-scroll.animated,
.alignment-grid .animate-on-scroll.animated,
.expertise-grid .animate-on-scroll.animated,
.project-grid .animate-on-scroll.animated,
.developer-grid .animate-on-scroll.animated,
.webapp-grid .animate-on-scroll.animated {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ========================================
   COMPANY HOVER POPUP
   ======================================== */

.company-hover {
    position: relative;
    display: inline;
    cursor: help;
    text-decoration: none;
    background: linear-gradient(to right, rgba(25, 184, 166, 0.3), rgba(109, 169, 255, 0.3));
    background-size: 0 2px;
    background-repeat: no-repeat;
    background-position: left bottom;
    transition: background-size 0.3s ease, color 0.3s ease;
    border-radius: 2px;
    font-weight: 600;
}

.company-hover:hover {
    background-size: 100% 2px;
    color: #19b8a6;
}

.company-popup {
    position: fixed;
    z-index: 99999;
    width: 300px;
    background: #1a1f2e;
    border: 1px solid rgba(25, 184, 166, 0.25);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(25, 184, 166, 0.08);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.company-popup.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.company-popup .popup-logo {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.company-popup .popup-info strong {
    display: block;
    font-size: 0.85rem;
    color: #19b8a6;
    margin-bottom: 4px;
    line-height: 1.2;
}

.company-popup .popup-info p {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.5;
    color: #b0b8c8;
}

@media print {
    .company-hover {
        background: none !important;
        font-weight: inherit !important;
        color: inherit !important;
        text-decoration: none !important;
    }

    .company-popup {
        display: none !important;
    }
}

/* ========================================
   PRINT - DISABLE ANIMATIONS
   ======================================== */

@media print {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }

    .hero-name,
    h2 {
        background: none !important;
        -webkit-background-clip: unset !important;
        -webkit-text-fill-color: #101418 !important;
        background-clip: unset !important;
        color: #101418 !important;
    }
}