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

:root {
    /* Light Theme */
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8edf4;
    --bg-input: #fafbfc;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --border-focus: #6366f1;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --success-color: #10b981;
    --success-bg: #ecfdf5;
    --danger-color: #ef4444;
    --danger-bg: #fef2f2;
    --warning-color: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
    --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f26;
    --bg-tertiary: #252b33;
    --bg-input: #0f1419;
    --text-primary: #f0f4f8;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #2d3748;
    --border-focus: #818cf8;
    --primary-color: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: #1e1b4b;
    --success-color: #34d399;
    --success-bg: #064e3b;
    --danger-color: #f87171;
    --danger-bg: #7f1d1d;
    --warning-color: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--transition), color var(--transition);
}

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition), border-color var(--transition);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 36px;
    height: 36px;
    color: var(--primary-color);
    transition: color var(--transition);
}

.title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    transition: color var(--transition);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    position: relative;
    overflow: hidden;
}

.theme-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-color);
    opacity: 0;
    transition: opacity var(--transition);
}

.theme-toggle:hover {
    color: var(--primary-color);
    transform: scale(1.05);
}

.theme-toggle:hover::before {
    opacity: 0.1;
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    position: relative;
    z-index: 1;
}

[data-theme="light"] .moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* Input Section */
.input-section {
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: color var(--transition);
}

.section-title svg {
    width: 20px;
    height: 20px;
    color: var(--primary-color);
}

.input-actions {
    display: flex;
    gap: 0.5rem;
}

/* Text Area */
.text-area {
    width: 100%;
    min-height: 250px;
    max-height: 50vh;
    padding: 1.25rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    resize: vertical;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.text-area:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12), var(--shadow-sm);
}

.text-area::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

.input-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
    padding-right: 0.25rem;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', monospace;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-family: inherit;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* File Label */
.file-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.file-label:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.file-label svg {
    width: 16px;
    height: 16px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border-color);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card:hover::before {
    background: var(--primary-color);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.words-icon {
    background: #ede9fe;
    color: #7c3aed;
}

.chars-icon {
    background: #dbeafe;
    color: #2563eb;
}

.space-chars-icon {
    background: #fef3c7;
    color: #d97706;
}

.sentences-icon {
    background: #dcfce7;
    color: #16a34a;
}

.paragraphs-icon {
    background: #fce7f3;
    color: #db2777;
}

.time-icon {
    background: #e0e7ff;
    color: #4f46e5;
}

[data-theme="dark"] .words-icon {
    background: rgba(124, 58, 237, 0.15);
}

[data-theme="dark"] .chars-icon {
    background: rgba(37, 99, 235, 0.15);
}

[data-theme="dark"] .space-chars-icon {
    background: rgba(217, 119, 6, 0.15);
}

[data-theme="dark"] .sentences-icon {
    background: rgba(22, 163, 74, 0.15);
}

[data-theme="dark"] .paragraphs-icon {
    background: rgba(219, 39, 119, 0.15);
}

[data-theme="dark"] .time-icon {
    background: rgba(79, 70, 229, 0.15);
}

.stat-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    transition: color var(--transition);
}

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

.highlight-card {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg-secondary) 100%);
    border-color: var(--primary-color);
}

.highlight-card::before {
    background: var(--primary-color);
}

.highlight-card .stat-value {
    color: var(--primary-color);
}

/* Averages Section */
.averages-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.average-stat {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    text-align: center;
    transition: var(--transition);
}

.average-stat:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.average-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: color var(--transition);
}

.average-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
}

/* Frequency Section */
.frequency-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    transition: var(--transition);
}

.frequency-section .section-header {
    margin-bottom: 1rem;
}

.frequency-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.frequency-item {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    text-align: center;
    transition: var(--transition);
}

.frequency-item:hover {
    background: var(--primary-light);
    transform: scale(1.02);
}

.frequency-word {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.frequency-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', monospace;
}

.frequency-bar {
    height: 3px;
    background: var(--primary-color);
    border-radius: 2px;
    margin-top: 0.5rem;
    transition: width 0.5s ease;
}

/* Drop Overlay */
.drop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 20, 25, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.drop-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.drop-content {
    background: var(--bg-secondary);
    padding: 2.5rem 3.5rem;
    border-radius: var(--radius-xl);
    text-align: center;
    box-shadow: var(--shadow-xl);
    transform: scale(0.9) translateY(10px);
    transition: transform 0.2s ease;
    border: 2px dashed var(--border-color);
}

.drop-overlay.active .drop-content {
    transform: scale(1) translateY(0);
}

.drop-content svg {
    width: 64px;
    height: 64px;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.drop-content h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.drop-content p {
    color: var(--text-muted);
}

/* Footer */
.footer {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    transition: var(--transition);
}

.footer p {
    max-width: 600px;
    margin: 0 auto;
}

/* Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card {
    animation: fadeInUp 0.4s ease forwards;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }
.stat-card:nth-child(5) { animation-delay: 0.25s; }
.stat-card:nth-child(6) { animation-delay: 0.3s; }

/* Scrollbar */
.text-area::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.text-area::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 5px;
}

.text-area::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 5px;
    border: 2px solid var(--bg-tertiary);
}

.text-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Text Selection */
.text-area ::selection {
    background: var(--primary-color);
    color: white;
}

/* Focus Visible */
.btn:focus-visible,
.file-label:focus-visible,
.theme-toggle:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Responsive */
@media (max-width: 1024px) {
    .averages-section {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .header-content {
        padding: 0;
    }
    
    .main-content {
        padding: 1rem 0.75rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .input-actions {
        width: 100%;
    }
    
    .input-actions .btn,
    .input-actions .file-label {
        flex: 1;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .stat-icon {
        width: 38px;
        height: 38px;
    }
    
    .stat-icon svg {
        width: 18px;
        height: 18px;
    }
    
    .stat-value {
        font-size: 1.4rem;
    }
    
    .averages-section {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .frequency-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .text-area {
        min-height: 200px;
        font-size: 0.9rem;
        padding: 1rem;
    }
    
    .title {
        font-size: 1.1rem;
    }
    
    .logo-icon {
        width: 28px;
        height: 28px;
    }
    
    .drop-content {
        padding: 2rem;
        margin: 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .frequency-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .logo-section {
        gap: 0.5rem;
    }
    
    .logo-icon {
        width: 24px;
        height: 24px;
    }
    
    .title {
        font-size: 0.95rem;
    }
    
    .theme-toggle {
        width: 42px;
        height: 42px;
    }
    
    .theme-toggle svg {
        width: 20px;
        height: 20px;
    }
}

/* Utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
