/* ============================================
   CLARITY EMERGENCE - "Thrives in the Gray"
   Focus effect: blur + desaturation → sharp clarity
   ============================================ */

:root {
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.1);
    --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
}

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

.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: transparent;
    z-index: 100;
    pointer-events: none;
    /* iOS fixes */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.scroll-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #2563EB, #60A5FA);
    transform-origin: left;
    transform: scaleX(var(--scroll-progress, 0));
    transition: transform 0.1s linear;
}

.dark .scroll-progress::after {
    background: linear-gradient(90deg, #60A5FA, #93C5FD);
}

@media (prefers-reduced-motion: reduce) {
    .scroll-progress::after {
        transition: none;
    }
}

html {
    background-color: #FFFFFF;
    overflow-x: hidden;
    /* Prevent horizontal scroll on iOS when keyboard appears */
    position: relative;
    width: 100%;
}

.dark html {
    background-color: #000000;
}

/* ============================================
   FOCUS EMERGENCE
   Page starts soft/gray, comes into sharp clarity
   ============================================ */

body {
    background-color: #FFFFFF;
    overflow-x: hidden;
    /* Prevent horizontal scroll on iOS */
    position: relative;
    width: 100%;
    min-height: 100%;
}

.dark body {
    background-color: #000000;
}

/* ============================================
   HEADLINE WORD-BY-WORD EMERGENCE
   ============================================ */

.headline-word {
    display: inline;
    color: #9CA3AF; /* Start as muted gray - visible but unclear */
    transition: color 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.headline-word.emerged {
    color: #000000;
}

.dark .headline-word {
    color: #6B7280;
}

.dark .headline-word.emerged {
    color: #FFFFFF;
}

/* Special treatment for "the gray" - stays gray with shimmer */
.headline-word.the-gray {
    position: relative;
}

.headline-word.the-gray.emerged {
    color: #6B7280 !important; /* Stays gray */
    background: linear-gradient(
        90deg,
        #6B7280 0%,
        #9CA3AF 25%,
        #6B7280 50%,
        #4B5563 75%,
        #6B7280 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 8s ease-in-out infinite;
}

.dark .headline-word.the-gray.emerged {
    background: linear-gradient(
        90deg,
        #9CA3AF 0%,
        #D1D5DB 25%,
        #9CA3AF 50%,
        #6B7280 75%,
        #9CA3AF 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ============================================
   STAGGERED CONTENT EMERGENCE
   ============================================ */

/* Start visible by default - JS will add .animated class to enable transitions */
.emerge {
    opacity: 1;
    transform: translateY(0);
}

/* Only animate when JS has loaded and added the setup class */
.js-ready .emerge {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.js-ready .emerge.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Delay classes for staggered animation */
.emerge-delay-1 { transition-delay: 0.1s; }
.emerge-delay-2 { transition-delay: 0.3s; }
.emerge-delay-3 { transition-delay: 0.5s; }
.emerge-delay-4 { transition-delay: 0.7s; }
.emerge-delay-5 { transition-delay: 0.9s; }
.emerge-delay-6 { transition-delay: 1.1s; }

/* ============================================
   STATUS INDICATOR
   ============================================ */

/* Visible by default, animated only when JS ready */
.status-indicator {
    opacity: 1;
    transform: translateX(0);
}

.js-ready .status-indicator {
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.js-ready .status-indicator.visible {
    opacity: 1;
    transform: translateX(0);
}

.status-dot {
    animation: pulse-gray 2s ease-in-out infinite;
}

@keyframes pulse-gray {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(107, 114, 128, 0.4);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 8px rgba(107, 114, 128, 0);
    }
}

/* ============================================
   MICRO-INTERACTIONS
   ============================================ */

/* Name sparkle - subtle periodic color shift */
.name-sparkle {
    background: linear-gradient(
        90deg,
        #6B7280 0%,
        #6B7280 40%,
        #000000 50%,
        #01AAFF 60%,
        #0071D6 70%,
        #000000 80%,
        #6B7280 100%
    );
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: nameSparkle 8s ease-in-out infinite;
    animation-delay: 2s; /* Wait for clarity effect to complete */
}

@keyframes nameSparkle {
    0% { background-position: 0% 50%; }
    /* First sparkle ~1s after animation starts (12.5% of 8s) */
    10%, 18% { background-position: 100% 50%; }
    28%, 85% { background-position: 0% 50%; }
    /* Second sparkle near end of cycle */
    90%, 95% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.dark .name-sparkle {
    background: linear-gradient(
        90deg,
        #9CA3AF 0%,
        #9CA3AF 40%,
        #FFFFFF 50%,
        #01AAFF 60%,
        #0071D6 70%,
        #FFFFFF 80%,
        #9CA3AF 100%
    );
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
}

/* Tag hover effects */
.tag {
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
    cursor: default;
}

.tag:hover {
    background-color: #E5E7EB;
    color: #374151;
    transform: translateY(-1px);
}

.dark .tag:hover {
    background-color: #1F2937;
    color: #D1D5DB;
}

/* ============================================
   PROJECT ICON SPARKLE
   Shimmer effect on hover matching name-sparkle
   ============================================ */

.project-icon {
    transition: transform 0.3s ease, background 0.3s ease;
}

.project-icon svg {
    stroke: #6B7280;
    transition: stroke 0.4s ease, filter 0.4s ease;
}

/* On card hover, icon does the sparkle then settles */
.project-card:hover .project-icon svg {
    stroke: #01AAFF;
    filter: brightness(1.1);
    animation: iconSparkle 4s ease-in-out;
    animation-fill-mode: forwards;
}

/* Icon container glow on hover */
.project-card:hover .project-icon {
    background: linear-gradient(
        135deg,
        rgba(1, 170, 255, 0.15) 0%,
        rgba(0, 113, 214, 0.1) 50%,
        rgba(107, 114, 128, 0.05) 100%
    );
    transform: scale(1.05);
}

.dark .project-card:hover .project-icon {
    background: linear-gradient(
        135deg,
        rgba(1, 170, 255, 0.2) 0%,
        rgba(0, 113, 214, 0.15) 50%,
        rgba(107, 114, 128, 0.1) 100%
    );
}

@keyframes iconSparkle {
    0% { 
        stroke: #6B7280;
        filter: brightness(1);
    }
    20% { 
        stroke: #01AAFF;
        filter: brightness(1.2);
    }
    40% { 
        stroke: #0071D6;
        filter: brightness(1.3);
    }
    60% { 
        stroke: #01AAFF;
        filter: brightness(1.2);
    }
    80%, 100% { 
        stroke: #01AAFF;
        filter: brightness(1.1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .project-card:hover .project-icon svg {
        animation: none;
        stroke: #01AAFF;
    }
}

/* ============================================
   FEATURED CARD
   ============================================ */

.featured-card {
    position: relative;
    overflow: hidden;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}

/* Color swoosh background - matches article imagery */
.featured-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        ellipse 120% 80% at 100% 100%,
        rgba(180, 230, 220, 0.4) 0%,
        rgba(148, 217, 209, 0.25) 30%,
        rgba(126, 204, 200, 0.1) 60%,
        transparent 80%
    );
    opacity: 0;
    transform: scale(0.8) translateX(20%);
    transform-origin: bottom right;
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
    z-index: 0;
    border-radius: inherit;
}

.featured-card:hover::before {
    opacity: 1;
    transform: scale(1) translateX(0);
}

/* Ensure content stays above the swoosh */
.featured-card > * {
    position: relative;
    z-index: 1;
}

.featured-card:hover {
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}

.dark .featured-card::before {
    background: radial-gradient(
        ellipse 120% 80% at 100% 100%,
        rgba(126, 204, 200, 0.2) 0%,
        rgba(94, 178, 170, 0.12) 30%,
        rgba(70, 150, 145, 0.05) 60%,
        transparent 80%
    );
}

.dark .featured-card:hover {
    box-shadow: 0 4px 20px rgba(96, 165, 250, 0.1);
}

@media (prefers-reduced-motion: reduce) {
    .featured-card::before {
        transition: opacity 0.2s ease;
        transform: scale(1) translateX(0);
    }
}

/* ============================================
   PROJECT CARD BORDER REVEAL
   ============================================ */

.project-card {
    position: relative;
    overflow: hidden;
}

.project-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, transparent 0%, transparent 50%, #2563EB 100%);
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.project-card:hover::before {
    opacity: 1;
}

.dark .project-card::before {
    background: linear-gradient(135deg, transparent 0%, transparent 50%, #60A5FA 100%);
}

@media (prefers-reduced-motion: reduce) {
    .project-card::before {
        transition: none;
    }
}

/* Social link brand colors */
.social-linkedin {
    transition: color 0.2s ease;
}

.social-linkedin:hover {
    color: #0A66C2 !important;
}

.social-linkedin:hover svg {
    stroke: #0A66C2;
}

/* LinkedIn bordered button variant */
.social-linkedin-btn:hover {
    color: #0A66C2;
    border-color: #0A66C2;
}

.social-linkedin-btn:hover svg {
    stroke: #0A66C2;
}

.social-x {
    transition: color 0.2s ease;
}

.social-x:hover {
    color: #000000 !important;
}

.social-x:hover svg {
    fill: #000000;
    stroke: none;
}

.dark .social-x:hover {
    color: #FFFFFF !important;
}

.dark .social-x:hover svg {
    fill: #FFFFFF;
}

.social-github {
    transition: color 0.2s ease;
}

.social-github:hover {
    color: #8250DF !important;
}

.social-github:hover svg {
    stroke: #8250DF;
}

/* ============================================
   GENERAL STYLES
   ============================================ */

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #9CA3AF;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #6B7280;
}
.dark ::-webkit-scrollbar-thumb {
    background: #4B5563;
}

/* Selection */
::selection {
    background-color: #6B7280;
    color: white;
}

/* Theme toggle icons */
.dark .icon-moon { display: none; }
.dark .icon-sun { display: block; }
.icon-sun { display: none; }

/* Hover line animation */
.hover-line {
    position: relative;
}
.hover-line::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: #6B7280;
    transition: width 0.3s ease;
}
.hover-line:hover::after {
    width: 100%;
}

/* Inline body links */
.body-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: #9CA3AF;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: text-decoration-color 0.2s ease, color 0.2s ease;
}

.body-link:hover {
    color: #000000;
    text-decoration-color: #2563EB;
}

.dark .body-link:hover {
    color: #FFFFFF;
    text-decoration-color: #2563EB;
}

/* Button hover states - gray accent with spring feedback */
.btn-primary {
    background-color: #000000;
    transition: background-color 0.2s ease, transform 0.15s ease;
}
.btn-primary:hover {
    background-color: #374151;
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: scale(0.97);
}
.btn-primary:not(:active) {
    transition: background-color 0.2s ease, transform 0.35s var(--ease-spring);
}
.dark .btn-primary {
    background-color: #FFFFFF;
    color: #000000;
}
.dark .btn-primary:hover {
    background-color: #D1D5DB;
}

/* Sections - no animation, always visible */
.section-emerge {
    opacity: 1;
    transform: none;
}

/* ============================================
   CHAT INTERFACE
   ============================================ */

.chat-container {
    max-width: 600px;
    width: 100%;
    overflow-x: hidden;
}

.chat-messages {
    margin-bottom: 16px;
    padding: 4px 0;
}

.chat-message {
    margin-bottom: 16px;
    animation: chatFadeIn 0.3s ease-out;
}

@keyframes chatFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.assistant {
    padding-right: 48px;
}

.chat-message.assistant .chat-bubble {
    max-width: calc(100% - 48px);
}

.chat-message.user {
    padding-left: 48px;
    text-align: right;
}

.chat-message.user .chat-bubble {
    max-width: calc(100% - 48px);
}

.chat-bubble {
    display: inline-block;
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 100%;
    text-align: left;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.assistant .chat-bubble {
    background: linear-gradient(
        135deg,
        #F3F4F6 0%,
        #E5E7EB 25%,
        #F9FAFB 50%,
        #E5E7EB 75%,
        #F3F4F6 100%
    );
    background-size: 400% 400%;
    animation: chatShimmer 8s ease-in-out infinite;
    color: #1F2937;
    border-bottom-left-radius: 4px;
}

@keyframes chatShimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.dark .chat-message.assistant .chat-bubble {
    background: linear-gradient(
        135deg,
        #1F2937 0%,
        #374151 25%,
        #1F2937 50%,
        #2D3748 75%,
        #1F2937 100%
    );
    background-size: 400% 400%;
    animation: chatShimmer 8s ease-in-out infinite;
    color: #E5E7EB;
}

@media (prefers-reduced-motion: reduce) {
    .chat-message.assistant .chat-bubble {
        animation: none;
        background: #F3F4F6;
    }
    .dark .chat-message.assistant .chat-bubble {
        animation: none;
        background: #1F2937;
    }
}

.chat-message.user .chat-bubble {
    background-color: #0071D6;
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.dark .chat-message.user .chat-bubble {
    background-color: #0071D6;
    color: #FFFFFF;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background-color: #F3F4F6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.dark .chat-typing {
    background-color: #1F2937;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #9CA3AF;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Input form */
.chat-input-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    font-size: 16px; /* Must be 16px+ to prevent iOS auto-zoom on focus */
    font-family: inherit;
    background: transparent;
    color: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input:focus {
    outline: none;
    border-color: #6B7280;
    box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.1);
}

.dark .chat-input {
    border-color: #374151;
}

.dark .chat-input:focus {
    border-color: #9CA3AF;
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.1);
}

.chat-input::placeholder {
    color: #9CA3AF;
}

.chat-new {
    padding: 12px;
    background-color: transparent;
    color: #9CA3AF;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    /* iOS touch fixes */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
}

.chat-new:hover {
    background-color: #F3F4F6;
    border-color: #9CA3AF;
    color: #6B7280;
}

.chat-new:active {
    transform: scale(0.97);
}
.chat-new:not(:active) {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.35s var(--ease-spring);
}

.dark .chat-new {
    border-color: #374151;
}

.dark .chat-new:hover {
    background-color: #1F2937;
    border-color: #6B7280;
    color: #D1D5DB;
}

.chat-submit {
    padding: 12px;
    background-color: #000000;
    color: #FFFFFF;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-submit:hover {
    background-color: #374151;
}

.chat-submit:active {
    transform: scale(0.97);
}
.chat-submit:not(:active) {
    transition: background-color 0.2s ease, transform 0.35s var(--ease-spring);
}

.chat-submit:disabled {
    background-color: #9CA3AF;
    cursor: not-allowed;
}

.dark .chat-submit {
    background-color: #FFFFFF;
    color: #000000;
}

.dark .chat-submit:hover {
    background-color: #E5E7EB;
}

.chat-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 12px;
    color: #9CA3AF;
    font-family: 'JetBrains Mono', monospace;
}

.chat-footer-icon {
    display: flex;
    align-items: center;
}

/* Conversation complete state */
.chat-complete {
    padding: 16px;
    background-color: #F0FDF4;
    border: 1px solid #BBF7D0;
    border-radius: 12px;
    margin-top: 16px;
}

.dark .chat-complete {
    background-color: #052E16;
    border-color: #166534;
}

.chat-complete-text {
    font-size: 14px;
    color: #166534;
}

.dark .chat-complete-text {
    color: #86EFAC;
}

/* ============================================
   BOTTOM-OF-PAGE CONFETTI
   Gray celebration when reaching the end
   ============================================ */

.confetti-container {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 200px;
    height: 200px;
    pointer-events: none;
    overflow: hidden;
    z-index: 50;
    /* iOS fixes */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.confetti-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #9CA3AF;
    border-radius: 2px;
    opacity: 0;
    animation: confettiFall 2s ease-out forwards;
}

.confetti-particle:nth-child(odd) {
    background: #6B7280;
    border-radius: 50%;
}

.confetti-particle:nth-child(3n) {
    background: #D1D5DB;
    width: 6px;
    height: 6px;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(150px) rotate(720deg) scale(0.5);
    }
}

@media (prefers-reduced-motion: reduce) {
    .confetti-particle {
        animation: none;
        display: none;
    }
}
