/* --- DESIGN SYSTEM & VARIABLES --- */
:root {
    --bg-main: #ffffff;
    --bg-secondary: #050505;
    --text-main: #09090b;
    --text-secondary: #52525b;
    --accent: #2563eb; /* Electric Blue */
    --border: #e4e4e7;
    --card-radius: 32px;
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
}

/* --- RESET & BASE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    /* Hide scrollbar completely for app-like feel */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

::-webkit-scrollbar {
    display: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    overflow-x: hidden;
    line-height: 1.6;
    /* Locked during intro */
    overflow: hidden;
    width: 100%;
    -webkit-font-smoothing: antialiased;
}

body.loaded {
    overflow-y: auto;
    overflow-x: hidden;
}

/* Global responsive media rules to prevent layout breaking */
img, picture, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

::selection {
    background-color: var(--text-main);
    color: var(--bg-main);
}

/* --- THREAD CURSOR CANVAS --- */
#thread-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
}

/* --- GRAIN OVERLAY --- */
.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9000;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* --- INTRO / PRELOADER --- */
#intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background-color: var(--bg-main);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 1s var(--ease-out-expo), visibility 1s;
}

#intro-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.stitch-container {
    position: relative;
    width: 80vw;
    max-width: 600px;
}

.stitch-text {
    font-family: var(--font-display);
    font-weight: 700;
    /* Adjusted clamp minimum for smaller mobile screens */
    font-size: clamp(2rem, 10vw, 6rem); 
    fill: none;
    stroke: var(--text-main);
    stroke-width: 2;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: stitch 2.5s var(--ease-out-expo) forwards;
}

.stitch-text.thread-effect {
    stroke: var(--accent);
    stroke-width: 1.5;
    stroke-dasharray: 4 4;
    stroke-dashoffset: 1000;
    opacity: 0.8;
    animation: stitch 2.5s var(--ease-out-expo) forwards, pulse-thread 2s infinite;
}

@keyframes stitch {
    to { stroke-dashoffset: 0; }
}

@keyframes pulse-thread {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* --- TYPOGRAPHY UTILS --- */
h1, h2, h3, h4, h5 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.display-text {
    /* Adjusted minimum value from 3.5rem to 2.5rem for ultra-small phones */
    font-size: clamp(2.5rem, 9vw, 8rem);
    line-height: 1.1;
    text-transform: uppercase;
    word-wrap: break-word;
}

.section-header {
    /* Adjusted for mobile */
    font-size: clamp(1.75rem, 5vw, 3.5rem);
    margin-bottom: 1.5rem;
    line-height: 1.1;
}

/* Reveal Animation Classes */
.reveal-text-wrap {
    overflow: hidden;
    display: block;
}

.reveal-text-content {
    display: block;
    transform: translateY(100%);
    transition: transform 1.2s var(--ease-out-expo);
}

.reveal-visible .reveal-text-content {
    transform: translateY(0);
}

.fade-up {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s var(--ease-out-expo);
}

.fade-up.is-in-view {
    opacity: 1;
    transform: translateY(0);
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 14px 28px;
    border-radius: 100px;
    font-family: var(--font-display);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.05em;
    transition: transform 0.2s linear, border-color 0.4s ease, color 0.4s ease;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    z-index: 1;
    border: none;
    cursor: pointer;
    will-change: transform;
    text-align: center;
}

.btn-black {
    background: var(--text-main);
    color: var(--bg-main);
    border: 1px solid var(--text-main);
}

.btn span {
    position: relative;
    z-index: 2;
}

.btn-black::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--accent);
    transform: translateY(100%);
    transition: transform 0.4s var(--ease-out-expo);
    z-index: 1;
}

/* Use hover media query so mobile taps don't get stuck in hover state */
@media (hover: hover) {
    .btn-black:hover::before {
        transform: translateY(0);
    }
    .btn-black:hover {
        color: white;
        border-color: var(--accent);
    }
}

/* --- NAVIGATION --- */
.navbar {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.05);
    opacity: 0;
    transform: translate(-50%, -30px);
    transition: opacity 1s 2.8s, transform 1.2s 2.8s var(--ease-out-expo);
    width: 90%;
    max-width: 1200px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem; /* Adjusted for nav content */
    border-radius: 100px; /* Optional: pill shape for desktop */
}

body.loaded .navbar {
    opacity: 1;
    transform: translate(-50%, 0);
}

.nav-links {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-link {
    position: relative;
    display: inline-block;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 500;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--text-main);
    transition: width 0.3s var(--ease-out-expo);
}

@media (hover: hover) {
    .nav-link:hover::after {
        width: 100%;
    }
}

/* Hamburger Menu Icon */
.hamburger {
    display: none;
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 5px;
    z-index: 100;
}

.hamburger .bar {
    display: block;
    width: 24px;
    height: 2px;
    margin: 5px auto;
    -webkit-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
    background-color: var(--text-main);
}

/* --- MARQUEE --- */
.marquee-container {
    mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
    -webkit-mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
    overflow: hidden;
    white-space: nowrap;
}

.marquee-content {
    display: inline-block;
    animation: marquee 30s linear infinite;
    will-change: transform;
}

@media (hover: hover) {
    .marquee-container:hover .marquee-content {
        animation-play-state: paused;
    }
}

@keyframes marquee {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.marquee-content1 {
    display: inline-block;
    animation: scroll 20s linear infinite;
    will-change: transform;
}

@keyframes scroll {
    0% { transform: translateX(0); }
    /* Shifts exactly 50% of the width, seamlessly matching up with the duplicated half */
    100% { transform: translateX(-50%); }
}

/* --- SERVICE CARDS (STICKY) --- */
.service-card {
    position: sticky;
    top: 100px;
    transform-origin: center top;
    transition: transform 0.3s ease;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.05);
    border-radius: var(--card-radius);
    overflow: hidden;
}

/* --- TESTIMONIALS --- */
.testimonial-card {
    transition: transform 0.3s ease, border-color 0.3s ease;
    border-radius: var(--card-radius);
}

@media (hover: hover) {
    .testimonial-card:hover {
        transform: translateY(-5px);
        border-color: var(--accent);
    }
}

/* --- MAP --- */
.map-wrapper {
    filter: grayscale(100%);
    transition: filter 0.5s ease;
    width: 100%;
}

@media (hover: hover) {
    .map-wrapper:hover {
        filter: grayscale(0%);
    }
}

/* --- INPUTS --- */
.styled-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid #d4d4d8;
    padding: 16px 0;
    outline: none;
    transition: border-color 0.3s;
    font-family: inherit;
    font-size: 1rem;
    color: inherit;
}

.styled-input:focus {
    border-color: var(--text-main);
}

/* --- BLOG CARDS --- */
.blog-card img {
    transition: transform 0.4s var(--ease-out-expo);
}

.blog-card h4 {
    transition: color 0.3s ease;
}

@media (hover: hover) {
    .blog-card:hover img {
        transform: scale(1.05);
    }
    .blog-card:hover h4 {
        color: var(--accent);
    }
}

/* --- ANIMATIONS & UTILS --- */
@keyframes scanline {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

.animate-scanline {
    animation: scanline 2.5s ease-in-out infinite;
}

/* Finom háttérháló (grid) effekt világos/fekete-fehér témához */
.bg-tech-grid {
    background-size: 30px 30px;
    background-image: 
        linear-gradient(to right, rgba(0, 0, 0, 0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
}

/* =========================================
   RESPONSIVE ADJUSTMENTS (TIERED SYSTEM)
   ========================================= */

/* --- TABLETS & SMALL DESKTOPS (Max 1024px) --- */
@media (max-width: 1024px) {
    .service-card {
        top: 90px;
    }
    
    .navbar {
        width: 95%;
    }
}

/* --- MOBILE DEVICES (Max 768px) --- */
@media (max-width: 768px) {
    #thread-canvas {
        display: none; /* Disable canvas on mobile to preserve performance and battery */
    }

    /* Hamburger Menu Logic */
    .hamburger {
        display: block;
    }

    /* Hamburger Animation */
    .hamburger.active .bar:nth-child(2) {
        opacity: 0;
    }
    .hamburger.active .bar:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    .hamburger.active .bar:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Mobile Nav Overlay */
    .nav-links {
        position: fixed;
        left: -100%;
        top: 70px; /* Offset to sit below navbar */
        gap: 0;
        flex-direction: column;
        background-color: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        width: 100%;
        text-align: center;
        transition: left 0.4s var(--ease-out-expo);
        box-shadow: 0 10px 27px rgba(0, 0, 0, 0.05);
        padding: 2rem 0;
        border-radius: 0 0 24px 24px;
        z-index: 90;
    }

    .nav-links.active {
        left: 0;
    }

    .nav-links .nav-link {
        margin: 16px 0;
        font-size: 1.25rem;
        display: block;
    }

    /* Cards stack higher to allow reading space */
    .service-card {
        top: 80px;
    }

    /* Compact Button sizes for touch interfaces */
    .btn {
        padding: 12px 24px;
        font-size: 12px;
    }
    
    /* Optimize the mask fade out space for smaller screens */
    .marquee-container {
        mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
        -webkit-mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
    }
}

/* --- SMALL MOBILE & PHONES (Max 480px) --- */
@media (max-width: 480px) {
    .service-card {
        top: 70px;
    }
    
    /* Make buttons span full width to maximize tap target sizes */
    .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .navbar {
        width: 100%;
        border-radius: 0;
    }
    
    .nav-links {
        top: 60px; /* Adjust dropdown top offset for smaller squared navbar */
    }
}

/* --- LANDSCAPE MOBILE FIXES --- */
@media (max-height: 500px) and (orientation: landscape) {
    .service-card {
        top: 20px; /* Don't eat up the entire vertical space on short screens */
    }
    
    #intro-overlay {
        min-height: 100vh; 
    }
    
    .nav-links {
        padding: 1rem 0;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        overflow-y: auto;
        max-height: calc(100vh - 60px);
    }
    
    .nav-links .nav-link {
        margin: 8px 16px;
    }
}