:root {
    --bg: #f6f8fc;
    --surface: #ffffff;
    --surface-muted: #eef3ff;
    --text: #152238;
    --muted: #4d607b;
    --primary: #3b82f6;
    --primary-contrast: #ffffff;
    --border: #d7e0f0;
}

html[data-theme="dark"] {
    --bg: #0f1628;
    --surface: #16213a;
    --surface-muted: #1c2a47;
    --text: #e9eefc;
    --muted: #b6c3df;
    --primary: #60a5fa;
    --primary-contrast: #0b1220;
    --border: #28395f;
}

* { box-sizing: border-box; }
html, body {
    height: 100%;
}
body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}
main {
    flex: 1;
}

.container { width: min(1100px, 92%); margin: 0 auto; }
.narrow { width: min(780px, 92%); }

.site-header, .site-footer {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.site-header { position: sticky; top: 0; z-index: 20; }
.site-footer {
    border-top: 1px solid var(--border);
    border-bottom: none;
    padding: 1.5rem 0;
    margin-top: auto;
    background: var(--surface);
}
.site-footer p {
    margin: 0;
    text-align: center;
    font-weight: 500;
}
.nav-wrap { display: flex; align-items: center; justify-content: flex-start; gap: 1.5rem; min-height: 70px; position: relative; width: 100%; }
.brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.2rem;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0;
    border: none;
    background: transparent;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.brand:hover {
    transform: translateY(-1px);
}
.brand-logo {
    display: block;
    width: auto;
    height: 92px;
    max-width: 220px;
    object-fit: contain;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}
.brand-text {
    font-weight: 800;
    letter-spacing: 0.2px;
}
.nav {
    display: flex;
    gap: 0.2rem;
    flex: 1;
    justify-content: center;
    flex-wrap: nowrap;
    padding: 0 1rem;
}
.nav a {
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    padding: 0.3rem 0;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
    white-space: nowrap;
    flex: 1;
    text-align: center;
}
.nav a:hover {
    color: var(--primary);
}
.nav a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.menu-toggle {
    display: none;
    border: none;
    background: transparent;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 25;
}

.menu-icon {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    position: relative;
    transition: background 0.2s ease;
}

.menu-icon::before,
.menu-icon::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: var(--text);
    left: 0;
    transition: transform 0.3s ease, top 0.3s ease;
}

.menu-icon::before {
    top: -7px;
}

.menu-icon::after {
    top: 7px;
}

.menu-toggle.active .menu-icon {
    background: transparent;
}

.menu-toggle.active .menu-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.menu-toggle.active .menu-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

.header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.account-menu-wrap {
    position: relative;
}

.account-toggle {
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    font-size: 1.25rem;
}

.account-menu {
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    width: min(260px, 86vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.45rem;
    display: grid;
    gap: 0.2rem;
    z-index: 40;
}

.account-menu[hidden] {
    display: none;
}

.account-header {
    display: grid;
    gap: 0.1rem;
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.2rem;
}

.account-name {
    font-weight: 700;
    color: var(--text);
}

.account-email {
    font-size: 0.84rem;
    color: var(--muted);
    word-break: break-word;
}

.account-menu a,
.account-signout-btn {
    text-decoration: none;
    color: var(--text);
    background: transparent;
    border: 0;
    width: 100%;
    text-align: left;
    border-radius: 0.5rem;
    padding: 0.5rem 0.6rem;
    font-size: 0.95rem;
    cursor: pointer;
}

.account-menu a:hover,
.account-signout-btn:hover {
    background: var(--surface-muted);
}

.account-signout-form {
    margin: 0;
}

.hero { padding: 4rem 0 2.5rem; }
.hero-home {
    background: linear-gradient(180deg, var(--surface-muted) 0%, var(--bg) 75%);
}
.hero-grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 1.5rem;
    align-items: center;
}
.hero-kicker {
    display: inline-block;
    margin-bottom: 0.8rem;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary);
}
.hero-visual {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 170px 170px;
    gap: 0.75rem;
}
.hero-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
    transition: transform 0.35s ease, filter 0.35s ease;
}
.hero-visual img:first-child {
    grid-column: 1 / 3;
}
.hero-visual img:hover {
    transform: translateY(-3px) scale(1.01);
    filter: saturate(1.08);
}
.hero-stats {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 0.7rem;
}
.stat-card h3 {
    margin: 0;
    color: var(--primary);
    font-size: 1.4rem;
}
.stat-card p {
    margin: 0.2rem 0 0;
    font-size: 0.9rem;
}
.section { padding: 3rem 0; }
.muted { background: var(--surface-muted); }

h1, h2, h3 { line-height: 1.2; margin-top: 0; }
p { color: var(--muted); }

.grid { display: grid; gap: 1rem; }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards-1 { grid-template-columns: 1fr; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    padding: 1rem;
    transition: border-color 0.2s ease, transform 0.2s ease;
}
.card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.tab-controls {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.tab-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 0.55rem 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.tab-btn.active {
    background: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}
.tab-panel {
    animation: fadeIn 0.35s ease;
}
.panel-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1rem;
    align-items: stretch;
}
.panel-grid img {
    width: 100%;
    height: 100%;
    min-height: 250px;
    object-fit: cover;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.reveal-ready {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.55s ease, transform 0.55s ease;
}

.reveal-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .reveal-ready,
    .reveal-visible {
        opacity: 1;
        transform: none;
        transition: none;
    }
}

.cta-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }
.btn {
    display: inline-block;
    border-radius: 0.7rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible,
.nav a:focus-visible,
.menu-toggle:focus-visible,
.account-toggle:focus-visible,
.account-menu a:focus-visible,
.account-signout-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.steps { display: grid; gap: 1rem; }
.step {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 0.9rem;
    align-items: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    padding: 1rem;
}
.step span {
    width: 48px;
    height: 48px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: var(--primary-contrast);
    font-weight: 700;
}
.step-points {
    margin: 0.45rem 0 0;
    padding-left: 1rem;
    color: var(--muted);
}
.step-points li {
    margin-bottom: 0.25rem;
}

.how-hero-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.how-visual img {
    width: 100%;
    min-height: 260px;
    object-fit: cover;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
}
.how-highlights {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.8rem;
}
.highlight-chip {
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 600;
}
.how-benefits {
    margin-top: 1.1rem;
}

.features-hero-grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 1.1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.features-visual img {
    width: 100%;
    min-height: 250px;
    object-fit: cover;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
}
.feature-card {
    position: relative;
    padding-top: 1.2rem;
}
.feature-icon {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    margin-bottom: 0.6rem;
    font-size: 1.1rem;
}

.chat-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; align-items: start; }
.chat-panel { display: grid; gap: 1rem; }
.chat-response {
    min-height: 280px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 0.9rem;
    padding: 1rem;
    overflow-y: auto;
}
.assistant-msg, .user-msg {
    margin: 0 0 0.75rem;
    padding: 0.75rem;
    border-radius: 0.6rem;
}
.user-msg { background: var(--surface-muted); }
.assistant-msg { background: var(--surface); border: 1px solid var(--border); }

.chat-form textarea,
.contact-form input,
.contact-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 0.7rem;
    padding: 0.75rem;
    margin: 0.4rem 0 1rem;
}
.api-note { font-size: 0.92rem; }

.contact-form { display: grid; }
.contact-layout {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 1rem;
    align-items: start;
}
.contact-side {
    display: grid;
    gap: 1rem;
}
.social { margin-top: 1rem; }
.resources-list { margin: 0; padding-left: 1rem; }
.resources-list li { margin-bottom: 0.35rem; }
.resources-list a { color: var(--primary); text-decoration: none; }
.resources-list a:hover { text-decoration: underline; }
.library-list li { display: flex; align-items: center; gap: 0.4rem; }
.download-links { margin-bottom: 1rem; }
.flash-wrap {
    padding-top: 1rem;
}
.flash {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 0.7rem;
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.6rem;
}
.flash.error {
    border-color: #ef4444;
}
.flash.success {
    border-color: #22c55e;
}

.auth-card {
    max-width: 620px;
    margin: 0 auto;
}
.auth-form {
    display: grid;
    gap: 0.35rem;
}
.auth-form input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 0.7rem;
    padding: 0.75rem;
    margin: 0.2rem 0 0.6rem;
}

.inline-form {
    display: inline;
    margin: 0;
    padding: 0;
}
.btn-nav {
    padding: 0.35rem 0.65rem;
    font-size: 0.9rem;
}
.nav-user {
    color: var(--muted);
    font-weight: 600;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 920px) {
    .cards-3, .cards-2, .chat-layout, .hero-grid, .panel-grid, .contact-layout { grid-template-columns: 1fr; }
    .hero-visual { grid-template-rows: 180px 140px; }
    .hero-stats { grid-template-columns: 1fr; }
    .how-hero-grid { grid-template-columns: 1fr; }
    .features-hero-grid { grid-template-columns: 1fr; }
    .nav {
        gap: 1rem;
    }
    .nav a {
        flex: 1;
        font-size: 0.95rem;
    }
}

@media (max-width: 760px) {
    .nav-wrap {
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    .brand-logo { height: 50px; max-width: 140px; }
    
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        order: 3;
        margin-left: auto;
    }
    
    .nav {
        display: none;
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: 1.5rem;
        flex-direction: column;
        justify-content: flex-start;
        gap: 0.5rem;
        overflow-y: auto;
        z-index: 30;
    }
    .nav a {
        text-align: left;
        flex: none;
        padding: 0.75rem 1rem;
        font-size: 1.1rem;
        border-radius: 0.5rem;
        border-bottom: none;
    }
    .nav a:hover,
    .nav a.active {
        background: var(--surface-muted);
        border-bottom: none;
    }
    .nav.open { display: flex; }
    
    .header-actions {
        gap: 0.45rem;
        order: 2;
    }
    
    .hero { padding: 2rem 0 1.5rem; }
    .hero h1 { font-size: 1.75rem; }
    .hero-visual {
        grid-template-columns: 1fr;
        grid-template-rows: 200px;
    }
    .hero-visual img:first-child {
        grid-column: 1;
    }
    .hero-visual img:not(:first-child) {
        display: none;
    }
    
    .section { padding: 2rem 0; }
    
    .chat-layout {
        grid-template-columns: 1fr;
    }
    .chat-panel {
        order: 2;
    }
    .chat-response {
        min-height: 200px;
        order: 1;
    }
    .chat-form textarea {
        min-height: 100px;
    }
    
    .step {
        grid-template-columns: 40px 1fr;
        gap: 0.7rem;
        padding: 0.85rem;
    }
    .step span {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }
    
    .btn {
        padding: 0.85rem 1.1rem;
        font-size: 1rem;
        width: 100%;
        text-align: center;
    }
    .cta-row {
        flex-direction: column;
    }
    
    .tab-controls {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }
    .tab-btn {
        flex-shrink: 0;
        padding: 0.6rem 1rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    .auth-card {
        padding: 1rem;
    }
    .auth-form input {
        padding: 0.9rem;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .contact-form input,
    .contact-form textarea,
    .chat-form textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.9rem;
    }
    
    h1 { font-size: 1.6rem; }
    h2 { font-size: 1.35rem; }
    h3 { font-size: 1.15rem; }
    
    .account-menu {
        position: fixed;
        top: 70px;
        right: 0.5rem;
        left: 0.5rem;
        width: auto;
        max-height: calc(100vh - 90px);
        overflow-y: auto;
    }
}

@media (max-width: 480px) {
    .container { width: 95%; }
    .brand-logo { height: 42px; max-width: 120px; }
    
    .hero h1 { font-size: 1.5rem; }
    .hero-stats {
        gap: 0.5rem;
    }
    .stat-card {
        padding: 0.6rem;
    }
    .stat-card h3 {
        font-size: 1.2rem;
    }
    .stat-card p {
        font-size: 0.85rem;
    }
    
    .highlight-chip {
        font-size: 0.8rem;
        padding: 0.3rem 0.55rem;
    }
    
    .feature-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .nav a {
        font-size: 1rem;
        padding: 0.65rem 0.85rem;
    }
}

/* Touch-friendly and mobile optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets for touch devices */
    .btn {
        min-height: 44px;
    }
    .nav a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    .tab-btn {
        min-height: 44px;
    }
    .account-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    .menu-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    /* Remove hover effects on touch */
    .card:hover {
        transform: none;
    }
    .btn:hover {
        transform: none;
    }
    .hero-visual img:hover {
        transform: none;
        filter: none;
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    .site-header {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    .site-footer {
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    @media (max-width: 760px) {
        .nav {
            padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        }
    }
}
