:root {
    /* Base Color Set (Default Light) */
    --accent: #E31837; /* EA Red — use for gradients and decorative elements */
    --accent-hover: #C5152F;
    --accent-gradient: linear-gradient(135deg, #E31837 0%, #FF5A1F 100%);
    /* Darker red for body text on light backgrounds — passes WCAG AA (5.5:1 on #f4f7f6) */
    --accent-on-light: #bf1130;

    --bg-page: #f4f7f6;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-main: #1a202c;   /* passes WCAG AA on bg #f4f7f6 */
    --text-muted: #4a5568;  /* passes WCAG AA (6.2:1 on white) */
    --text-on-accent: #ffffff;
    --border: rgba(203, 213, 224, 0.9);
    --input-bg: #ffffff;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --radius: 12px;
}

body.dark {
    --bg-page: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.85);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: rgba(51, 65, 85, 0.7);
    --input-bg: #1e293b;
    /* Bright red is fine for text on dark backgrounds */
    --accent-on-light: #E31837;
    color-scheme: dark;
}

/* Fix for number input spinners not matching theme in some browsers */
body.dark input[type="number"]::-webkit-inner-spin-button,
body.dark input[type="number"]::-webkit-outer-spin-button {
    filter: invert(1) hue-rotate(180deg) brightness(1.5);
    cursor: pointer;
}

/* Base Light variables already in :root, 
   but we can be explicit if we want to force .light */
body.light {
    --bg-page: #f4f7f6;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-main: #1a202c;
    --text-muted: #4a5568;
    --border: rgba(203, 213, 224, 0.9);
    --input-bg: #ffffff;
    --accent-on-light: #bf1130;
}

/* Visually hidden but accessible to screen readers */
.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;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-page);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* 56px top on mobile — leaves room for fixed theme toggle (48px) */
    padding: 3.5rem 0.75rem 2rem;
    transition: background 0.3s ease;
}

.container {
    width: 100%;
    max-width: 650px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 0.5rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
}

header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.version-tag {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: -0.3rem;
    margin-bottom: 0.6rem;
    opacity: 0.8;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-main);
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.mt-2 { margin-top: 1rem; }

/* Fields List */
.fields-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/*
 * Pre-reserve vertical space equal to ~3 stacked field rows on mobile.
 * JS removes this class after the first renderActiveFields() call.
 * Without it, inserting 3 rows causes a ~270px layout shift (CLS).
 */
.fields-list.fields-loading {
    min-height: 280px;
}

.field-row {
    display: flex;
    flex-direction: column;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    transition: all 0.2s ease;
}

.field-row:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.field-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.field-name {
    font-weight: 600;
    font-size: 1rem;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.remove-btn:hover {
    color: var(--accent);
}

.field-inputs {
    display: flex;
    gap: 1rem;
}

.input-mini {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.input-mini label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

input[type="number"], select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    /* 16px minimum prevents iOS Safari from zooming on input focus */
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-main);
    transition: all 0.2s ease;
    /* Minimum 44px touch target height (Apple HIG / WCAG 2.5.5) */
    min-height: 44px;
}

input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(227, 24, 55, 0.2);
}

/* Add Section */
.add-controls {
    display: flex;
    gap: 0.75rem;
}

.add-controls select {
    flex: 1;
}

.btn-primary {
    background: var(--accent-gradient);
    color: var(--text-on-accent);
    border: none;
    padding: 0 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    /* Minimum 44px touch target */
    min-height: 44px;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-secondary {
    background: transparent;
    color: var(--text-main);
    border: 2px solid var(--border);
    padding: 0 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    /* Minimum 44px touch target */
    min-height: 44px;
}

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

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    filter: grayscale(100%);
    transition: filter 0.2s, transform 0.2s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Minimum 44px touch target */
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    color: var(--text-muted);
}

.icon-btn:hover {
    filter: grayscale(0%);
    transform: scale(1.1);
}

/* Results Section */
.results-section {
    border-left: 5px solid var(--accent);
}

.total-result-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--input-bg);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.total-result-display .label {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.total-result-display .value {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--accent);
}

.ratios-result-display p {
    margin-bottom: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--input-bg);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.res-name {
    font-weight: 600;
}

.res-ratio {
    font-weight: 700;
    color: var(--text-on-accent);
    background: var(--accent-gradient);
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Summary & Disclaimer */
.summary-section {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 2rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.footer-links {
    margin-top: 0.75rem;
    text-align: center;
}

.report-issue-link {
    display: inline-block;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s;
}

.footer-dot {
    margin: 0 0.5rem;
    color: var(--text-muted);
    opacity: 0.5;
}

.report-issue-link:hover {
    color: var(--accent-on-light);
}

.disclaimer {
    display: block;
    margin-top: 0.5rem;
    font-style: italic;
    font-weight: 600;
    /* Use --accent-on-light (#bf1130) which passes WCAG AA (5.5:1) on the page background.
       The bright --accent (#E31837) only reaches ~4.24:1 on #f4f7f6, failing the 4.5:1 threshold. */
    color: var(--accent-on-light);
}

/* Reset link — uses --text-main to guarantee WCAG AA contrast at small sizes */
.reset-link {
    color: var(--text-main);
    font-size: 0.875rem;
    text-decoration: underline;
    text-underline-offset: 2px;
    opacity: 0.75;
    transition: opacity 0.2s;
}

.reset-link:hover {
    opacity: 1;
}

.theme-toggle-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 100;
}

#themeToggleBtn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.6rem;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
}

#themeToggleBtn:hover {
    transform: scale(1.1);
    border-color: var(--accent);
}

@media (min-width: 500px) {
    body {
        padding: 2rem 1rem;
    }

    .field-row {
        flex-direction: row;
        align-items: center;
    }
    .field-info {
        flex: 1.5;
        margin-bottom: 0;
        margin-right: 1.5rem;
    }
    .field-inputs {
        flex: 1;
    }
}

/* Mobile-first: stack add-controls on very small screens */
@media (max-width: 380px) {
    .add-controls {
        flex-direction: column;
    }
    .add-controls .btn-primary {
        width: 100%;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .total-result-display {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .result-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .res-ratio {
        align-self: flex-start;
    }
}

/* ====================================================
   Privacy Consent Banner
   ==================================================== */
.privacy-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    z-index: 500;
    padding: 0.875rem 1.25rem;
    transform: translateY(110%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.privacy-banner.visible {
    transform: translateY(0);
}

.privacy-banner-body {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.privacy-banner-text {
    flex: 1;
    min-width: 180px;
}

.privacy-banner-text strong {
    font-size: 0.9rem;
    color: var(--text-main);
}

.privacy-banner-text p {
    margin-top: 0.2rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.privacy-banner-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.privacy-details-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 0;
    transition: color 0.2s;
    min-height: 44px;
}

.privacy-details-btn:hover {
    color: var(--text-main);
}

.privacy-accept-btn {
    padding: 0.5rem 1.1rem;
    font-size: 0.875rem;
    min-height: 38px;
    white-space: nowrap;
}

.privacy-details-section {
    max-width: 700px;
    margin: 0.75rem auto 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.65;
}

/* Prevent display: flex from overriding the [hidden] attribute */
.privacy-details-section:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.privacy-details-section a {
    color: var(--text-muted);
    text-decoration: underline;
}

.privacy-details-section a:hover {
    color: var(--text-main);
}
