/*
 * UsDebt site styles.
 * Mobile first. Colors live in variables; dark mode swaps them.
 * Red (--trend, --trend-curve) is reserved for the trend lines only. Term lines use the
 * neutral --series-* colors (no party blue or red).
 */

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #526077;
    --border: #dde3ec;
    --accent: #1e3a8a;          /* navy: buttons, links, the debt line */
    --accent-hover: #172e6e;
    --accent-soft: rgba(30, 58, 138, 0.10);
    --on-accent: #ffffff;
    --topbar-bg: #13254f;
    --topbar-text: #ffffff;
    --focus: #2f6fdb;
    --notice-bg: #fff7e6;
    --notice-border: #f0c36d;
    --error-bg: #fdf0f0;
    --error-border: #e0a3a3;
    --grid: rgba(15, 23, 42, 0.08);
    --zero-line: rgba(15, 23, 42, 0.45);
    --trend: #c62828;           /* reserved: the straight trend line and its projection */
    --trend-curve: #7f1d1d;     /* reserved: the growth curve and its projection (darker red) */

    /* Neutral term colors, one per line on the Compare chart */
    --series-1: #0f766e;
    --series-2: #b45309;
    --series-3: #6d28d9;
    --series-4: #475569;
    --series-5: #4d7c0f;
    --series-6: #0e7490;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.05);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #121b2e;
        --surface-2: #17223a;
        --text: #e6ebf3;
        --muted: #9aa8bf;
        --border: #26334d;
        --accent: #8fb0ff;
        --accent-hover: #a9c2ff;
        --accent-soft: rgba(143, 176, 255, 0.14);
        --on-accent: #0b1220;
        --topbar-bg: #0e1830;
        --topbar-text: #e6ebf3;
        --focus: #8fb0ff;
        --notice-bg: #2b2412;
        --notice-border: #7a5f1c;
        --error-bg: #2d1717;
        --error-border: #7a2f2f;
        --grid: rgba(230, 235, 243, 0.08);
        --zero-line: rgba(230, 235, 243, 0.45);
        --trend: #f26b6b;
        --trend-curve: #ffb3b3;

        --series-1: #2dd4bf;
        --series-2: #fbbf24;
        --series-3: #b69cff;
        --series-4: #cbd5e1;
        --series-5: #a3e635;
        --series-6: #67e8f9;

        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
}

/* numbers line up in columns */
.num { font-variant-numeric: tabular-nums; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

img { max-width: 100%; }

.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;
}

.skip-link {
    position: absolute;
    left: 8px; top: -48px;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--accent);
    border-radius: var(--radius-sm);
    z-index: 10;
}
.skip-link:focus { top: 8px; }

.wrap {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ---- Top bar ---- */
.topbar {
    background: var(--topbar-bg);
    color: var(--topbar-text);
}
.topbar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 16px;
    min-height: 56px;
    padding-top: 8px;
    padding-bottom: 8px;
}
.brand {
    color: var(--topbar-text);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.01em;
    text-decoration: none;
}
.brand:hover { color: var(--topbar-text); opacity: 0.9; }
.topnav { display: flex; gap: 16px; }
.topnav a {
    color: var(--topbar-text);
    opacity: 0.85;
    font-size: 0.95rem;
    text-decoration: none;
    padding: 6px 0;
}
.topnav a:hover { opacity: 1; color: var(--topbar-text); text-decoration: underline; }

main.wrap {
    display: grid;
    gap: 16px;
    padding-top: 16px;
    padding-bottom: 32px;
}

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-width: 0; /* lets wide children scroll instead of stretching the page */
}
.card-title {
    margin: 0 0 12px;
    font-size: 1.1rem;
    font-weight: 650;
}
.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.results:focus { outline: none; }

.caption, .hint, .footnote, .lede {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0 0 12px;
}
.lede { font-size: 0.95rem; }

/* ---- Headline numbers ---- */
.headline {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}
.stat-card p { margin: 0; }
.stat-label {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 4px 0 !important;
}
.stat-detail { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

/* ---- Buttons ---- */
.btn {
    font: inherit;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: 10px 16px;
    min-height: 44px;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-quiet {
    background: transparent;
    color: var(--accent);
    border-color: var(--border);
    padding: 6px 12px;
    min-height: 36px;
    font-size: 0.9rem;
    white-space: nowrap;
}
.btn-quiet:hover { background: var(--accent-soft); }
/* on/off switch: the pressed state is shown by fill and border, and by the "On"/"Off" text */
.btn-toggle { flex: none; margin-bottom: 12px; } /* same gap below as the card title, also when it wraps on phones */
.btn-toggle[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.btn-toggle[aria-pressed="false"] { color: var(--muted); }

/* ---- Chart card buttons: Trend line + Share ---- */
.card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px; /* same gap below as the card title */
}
.card-actions .btn-toggle { margin-bottom: 0; }

/* ---- Share menu (a <details>, so it opens and closes without JavaScript) ---- */
/* The menu hangs from the card header's right edge, so it stays on screen on phones too. */
.results > .card-head { position: relative; }
.share { position: static; }
.share-button {
    display: inline-flex;
    align-items: center;
    list-style: none;
}
.share-button::-webkit-details-marker { display: none; }
.share-button::marker { content: ""; }
.share[open] > .share-button {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.share-panel {
    position: absolute;
    right: 0;
    top: calc(100% - 6px);
    z-index: 20;
    box-sizing: border-box;
    width: 20rem;
    max-width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
    padding: 12px;
}
/* phones: the buttons wrap under the title, so the menu takes the card's full width */
@media (max-width: 639px) {
    .share-panel { left: 0; width: auto; }
}
.share-title {
    margin: 0 0 8px;
    font-weight: 650;
}
.share-native { width: 100%; margin-bottom: 10px; }
.share-thumb {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1200 / 630;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    margin-bottom: 10px;
}
.share-copy {
    display: flex;
    gap: 6px;
}
.share-url {
    flex: 1 1 auto;
    min-width: 0;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
}
.share-status {
    min-height: 1.2em;
    margin: 6px 0;
    font-size: 0.85rem;
    color: var(--muted);
}
.share-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--border);
}
.share-item {
    display: block;
    padding: 10px 4px;
    min-height: 44px;
    box-sizing: border-box;
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}
.share-list li:last-child .share-item { border-bottom: 0; }
.share-item:hover { background: var(--accent-soft); }

/* ---- Date range controls ---- */
.range-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: end;
}
.range-form .btn { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field input {
    font: inherit;
    font-variant-numeric: tabular-nums;
    width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.chip {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--surface-2);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-current="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

/* ---- "Show numbers as": Total / Per person / Per household (plain links) ---- */
.per-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}
.per-label {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.per-switch {
    display: flex;
    flex: 1 1 100%;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
}
.per-option {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 4px 12px;
    border-radius: 999px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
}
.per-option:hover { color: var(--accent); background: var(--accent-soft); }
.per-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.per-option[aria-current="true"],
.per-option[aria-current="true"]:hover {
    background: var(--accent);
    color: var(--on-accent);
}
.per-help {
    flex: 1 1 100%;
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}
.chart-source { margin: 12px 0 0; font-size: 0.85rem; }

/* ---- Presidential term strip: scrolls sideways on phones ---- */
.term-strip {
    list-style: none;
    margin: 0 -16px;
    padding: 4px 16px 8px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 132px;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
}
.term {
    position: relative; /* keeps its hidden screen-reader text inside the scrolling strip, not stretching the page */
    scroll-snap-align: start;
    display: grid;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
}
.term-link {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 2px;
    color: var(--text);
    text-decoration: none;
}
.term-link:hover .term-name { color: var(--accent); text-decoration: underline; }
.term-link img {
    width: 56px;
    height: 72px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 4px;
    background: var(--border);
}
.term-name { font-weight: 600; font-size: 0.9rem; line-height: 1.25; }
.term-years { color: var(--muted); font-size: 0.85rem; }
.term-pick {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    font-size: 0.85rem;
    cursor: pointer;
    border-top: 1px solid var(--border);
    padding-top: 6px;
}
.term-pick input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.term:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.form-actions {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}
.form-actions .hint { margin: 0; }

/* ---- Results: segmented switch ---- */
.segmented { display: none; }
.js .segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
}
.segmented button {
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 36px;
    padding: 4px 16px;
    border: 0;
    border-radius: 999px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
}
.segmented button[aria-selected="true"] {
    background: var(--accent);
    color: var(--on-accent);
}
.panel + .panel { margin-top: 24px; }
.js .panel + .panel { margin-top: 0; }

/* ---- Chart ---- */
.chart-figure { margin: 0; }
.chart-box {
    position: relative;
    height: 300px;
    width: 100%;
}
.chart-box-tall { height: 360px; }
.chart-summary {
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}
.chart-summary ul { margin: 0; padding-left: 1.2em; }
.chart-summary p { margin: 0; }
.chart-summary .trend-summary { margin-top: 6px; }
.chart-summary .term-note { margin: 8px 0 0; }

/* ---- Stats ---- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0 0 12px;
}
.stats-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.stats-item dt { color: var(--muted); font-size: 0.85rem; }
.stats-item dd { margin: 2px 0 0; font-size: 1.1rem; font-weight: 650; overflow-wrap: anywhere; }

/* ---- Table ---- */
.table-scroll {
    max-height: 480px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
.data-table th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    text-align: left;
    font-size: 0.85rem;
    color: var(--muted);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.data-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .currency { text-align: right; }

/* ---- Messages ---- */
.message, .notice, .error {
    margin: 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.notice { background: var(--notice-bg); border-color: var(--notice-border); }
.error { background: var(--error-bg); border-color: var(--error-border); }

/* ---- Footer ---- */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.9rem;
    padding: 24px 0 32px;
}
.site-footer h2 { color: var(--text); font-size: 1rem; margin: 0 0 8px; }
.site-footer p { margin: 0 0 8px; max-width: 70ch; }

/* ---- Tablet ---- */
@media (min-width: 640px) {
    .headline { grid-template-columns: repeat(3, 1fr); }
    .per-switch { flex: 0 1 auto; }
    .per-option { flex: 0 0 auto; padding: 4px 18px; }
    .per-help { flex: 1 1 220px; }
    .range-form { grid-template-columns: 1fr 1fr auto; }
    .range-form .btn { grid-column: auto; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-box { height: 380px; }
    .chart-box-tall { height: 440px; }
    .form-actions { grid-template-columns: 1fr auto; align-items: center; }
    .card { padding: 20px; }
    .term-strip { margin: 0 -20px; padding-left: 20px; padding-right: 20px; }
}

/* ---- Desktop ---- */
@media (min-width: 1024px) {
    .controls {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: 12px 24px;
    }
    .controls .card-title { flex: 1 0 100%; margin-bottom: 0; }
    .controls .range-form { flex: 1 1 520px; }
    .controls .chips { margin-top: 0; padding-bottom: 4px; }
    .term-strip {
        grid-auto-flow: row;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        overflow: visible;
        margin: 0;
        padding: 4px 0 8px;
    }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .chart-box { height: 460px; }
    .chart-box-tall { height: 500px; }
    .stat-value { font-size: 2rem; }
}
