:root {
    --primary: #4361ee;
    --primary-dark: #3f37c9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-100: #f8fafc;
    --gray-200: #e2e8f0;
    --gray-600: #475569;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 16px;
    --shadow: 0 20px 40px rgba(0,0,0,0.12);
}

[data-theme="dark"] {
    --gray-100: #0f172a;
    --gray-200: #1e293b;
    --gray-600: #94a3b8;
    --gray-800: #e2e8f0;
    --gray-900: #f8fafc;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    padding: 12px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 1000px;
    margin: 16px auto;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

[data-theme="dark"] .container { background: var(--gray-900); }

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 16px;
    text-align: center;
}

.header h1 { font-size: 1.8rem; font-weight: 800; margin: 0; }
.header p { font-size: 1rem; opacity: 0.95; margin-top: 6px; }

.body { padding: 20px 16px; }

.toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.btn {
    padding: 14px 16px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.25s ease;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }

.btn:hover, .btn:active { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.2); }
.btn:active { transform: translateY(0); }

.textarea {
    width: 100%;
    min-height: 240px;
    padding: 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 17px;
    resize: vertical;
    background: white;
    color: var(--gray-900);
    margin-bottom: 16px;
}

[data-theme="dark"] .textarea { background: var(--gray-800); border-color: var(--gray-700); color: white; }

.textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(67,97,238,0.2); }

.progress-container {
    height: 12px;
    background: var(--gray-200);
    border-radius: 6px;
    overflow: hidden;
    margin: 16px 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    width: 0%;
    transition: width 0.6s ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 20px 0;
}

@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .stats-grid { grid-template-columns: repeat(5, 1fr); } }

.stat {
    background: var(--gray-100);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid var(--gray-200);
}

[data-theme="dark"] .stat { background: var(--gray-800); }

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    margin: 6px 0;
}

.stat-label { font-size: 0.85rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.5px; }

.tabs {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    margin: 20px 0;
    padding-bottom: 8px;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 12px 20px;
    background: var(--gray-200);
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab.active {
    background: var(--primary);
    color: white;
}

.tab-content { display: none; padding: 20px; background: var(--gray-100); border-radius: var(--radius); }
.tab-content.active { display: block; }

#wordCloud { height: 280px; background: var(--gray-100); border-radius: var(--radius); margin-top: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid var(--gray-200); }
th { background: var(--primary); color: white; font-size: 13px; }

.switch { position: relative; display: inline-block; width: 52px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(24px); }

.voice-pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(67,97,238,0.7); } 70% { box-shadow: 0 0 0 10px rgba(67,97,238,0); } 100% { box-shadow: 0 0 0 0 rgba(67,97,238,0); } }

#findText, #replaceText, #seoKeyword, #wordGoal {
    width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--gray-300); font-size: 16px; margin: 8px 0;
}

.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85);
    z-index: 9999; justify-content: center; align-items: center; padding: 20px;
}

.modal-content {
    background: white; padding: 24px; border-radius: 16px; max-width: 500px; width: 100%;
}

[data-theme="dark"] .modal-content { background: #1e293b; color: white; }

.char-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    font-size: 1.8rem;
    text-align: center;
}

.char-grid span {
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    background: var(--gray-100);
    transition: 0.2s;
}

.char-grid span:hover {
    background: var(--primary);
    color: white;
}