:root {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color-scheme: light dark;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background-color: var(--page-bg); background-image: var(--page-bg-image, none); background-size: var(--page-bg-size, auto); color: var(--text); }
a { color: var(--link); }

.brand-wrap { display: inline-flex; align-items: flex-start; gap: .35rem; width: max-content; }
.revision-label { font-size: .64rem; line-height: 1; opacity: .55; white-space: nowrap; margin-top: .12rem; }

.site-header { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto minmax(260px, 560px) auto; align-items: center; gap: .75rem; padding: .75rem clamp(.85rem, 3vw, 2rem); background: var(--header-bg); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px); }
.brand { justify-self: start; width: max-content; max-width: max-content; color: #18864b; font-size: 1.25rem; font-weight: 850; text-decoration: none; letter-spacing: -.03em; white-space: nowrap; padding: .55rem .78rem; border: 1px solid color-mix(in srgb, #18864b 45%, var(--border)); border-radius: 11px; background: color-mix(in srgb, var(--surface) 86%, #18864b 14%); box-shadow: var(--shadow-soft); transition: transform .15s ease, box-shadow .15s ease; }
.brand:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.theme-control { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.theme-picker-label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.theme-picker { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: .55rem .7rem; cursor: pointer; }
.page-shell { width: min(840px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.5rem) 0; }
.summary-shell { width: min(900px, calc(100% - 2rem)); }
.hero { padding: clamp(1.35rem, 3.8vw, 3rem); border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.hero h1, .summary-card h1 { margin: .2rem 0 1.05rem; line-height: 1.08; letter-spacing: -.035em; }
.hero h1 { font-size: clamp(1.8rem, 3.8vw, 3rem); max-width: 780px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 800; color: var(--muted); }
.topic-search { display: flex; gap: .6rem; max-width: 720px; }
.topic-search.compact { width: 100%; max-width: 560px; }
.topic-search input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 11px; padding: .78rem .9rem; font-size: .98rem; background: var(--input-bg); color: var(--text); }
.topic-search.compact input { padding: .58rem .72rem; }
.topic-search.compact .button { padding: .58rem .78rem; }
.button { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 11px; padding: .75rem .95rem; background: var(--accent); color: var(--accent-text); font-weight: 750; text-decoration: none; cursor: pointer; }
.button:disabled { opacity: .7; cursor: progress; }
.button.secondary { background: var(--soft); color: var(--text); border: 1px solid var(--border); }
.button.disabled { background: var(--soft); color: var(--muted); cursor: default; }
.recent-section { margin-top: 1.75rem; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.section-heading span { color: var(--muted); font-size: .83rem; }
.topic-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.topic-card { min-height: 82px; display: flex; align-items: end; padding: .9rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); text-decoration: none; font-weight: 750; box-shadow: var(--shadow-soft); transition: transform .15s ease, border-color .15s ease; overflow: hidden; }
.topic-card-with-image { display: grid; grid-template-rows: auto auto; align-items: stretch; padding: 0; container-type: inline-size; }
.topic-card-image { width: 100%; max-width: 100%; height: auto; max-height: 200cqw; object-fit: contain; display: block; background: var(--soft); }
.topic-card-placeholder { display: grid; place-content: center; width: 100%; min-height: 110px; max-height: 200cqw; color: var(--muted); font-size: 2rem; }
.topic-card-body { display: grid; gap: .38rem; padding: .78rem .85rem .9rem; }
.topic-card-title { display: block; align-self: end; }
.topic-card-text { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: .84rem; line-height: 1.38; font-weight: 500; }
.topic-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.empty-state { padding: 1.15rem; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-soft); }





.summary-card { padding: clamp(1.15rem, 3vw, 2.2rem); border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.summary-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.summary-card h1 { font-size: clamp(1.7rem, 3.4vw, 2.65rem); }
.summary-text { font-family: Georgia, "Times New Roman", serif; font-size: clamp(.98rem, 1.15vw, 1.08rem); line-height: 1.68; overflow-wrap: anywhere; }
.summary-text p:first-child { margin-top: 0; }
.summary-text img, .summary-text figure, .summary-text .infobox, .summary-text .thumb { max-width: 100%; height: auto; }
.summary-text table, .summary-text .navbox, .summary-text .metadata, .summary-text .reflist { display: none !important; }
.summary-text sup, .summary-text .reference, .summary-text .citation-needed { display: none !important; }
.wiki-topic-link { text-decoration-thickness: .08em; text-underline-offset: .15em; }
.summary-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.6rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.expand-status { margin-top: .75rem; color: var(--muted); min-height: 1.2em; }
.suggestion-list { display: grid; gap: .5rem; padding-left: 1.2rem; }
.error-message { color: var(--error); }
.loading-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; gap: 1rem; background: color-mix(in srgb, var(--page-bg) 82%, transparent); text-align: center; font-weight: 700; pointer-events: none; }
.loading-overlay[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin .75s linear infinite; margin: auto; }
.link-preview { position: absolute; z-index: 50; width: min(360px, calc(100vw - 24px)); padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: .92rem; line-height: 1.45; }
.link-preview[hidden] { display: none; }
.link-preview-image { width: 110px; max-width: 42%; height: auto; max-height: 150px; object-fit: contain; float: right; margin: 0 0 .55rem .7rem; border-radius: 9px; border: 1px solid var(--border); background: var(--soft); }
.link-preview strong { display: block; font-size: 1rem; margin-bottom: .35rem; }
.link-preview p { margin: 0 0 .5rem; }
.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; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
    .site-header { grid-template-columns: auto 1fr auto; }
    .theme-control { justify-self: end; }
    .header-search { grid-column: 1 / -1; grid-row: 2; max-width: none !important; }
}

@media (max-width: 650px) {
    .page-shell, .summary-shell { width: min(100% - 1rem, 900px); padding-top: .8rem; }
    .topic-search:not(.compact) { flex-direction: column; }
    .summary-heading { display: block; }
    .summary-actions .button { width: 100%; }
    .hero { border-radius: 16px; padding: 1.2rem; }
    .summary-card { border-radius: 16px; padding: 1rem; }
}


/* Revision 6 */
.summary-lead-image { margin: 0 0 1.15rem; }
.summary-lead-image img { display: block; width: auto; max-width: 100%; max-height: 430px; object-fit: contain; border-radius: 14px; background: var(--soft); }
.wikipedia-source-link { margin-left: auto; color: var(--muted); font-size: .84rem; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; opacity: .78; }
.wikipedia-source-link:hover { opacity: 1; color: var(--link); }
@media (max-width: 820px) { .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .topic-grid { grid-template-columns: 1fr; } .summary-heading { flex-direction: column; } .wikipedia-source-link { margin-left: 0; } }

/* Revision 8 - geographic card ranking */
.regional-heading { align-items: end; margin-bottom: .65rem; }
.regional-heading h2 { margin-bottom: .18rem; }
.regional-location { display: block; }
.regional-view-form { display: flex; align-items: center; gap: .45rem; }
.regional-view-form label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.regional-view-form select { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: .52rem .65rem; }
.regional-apply { padding: .52rem .72rem; }
@media (max-width: 650px) {
    .regional-heading { align-items: stretch; flex-direction: column; }
    .regional-view-form { width: 100%; }
    .regional-view-form select { flex: 1; min-width: 0; }
}

/* Revision 18: isolated Amazon diagnostic page */
.amazon-test-page {
    padding-bottom: 3rem;
}

.amazon-test-panel {
    margin-bottom: 1.25rem;
}

.amazon-status-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem 1rem;
    margin: 1rem 0;
    font-size: .92rem;
}

.amazon-warning,
.amazon-error-panel {
    border: 1px solid var(--border-color);
    border-radius: .75rem;
    padding: .9rem 1rem;
    margin-top: 1rem;
}

.amazon-test-form {
    margin-top: 1rem;
}

.amazon-product-image {
    object-fit: contain;
    background: #fff;
}

.amazon-price {
    display: block;
    font-weight: 700;
    margin-top: .35rem;
}

.amazon-label {
    display: block;
    margin-top: .5rem;
    font-size: .78rem;
    opacity: .68;
}

@media (max-width: 650px) {
    .amazon-status-grid {
        grid-template-columns: 1fr;
    }
}
