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

:root {
    --primary: #1e3a5f;
    --primary-dark: #15293f;
    --accent: #2c7be5;
    --accent-dark: #1a68d1;
    --teal: #14908a;
    --success: #1ca672;
    --success-dark: #158a5f;
    --warning: #e8930c;
    --danger: #e74c3c;
    --bg-soft: #f5f8fc;
    --bg-card: #ffffff;
    --line: #e2e8f0;
    --text: #1f2d3d;
    --text-soft: #5a6b7e;
    --text-faint: #8a99ab;
    --shadow-sm: 0 1px 3px rgba(30, 58, 95, 0.08);
    --shadow: 0 4px 18px rgba(30, 58, 95, 0.10);
    --shadow-lg: 0 18px 50px rgba(30, 58, 95, 0.22);
    --radius: 14px;
    --radius-sm: 9px;
}

body {
    font-family: 'Be Vietnam Pro', 'Segoe UI', Tahoma, sans-serif;
    background:
        radial-gradient(circle at 12% 18%, rgba(44, 123, 229, 0.18), transparent 42%),
        radial-gradient(circle at 88% 78%, rgba(20, 144, 138, 0.20), transparent 45%),
        linear-gradient(135deg, #243b55 0%, #141e30 100%);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
    padding: 28px 16px;
}

.container {
    max-width: 940px;
    margin: 0 auto;
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ===== Header ===== */
.header {
    position: relative;
    background:
        radial-gradient(circle at 80% -10%, rgba(255, 255, 255, 0.14), transparent 40%),
        linear-gradient(135deg, var(--primary) 0%, var(--accent) 120%);
    color: #fff;
    padding: 46px 30px 40px;
    text-align: center;
}

.header-icon {
    width: 78px;
    height: 78px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    backdrop-filter: blur(4px);
}

.header h1 {
    font-family: 'Roboto Slab', serif;
    font-size: 2.4rem;
    margin-bottom: 8px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.header .subtitle {
    font-size: 1.12rem;
    margin-bottom: 10px;
    opacity: 0.96;
    font-weight: 500;
}

.header .author {
    display: inline-block;
    font-size: 0.9rem;
    opacity: 0.95;
    font-style: italic;
    padding: 5px 16px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 30px;
}

/* ===== Navigation ===== */
.modules-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line);
}

.module-btn {
    flex: 1;
    min-width: 260px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--bg-card);
    color: var(--text);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.25s ease;
    font-size: 0.92rem;
    text-align: left;
    font-family: inherit;
}

.module-btn-number {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-soft);
    color: var(--text-soft);
    border-radius: 50%;
    font-weight: 700;
    transition: all 0.25s ease;
}

.module-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.module-btn.active {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.module-btn.active .module-btn-number {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* ===== Main Content ===== */
.main-content {
    padding: 34px 30px;
}

.module { display: none; }
.module.active { display: block; }

.module-header {
    margin-bottom: 28px;
    border-bottom: 2px solid var(--bg-soft);
    padding-bottom: 22px;
}

.module-header h2 {
    font-family: 'Roboto Slab', serif;
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 20px;
    line-height: 1.35;
}

/* ===== Formula display (kiểu dễ đọc) ===== */
.formula-box {
    background: linear-gradient(135deg, #f0f6ff 0%, #eef7f5 100%);
    border: 1px solid #d6e6fb;
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    margin-bottom: 18px;
}

.formula-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-soft);
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.formula-display {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    font-family: 'Roboto Slab', serif;
    font-size: 1.5rem;
    color: var(--primary);
}

.formula-display .var {
    font-style: italic;
    font-weight: 600;
}

.formula-display .eq,
.formula-display .times {
    color: var(--text-soft);
    margin: 0 2px;
}

.formula-display sup {
    font-size: 0.6em;
    vertical-align: super;
}

.formula-display sub {
    font-size: 0.55em;
    vertical-align: sub;
    font-style: normal;
}

/* Z với số mũ (2) chồng trên chỉ số dưới (1-α/2) */
.supsub {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: 1.05;
    font-style: normal;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 1px;
}

.supsub .ss-sup,
.supsub .ss-sub {
    font-size: 0.5em;
}

.supsub .ss-sup {
    margin-bottom: 0.15em;
}

.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
}

.fraction .numerator {
    padding: 0 12px 4px;
    border-bottom: 2px solid var(--primary);
    font-size: 0.92em;
}

.fraction .denominator {
    padding: 4px 12px 0;
    font-size: 0.92em;
}

.formula-legend {
    color: var(--text);
    font-size: 0.95rem;
}

.formula-legend p { margin-bottom: 8px; }

.formula-legend ul {
    list-style: none;
    padding-left: 4px;
}

.formula-legend li {
    position: relative;
    padding: 5px 0 5px 22px;
    color: var(--text-soft);
}

.formula-legend li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 14px;
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
}

.formula-legend li strong { color: var(--text); }

/* ===== Form ===== */
.input-section {
    background: var(--bg-soft);
    padding: 26px;
    border-radius: var(--radius);
    margin-bottom: 28px;
    border: 1px solid var(--line);
}

.section-title {
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px dashed var(--line);
}

.form-group { margin-bottom: 22px; }
.form-group:last-of-type { margin-bottom: 0; }

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.95rem;
}

.required { color: var(--danger); }

.form-group select,
.form-group input {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-card);
    transition: all 0.2s ease;
    font-family: inherit;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(44, 123, 229, 0.13);
}

.input-with-hint {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-with-hint input { flex: 1; }

/* ===== Segmented control (độ tin cậy) ===== */
.segmented {
    display: flex;
    gap: 8px;
    background: var(--bg-card);
    padding: 6px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
}

.seg-btn {
    flex: 1;
    padding: 11px 8px;
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-soft);
    font-family: inherit;
    transition: all 0.2s ease;
}

.seg-btn:hover {
    background: var(--bg-soft);
    color: var(--accent);
}

.seg-btn.active {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    box-shadow: 0 3px 10px rgba(44, 123, 229, 0.3);
}

.custom-conf {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    animation: fadeInUp 0.3s ease;
}

.custom-conf input { flex: 1; }

.z-badge {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
    padding: 11px 16px;
    background: linear-gradient(135deg, #eef6ff 0%, #eafaf7 100%);
    border: 1px solid #d6e6fb;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    color: var(--text-soft);
}

.z-badge strong {
    color: var(--accent-dark);
    font-size: 1.05rem;
}

.z-divider {
    width: 1px;
    height: 18px;
    background: var(--line);
}

.unit {
    font-weight: 700;
    color: var(--accent);
    font-size: 1.15rem;
    min-width: 18px;
}

.form-group small {
    display: block;
    margin-top: 7px;
    color: var(--text-faint);
    font-size: 0.85rem;
}

/* ===== Buttons ===== */
.btn-calculate,
.btn-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    font-size: 1.05rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: inherit;
}

.btn-calculate {
    width: 100%;
    margin-top: 24px;
    background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
    color: #fff;
    box-shadow: 0 6px 16px rgba(28, 166, 114, 0.32);
}

.btn-calculate:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(28, 166, 114, 0.42);
}

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

.btn-reset {
    background: var(--bg-card);
    color: var(--accent);
    border: 1.5px solid var(--accent);
    width: auto;
    min-width: 160px;
    margin: 26px auto 0;
}

.btn-reset:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
}

/* ===== Result Section ===== */
.result-section {
    background: #fbfdff;
    border: 1px solid #d6e6fb;
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 28px;
    animation: fadeInUp 0.45s ease;
}

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

.result-header {
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--accent);
}

.result-header h3 {
    color: var(--accent);
    font-family: 'Roboto Slab', serif;
    font-size: 1.4rem;
}

.result-steps {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.step {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
}

.step-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 20px;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.step h4 {
    color: var(--primary);
    margin-bottom: 14px;
    font-size: 1.12rem;
}

/* Param table */
.param-table {
    width: 100%;
    border-collapse: collapse;
}

.param-table td {
    padding: 9px 6px;
    border-bottom: 1px solid var(--bg-soft);
    font-size: 0.96rem;
}

.param-table tr:last-child td { border-bottom: none; }

.param-table td:first-child {
    color: var(--text-soft);
    width: 62%;
}

.param-table td:last-child {
    font-weight: 600;
    color: var(--text);
    text-align: right;
}

/* Calculation line (dạng câu chữ dễ đọc) */
.calc-line {
    background: var(--bg-soft);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    color: var(--text);
    margin-bottom: 14px;
    font-size: 0.98rem;
    line-height: 1.7;
}

.calc-line .num {
    font-weight: 700;
    color: var(--accent);
}

.result-highlight {
    background: #e9f9f1;
    border: 1.5px solid var(--success);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    color: var(--success-dark);
    text-align: center;
    font-size: 1.04rem;
}

.result-highlight strong { font-size: 1.18rem; }

.result-highlight.final-result {
    background: #fef4e3;
    border-color: var(--warning);
    color: #a8650a;
}

/* ===== Conclusion box (câu trả lời) ===== */
.conclusion-box {
    margin-top: 22px;
    background: linear-gradient(135deg, #fffaf0 0%, #fef6e9 100%);
    border: 1px solid #f5dcae;
    border-radius: var(--radius);
    padding: 24px;
}

.conclusion-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--warning);
    margin-bottom: 14px;
}

.conclusion-header h4 {
    font-size: 1.08rem;
    color: #a8650a;
}

.conclusion-text {
    background: var(--bg-card);
    border: 1px dashed #e6c98a;
    border-radius: var(--radius-sm);
    padding: 18px 20px;
    font-size: 1.04rem;
    line-height: 1.85;
    color: var(--text);
    text-align: justify;
}

.conclusion-text strong { color: var(--accent-dark); }

.btn-copy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding: 9px 18px;
    background: var(--bg-card);
    color: var(--warning);
    border: 1.5px solid var(--warning);
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
}

.btn-copy:hover {
    background: var(--warning);
    color: #fff;
}

.btn-copy.copied {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

/* ===== Instructions ===== */
.instructions {
    background: var(--bg-soft);
    padding: 24px 26px;
    border-radius: var(--radius);
    border-left: 4px solid var(--teal);
}

.instructions h3 {
    color: var(--primary);
    margin-bottom: 14px;
    font-size: 1.15rem;
}

.instructions ul { list-style: none; }

.instructions li {
    padding: 9px 0 9px 26px;
    position: relative;
    color: var(--text-soft);
    border-bottom: 1px solid var(--line);
}

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

.instructions li::before {
    content: "→";
    position: absolute;
    left: 2px;
    color: var(--teal);
    font-weight: bold;
}

.instructions li strong { color: var(--text); }

/* ===== Footer ===== */
.footer {
    background: var(--primary-dark);
    color: rgba(255, 255, 255, 0.85);
    text-align: center;
    padding: 22px;
    font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    body { padding: 0; }

    .container { border-radius: 0; }

    .header { padding: 34px 20px 30px; }
    .header h1 { font-size: 1.7rem; }
    .header .subtitle { font-size: 1rem; }

    .modules-nav { flex-direction: column; padding: 16px; }
    .module-btn { min-width: 100%; }

    .main-content { padding: 22px 18px; }
    .module-header h2 { font-size: 1.25rem; }

    .formula-box { padding: 16px; }
    .formula-display { font-size: 1.2rem; }

    .input-section { padding: 20px; }

    .result-section { padding: 20px; }
    .step { padding: 16px; }

    .param-table td { font-size: 0.9rem; }
    .param-table td:first-child { width: 58%; }

    .conclusion-text { font-size: 0.98rem; padding: 15px; }
}
