/* ============================================================
   4-Function Calculator — Full Website Design System
   Glassmorphism aesthetic with CSS custom properties
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --bg-dark: #06060e;
    --bg-section: #0a0a16;
    --bg-section-alt: #0c0c1a;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --glass: rgba(18, 18, 36, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-strong: rgba(255, 255, 255, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #8888a4;
    --text-muted: #555570;

    /* Accent palette */
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.35);
    --accent-light: #a29bfe;
    --accent-2: #e17055;
    --accent-3: #00cec9;

    /* Gradients */
    --gradient-main: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 50%, #e17055 100%);
    --gradient-hero: linear-gradient(160deg, #6c5ce7 0%, #e17055 100%);
    --gradient-text: linear-gradient(135deg, #a29bfe 0%, #e17055 50%, #00cec9 100%);

    /* Operator button */
    --op-bg: rgba(108, 92, 231, 0.14);
    --op-hover: rgba(108, 92, 231, 0.25);
    --op-text: #a29bfe;

    /* Equals button */
    --eq-gradient: linear-gradient(160deg, #6c5ce7 0%, #e17055 100%);
    --eq-glow: rgba(108, 92, 231, 0.4);

    /* Function button */
    --func-bg: rgba(255, 255, 255, 0.07);
    --func-hover: rgba(255, 255, 255, 0.13);
    --func-text: #c0c0d0;

    /* Number button */
    --num-bg: rgba(255, 255, 255, 0.045);
    --num-hover: rgba(255, 255, 255, 0.1);
    --num-text: #e8e8f0;

    /* Orb colors */
    --orb-1: #6c5ce7;
    --orb-2: #e17055;
    --orb-3: #00cec9;
    --orb-4: #a29bfe;

    /* Sizing */
    --radius: 18px;
    --radius-sm: 14px;
    --radius-xs: 10px;
    --radius-lg: 24px;
    --btn-gap: 8px;

    /* Typography */
    --font-ui: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    /* Layout */
    --section-padding: 100px 0;
    --container-max: 1100px;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
    line-height: 1.6;
}

/* ---- Animated Background Orbs ---- */
.bg-orbs {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.3;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 450px;
    height: 450px;
    background: var(--orb-1);
    top: -15%;
    left: -10%;
}

.orb-2 {
    width: 380px;
    height: 380px;
    background: var(--orb-2);
    bottom: -12%;
    right: -12%;
    animation-delay: -7s;
    animation-duration: 25s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: var(--orb-3);
    top: 55%;
    left: 55%;
    animation-delay: -14s;
    animation-duration: 22s;
}

.orb-4 {
    width: 200px;
    height: 200px;
    background: var(--orb-4);
    top: 30%;
    right: 20%;
    animation-delay: -10s;
    animation-duration: 28s;
    opacity: 0.2;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25%      { transform: translate(35px, -25px) scale(1.04); }
    50%      { transform: translate(-15px, 35px) scale(0.96); }
    75%      { transform: translate(25px, 15px) scale(1.02); }
}

/* ---- Utility: Gradient text ---- */
.gradient-text {
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================================
   NAVIGATION
   ============================================================ */
.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0 24px;
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    background: rgba(6, 6, 14, 0.7);
    border-bottom: 1px solid var(--glass-border);
    transition: all 0.3s ease;
}

.site-nav.scrolled {
    background: rgba(6, 6, 14, 0.92);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

.nav-container {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
    transition: opacity 0.2s;
}

.nav-brand:hover { opacity: 0.85; }

.nav-brand-icon {
    font-size: 22px;
    color: var(--accent-light);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.nav-brand-text {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    z-index: 101;
}

.nav-hamburger span {
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.nav-hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-hamburger.active span:nth-child(2) { opacity: 0; }
.nav-hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

.nav-links {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-xs);
    transition: all 0.2s ease;
    position: relative;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 20px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
    transition: transform 0.25s ease;
}

.nav-link:hover::after {
    transform: translateX(-50%) scaleX(1);
}

/* ============================================================
   HERO SECTION
   ============================================================ */
.hero {
    position: relative;
    z-index: 1;
    padding: 80px 24px 4px;
    text-align: center;
}

.hero-content {
    max-width: 720px;
    animation: heroFadeIn 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.hero-title {
    font-size: clamp(24px, 4.5vw, 40px);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
    animation: heroFadeIn 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}

.hero-subtitle {
    font-size: clamp(16px, 2.2vw, 19px);
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 600px;
    margin: 0 auto 36px;
    animation: heroFadeIn 1s cubic-bezier(0.22, 1, 0.36, 1) 0.45s both;
}

.hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 48px;
    animation: heroFadeIn 1s cubic-bezier(0.22, 1, 0.36, 1) 0.6s both;
}

.btn-hero-primary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-ui);
    color: #fff;
    background: var(--gradient-hero);
    border: none;
    border-radius: 50px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 24px var(--accent-glow), 0 0 60px rgba(108, 92, 231, 0.15);
}

.btn-hero-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px var(--accent-glow), 0 0 80px rgba(108, 92, 231, 0.2);
    filter: brightness(1.1);
}

.btn-hero-primary:active {
    transform: translateY(0) scale(0.98);
}

.btn-hero-secondary {
    display: inline-flex;
    align-items: center;
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-ui);
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 50px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-hero-secondary:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
    border-color: var(--glass-border-strong);
    transform: translateY(-2px);
}

.hero-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    animation: heroFadeIn 1s cubic-bezier(0.22, 1, 0.36, 1) 0.75s both;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-number {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-divider {
    width: 1px;
    height: 36px;
    background: var(--glass-border);
}

/* ============================================================
   SECTION SHARED STYLES
   ============================================================ */
.section-container {
    position: relative;
    z-index: 1;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 24px;
}

.section-header {
    text-align: center;
    margin-bottom: 60px;
}

.section-tag {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--accent-light);
    background: var(--op-bg);
    border: 1px solid rgba(108, 92, 231, 0.12);
    padding: 6px 18px;
    border-radius: 50px;
    margin-bottom: 18px;
}

.section-title {
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
    margin-bottom: 14px;
}

.section-desc {
    font-size: clamp(15px, 1.8vw, 17px);
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ============================================================
   CALCULATOR SECTION
   ============================================================ */
.calculator-section {
    position: relative;
    z-index: 1;
    padding: 4px 24px 40px;
}

.calc-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ---- Calculator Shell ---- */
.calculator {
    width: 100%;
    max-width: 420px;
    height: clamp(400px, 60vh, 540px);
    max-height: calc(100dvh - 130px);
    background: var(--glass);
    backdrop-filter: blur(40px) saturate(1.5);
    -webkit-backdrop-filter: blur(40px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow:
        0 4px 30px rgba(0, 0, 0, 0.45),
        0 0 80px rgba(108, 92, 231, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    animation: calcAppear 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
    display: flex;
    flex-direction: column;
    position: relative;
}

@keyframes calcAppear {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Keyboard Hint ---- */
.keyboard-hint {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    max-width: 440px;
    width: 100%;
    transition: all 0.2s;
}

.keyboard-hint:hover {
    border-color: var(--glass-border-strong);
    background: var(--surface-hover);
}

.hint-icon {
    color: var(--accent-light);
    flex-shrink: 0;
    opacity: 0.7;
}

.hint-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hint-text strong {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
}

.hint-text span {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Header ---- */
.calc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 4px;
    flex-shrink: 0;
}

.calc-brand {
    display: flex;
    align-items: center;
    gap: 7px;
}

.brand-icon {
    font-size: 16px;
    color: var(--accent-light);
}

.brand-text {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.brand-badge {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent-light);
    background: var(--op-bg);
    padding: 3px 8px;
    border-radius: 16px;
}

/* ---- Display Area ---- */
.display-area {
    padding: 12px 18px 8px;
    text-align: right;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    flex-shrink: 0;
    min-height: 100px;
    position: relative;
}

.memory-indicator {
    position: absolute;
    top: 8px;
    left: 18px;
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-light);
    letter-spacing: 0.5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.memory-indicator.visible {
    opacity: 1;
}

.expression-line {
    font-family: var(--font-mono);
    font-size: 38px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.2;
    word-break: break-all;
    transition: font-size 0.2s ease;
    min-height: 46px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.expression-line.shrink {
    font-size: 28px;
}

.expression-line.shrink-more {
    font-size: 21px;
}

.result-line {
    font-family: var(--font-mono);
    font-size: 15px;
    color: var(--text-muted);
    margin-top: 4px;
    min-height: 20px;
    transition: all 0.25s ease;
}

.result-line.highlight {
    color: var(--accent-light);
    font-size: 16px;
}

/* ---- Buttons Area ---- */
.buttons-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--btn-gap);
    padding: 6px 12px 12px;
    min-height: 0;
}

/* ---- Memory Row ---- */
.memory-row {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.mem-btn {
    flex: 1;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 0;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.3px;
}

.mem-btn:hover {
    background: var(--surface-hover);
    color: var(--text-secondary);
}

.mem-btn:active {
    transform: scale(0.96);
}

/* ---- Button Rows ---- */
.btn-row {
    display: flex;
    gap: var(--btn-gap);
    flex: 1;
    min-height: 0;
}

/* ---- Buttons ---- */
.btn {
    flex: 1;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 0;
}

/* Ripple */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%), rgba(255,255,255,0.18) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.btn.ripple::after {
    opacity: 1;
    animation: rippleFade 0.5s ease forwards;
}

@keyframes rippleFade {
    from { opacity: 1; transform: scale(0.8); }
    to   { opacity: 0; transform: scale(1.2); }
}

/* Number buttons */
.btn-num {
    background: var(--num-bg);
    color: var(--num-text);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.btn-num:hover {
    background: var(--num-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-num:active {
    transform: translateY(0) scale(0.97);
    box-shadow: none;
}

/* Function buttons */
.btn-func {
    background: var(--func-bg);
    color: var(--func-text);
    font-family: var(--font-ui);
    font-size: 16px;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.btn-func:hover {
    background: var(--func-hover);
    transform: translateY(-1px);
}

.btn-func:active {
    transform: translateY(0) scale(0.97);
}

#clearBtn {
    color: #e17055;
}

#clearBtn:hover {
    background: rgba(225, 112, 85, 0.12);
    color: #ff7675;
}

/* Operator buttons */
.btn-op {
    background: var(--op-bg);
    color: var(--op-text);
    border: 1px solid rgba(108, 92, 231, 0.1);
    font-size: 22px;
}

.btn-op:hover {
    background: var(--op-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.12);
}

.btn-op:active {
    transform: translateY(0) scale(0.97);
    box-shadow: none;
}

.btn-op.active-op {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 18px var(--accent-glow);
}

/* Equals button */
.btn-equals {
    background: var(--eq-gradient);
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    border: none;
    box-shadow: 0 4px 18px var(--eq-glow);
    grid-area: eq;
}

/* Bottom grid */
.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    grid-template-areas:
        "n1 n2 n3 eq"
        "n0 n0 dot eq";
    gap: var(--btn-gap);
    flex: 2;
    min-height: 0;
}

.bottom-grid .btn-num[data-value="1"] { grid-area: n1; }
.bottom-grid .btn-num[data-value="2"] { grid-area: n2; }
.bottom-grid .btn-num[data-value="3"] { grid-area: n3; }
.bottom-grid .btn-num[data-value="0"] { grid-area: n0; }
.bottom-grid .btn-num[data-value="."] { grid-area: dot; }

.btn-equals:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--eq-glow);
    filter: brightness(1.1);
}

.btn-equals:active {
    transform: translateY(0) scale(0.97);
    box-shadow: 0 2px 8px var(--eq-glow);
}

/* Zero button */
.btn-zero {
    font-size: 20px;
}

/* ---- History Overlay ---- */
.history-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.history-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.history-panel {
    width: 88%;
    max-height: 70%;
    background: rgba(22, 22, 44, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.history-overlay.open .history-panel {
    transform: translateY(0) scale(1);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.history-close-btn {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.history-close-btn:hover {
    color: #e17055;
    background: rgba(225, 112, 85, 0.1);
}

.history-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 0 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.history-list li {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-list li:hover:not(.history-empty) {
    color: var(--text-primary);
}

.history-list li:last-child {
    border-bottom: none;
}

.history-empty {
    cursor: default !important;
    font-style: italic;
    font-family: var(--font-ui) !important;
    font-size: 12px !important;
    color: var(--text-muted) !important;
    justify-content: center !important;
    padding: 24px 0 !important;
}

.hist-expr {
    color: var(--text-muted);
    font-size: 12px;
}

.hist-result {
    color: var(--accent-light);
    font-weight: 500;
}

.history-clear-all {
    background: none;
    border: none;
    border-top: 1px solid var(--glass-border);
    color: #e17055;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    padding: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-clear-all:hover {
    background: rgba(225, 112, 85, 0.08);
}

/* Scrollbar */
.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 3px; }

/* Error State */
.display-area.error .expression-line {
    color: #e17055;
    animation: errorShake 0.4s ease;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-8px); }
    40%      { transform: translateX(8px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

/* ============================================================
   FEATURES SECTION
   ============================================================ */
.features-section {
    position: relative;
    z-index: 1;
    padding: var(--section-padding);
    background: var(--bg-section-alt);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.feature-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 32px 28px;
    transition: all 0.35s ease;
    position: relative;
    overflow: hidden;
}

.feature-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-main);
    opacity: 0;
    transition: opacity 0.35s ease;
}

.feature-card:hover {
    border-color: var(--glass-border-strong);
    background: var(--surface-hover);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

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

.feature-icon-wrap {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--op-bg);
    border: 1px solid rgba(108, 92, 231, 0.12);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    color: var(--accent-light);
    transition: all 0.35s ease;
}

.feature-card:hover .feature-icon-wrap {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 20px var(--accent-glow);
    border-color: transparent;
}

.feature-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.feature-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* ============================================================
   HOW TO USE SECTION
   ============================================================ */
.howto-section {
    position: relative;
    z-index: 1;
    padding: var(--section-padding);
    background: var(--bg-section);
}

.steps-grid {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.step-card {
    flex: 1;
    min-width: 220px;
    max-width: 300px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 36px 28px;
    text-align: center;
    transition: all 0.35s ease;
}

.step-card:hover {
    border-color: var(--glass-border-strong);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.step-number {
    font-size: 48px;
    font-weight: 900;
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    margin-bottom: 16px;
}

.step-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.step-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.step-connector {
    color: var(--text-muted);
    opacity: 0.4;
    flex-shrink: 0;
}

/* ============================================================
   FAQ SECTION
   ============================================================ */
.faq-section {
    position: relative;
    z-index: 1;
    padding: var(--section-padding);
    background: var(--bg-section-alt);
}

.faq-list {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.faq-item {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: all 0.3s ease;
}

.faq-item:hover {
    border-color: var(--glass-border-strong);
}

.faq-item[open] {
    border-color: rgba(108, 92, 231, 0.2);
    background: var(--surface-hover);
}

.faq-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    list-style: none;
    transition: color 0.2s;
}

.faq-question::-webkit-details-marker { display: none; }

.faq-question:hover {
    color: var(--accent-light);
}

.faq-toggle {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.3s ease, color 0.2s;
}

.faq-item[open] .faq-toggle {
    transform: rotate(45deg);
    color: var(--accent-light);
}

.faq-answer {
    padding: 0 24px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.8;
    animation: faqOpen 0.3s ease;
}

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

.faq-answer ul {
    margin: 10px 0;
    padding-left: 20px;
}

.faq-answer li {
    margin-bottom: 6px;
}

.faq-answer strong {
    color: var(--text-primary);
}

/* ============================================================
   CTA SECTION
   ============================================================ */
.cta-section {
    position: relative;
    z-index: 1;
    padding: 80px 0;
    background: var(--bg-section);
}

.cta-card {
    text-align: center;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.1) 0%, rgba(225, 112, 85, 0.08) 100%);
    border: 1px solid rgba(108, 92, 231, 0.15);
    border-radius: var(--radius-lg);
    padding: 60px 40px;
    position: relative;
    overflow: hidden;
}

.cta-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-main);
}

.cta-title {
    font-size: clamp(28px, 4vw, 40px);
    font-weight: 800;
    margin-bottom: 14px;
}

.cta-desc {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.cta-btn {
    display: inline-flex;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--glass-border);
    background: rgba(6, 6, 14, 0.9);
    padding: 48px 24px 32px;
}

.footer-container {
    max-width: var(--container-max);
    margin: 0 auto;
    text-align: center;
}

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.footer-tagline {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 28px;
}

.footer-links a {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent-light);
}

.footer-bottom {
    border-top: 1px solid var(--glass-border);
    padding-top: 20px;
}

.footer-bottom p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   SCROLL-BASED ANIMATIONS (Intersection Observer)
   ============================================================ */
.feature-card,
.step-card,
.faq-item,
.keyboard-hint,
.cta-card {
    opacity: 0;
    transform: translateY(24px);
}

.feature-card.visible,
.step-card.visible,
.faq-item.visible,
.keyboard-hint.visible,
.cta-card.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Stagger animation delays for feature cards */
.feature-card:nth-child(1).visible { transition-delay: 0s; }
.feature-card:nth-child(2).visible { transition-delay: 0.08s; }
.feature-card:nth-child(3).visible { transition-delay: 0.16s; }
.feature-card:nth-child(4).visible { transition-delay: 0.24s; }
.feature-card:nth-child(5).visible { transition-delay: 0.32s; }
.feature-card:nth-child(6).visible { transition-delay: 0.4s; }

.step-card:nth-child(1).visible { transition-delay: 0s; }
.step-card:nth-child(3).visible { transition-delay: 0.12s; }
.step-card:nth-child(5).visible { transition-delay: 0.24s; }

.faq-item:nth-child(1).visible { transition-delay: 0s; }
.faq-item:nth-child(2).visible { transition-delay: 0.06s; }
.faq-item:nth-child(3).visible { transition-delay: 0.12s; }
.faq-item:nth-child(4).visible { transition-delay: 0.18s; }
.faq-item:nth-child(5).visible { transition-delay: 0.24s; }
.faq-item:nth-child(6).visible { transition-delay: 0.3s; }

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

/* Mobile: < 768px */
@media (max-width: 768px) {
    :root {
        --section-padding: 64px 0;
    }

    .nav-hamburger {
        display: flex;
    }

    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: rgba(10, 10, 20, 0.97);
        backdrop-filter: blur(20px);
        flex-direction: column;
        align-items: flex-start;
        padding: 80px 32px 32px;
        gap: 8px;
        transition: right 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        border-left: 1px solid var(--glass-border);
        z-index: 100;
    }

    .nav-links.open {
        right: 0;
    }

    .nav-link {
        font-size: 16px;
        width: 100%;
        padding: 12px 16px;
    }

    .features-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .steps-grid {
        flex-direction: column;
        gap: 12px;
    }

    .step-connector {
        display: none;
    }

    .step-card {
        max-width: 100%;
    }

    .hero-stats {
        gap: 20px;
    }

    .stat-number {
        font-size: 20px;
    }

    .cta-card {
        padding: 40px 24px;
    }

    .hero {
        padding: 72px 12px 2px;
    }

    .hero-title {
        font-size: 20px;
    }

    .calculator-section {
        padding: 0 10px 16px;
    }

    .calculator {
        height: min(460px, calc(100dvh - 120px));
        max-height: calc(100dvh - 120px);
    }

    .keyboard-hint {
        display: none;
    }
}

/* Small phones */
@media (max-width: 420px) {
    .hero {
        padding: 68px 8px 0px;
    }

    .hero-title {
        font-size: 18px;
    }

    .calculator {
        border-radius: var(--radius-sm);
        height: min(430px, calc(100dvh - 110px));
        max-height: calc(100dvh - 110px);
    }

    .display-area {
        padding: 4px 10px 2px;
        min-height: 58px;
    }

    .expression-line {
        font-size: 26px;
    }

    .buttons-area {
        gap: 4px;
        padding: 3px 6px 6px;
    }

    .btn {
        border-radius: 8px;
        font-size: 16px;
    }
}

/* Tablets */
@media (min-width: 768px) and (max-width: 1024px) {
    .features-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop enhancements */
@media (min-width: 768px) {
    .btn {
        font-size: 20px;
        border-radius: var(--radius-sm);
    }

    .btn-func {
        font-size: 16px;
    }

    .expression-line {
        font-size: 38px;
    }

    .btn:hover {
        transform: translateY(-2px);
    }
}

@media (min-width: 1200px) {
    .calculator {
        max-width: 440px;
        height: clamp(420px, 62vh, 560px);
        max-height: calc(100vh - 140px);
    }
}

/* ---- Accessibility ---- */
.btn:focus-visible,
.icon-btn:focus-visible,
.mem-btn:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 2px;
}

a:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 3px;
    border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    html { scroll-behavior: auto; }

    .feature-card,
    .step-card,
    .faq-item,
    .keyboard-hint,
    .cta-card {
        opacity: 1;
        transform: none;
    }
}
