:root {
    --ink: #0e221c;
    --ink-soft: #1a3a30;
    --mist: #e7f3ee;
    --mist-deep: #d3e8df;
    --surface: #f3faf6;
    --text: #12261f;
    --text-muted: #5a7369;
    --border: #c5d9cf;
    --accent: #1f7a55;
    --accent-bright: #2a9d6a;
    --citrus: #d6f25c;
    --citrus-deep: #b8d63a;
    --shadow: 0 8px 28px rgba(14, 34, 28, 0.08);
    --radius: 14px;
    --radius-sm: 8px;
    /* IBM Plex Sans: compact, readable headings with true tabular figures for prices */
    --font-brand: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --card: #ffffff;
    --good: #157347;
    --good-bg: #e3f6ea;
    --good-border: #9fd8b5;
    --warn: #8a5a00;
    --warn-bg: #fff4d6;
    --row-alt: rgba(14, 34, 28, 0.025);
    --page-bg:
        radial-gradient(ellipse 80% 50% at 10% -10%, rgba(214, 242, 92, 0.22), transparent 55%),
        radial-gradient(ellipse 60% 40% at 95% 5%, rgba(31, 122, 85, 0.12), transparent 50%),
        linear-gradient(180deg, var(--mist) 0%, var(--surface) 38%, #eef6f2 100%);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --mist: #13201b;
        --mist-deep: #1b2c25;
        --surface: #15231d;
        --card: #182821;
        --text: #e4efe9;
        --text-muted: #9bb3a8;
        --border: #2b4238;
        --accent: #4cc38a;
        --accent-bright: #5fd39b;
        --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
        --good: #6ee0a2;
        --good-bg: rgba(76, 195, 138, 0.14);
        --good-border: rgba(110, 224, 162, 0.4);
        --warn: #f2c565;
        --warn-bg: rgba(242, 197, 101, 0.12);
        --row-alt: rgba(255, 255, 255, 0.02);
        --page-bg:
            radial-gradient(ellipse 80% 50% at 10% -10%, rgba(214, 242, 92, 0.06), transparent 55%),
            linear-gradient(180deg, #0f1a16 0%, #111d18 100%);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background: var(--page-bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Prices: equal-width lining digits so totals line up and compare at a glance */
.amount, .summary-total, .summary-save, .store-total, .store-breakdown dd,
.compare-price, .compare-was, .compare-total,
.deal-now, .deal-was, .deal-save, .deal-unit,
.line-total, table td {
    font-variant-numeric: tabular-nums lining-nums;
}

/* Hero — full-bleed market atmosphere */
.hero {
    position: relative;
    overflow: hidden;
    color: #f4fff8;
    padding: clamp(3.5rem, 9vw, 6.5rem) 1.5rem clamp(4rem, 10vw, 7rem);
    isolation: isolate;
}

.hero-atmosphere {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(118deg, #0a1c17 0%, #14352b 42%, #1b5c42 78%, #246b4c 100%),
        radial-gradient(circle at 78% 28%, rgba(214, 242, 92, 0.28), transparent 42%);
    animation: hero-shift 14s ease-in-out infinite alternate;
}

.hero-atmosphere::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 18% 70%, rgba(255, 255, 255, 0.06) 0 2px, transparent 3px),
        radial-gradient(circle at 62% 40%, rgba(214, 242, 92, 0.12) 0 1.5px, transparent 3px),
        radial-gradient(circle at 88% 78%, rgba(255, 255, 255, 0.05) 0 2px, transparent 3px);
    background-size: 48px 48px, 36px 36px, 56px 56px;
    opacity: 0.7;
    animation: grain-drift 22s linear infinite;
}

.hero-atmosphere::after {
    content: "";
    position: absolute;
    right: -8%;
    bottom: -35%;
    width: min(58vw, 520px);
    height: min(58vw, 520px);
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 35%, rgba(214, 242, 92, 0.35), transparent 55%),
        radial-gradient(circle at 65% 60%, rgba(255, 255, 255, 0.08), transparent 60%);
    filter: blur(2px);
    animation: orb-float 9s ease-in-out infinite alternate;
}

.hero-inner {
    max-width: var(--page-max, 1100px);
    margin: 0 auto;
    position: relative;
}

.brand {
    font-family: var(--font-brand);
    font-size: clamp(2.4rem, 7vw, 4.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 0.95;
    margin-bottom: 1.1rem;
    color: #fff;
    text-wrap: balance;
    animation: rise-in 0.7s ease-out both;
}

.hero h1 {
    font-family: var(--font-brand);
    font-size: clamp(1.35rem, 3.2vw, 2rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 0.85rem;
    color: var(--citrus);
    max-width: 18ch;
    animation: rise-in 0.7s ease-out 0.08s both;
}

.subtitle {
    font-size: 1.05rem;
    opacity: 0.9;
    max-width: 36rem;
    margin-bottom: 1.75rem;
    animation: rise-in 0.7s ease-out 0.16s both;
}

.hero-cta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    animation: rise-in 0.7s ease-out 0.24s both;
}

.btn-hero {
    background: var(--citrus);
    color: var(--ink);
    border: none;
    padding: 0.85rem 1.35rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.btn-hero:hover {
    background: #e4ff7a;
    transform: translateY(-1px);
}

.btn-hero-ghost {
    background: transparent;
    color: #f4fff8;
    border: 1px solid rgba(244, 255, 248, 0.35);
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: border-color 0.2s, background 0.2s;
}

.btn-hero-ghost:hover {
    border-color: rgba(244, 255, 248, 0.7);
    background: rgba(255, 255, 255, 0.06);
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes hero-shift {
    from { filter: hue-rotate(0deg) saturate(1); }
    to { filter: hue-rotate(-6deg) saturate(1.08); }
}

@keyframes grain-drift {
    from { background-position: 0 0, 0 0, 0 0; }
    to { background-position: 48px 24px, -24px 36px, 20px -28px; }
}

@keyframes orb-float {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(-18px, -22px) scale(1.06); }
}

/* Container */
.container {
    max-width: var(--page-max, 1100px);
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
}

/* Controls */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: -1.75rem;
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 5;
    background: rgba(243, 250, 246, 0.92);
    backdrop-filter: blur(10px);
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.controls-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-left: auto;
}

.controls-hint strong {
    color: var(--accent);
}

.controls-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-left: auto;
}

.controls-actions .btn {
    flex: none;
}

.controls-actions .btn-primary {
    background: var(--accent);
    color: white;
}

.refresh-form {
    margin: 0;
    display: inline-flex;
}

.household-tabs {
    display: flex;
    background: var(--mist-deep);
    border-radius: var(--radius-sm);
    padding: 0.3rem;
    gap: 0.2rem;
    border: 1px solid var(--border);
}

.tab {
    padding: 0.65rem 1.15rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    transition: color 0.2s, background 0.2s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    background: var(--ink);
    color: var(--citrus);
}

.last-updated {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.alert-warning {
    background: #fff7e0;
    border: 1px solid #e6d08a;
    color: #5c4a00;
}

.alert code {
    font-size: 0.85em;
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

/* Comparison grid — interaction cards */
.comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
    margin-bottom: 3rem;
}

.retailer-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    transition: transform 0.25s ease, border-color 0.25s ease;
    animation: rise-in 0.55s ease-out both;
    animation-delay: var(--reveal-delay, 0ms);
}

.retailer-card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--brand-color, var(--accent)) 45%, var(--border));
}

.retailer-card.best-value {
    border-color: var(--accent);
    background:
        linear-gradient(160deg, rgba(214, 242, 92, 0.18), transparent 42%),
        var(--surface);
}

.card-rank {
    position: absolute;
    top: -10px;
    left: 1.5rem;
    background: var(--brand-color, var(--accent));
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.best-value .card-rank {
    background: var(--ink);
    color: var(--citrus);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 0.5rem;
    margin-bottom: 1.25rem;
}

.card-header h2 {
    font-family: var(--font-brand);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: color-mix(in srgb, var(--citrus) 55%, #fff);
    color: var(--ink);
    margin-right: 0.35rem;
}

.badge-sub {
    background: #fff3cd;
    color: #856404;
}

.badge-type {
    background: var(--mist-deep);
    color: var(--text-muted);
}

.total-price {
    text-align: right;
}

.total-price .currency {
    font-size: 1rem;
    color: var(--text-muted);
}

.total-price .amount {
    font-family: var(--font-brand);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.price-breakdown {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-bottom: 1rem;
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    padding: 0.25rem 0;
    color: var(--text-muted);
}

.breakdown-row.saving {
    color: var(--accent);
}

.breakdown-row.highlight {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border);
    font-weight: 600;
    color: var(--text);
}

.saving-amount {
    color: var(--accent);
}

.coverage {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.card-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.25rem;
    font-size: 0.8rem;
}

.card-items th {
    text-align: left;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.35rem 0.4rem 0.45rem 0;
    border-bottom: 1px solid var(--border);
}

.card-items th:nth-child(2),
.card-items td:nth-child(2) {
    text-align: right;
    white-space: normal;
}

.card-items td {
    padding: 0.4rem 0.4rem 0.4rem 0;
    border-bottom: 1px solid rgba(14, 34, 28, 0.05);
    vertical-align: top;
    color: var(--text);
}

.card-items tbody tr:last-child td {
    border-bottom: none;
}

.card-item-name {
    max-width: 12rem;
    white-space: normal;
}

.card-item-text {
    display: block;
    line-height: 1.25;
}

.retailer-card[data-retailer="AB"] {
    --offer-color: #0b63ce;
    --offer-color-deep: #084a9c;
}

.retailer-card[data-retailer="SKLAVENITIS"] {
    --offer-color: #c45a00;
    --offer-color-deep: #9a4500;
}

.retailer-card[data-retailer="GALAXIAS"] {
    --offer-color: #8a6700;
    --offer-color-deep: #6b5000;
}

/* Galaxias: yellow with blue details, like its logo. Dark blue text keeps the yellow readable. */
[data-retailer="GALAXIAS"] .btn-primary,
[data-retailer="GALAXIAS"] .card-rank,
[data-retailer="GALAXIAS"] .store-rank {
    color: #0b3a82;
    box-shadow: inset 0 -3px 0 #0b3a82;
}

.deal[data-retailer="GALAXIAS"] .deal-store,
.store[data-retailer="GALAXIAS"] .store-name {
    color: color-mix(in srgb, #4f8ff0 70%, var(--text));
}

.card-offer-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.3rem;
    padding: 0.2rem 0.55rem 0.2rem 0.3rem;
    border-radius: 6px;
    background: color-mix(in srgb, var(--offer-color, #6b7280) 12%, #fff);
    color: var(--offer-color, #6b7280);
    border: 1px solid color-mix(in srgb, var(--offer-color, #6b7280) 35%, #fff);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: nowrap;
}

.card-offer-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: var(--offer-color, #6b7280);
    color: #fff;
}

.card-offer-icon {
    display: block;
    flex-shrink: 0;
}

.card-offer-label {
    overflow: visible;
    color: var(--offer-color-deep, var(--offer-color, #4b5563));
}

.card-item-price {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    text-align: right;
    min-width: 4.2rem;
}

.card-price-was {
    display: block;
    font-size: 0.72rem;
    font-weight: 400;
    color: #8a867c;
    text-decoration: line-through;
    text-decoration-thickness: 1.5px;
    line-height: 1.15;
    margin-bottom: 0.05rem;
}

.card-price-now {
    display: block;
    line-height: 1.2;
}

.card-price-now.is-offer {
    color: var(--offer-color, var(--brand-color, #b45309));
    font-weight: 700;
}

.card-actions {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
}

.btn-primary {
    background: var(--brand-color, var(--accent));
    color: white;
    flex: 1;
    justify-content: center;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.btn-secondary:hover {
    background: var(--mist);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-history {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.btn-history:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-disabled,
.btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    pointer-events: none;
    background: var(--mist-deep) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border) !important;
}

.scrape-timing {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: -0.75rem 0 1.25rem;
}

.scrape-cdp-alert p {
    margin: 0.5rem 0 0;
}

.scrape-cdp-steps {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.scrape-cdp-steps code {
    font-size: 0.85em;
}

.scrape-status {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.scrape-status--running {
    border-color: color-mix(in srgb, var(--citrus) 55%, var(--border));
    background: color-mix(in srgb, var(--citrus) 18%, var(--surface));
}

.scrape-status strong {
    display: block;
    margin-bottom: 0.2rem;
}

.scrape-status-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid color-mix(in srgb, var(--citrus) 45%, #fff);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
    margin-top: 0.15rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.badge-loading {
    background: color-mix(in srgb, var(--citrus) 40%, #fff);
    color: var(--ink);
}

.badge-pending {
    background: #e8eef8;
    color: #1d4e89;
}

.retailer-card--preliminary {
    opacity: 0.95;
    border-style: dashed;
}

.retailer-card--preliminary .card-rank {
    display: none;
}

.btn-large {
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
}

/* Info section */
.info-section, .categories-section {
    margin-bottom: 2.5rem;
}

.info-section h3, .categories-section h3 {
    font-family: var(--font-brand);
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 1.25rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
}

.info-card {
    padding: 0.25rem 0 0.5rem;
    border-top: 2px solid var(--ink);
}

.info-mark {
    width: 1.75rem;
    height: 4px;
    margin-bottom: 0.85rem;
    background: linear-gradient(90deg, var(--citrus), var(--accent));
    border-radius: 2px;
}

.info-card h4 {
    font-family: var(--font-brand);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.info-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    background: transparent;
    border: 1px solid var(--border);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: border-color 0.2s, color 0.2s;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* Detail page */
.detail-page .detail-header {
    background:
        linear-gradient(118deg, #0a1c17 0%, #14352b 50%, var(--brand-color, #1f7a55) 100%);
    color: white;
    padding: 2rem 1.5rem 2.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.back-link:hover {
    color: white;
}

.detail-header h1 {
    font-family: var(--font-brand);
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.detail-header p {
    opacity: 0.85;
    margin-top: 0.25rem;
}

.detail-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-top: -1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.summary-total .label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.summary-total .amount {
    font-family: var(--font-brand);
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.items-table-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th,
.items-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.items-table th {
    background: var(--mist);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.items-table tbody tr:hover {
    background: color-mix(in srgb, var(--citrus) 10%, transparent);
}

.cat-label {
    font-weight: 500;
}

.offer-tag {
    display: inline-block;
    background: #fff3cd;
    color: #856404;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.5rem;
}

.offer-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--accent);
    margin-top: 0.25rem;
    font-weight: 500;
}

.price-was {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: line-through;
}

.top-offers-section {
    margin-top: 2.5rem;
    margin-bottom: 2.5rem;
}

.toilet-deals-section {
    margin-top: 2.5rem;
    margin-bottom: 2.5rem;
}

.top-offers-section h3,
.toilet-deals-section h3 {
    font-family: var(--font-brand);
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.toilet-deals-intro {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1rem;
    max-width: 40rem;
}

.top-offers-grid,
.toilet-deals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.toilet-per-roll {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.toilet-deal-link {
    margin-top: 0.75rem;
    display: inline-flex;
}

.offer-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    border-top: 3px solid var(--brand-color, var(--accent));
}

.offer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.offer-product {
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.offer-prices {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.offer-now {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.offer-was {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: line-through;
}

.offer-desc {
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.offer-saving {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
}

.line-total {
    font-weight: 600;
}

.item-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
}

.item-link:hover {
    text-decoration: underline;
}

.items-table tfoot td {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.items-table .saving-row td {
    color: var(--accent);
}

.items-table .total-row td {
    background: var(--mist);
    font-size: 1rem;
    color: var(--text);
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state a {
    color: var(--accent);
}

.pack-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.autoload-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.autoload-note {
    margin-top: 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
    border: 1px solid var(--border);
}

@media (max-width: 640px) {
    .hero {
        padding: 3rem 1.25rem 3.5rem;
    }

    .hero-cta {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-hero,
    .btn-hero-ghost,
    .hero-cta .refresh-form {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        margin-top: -1.25rem;
    }

    .controls-hint {
        margin-left: 0;
    }

    .controls-actions {
        margin-left: 0;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .controls-actions .btn,
    .controls-actions .refresh-form {
        width: 100%;
        justify-content: center;
    }

    .household-tabs {
        overflow-x: auto;
    }

    .card-actions {
        flex-direction: column;
    }

    .items-table-wrapper {
        overflow-x: auto;
    }
}

/* ===================== Dashboard (index) ===================== */

.skip-link {
    position: absolute;
    left: -999px;
    top: 0.5rem;
    z-index: 100;
    background: var(--ink);
    color: var(--citrus);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    left: 0.75rem;
}

:where(a, button, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 2px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(10, 28, 23, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar-inner {
    max-width: var(--page-max, 1100px);
    margin: 0 auto;
    padding: 0.7rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: #fff;
    text-decoration: none;
    font-family: var(--font-brand);
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.logo-mark {
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 8px;
    background: var(--citrus);
    color: var(--ink);
    font-weight: 800;
}

.topnav {
    display: flex;
    gap: 0.25rem;
}

.topnav-link {
    color: rgba(244, 255, 248, 0.72);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    transition: background 0.2s, color 0.2s;
}

.topnav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.topnav-link.is-current {
    color: var(--ink);
    background: var(--citrus);
}

/* Summary band: answer first */
.summary {
    background:
        radial-gradient(circle at 85% 0%, rgba(214, 242, 92, 0.22), transparent 45%),
        linear-gradient(118deg, #0a1c17 0%, #14352b 55%, #1b5c42 100%);
    color: #f4fff8;
    padding: 2.25rem 1.5rem 3.5rem;
}

.summary-inner {
    max-width: var(--page-max, 1100px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 320px);
    gap: 2rem;
    align-items: center;
}

.eyebrow {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--citrus);
    margin-bottom: 0.6rem;
}

.summary-title {
    font-family: var(--font-brand);
    font-size: clamp(1.6rem, 3.6vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.12;
    text-wrap: balance;
}

.summary-sub {
    margin-top: 0.6rem;
    max-width: 38rem;
    opacity: 0.85;
}

.summary-figure {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.4rem 1rem;
    margin-top: 0.75rem;
}

.summary-total {
    font-family: var(--font-brand);
    font-size: clamp(2.4rem, 6vw, 3.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.summary-save {
    font-weight: 700;
    color: var(--ink);
    background: var(--citrus);
    border-radius: 999px;
    padding: 0.3rem 0.85rem;
    font-size: 0.95rem;
}

.status-panel {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    display: grid;
    gap: 0.75rem;
}

.freshness {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    font-size: 0.92rem;
    line-height: 1.35;
}

.freshness strong {
    color: #fff;
}

.freshness-when {
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
}

.freshness-dot {
    flex: none;
    width: 0.65rem;
    height: 0.65rem;
    margin-top: 0.3rem;
    border-radius: 50%;
    background: #6ee0a2;
    box-shadow: 0 0 0 4px rgba(110, 224, 162, 0.2);
}

.freshness.is-stale .freshness-dot {
    background: #f2c565;
    box-shadow: 0 0 0 4px rgba(242, 197, 101, 0.22);
}

.freshness.is-stale strong {
    color: #f7d58a;
}

.btn-run {
    width: 100%;
    justify-content: center;
    background: var(--citrus);
    color: var(--ink);
    font-weight: 700;
    padding: 0.75rem 1rem;
}

.btn-run:hover {
    background: #e4ff7a;
}

.status-panel .refresh-form {
    display: block;
}

.status-panel .btn-disabled,
.status-panel .btn:disabled {
    background: rgba(255, 255, 255, 0.1) !important;
    color: rgba(244, 255, 248, 0.7) !important;
    border-color: transparent !important;
    opacity: 1;
}

.status-note {
    font-size: 0.82rem;
    opacity: 0.78;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-top: -1.6rem;
    margin-bottom: 1.75rem;
    position: relative;
    z-index: 5;
    background: var(--card);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.toolbar-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-right: 0.25rem;
}

.dash .household-tabs {
    background: var(--mist);
}

.dash .tab.active {
    background: var(--ink);
    color: var(--citrus);
}

/* Sections */
.section {
    margin-bottom: 2.75rem;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    margin-bottom: 1rem;
}

.section-title {
    font-family: var(--font-brand);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.section-sub {
    color: var(--text-muted);
    font-size: 0.88rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Store ranking */
.ranking {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 1rem;
}

.store {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.2rem 1.2rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    border-top: 4px solid var(--brand-color, var(--accent));
}

.store.is-best {
    border-color: var(--good-border);
    border-top-color: var(--brand-color, var(--accent));
    background:
        linear-gradient(170deg, var(--good-bg), transparent 55%),
        var(--card);
}

.store.is-preliminary {
    border-style: dashed;
}

.store-top {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.store-rank {
    flex: none;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--mist-deep);
    color: var(--text);
    font-weight: 800;
    font-size: 0.9rem;
}

.store.is-best .store-rank {
    background: var(--ink);
    color: var(--citrus);
}

.store-id {
    flex: 1;
    min-width: 0;
}

.store-name {
    font-family: var(--font-brand);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.store-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.35rem;
}

.tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--warn-bg);
    color: var(--warn);
    letter-spacing: 0.01em;
}

.tag-best {
    background: var(--good-bg);
    color: var(--good);
}

.tag-pending {
    background: #e8eef8;
    color: #1d4e89;
}

.tag-muted {
    background: var(--mist);
    color: var(--text-muted);
}

/* A store that only stocks some basket lines (Lidl): its total is not comparable with the others. */
.tag-partial {
    background: #fff1d6;
    color: #8a5300;
}

.store-partial-note {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.store.is-partial .store-total {
    opacity: 0.8;
}

.compare-partial {
    margin-left: 0.25rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}

.logo-version {
    margin-left: 0.15rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--citrus);
    color: var(--ink);
    font-size: 0.7rem;
    font-weight: 800;
    vertical-align: 0.15em;
}

.store-total {
    font-family: var(--font-brand);
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.store-currency {
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-left: 0.1rem;
    vertical-align: 0.55em;
}

.store-bar {
    height: 6px;
    background: var(--mist);
    border-radius: 999px;
    overflow: hidden;
}

.store-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--brand-color, var(--accent));
}

.store-breakdown {
    display: grid;
    gap: 0.25rem;
    font-size: 0.86rem;
}

.store-breakdown div {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
}

.store-breakdown dd {
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.store-breakdown .is-saving,
.store-breakdown .is-saving dd {
    color: var(--good);
    font-weight: 600;
}

.store-breakdown .is-extra dd {
    color: var(--warn);
    font-weight: 600;
}

.store-actions {
    display: grid;
    gap: 0.55rem;
    margin-top: auto;
    text-align: center;
}

.store-actions .btn {
    justify-content: center;
    min-height: 2.6rem;
}

.store-details-link {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
}

.store-details-link:hover {
    color: var(--text);
    text-decoration: underline;
}

/* Item-by-item comparison */
.legend {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.legend::before {
    content: "";
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 3px;
}

.legend-cheapest::before {
    background: var(--good-bg);
    border: 1px solid var(--good-border);
}

.legend-offer::before {
    background: var(--warn-bg);
    border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}

.compare-scroll {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.compare {
    width: 100%;
    min-width: 520px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.92rem;
}

.compare th,
.compare td {
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
    vertical-align: middle;
}

.compare thead th {
    position: sticky;
    top: 0;
    background: var(--card);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.compare .compare-item-col,
.compare .compare-item,
.compare tfoot th {
    text-align: left;
}

.compare-store {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.85rem;
}

.compare-store::before {
    content: "";
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--brand-color, var(--accent));
}

.compare tbody tr:nth-child(even) {
    background: var(--row-alt);
}

.compare-item {
    position: sticky;
    left: 0;
    background: var(--card);
    font-weight: 600;
    white-space: nowrap;
}

.compare tbody tr:nth-child(even) .compare-item {
    background: color-mix(in srgb, var(--card) 97%, var(--text));
}

.compare-qty {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.compare-cell {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.compare-price {
    font-weight: 600;
}

.compare-was {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-decoration: line-through;
}

.compare-bought {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.72rem;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

.compare-prod {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    margin-top: 0.15rem;
    font-size: 0.75rem;
    line-height: 1.3;
    opacity: 0.8;
    max-width: 11rem;
    margin-left: auto;
}

.compare-unit {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.compare-equiv {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.72rem;
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}

.store-amounts {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
}

.store-cash {
    margin: 0.3rem 0 0;
    font-size: 0.78rem;
    opacity: 0.75;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.intro-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    height: fit-content;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    max-width: min(34rem, calc(100vw - 2rem));
    padding: 1.4rem 1.5rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow);
    line-height: 1.55;
}

.intro-dialog::backdrop {
    background: rgba(8, 20, 15, 0.6);
}

.intro-dialog h2 {
    margin: 0 0 0.6rem;
    font-family: var(--font-brand);
    font-size: 1.25rem;
}

.intro-dialog p {
    margin: 0.6rem 0 0;
}

.intro-close {
    margin-top: 1.1rem;
    cursor: pointer;
}

.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.store-adjusted-note {
    margin: 0.6rem 0 0;
    font-size: 0.78rem;
    line-height: 1.4;
    opacity: 0.8;
}

.flyer {
    position: relative;
}

.flyer-track {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 0.2rem 0;
}

.flyer-track::-webkit-scrollbar {
    display: none;
}

.flyer-slide {
    flex: 0 0 min(88%, 26rem);
    scroll-snap-align: start;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-size: 0.9rem;
}

.flyer-lines {
    margin: 0.3rem 0 0.6rem;
    padding-left: 1.1rem;
    line-height: 1.45;
    max-height: 17rem;
    overflow-y: auto;
}

.flyer-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.flyer-btn {
    min-width: 2.75rem;
    min-height: 2.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}

.flyer-dots {
    display: flex;
    gap: 0.15rem;
}

.flyer-dot {
    width: 1.5rem;
    height: 2.75rem;
    border: 0;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.flyer-dot::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--border);
    transform: translate(-50%, -50%);
    transition: background 0.2s, transform 0.2s;
}

.flyer-dot.is-on::after {
    background: var(--accent);
    transform: translate(-50%, -50%) scale(1.3);
}

.week-market-name {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.deal-bargain .deal-desc {
    opacity: 0.85;
}

.compare-explain {
    margin: 0.9rem 0 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.compare-explain summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.compare-explain p {
    margin: 0.6rem 0 0;
    max-width: 62rem;
}

.compare-footnote {
    margin: 0.6rem 0 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.compare-offer {
    display: block;
    width: fit-content;
    margin-left: auto;
    margin-top: 0.15rem;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--warn-bg);
    color: var(--warn);
}

.compare-cell.is-cheapest {
    background: var(--good-bg);
    box-shadow: inset 3px 0 0 var(--good);
}

.compare-cell.is-cheapest .compare-price {
    color: var(--good);
}

.compare-cell.is-cheapest .compare-price::before {
    content: "✓ ";
    font-size: 0.8em;
}

.compare-missing {
    color: var(--text-muted);
}

.compare tfoot th,
.compare tfoot td {
    border-bottom: none;
    font-weight: 700;
    font-size: 0.98rem;
    background: var(--mist);
}

.compare tfoot .compare-total.is-cheapest {
    color: var(--good);
    background: var(--good-bg);
}

/* Deal cards */
.deal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0.9rem;
}

.deal {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand-color, var(--accent));
    border-radius: var(--radius-sm);
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.deal-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.deal-store {
    color: var(--text);
}

.deal-name {
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.deal-prices {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.deal-now {
    font-size: 1.2rem;
    font-weight: 800;
}

.deal-was {
    color: var(--text-muted);
    text-decoration: line-through;
    font-size: 0.85rem;
}

.deal-save {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--good);
    background: var(--good-bg);
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
}

.deal-unit {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.deal-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.deal-link {
    margin-top: auto;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.deal-link:hover {
    text-decoration: underline;
}

/* Explainer */
.explainer {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem 1.25rem;
}

.explainer summary {
    cursor: pointer;
    font-family: var(--font-brand);
    font-weight: 700;
    font-size: 1.05rem;
    padding: 0.85rem 0;
}

.explainer[open] {
    padding-bottom: 1.25rem;
}

.explainer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin: 0.5rem 0 1.5rem;
}

.explainer h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.explainer p {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.explainer-basket-title {
    margin-bottom: 0.6rem;
}

/* Progress */
.scrape-status-body {
    flex: 1;
}

.progress {
    height: 6px;
    margin-top: 0.5rem;
    background: color-mix(in srgb, var(--citrus) 25%, var(--mist));
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: inherit;
    transition: width 0.4s ease;
}

.dash .alert p {
    margin-top: 0.35rem;
}

.dash .empty-state {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.dash .empty-state p {
    margin-top: 0.5rem;
}

.dash .btn-ghost {
    color: var(--text);
}

.dash .btn-primary {
    background: var(--brand-color, var(--accent));
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .alert-warning {
        background: var(--warn-bg);
        border-color: color-mix(in srgb, var(--warn) 35%, transparent);
        color: var(--warn);
    }

    :root:not([data-theme="light"]) .tag-pending {
        background: rgba(120, 160, 230, 0.15);
        color: #a8c4f0;
    }

    :root:not([data-theme="light"]) .dash .tab.active {
        background: var(--citrus);
        color: var(--ink);
    }
}

@media (max-width: 760px) {
    .summary {
        padding: 1.5rem 1rem 3rem;
    }

    .summary-inner {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .topbar-inner {
        padding: 0.6rem 1rem;
    }

    .logo-text {
        font-size: 0.95rem;
    }

    .dash .container {
        padding: 0 1rem 2.5rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .dash .household-tabs {
        justify-content: space-between;
    }

    .dash .tab {
        flex: 1;
        text-align: center;
        padding: 0.6rem 0.5rem;
    }

    .toolbar-note {
        text-align: center;
    }

    .compare th,
    .compare td {
        padding: 0.55rem 0.6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================== Mobile UX layer =====================
   Phone-first fixes, all additive: nothing here changes the desktop layout.
   - no sideways scrolling (the top bar used to overflow at 375px)
   - every tap target >= 44px with >= 8px between neighbours
   - the household-size switch stays reachable while scrolling (sticky)
   - the 21-row item comparison and the other tables become one card per row instead of
     a wide table inside a sideways scroller
   - safe areas, readable minimum text size, chart that fits the screen                 */

:root {
    --topbar-h: 3.5rem;
    --tap: 44px;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: calc(var(--topbar-h) + 4.75rem);
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

a, button, summary, .tab {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(214, 242, 92, 0.25);
}

.size-note {
    display: none;
}

.chart-box {
    position: relative;
    height: 360px;
}

/* Touch devices (any width) */
@media (pointer: coarse) {
    .btn,
    .tab,
    .topnav-link,
    .back-link,
    .store-details-link,
    .deal-link,
    .item-link {
        min-height: var(--tap);
    }

    .store-details-link,
    .deal-link,
    .item-link,
    .back-link {
        display: inline-flex;
        align-items: center;
    }

    .tab {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .explainer summary {
        min-height: var(--tap);
        display: flex;
        align-items: center;
    }
}

@media (max-width: 640px) {
    body {
        overflow-x: clip;
    }

    /* ---- Top bar: fits 375px without sideways scroll ---- */
    .topbar-inner {
        min-height: var(--topbar-h);
        padding: 0.3rem max(0.75rem, env(safe-area-inset-right)) 0.3rem max(0.75rem, env(safe-area-inset-left));
        gap: 0.5rem;
    }

    .logo {
        min-width: 0;
        min-height: var(--tap);
        gap: 0.4rem;
    }

    .logo-mark {
        flex: none;
    }

    .logo-text {
        font-size: 0.9rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topnav {
        flex: none;
        gap: 0.15rem;
    }

    .topnav-link {
        display: inline-flex;
        align-items: center;
        min-height: var(--tap);
        padding: 0.4rem 0.75rem;
        font-size: 0.88rem;
    }

    /* ---- Summary band ---- */
    .summary-title {
        font-size: clamp(1.5rem, 6.4vw, 2rem);
        line-height: 1.15;
    }

    .summary-total {
        font-size: 2.3rem;
    }

    .status-panel .btn-run,
    .status-panel .refresh-form {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* ---- Household size switch: slim and sticky under the top bar ---- */
    .dash .toolbar {
        position: sticky;
        top: var(--topbar-h);
        z-index: 15;
        margin-top: -1.2rem;
        padding: 0.35rem;
        border-radius: 14px;
    }

    .dash .toolbar .toolbar-note {
        display: none;
    }

    .dash .household-tabs {
        width: 100%;
        overflow: visible;
    }

    .tab,
    .dash .tab {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: var(--tap);
        padding: 0.45rem 0.35rem;
        line-height: 1.15;
        font-size: 0.9rem;
    }

    .size-note {
        display: block;
        margin: -0.75rem 0 1.5rem;
        padding: 0 0.25rem;
        text-align: center;
        font-size: 0.82rem;
        line-height: 1.4;
        color: var(--text-muted);
    }

    .section-title {
        font-size: 1.25rem;
    }

    .section-head {
        margin-bottom: 0.75rem;
    }

    .section-sub {
        gap: 0.4rem 1rem;
        flex-wrap: wrap;
    }

    /* ---- Store ranking cards ---- */
    .store-actions .btn {
        min-height: 48px;
    }

    .store-details-link {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: var(--tap);
        font-size: 0.9rem;
    }

    .store-tags .tag {
        font-size: 0.75rem;
    }

    /* ---- Item by item: one card per product instead of a wide table ---- */
    .compare-scroll {
        overflow: visible;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .compare {
        display: block;
        min-width: 0;
        font-size: 0.95rem;
    }

    .compare thead {
        display: none; /* store names are repeated on every cell via data-store */
    }

    .compare tbody {
        display: grid;
        gap: 0.75rem;
    }

    .compare tbody tr {
        display: block;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        overflow: hidden;
        box-shadow: var(--shadow);
    }

    .compare tbody tr:nth-child(even) {
        background: var(--card);
    }

    .compare .compare-item,
    .compare tbody tr:nth-child(even) .compare-item {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 0.75rem;
        position: static;
        padding: 0.7rem 0.9rem;
        background: var(--mist);
        border-bottom: 1px solid var(--border);
        white-space: normal;
        text-align: left;
    }

    .compare-qty {
        display: inline;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .compare .compare-cell {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 0.75rem;
        padding: 0.6rem 0.9rem;
        text-align: right;
        white-space: normal;
        border-bottom: 1px solid var(--border);
    }

    .compare .compare-cell:last-child {
        border-bottom: 0;
    }

    /* store name with its brand-colour dot, left of the price */
    .compare .compare-cell::before,
    .compare tfoot .compare-total::before {
        content: attr(data-store);
        grid-column: 1;
        grid-row: 1 / span 4;
        padding-left: 1.1rem;
        background: radial-gradient(circle at 4px 50%, var(--brand-color, var(--accent)) 0 4px, transparent 5px) no-repeat;
        font-size: 0.9rem;
        font-weight: 600;
        text-align: left;
        color: var(--text);
    }

    .compare .compare-cell > * {
        grid-column: 2;
    }

    .compare-price {
        font-size: 1.05rem;
    }

    .compare-was,
    .compare-bought,
    .compare-equiv,
    .compare-offer {
        font-size: 0.75rem;
    }

    .compare-offer {
        margin-left: auto;
    }

    .compare-missing {
        font-size: 1.1rem;
    }

    .compare tfoot {
        display: block;
        margin-top: 0.75rem;
        background: var(--mist);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        overflow: hidden;
    }

    .compare tfoot tr {
        display: block;
    }

    .compare tfoot th {
        display: block;
        padding: 0.7rem 0.9rem;
        background: var(--mist-deep);
        border-bottom: 1px solid var(--border);
    }

    .compare tfoot td {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 0.75rem;
        padding: 0.6rem 0.9rem;
        text-align: right;
        border-bottom: 1px solid var(--border);
    }

    .compare tfoot td:last-child {
        border-bottom: 0;
    }

    .compare tfoot .compare-total::before {
        grid-row: 1;
    }

    /* ---- Offer cards ---- */
    .deal-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .deal-link {
        display: inline-flex;
        align-items: center;
        min-height: var(--tap);
    }

    .explainer summary {
        min-height: var(--tap);
        display: flex;
        align-items: center;
    }

    .explainer {
        padding: 0.25rem 1rem;
    }

    /* ---- Detail / auto-load / history pages ---- */
    .detail-page .detail-header {
        padding: 0.75rem max(1rem, env(safe-area-inset-right)) 2.25rem max(1rem, env(safe-area-inset-left));
    }

    .back-link {
        display: inline-flex;
        align-items: center;
        min-height: var(--tap);
        margin-bottom: 0.25rem;
    }

    .detail-header h1 {
        font-size: 1.7rem;
        line-height: 1.15;
    }

    .detail-page .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .detail-summary {
        padding: 1rem;
        margin-top: -1.25rem;
    }

    .summary-total .amount {
        font-size: 2.1rem;
    }

    .detail-summary .btn-large,
    .autoload-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    .autoload-actions {
        flex-direction: column;
    }

    .autoload-note {
        padding: 0.9rem 1rem;
    }

    .chart-box {
        height: 300px;
    }

    .items-table-wrapper:has(.items-table--stack) {
        overflow: visible;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .items-table--stack,
    .items-table--stack tbody {
        display: block;
    }

    .items-table--stack thead {
        display: none;
    }

    .items-table--stack tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        padding: 0.7rem 0.9rem;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }

    .items-table--stack tbody tr:hover {
        background: var(--card);
    }

    .items-table--stack tbody td {
        display: grid;
        grid-template-columns: minmax(6rem, auto) 1fr;
        align-items: baseline;
        column-gap: 0.75rem;
        padding: 0.3rem 0;
        border: 0;
        text-align: left;
    }

    .items-table--stack tbody td::before {
        content: attr(data-label);
        grid-column: 1;
        grid-row: 1 / span 6;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-muted);
    }

    .items-table--stack tbody td > * {
        grid-column: 2;
        text-align: right;
    }

    .items-table--stack tbody td.cell-head,
    .items-table--stack tbody td.cell-name,
    .items-table--stack tbody td.cell-action {
        display: block;
        text-align: left;
    }

    .items-table--stack tbody td.cell-head::before,
    .items-table--stack tbody td.cell-name::before,
    .items-table--stack tbody td.cell-action::before,
    .items-table--stack tbody td.cell-index {
        display: none;
    }

    .items-table--stack tbody td.cell-head {
        font-weight: 700;
        font-size: 1.02rem;
    }

    .items-table--stack tbody td.cell-name {
        padding-bottom: 0.5rem;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid var(--border);
        color: var(--text);
    }

    .items-table--stack tbody td.cell-action {
        padding-top: 0.6rem;
    }

    .items-table--stack .item-link,
    .items-table--stack .item-search-link {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: var(--tap);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }

    .items-table--stack tfoot {
        display: block;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    .items-table--stack tfoot tr {
        display: flex;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.55rem 0.9rem;
        border-bottom: 1px solid var(--border);
    }

    .items-table--stack tfoot td {
        display: block;
        padding: 0;
        border: 0;
    }

    .items-table--stack tfoot td:empty {
        display: none;
    }

    .items-table--stack tfoot td[colspan] {
        flex: 1;
    }

    .footer {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    }
}

/* Very small phones */
@media (max-width: 360px) {
    .logo-version {
        display: none;
    }

    .topnav-link {
        padding: 0.4rem 0.6rem;
    }

    .summary-total {
        font-size: 2rem;
    }
}

/* Landscape phones: the sticky switch would eat too much of the short screen */
@media (max-width: 900px) and (max-height: 480px) {
    .dash .toolbar {
        position: static;
    }
}

/* ---- Update banner: shown across the top while the daily price scrape runs ---- */
.update-banner {
    background: color-mix(in srgb, var(--citrus) 30%, var(--surface));
    border-bottom: 1px solid color-mix(in srgb, var(--citrus) 60%, var(--border));
    color: var(--text);
}

.update-banner-inner {
    max-width: 72rem;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.update-banner-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.35;
}

.update-banner-text span {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.update-banner-pct {
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
}

.update-banner-bar {
    height: 6px;
    background: color-mix(in srgb, var(--citrus) 25%, transparent);
}

.update-banner-bar span {
    display: block;
    height: 100%;
    min-width: 6px;
    background: repeating-linear-gradient(135deg, var(--accent) 0 10px, color-mix(in srgb, var(--accent) 65%, #fff) 10px 20px);
    transition: width 0.4s ease;
}

@media (prefers-reduced-motion: no-preference) {
    .update-banner-bar span {
        background-size: 28px 28px;
        animation: banner-stripes 1s linear infinite;
    }
}

@keyframes banner-stripes {
    to { background-position: 28px 0; }
}

/* Info popup open: the page behind it must not scroll (also stops scroll chaining from the popup on phones). */
html:has(.intro-dialog[open]),
html:has(.intro-dialog[open]) body {
    overflow: hidden;
}

.intro-dialog {
    overscroll-behavior: contain;
}

/* ---- Shopping list page: real checkboxes, ticks kept on the device ---- */
.checklist-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1rem 0;
}

.checklist-count {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.checklist-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.check-list {
    list-style: none;
    margin: 0 0 2rem;
    padding: 0;
    display: grid;
    gap: 0.5rem;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 0.75rem 0 0;
}

.check-item label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
    min-height: var(--tap, 44px);
    padding: 0.6rem 0 0.6rem 0.75rem;
    cursor: pointer;
}

.check-item input[type="checkbox"] {
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.check-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-wrap: anywhere;
}

.check-amount {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.check-item .item-link {
    flex-shrink: 0;
    min-height: var(--tap, 44px);
    display: inline-flex;
    align-items: center;
}

.check-item.is-done .check-name {
    text-decoration: line-through;
    opacity: 0.55;
}

.check-item.is-done .check-amount {
    opacity: 0.55;
}

.detail-header .prices-at {
    font-size: 0.9rem;
    opacity: 0.9;
}

.add-item {
    margin: 0 0 2rem;
}

.add-item-label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
}

.add-item-row {
    display: flex;
    gap: 0.5rem;
}

.add-item-row input[type="text"] {
    flex: 1;
    min-width: 0;
    min-height: var(--tap, 44px);
    padding: 0 0.75rem;
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.item-remove {
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
    color: var(--text-muted);
}

/* ---- Donate button and popup ---- */
.donate-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--tap, 44px);
    margin: 0.75rem 0;
    padding: 0 1.1rem;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: color-mix(in srgb, var(--citrus) 28%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--citrus) 60%, var(--border));
    border-radius: 999px;
    cursor: pointer;
}

.donate-btn svg {
    color: #d6455d;
}

.donate-btn:hover {
    background: color-mix(in srgb, var(--citrus) 45%, var(--surface));
}

.donate-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
}

.footer-donate,
.footer .donate-btn {
    text-align: center;
}

/* ---- Brand line: the address next to the name ---- */
.logo-words {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.logo-domain {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0;
    opacity: 0.78;
    color: var(--citrus);
}

@media (max-width: 640px) {
    /* The top bar is tight on phones: the address stays in the footer and the page title. */
    .logo-domain {
        display: none;
    }
}

/* ---- Shopping list: prices and totals ---- */
.check-cost {
    display: block;
    margin-top: 0.1rem;
}

.check-price {
    font-variant-numeric: tabular-nums;
}

.check-unit {
    margin-left: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.check-item.is-done .check-cost {
    opacity: 0.55;
}

.check-totals {
    margin: 0 0 1.5rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.check-totals dl {
    margin: 0;
    display: grid;
    gap: 0.35rem;
}

.check-totals dl > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-variant-numeric: tabular-nums;
}

.check-totals dt {
    color: var(--text-muted);
}

.check-totals dd {
    margin: 0;
}

.check-totals .check-total {
    margin-top: 0.3rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-weight: 700;
    font-size: 1.1rem;
}

.check-totals .check-total dt {
    color: var(--text);
}

/* ---- Price disclaimer ---- */
.disclaimer {
    margin: 1.25rem 0;
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.footer .disclaimer {
    max-width: 52rem;
    margin: 1rem auto 0;
    text-align: left;
}

/* ---- Shopping list rows on one line: name, amount, pack, price. They wrap only when the screen is too narrow. ---- */
.check-text {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 0.75rem;
    row-gap: 0.1rem;
}

.check-text .check-name {
    flex: 1 1 11rem;
}

.check-text .check-amount,
.check-text .check-cost {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 0.4rem;
    margin: 0;
    white-space: nowrap;
}

.check-text .check-cost {
    min-width: 5.5rem;
    margin-left: auto;
    justify-content: flex-end;
}

.check-text .check-unit {
    margin-left: 0;
}

@media (max-width: 640px) {
    /* Phones: the name takes its own line, the amount and price share the next one. */
    .check-text .check-name {
        flex-basis: 100%;
    }

    .check-text .check-cost {
        margin-left: auto;
    }
}

@media (max-width: 640px) {
    /* The per-pack price is secondary: on a phone the amount and the line total stay on one line without it. */
    .check-text .check-unit {
        display: none;
    }

    .check-text .check-cost {
        min-width: 0;
    }
}

/* ---- Wide screens: header text lines up with the page content, and the list reads as columns ---- */
@media (min-width: 641px) {
    .detail-page .detail-header {
        padding-left: max(1.5rem, calc((100% - 1100px) / 2 + 1.5rem));
        padding-right: max(1.5rem, calc((100% - 1100px) / 2 + 1.5rem));
    }

    .check-text {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 13rem 11rem;
        column-gap: 0.75rem;
        align-items: baseline;
    }

    .check-text .check-amount {
        white-space: normal;
    }

    .check-text .check-cost {
        justify-content: flex-end;
        margin-left: 0;
        text-align: right;
    }
}

@media (min-width: 641px) {
    /* The price and the per-pack price stay on one line, right-aligned, so the prices form a column. */
    .check-text .check-cost {
        flex-wrap: nowrap;
    }
}

@media (min-width: 641px) {
    /* The line total sits at the right edge of its column (the per-pack price goes to its left), so totals line up. */
    .check-text .check-cost {
        flex-direction: row-reverse;
        justify-content: flex-start;
    }
}

/* The text block fills the whole row, so every row has the same columns. */
.check-item label .check-text {
    flex: 1 1 auto;
}

/* Phone menu */
.menu-btn {
    display: none;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    place-items: center;
}

.menu-bars,
.menu-bars::before,
.menu-bars::after {
    display: block;
    width: 1.2rem;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    content: "";
    position: relative;
}

.menu-bars::before {
    position: absolute;
    top: -6px;
}

.menu-bars::after {
    position: absolute;
    top: 6px;
}

.site-menu {
    max-width: var(--page-max, 1100px);
    margin: 0 auto;
    padding: 0.3rem 1.5rem 0.8rem;
    display: grid;
    gap: 0.1rem;
}

.site-menu[hidden] {
    display: none;
}

.site-menu a {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    color: rgba(244, 255, 248, 0.9);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.section-title {
    scroll-margin-top: 4.5rem;
}

.explainer {
    scroll-margin-top: 4.5rem;
}

@media (max-width: 640px) {
    .menu-btn {
        display: grid;
    }

    .topnav {
        display: none;
    }
}

@media (min-width: 641px) {
    .site-menu {
        display: none;
    }
}

/* Phone: per item show the cheapest, second cheapest and dearest store; «…» reveals the rest */
.compare-more-cell {
    display: none;
}

@media (max-width: 640px) {
    .compare tbody tr.compare-row {
        display: flex;
        flex-direction: column;
    }

    .compare .compare-item {
        order: 0;
    }

    .compare .compare-cell {
        order: calc(var(--rank, 99) * 2);
    }

    .compare tbody tr.compare-row .compare-cell.phone-hidden {
        display: none;
    }

    .compare tbody tr.compare-row.is-expanded .compare-cell.phone-hidden {
        display: grid;
    }

    .compare-more-cell {
        display: block;
        order: 5;
        border-bottom: 1px solid var(--border);
    }

    .compare-more {
        width: 100%;
        min-height: 2.75rem;
        border: 0;
        background: transparent;
        color: var(--accent);
        font-weight: 700;
        font-size: 0.95rem;
        cursor: pointer;
    }
}

/* Wide screens: five stores need the room */
:root {
    --page-max: 1100px;
}

@media (min-width: 1280px) {
    :root {
        --page-max: 1440px;
    }
}

/* Deal groups with more than two cards turn like the weekly-offers flyer */
.flyer-track > .deal {
    flex: 0 0 min(78%, 17rem);
    scroll-snap-align: start;
}

.deal-wrap {
    min-width: 0;
}

/* Today's best offers, grouped per store */
.offer-groups {
    display: grid;
    gap: 1.1rem;
}

.offer-group-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: 0 0 0.6rem;
    padding-left: 0.7rem;
    border-left: 4px solid var(--brand-color, var(--accent));
    font-size: 1.02rem;
}

.offer-group-count {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Price update: playful maintenance page */
.maint {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    padding: 1.2rem;
    background:
        radial-gradient(60rem 30rem at 15% 0%, rgba(120, 220, 120, 0.18), transparent 60%),
        radial-gradient(50rem 28rem at 90% 100%, rgba(242, 182, 0, 0.14), transparent 60%),
        #0a1c17;
    color: #f4fff8;
    overflow-y: auto;
}

.maint[hidden] {
    display: none;
}

body.maint-open {
    overflow: hidden;
}

.maint-card {
    width: min(34rem, 100%);
    text-align: center;
}

.maint-cart {
    position: relative;
    display: inline-block;
    color: #c7f26b;
    animation: maint-bob 2.4s ease-in-out infinite;
}

.maint-coin {
    position: absolute;
    top: -6px;
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: #f2b600;
    color: #0a1c17;
    font-weight: 800;
    font-size: 0.9rem;
    opacity: 0;
    animation: maint-coin 2.4s ease-in infinite;
}

.maint-coin-1 { left: 14px; animation-delay: 0s; }
.maint-coin-2 { left: 38px; animation-delay: 0.8s; }
.maint-coin-3 { left: 60px; animation-delay: 1.6s; }

.maint-title {
    margin: 1rem 0 0.4rem;
    font-family: var(--font-brand);
    font-size: clamp(1.5rem, 5vw, 2.1rem);
    letter-spacing: -0.02em;
}

.maint-sub {
    margin: 0 auto 1.2rem;
    max-width: 28rem;
    color: rgba(244, 255, 248, 0.78);
    line-height: 1.5;
}

.maint-bar {
    height: 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.maint-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4ade80, #c7f26b);
    transition: width 0.6s ease;
}

.maint-pct {
    margin: 0.5rem 0 1.4rem;
    font-size: 0.88rem;
    color: rgba(244, 255, 248, 0.7);
}

.maint-quote {
    min-height: 5.2rem;
    margin: 0 auto 1rem;
    padding: 0.9rem 1.1rem;
    max-width: 30rem;
    border-left: 4px solid #f2b600;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 1.05rem;
    line-height: 1.5;
    text-align: left;
}

.maint-quote.is-in {
    animation: maint-fade 0.6s ease both;
}

.maint-note {
    margin: 0 0 0.6rem;
    font-size: 0.8rem;
    color: rgba(244, 255, 248, 0.55);
}

.maint-peek {
    min-height: 2.75rem;
    padding: 0 1.1rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: transparent;
    color: #f4fff8;
    font-weight: 600;
    cursor: pointer;
}

@keyframes maint-bob {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-8px) rotate(2deg); }
}

@keyframes maint-coin {
    0% { opacity: 0; transform: translateY(-14px); }
    20% { opacity: 1; }
    80% { opacity: 1; transform: translateY(26px); }
    100% { opacity: 0; transform: translateY(32px); }
}

@keyframes maint-fade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .maint-cart, .maint-coin, .maint-quote.is-in {
        animation: none;
    }
}

/* Everything fits on one screen: no controls, the cards wrap like a plain grid */
.flyer.is-fit .flyer-controls,
.deal-wrap.is-fit .flyer-controls {
    display: none;
}

.flyer.is-fit .flyer-track,
.deal-wrap.is-fit .flyer-track {
    flex-wrap: wrap;
    overflow-x: visible;
}

/* Quiet pills: lowest price per unit / lowest paid at the till when that is not the ticked store */
.compare-tag {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Phone: item cards start as one summary line; a tap opens the stores */
.compare-summary,
.compare-chevron {
    display: none;
}

@media (max-width: 640px) {
    .compare .compare-item {
        flex-wrap: wrap;
        cursor: pointer;
        position: relative;
        padding-right: 2.2rem;
    }

    .compare-summary {
        display: block;
        flex: 1 0 100%;
        font-size: 0.82rem;
        font-weight: 500;
        color: var(--text-muted);
    }

    .compare-summary strong {
        color: var(--text);
    }

    .compare-chevron {
        display: block;
        position: absolute;
        right: 0.9rem;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.2s;
        color: var(--accent);
    }

    .compare tbody tr.compare-row.is-open .compare-chevron {
        transform: translateY(-50%) rotate(180deg);
    }

    .compare tbody tr.compare-row:not(.is-open) .compare-cell,
    .compare tbody tr.compare-row:not(.is-open) .compare-more-cell {
        display: none;
    }

    .compare tbody tr.compare-row:not(.is-open) .compare-item {
        border-bottom: 0;
    }
}

.intro-disclaimer {
    padding: 0.6rem 0.8rem;
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    background: var(--mist);
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* The two clear winners: cheapest for the requested amount (green) and cheapest per unit (blue) */
.compare-tag {
    display: block;
    width: fit-content;
    margin: 0.25rem 0 0 auto;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.compare-tag-qty {
    background: rgba(74, 222, 128, 0.18);
    border: 1px solid rgba(74, 222, 128, 0.6);
    color: #4ade80;
}

.compare-tag-unit {
    background: rgba(96, 165, 250, 0.16);
    border: 1px solid rgba(96, 165, 250, 0.6);
    color: #60a5fa;
}

:root[data-theme="light"] .compare-tag-qty { color: #15803d; }
:root[data-theme="light"] .compare-tag-unit { color: #1d4ed8; }
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .compare-tag-qty { color: #15803d; }
    :root:not([data-theme="dark"]) .compare-tag-unit { color: #1d4ed8; }
}

/* Cheapest for the requested amount AND per unit: a golden crown */
.compare-tag-crown {
    white-space: normal;
    text-align: left;
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(250, 204, 21, 0.18);
    border: 1px solid rgba(250, 204, 21, 0.75);
    color: #facc15;
}

:root[data-theme="light"] .compare-tag-crown { color: #a16207; }
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .compare-tag-crown { color: #a16207; }
}

/* Maintenance page memes */
.maint-meme {
    display: grid;
    gap: 0.3rem;
    justify-items: center;
    min-height: 9rem;
    margin: 0 auto 1rem;
    padding: 0.9rem 1rem;
    max-width: 30rem;
    border-radius: 10px;
    background: linear-gradient(160deg, #1c3a2c, #0d1f18);
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: center;
}

.maint-meme[hidden],
.maint-quote[hidden] {
    display: none;
}

.maint-meme.is-in {
    animation: maint-fade 0.6s ease both;
}

.maint-meme-top,
.maint-meme-bottom {
    font-family: var(--font-brand), "Segoe UI", system-ui, sans-serif;
    font-weight: 800;
    font-size: 1.05rem;
    line-height: 1.25;
    letter-spacing: 0.01em;
    color: #fff;
    /* a clean outline: stroke painted under the fill instead of four offset shadows */
    -webkit-text-stroke: 4px #000;
    paint-order: stroke fill;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.maint-meme-emoji {
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
    font-size: 2.4rem;
    line-height: 1.2;
    -webkit-text-stroke: 0;
    font-variant-emoji: emoji;
}

/* All stores in one row on wide screens; a golden crown on the cheapest */
@media (min-width: 1100px) {
    .ranking {
        grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
        gap: 0.8rem;
    }

    .ranking .store {
        padding: 1rem 0.9rem 1.05rem;
    }

    .ranking .store-top {
        gap: 0.5rem;
    }

    .ranking .store-name {
        font-size: 1rem;
    }
}

.store {
    position: relative;
}

.store-crown {
    position: absolute;
    top: -17px;
    right: 14px;
    color: #facc15;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
    transform: rotate(8deg);
    pointer-events: none;
}

/* The product-count pill stays on one line in the narrow one-row cards */
.ranking .tag {
    display: inline-block;
    white-space: nowrap;
}

/* One-row cards are narrow: the amounts go on their own line so the name and the tags never run under the price */
@media (min-width: 1100px) {
    .ranking .store-top {
        flex-wrap: wrap;
    }

    .ranking .store-id {
        flex: 1 1 0;
        min-width: 0;
    }

    .ranking .store-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .ranking .store-amounts {
        flex: 1 0 100%;
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .ranking .store-cash {
        margin: 0;
    }
}

/* Wide screens: the store names stay under the top bar while scrolling the item table */
@media (min-width: 1280px) {
    .compare-scroll {
        overflow: clip;
        overflow-clip-margin: 0;
    }

    .compare thead th {
        position: sticky;
        top: 3.9rem;
        z-index: 6;
        background: var(--card);
        box-shadow: 0 1px 0 var(--border);
    }

    .compare thead th.compare-item-col {
        left: 0;
        z-index: 7;
    }
}

/* Deal cards may shrink a little so that a row that is only slightly too wide needs no carousel */
.flyer.is-compact .flyer-track > .deal,
.deal-wrap.is-compact .flyer-track > .deal {
    flex: 1 1 13rem;
    min-width: 13rem;
}

/* In a real carousel the card in view is marked */
.flyer-track > .is-current {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}
