:root {
  --color-bg: #f7f7fb;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-muted: #5b5b6e;
  --color-accent: #2563eb;
  --color-border: #e4e4ee;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Header */
.site-header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 16px 0;
}

.header-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Sprint 7: site-wide nav + search box, present on every public page via
   partials/header.ejs. */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
}

.site-nav a {
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.site-nav a:hover {
  text-decoration: underline;
}

.site-search {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  max-width: 360px;
}

.site-search input[type='search'] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

.site-search button {
  background-color: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

.site-search button:hover {
  opacity: 0.9;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--color-text);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background-color: var(--color-accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.tagline {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.85rem;
}

/* Main content */
main {
  flex: 1;
  padding: 24px 16px 48px;
}

.page-intro {
  margin-bottom: 24px;
}

.page-intro h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
}

.page-intro p {
  margin: 0;
  color: var(--color-muted);
  max-width: 640px;
}

/* Product grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.product-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.product-card:hover,
.product-card:focus-within {
  box-shadow: 0 4px 14px rgba(26, 26, 46, 0.12);
  transform: translateY(-2px);
}

/* Sprint 7: the card used to be a single <a> wrapping everything. Tag pills
   now need their own links to /tags/:slug, and an <a> cannot nest inside
   another <a>, so .product-card is a plain container and
   .product-card-link is the (still large, still fully clickable) inner
   link covering rank/image/name/description -- tags live as siblings below
   it, inside the same bordered card. */
.product-card-link {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.product-rank {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: rgba(26, 26, 46, 0.85);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  z-index: 1;
}

.product-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #eceef7;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-image-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.85rem;
  padding: 8px;
}

.product-body {
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.product-name {
  margin: 0;
  font-size: 1.05rem;
  word-break: break-word;
}

.product-description {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.92rem;
  word-break: break-word;
}

/* Sprint 7: tag pills, shared by product cards, the product detail page,
   and the tag index page. On cards they sit outside .product-card-link so
   each pill can be its own link to /tags/:slug (see the comment on
   .product-card-link above for why). */
.product-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 14px;
}

.product-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 20px;
}

.tag-pill {
  display: inline-block;
  background-color: #eceef7;
  color: var(--color-accent);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-decoration: none;
}

.tag-pill:hover,
.tag-pill:focus-visible {
  background-color: #dde1f5;
  text-decoration: underline;
}

/* Sprint 7: archived-product notice on the detail page. */
.archived-notice {
  background-color: #fff3cd;
  border: 1px solid #f0d78c;
  color: #7a5b00;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

/* Sprint 7: /tags tag index page. */
.tag-index {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-index-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 8px 16px;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 600;
}

.tag-index-item:hover,
.tag-index-item:focus-visible {
  box-shadow: 0 2px 8px rgba(26, 26, 46, 0.1);
}

.tag-index-count {
  background-color: #eceef7;
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* "View more" link under a capped product grid (Sprint 5) */
.view-more {
  margin: 24px 0 0;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.view-more a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.view-more a:hover {
  text-decoration: underline;
}

/* Empty state */
.empty-state {
  background-color: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--color-muted);
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--color-text);
}

/* Error / 404 state */
.error-state {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
}

.error-state h1 {
  margin-top: 0;
}

.back-link {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.back-link:hover {
  text-decoration: underline;
}

/* Breadcrumb (product detail) */
.breadcrumb {
  margin: 16px 0;
}

.breadcrumb a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* Product detail page */
.product-detail {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  gap: 28px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
}

.product-detail-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #eceef7;
  border-radius: var(--radius);
  overflow: hidden;
}

.product-detail-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-detail-body {
  min-width: 0;
}

.product-rank-inline {
  display: inline-block;
  background-color: rgba(26, 26, 46, 0.85);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.product-detail-name {
  margin: 0 0 16px;
  font-size: 1.6rem;
  word-break: break-word;
}

.product-detail-summary {
  margin: 0 0 20px;
  color: var(--color-text);
}

.why-trending {
  margin-bottom: 24px;
}

.why-trending h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.why-trending p {
  margin: 0;
  color: var(--color-muted);
}

.amazon-cta {
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
}

.amazon-button {
  display: inline-block;
  background-color: #f0a30a;
  color: #1a1a2e;
  font-weight: 700;
  text-decoration: none;
  padding: 12px 24px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 1rem;
}

.amazon-button:hover {
  background-color: #d98f05;
}

.amazon-button-disabled {
  background-color: var(--color-border);
  color: var(--color-muted);
  cursor: not-allowed;
}

.affiliate-note {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--color-muted);
}

.affiliate-note-muted {
  opacity: 0.85;
}

/* Sprint 9: "Share this product" control on the product detail page. */
.share-section {
  margin-top: 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.share-button {
  display: inline-block;
  background-color: var(--color-surface);
  color: var(--color-accent);
  font-weight: 700;
  border: 1px solid var(--color-accent);
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.92rem;
}

.share-button:hover,
.share-button:focus-visible {
  background-color: var(--color-accent);
  color: #fff;
}

.share-feedback {
  color: var(--color-muted);
  font-size: 0.85rem;
  word-break: break-word;
}

@media (max-width: 640px) {
  .product-detail {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}

/* Static pages (About / Affiliate Disclosure / Privacy / Contact) */
.static-page {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 720px;
}

.static-page h1 {
  margin-top: 0;
}

.static-page p {
  color: var(--color-muted);
  line-height: 1.65;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 20px 0;
  background-color: var(--color-surface);
}

.site-footer p {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.85rem;
  text-align: center;
}

.footer-nav {
  text-align: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

.footer-nav a {
  color: var(--color-accent);
  text-decoration: none;
}

.footer-nav a:hover {
  text-decoration: underline;
}

.footer-nav-sep {
  margin: 0 8px;
  color: var(--color-border);
}

.disclosure-text {
  margin: 0 0 6px !important;
  font-weight: 600;
}

/* Small-screen safety net (grid already reflows via auto-fit, but keep
   spacing comfortable on narrow phones). */
@media (max-width: 400px) {
  .container {
    padding: 0 12px;
  }

  .page-intro h1 {
    font-size: 1.5rem;
  }
}
