:root {
    --blue: #2563eb;
    --green: #10b981;
    --orange: #f59e0b;
    --red: #ef4444;
    --slate: #64748b;
    --text-gray: #475569;
    --bg: #f8fafc;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    padding: 40px 20px;
    display: flex;
    justify-content: center;
    margin: 0;
}

.box {
    width: 100%;
    max-width: 650px;
    background: white;
    padding: 35px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    position: relative;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h2 {
    color: var(--blue);
    margin: 0;
    font-size: 1.6rem;
    text-align: left;
}

.beta {
    display: inline-block;
    font-size: 0.8rem;
    background: #e2e8f0;
    color: #334155;
    /* Improved contrast from #475569 */
    padding: 2px 8px;
    border-radius: 6px;
    vertical-align: middle;
    margin-left: 8px;
    font-weight: 600;
    transform: translateY(-2px);
}

.reset-btn {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 0.6rem;
    /* smaller on all screens */
    font-weight: 500;
    cursor: pointer;
    padding: 2px 6px;
    /* tighter padding */
    border-radius: 6px;
    transition: all 0.2s;
    opacity: 0.4;
    /* less prominent */
    margin-left: 8px;
}

.reset-btn:hover {
    background: #fecaca;
    border-color: #fca5a5;
    color: #991b1b;
    opacity: 0.7;
    /* still subtle on hover */
}

.reset-btn:active {
    transform: scale(0.95);
    opacity: 1;
}

@media (max-width: 500px) {
    body {
        padding: 5px;
        /* Minimal padding */
    }

    .box {
        padding: 12px 10px;
        /* Minimal box padding */
        display: flex;
        flex-direction: column;
    }

    /* 1. Header */
    .header-row {
        flex-direction: column;
        gap: 2px;
        margin-bottom: 5px;
        order: -3;
        margin-top: -5px;
    }

    h2 {
        text-align: center;
        font-size: 1.1rem;
        /* Smaller title */
        margin-bottom: 2px;
    }

    /* 2. Redditi Inputs (Side-by-Side) */
    .input-group-redditi {
        order: -2;
        margin-bottom: 5px;
    }

    .input-group-redditi .grid {
        grid-template-columns: 1fr 1fr;
        /* 2 Columns! */
        gap: 8px;
    }

    .input-group-redditi .field {
        margin-bottom: 0;
        /* Remove internal margin */
    }

    /* 3. Results */
    .res-box {
        padding: 10px;
        margin-top: 2px;
        margin-bottom: 15px;
        order: -1;
        border-radius: 10px;
    }

    /* General Compact Styles */
    .section-title {
        margin: 8px 0 4px;
        font-size: 0.65rem;
    }

    .grid {
        gap: 8px;
        margin-bottom: 5px;
    }

    .field {
        margin-bottom: 8px;
    }

    input,
    select {
        padding: 6px;
        /* Ultra slim inputs */
        font-size: 0.9rem;
    }

    .line {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }

    .line.sub {
        font-size: 0.75rem;
    }

    .total-bonus {
        font-size: 1.1rem;
        margin-top: 8px;
        padding-top: 8px;
    }

    .alert {
        padding: 8px;
        font-size: 0.75rem;
        margin-top: 8px;
    }
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--slate);
    font-weight: 600;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin: 0 8px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--blue);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* --- */

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--slate);
    border-bottom: 1px solid #e2e8f0;
    margin: 25px 0 15px;
    padding-bottom: 8px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 10px;
}

.field {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-gray);
}

.form-note {
    font-size: 0.75rem;
    color: var(--slate);
    margin-bottom: 8px;
    font-weight: normal;
    margin-top: -4px;
}

input,
select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    box-sizing: border-box;
    margin-top: auto;
}

input:focus {
    border-color: var(--blue);
}

input.invalid {
    border-color: var(--red);
    background-color: #fef2f2;
}

.res-box {
    background: #f1f5f9;
    padding: 25px;
    border-radius: 16px;
    margin-top: 25px;
    border: 1px solid #e2e8f0;
}

.badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 99px;
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    margin-bottom: 15px;
    text-transform: uppercase;
    background: var(--slate);
}

.line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.line.sub {
    padding-left: 15px;
    font-size: 0.85rem;
    color: var(--slate);
    border-left: 3px solid #cbd5e1;
}

.line.highlight {
    font-weight: 700;
    color: #0f172a;
    padding-top: 10px;
    border-top: 1px solid #cbd5e1;
    margin-top: 5px;
}

.alert {
    padding: 15px;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-top: 15px;
    display: none;
}

.alert-gap {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.alert-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.alert-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.alert-warning {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
}

.total-bonus {
    font-weight: 800;
    font-size: 1.6rem;
    color: var(--blue);
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #cbd5e1;
}

/* Hiding Logic */
.adv-only {
    display: none;
}

.mode-full .adv-only {
    display: block;
}

.mode-full .adv-field {
    display: flex;
}