/* ===== CSS Variables & Reset ===== */
:root {
    /* Colors - Excel Green Theme */
    --primary-500: #217346;
    --primary-600: #2d9f5e;
    --primary-700: #3fb878;
    --secondary-500: #2d9f5e;
    --secondary-600: #3fb878;

    --success-500: #2d9f5e;
    --success-600: #3fb878;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    --spacing-3xl: 4rem;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-family);
    background: #0e1117;
    color: #e8eaed;
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* ===== Background Effects ===== */
.background-gradient {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0e1117 0%, #1a1d24 50%, #0e1117 100%);
    z-index: -2;
}

.grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(rgba(33, 150, 83, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(33, 150, 83, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    z-index: -1;
    animation: gridMove 20s linear infinite;
}

.grid-overlay::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(33, 150, 83, 0.08) 0%, transparent 70%);
    animation: rotate 30s linear infinite;
}

@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes gridMove {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(50px, 50px);
    }
}

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

/* ===== Header ===== */
.header {
    padding: var(--spacing-md) 0;
    position: relative;
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: white;
    letter-spacing: -0.02em;
}

.logo h1 span {
    background: linear-gradient(135deg, #2d9f5e, #3fb878);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-stats {
    display: flex;
    gap: var(--spacing-xl);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-500), var(--secondary-500));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-400);
    font-weight: 500;
}

/* ===== Main Content ===== */
.main {
    padding: var(--spacing-2xl) 0 var(--spacing-3xl);
}

/* ===== Hero Section ===== */
.hero {
    text-align: center;
    margin-bottom: var(--spacing-3xl);
    animation: fadeInUp 0.6s ease-out;
}

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

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

.hero-title {
    font-size: 3rem;
    font-weight: 800;
    color: white;
    margin-bottom: var(--spacing-md);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--gray-400);
    max-width: 600px;
    margin: 0 auto;
    font-weight: 400;
}

/* ===== Input Section ===== */
.input-section {
    margin-bottom: var(--spacing-3xl);
    animation: fadeInUp 0.6s ease-out 0.1s backwards;
}

.input-card {
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(33, 150, 83, 0.2);
    border-radius: var(--radius-2xl);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-2xl);
    transition: all var(--transition-slow);
}

.input-card:hover {
    border-color: rgba(33, 150, 83, 0.4);
    box-shadow: 0 25px 50px -12px rgba(33, 115, 70, 0.25);
}

.input-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-300);
    margin-bottom: var(--spacing-md);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-label svg {
    color: var(--primary-500);
}

.input-textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(33, 150, 83, 0.2);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    color: white;
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    transition: all var(--transition-base);
    min-height: 120px;
}

.input-textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(33, 150, 83, 0.1);
}

.input-textarea::placeholder {
    color: var(--gray-500);
}

.input-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: var(--font-family);
    position: relative;
    overflow: hidden;
}

.btn::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;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, #217346, #2d9f5e);
    color: white;
    box-shadow: 0 4px 16px rgba(33, 115, 70, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(33, 115, 70, 0.6);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gray-300);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-copy {
    background: rgba(33, 150, 83, 0.1);
    color: var(--success-500);
    border: 1px solid rgba(45, 159, 94, 0.3);
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
}

.btn-copy:hover {
    background: rgba(33, 150, 83, 0.2);
    border-color: var(--success-500);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== Popular Section ===== */
.popular-section {
    margin-bottom: var(--spacing-3xl);
    animation: fadeInUp 0.6s ease-out 0.2s backwards;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: var(--spacing-xl);
    text-align: center;
}

.popular-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--spacing-lg);
}

.popular-card {
    background: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(33, 150, 83, 0.15);
    border-radius: var(--radius-xl);
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    cursor: pointer;
    transition: all var(--transition-base);
    text-align: left;
}

.popular-card:hover {
    background: rgba(17, 24, 39, 0.6);
    border-color: var(--primary-500);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(33, 115, 70, 0.2);
}

.popular-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary-600), var(--secondary-600));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.popular-content h4 {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    margin-bottom: 0.25rem;
}

.popular-content p {
    font-size: 0.875rem;
    color: var(--gray-400);
}

/* ===== Result Section ===== */
.result-section {
    animation: fadeInUp 0.6s ease-out;
}

.result-card {
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(45, 159, 94, 0.3);
    border-radius: var(--radius-2xl);
    padding: var(--spacing-xl);
    box-shadow: 0 25px 50px -12px rgba(33, 115, 70, 0.2);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.result-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success-500);
}

.formula-display {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(45, 159, 94, 0.3);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
    position: relative;
    overflow-x: auto;
}

.formula-display code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 1.125rem;
    color: var(--success-500);
    font-weight: 600;
    display: block;
    white-space: pre-wrap;
    word-break: break-all;
}

.explanation-section {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

.explanation-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-300);
    margin-bottom: var(--spacing-md);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.explanation-text {
    color: var(--gray-300);
    line-height: 1.8;
    font-size: 0.9375rem;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(33, 150, 83, 0.2);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--spacing-lg);
}

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

.loading-spinner p {
    color: var(--gray-300);
    font-size: 1rem;
    font-weight: 500;
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    background: linear-gradient(135deg, var(--success-600), var(--success-500));
    color: white;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    transform: translateY(150%);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--transition-slow), opacity var(--transition-slow);
    z-index: 2000;
    visibility: hidden;
}

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

/* ===== Responsive Design ===== */

/* Tablet and iPad (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .container {
        padding: 0 var(--spacing-lg);
    }

    .hero-title {
        font-size: 2.5rem;
    }

    .popular-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .header-content {
        gap: var(--spacing-md);
    }
}

/* Mobile (768px and below) */
@media (max-width: 768px) {
    .container {
        padding: 0 var(--spacing-md);
    }

    .hero-title {
        font-size: 2.25rem;
        line-height: 1.2;
    }

    .hero-subtitle {
        font-size: 1.125rem;
        padding: 0 var(--spacing-md);
    }

    .popular-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .input-actions {
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .input-actions .btn {
        width: 100%;
    }

    .btn {
        padding: 1rem 1.5rem;
        /* Larger touch targets */
        font-size: 1.0625rem;
        min-height: 48px;
    }

    .btn-primary {
        width: 100%;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .result-header .btn-copy {
        width: 100%;
    }

    .header-stats {
        width: 100%;
        justify-content: space-around;
    }

    .stat {
        align-items: center;
    }

    .header-content {
        flex-wrap: wrap;
        gap: var(--spacing-md);
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .logo svg {
        width: 28px;
        height: 28px;
    }

    .input-card,
    .result-card {
        padding: var(--spacing-lg);
    }

    .popular-card {
        padding: var(--spacing-md);
    }

    .formula-display {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .formula-display code {
        word-break: break-all;
        white-space: pre-wrap;
    }
}

@media (max-width: 480px) {
    :root {
        /* Adjust spacing for mobile */
        --spacing-xl: 1.5rem;
        --spacing-2xl: 2rem;
        --spacing-3xl: 2.5rem;
    }

    .container {
        padding: 0 var(--spacing-md);
    }

    .main {
        padding: var(--spacing-xl) 0 var(--spacing-2xl);
    }

    .hero {
        margin-bottom: var(--spacing-2xl);
    }

    .hero-title {
        font-size: 1.875rem;
        line-height: 1.15;
        margin-bottom: var(--spacing-sm);
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .header-content {
        flex-wrap: nowrap;
        gap: var(--spacing-sm);
    }

    .logo {
        flex-shrink: 0;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .logo svg {
        width: 24px;
        height: 24px;
    }

    .input-card,
    .result-card {
        padding: var(--spacing-md);
        border-radius: var(--radius-xl);
    }

    .input-textarea {
        font-size: 1rem;
        padding: var(--spacing-md);
        min-height: 100px;
    }

    .input-section {
        margin-bottom: var(--spacing-2xl);
    }

    .popular-section {
        margin-bottom: var(--spacing-2xl);
    }

    .btn {
        padding: 0.9375rem 1.25rem;
        font-size: 1rem;
        min-height: 48px;
        /* Better touch target */
    }

    .popular-card {
        padding: var(--spacing-md);
        gap: var(--spacing-sm);
    }

    .popular-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .popular-content h4 {
        font-size: 0.9375rem;
    }

    .popular-content p {
        font-size: 0.8125rem;
    }

    .formula-display {
        padding: var(--spacing-md);
        font-size: 0.9375rem;
    }

    .formula-display code {
        font-size: 0.9375rem;
        line-height: 1.5;
    }

    .explanation-section {
        padding: var(--spacing-md);
    }

    .explanation-title {
        font-size: 1rem;
    }

    .explanation-text {
        font-size: 0.9375rem;
        line-height: 1.6;
    }

    .toast {
        bottom: var(--spacing-md);
        right: var(--spacing-md);
        left: var(--spacing-md);
        font-size: 0.9375rem;
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.8125rem;
    }
}

/* ===== Extra Small Devices ===== */
@media (max-width: 360px) {
    .container {
        padding: 0 var(--spacing-sm);
    }

    .hero-title {
        font-size: 1.625rem;
        line-height: 1.1;
    }

    .hero-subtitle {
        font-size: 0.9375rem;
    }

    .logo h1 {
        font-size: 1.125rem;
    }

    .logo svg {
        width: 20px;
        height: 20px;
    }

    .input-card,
    .result-card {
        padding: var(--spacing-sm);
    }

    .btn {
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
        min-height: 44px;
    }

    .formula-display code {
        font-size: 0.875rem;
    }

    .popular-card {
        padding: var(--spacing-sm);
    }

    .popular-icon {
        width: 36px;
        height: 36px;
        font-size: 1.125rem;
    }
}