:root {
    --primary-color: #3498db;
    --primary-dark: #2980b9;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --text-muted: #7f8c8d;
    --border-color: #e5e7eb;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 6px 12px rgba(0, 0, 0, 0.15);
    --radius: 10px;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 20px;
}

.benford-container {
    max-width: 1100px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 2.2rem;
    color: #2c3e50;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.math {
    font-family: 'Times New Roman', Times, serif;
    font-style: italic;
    background: #eee;
    padding: 2px 5px;
    border-radius: 4px;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 8px 8px 0;
    box-shadow: var(--shadow);
    margin-bottom: 0;
}

.tab-btn {
    padding: 10px 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    color: var(--primary-color);
    background: rgba(52, 152, 219, 0.05);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: rgba(52, 152, 219, 0.08);
    font-weight: 600;
}

/* Tab Panels */
.tab-panel {
    display: none;
    background: var(--card-bg);
    padding: 24px;
    box-shadow: var(--shadow);
    border-radius: 0 0 var(--radius) var(--radius);
    margin-bottom: 20px;
}

.tab-panel.active {
    display: block;
}

/* Controls Row */
.controls-row {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    flex-wrap: wrap;
}

.control-group {
    flex: 1;
    min-width: 180px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #2c3e50;
}

.control-group select,
.control-group input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-color);
    background: #fff;
    transition: border-color 0.2s;
    outline: none;
}

.control-group select:focus,
.control-group input[type="text"]:focus {
    border-color: var(--primary-color);
}

.size-control {
    max-width: 260px;
    flex: 0.6;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.analyze-btn {
    padding: 10px 32px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    align-self: flex-end;
}

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

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

/* Custom Data Section */
.custom-data-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.custom-data-section textarea {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.5;
}

.custom-data-section textarea:focus {
    border-color: var(--primary-color);
}

.custom-data-section .hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.custom-data-section .analyze-btn {
    align-self: flex-start;
}

/* Formula Section */
.formula-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.formula-examples {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.formula-examples-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.formula-preset {
    padding: 5px 12px;
    border: 1px solid var(--border-color);
    background: #f8f9fa;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-color);
}

.formula-preset:hover {
    border-color: var(--primary-color);
    background: rgba(52, 152, 219, 0.08);
    color: var(--primary-color);
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.chart-container {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.chart-container.small {
    min-height: 300px;
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.stats-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stats-card h3 {
    font-size: 1rem;
    color: #2c3e50;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
}

.conclusion-item .stat-value.conforms {
    color: var(--success-color);
}

.conclusion-item .stat-value.not-conforms {
    color: var(--accent-color);
}

/* Formula Card */
.formula-display {
    font-size: 1.3rem;
    font-family: 'Times New Roman', Times, serif;
    color: var(--primary-color);
    text-align: center;
    padding: 12px;
    margin-bottom: 8px;
}

.formula-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Table */
.table-container {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow-x: auto;
}

.table-container h3 {
    font-size: 1.05rem;
    color: #2c3e50;
    margin-bottom: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: #f8f9fa;
    padding: 10px 14px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 2px solid var(--border-color);
}

tbody td {
    padding: 9px 14px;
    text-align: center;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0f0f0;
}

tbody tr:hover {
    background: rgba(52, 152, 219, 0.04);
}

tbody tr:last-child td {
    border-bottom: none;
}

.diff-positive {
    color: var(--success-color);
    font-weight: 600;
}

.diff-negative {
    color: var(--accent-color);
    font-weight: 600;
}

/* Explanation Section */
.explanation {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.explanation h2 {
    color: #2c3e50;
    margin-bottom: 15px;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    font-size: 1.4rem;
}

.explanation h3 {
    color: #2c3e50;
    margin: 20px 0 10px;
    font-size: 1.15rem;
}

.explanation p {
    margin-bottom: 12px;
    color: #555;
}

.explanation ul {
    margin-left: 20px;
    margin-top: 10px;
    margin-bottom: 16px;
}

.explanation li {
    margin-bottom: 8px;
    color: #555;
}

.explanation li strong {
    color: #2c3e50;
}

.tips-section {
    background: #f0f7ff;
    padding: 20px;
    border-radius: 8px;
    margin-top: 10px;
    border-left: 4px solid var(--primary-color);
}

.chi-squared-note {
    background: #fef9e7;
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
    border-left: 4px solid var(--warning-color);
}

.chi-squared-note p {
    margin: 0;
    font-size: 0.9rem;
    color: #666;
}

/* Responsive */
@media (max-width: 768px) {
    .charts-row {
        grid-template-columns: 1fr;
    }

    .stats-row {
        grid-template-columns: 1fr;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .size-control {
        max-width: 100%;
        flex: 1;
    }

    .tab-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }

    h1 {
        font-size: 1.6rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .tab-nav {
        overflow-x: auto;
    }

    .formula-examples {
        gap: 4px;
    }

    .formula-preset {
        padding: 4px 8px;
        font-size: 0.8rem;
    }
}
