:root {
  color-scheme: light;
  --ink: #14201a;
  --ink-muted: #52605a;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --border: #dde2d8;
  --accent: #1f7a5c;
  --accent-ink: #f6f7f4;
  --accent-soft: #dceae2;
  --danger: #a3402c;
  --caveat: #9a6a1f;
  --caveat-bg: #fdf3df;
  --caveat-ink: #4a3714;
  --font-body: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

/* System/browser preference only — no manual toggle, so this is the only place dark mode is
   decided. Every rule below styles through the tokens above, never a literal color, so
   redefining them here is enough to re-theme the whole site. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e7ece6;
    --ink-muted: #9baaa0;
    --bg: #0e1512;
    --surface: #141c18;
    --border: #28352d;
    --accent: #4fbe93;
    --accent-ink: #0e1512;
    --accent-soft: #17251e;
    --danger: #e0836c;
    --caveat: #e3aa66;
    --caveat-bg: #2a2113;
    --caveat-ink: #f0dcb8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
}

a { color: var(--accent); }

/* A baseline every more specific input/textarea rule below relies on — none of them set their
   own background or color, which is fine while --surface/--ink are near-white/near-black, but
   would mean invisible light-on-light (or dark-on-dark) text the moment those tokens flip. */
input, textarea, select {
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}

.site-header, .admin-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 2rem;
  flex-wrap: wrap;
}
/* A separate inner wrapper (rather than sizing .site-header itself) so the background/border
   still spans edge to edge while the logo and search stay centered at a sane reading width
   instead of stretching apart across the full viewport on a wide screen. */
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.1rem 2rem;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}
.brand span { color: var(--accent); }

.site-search { display: flex; gap: 0.6rem; flex: 1; max-width: 420px; }
.site-search input { flex: 1; min-width: 0; padding: 0.55rem 0.9rem; border: 1px solid var(--border); border-radius: 6px; }
.site-search button, .admin-nav button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  cursor: pointer;
}

.admin-nav { display: flex; align-items: center; gap: 1.2rem; }
.admin-nav a { text-decoration: none; color: var(--ink-muted); }
.admin-nav form { margin: 0; }
.admin-nav button { background: none; color: var(--ink-muted); border-color: var(--border); }

.site-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 2.5rem 2rem 4rem; }
.admin-main { max-width: 1240px; margin: 0 auto; padding: 2.5rem 2rem 4rem; }

/* width: fit-content so the border-bottom hugs the text instead of stretching across the
   full site-main width. No max-width on the h1/p themselves — they're free to use the full
   site-main column (960px) before wrapping; text-wrap: balance keeps a forced wrap even. */
.hero { padding: 1.5rem 0 2.2rem; border-bottom: 1px solid var(--border); width: fit-content; max-width: 100%; }
.hero h1 { font-family: var(--font-display); font-size: 2.5rem; line-height: 1.15; margin: 0 0 0.6rem; text-wrap: balance; }
.hero p { color: var(--ink-muted); font-size: 1.05rem; margin: 0; }

.guides-section { padding-top: 2.2rem; }
.guides-section h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin: 0 0 1.1rem;
}

.page-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.1rem; }
.page-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.page-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(20, 32, 26, 0.08); border-color: var(--accent); }
.tile-footer { display: flex; flex-direction: column; gap: 0.3rem; padding: 1.1rem 1.3rem 1.3rem; text-decoration: none; color: var(--ink); }
.page-card-category { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.page-card-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.page-card-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 0.6rem; font-size: 0.85rem; color: var(--ink-muted); }
.page-card-arrow { opacity: 0; transform: translateX(-4px); transition: opacity 0.12s ease, transform 0.12s ease; }
.page-card:hover .page-card-arrow { opacity: 1; transform: translateX(0); color: var(--accent); }

/* Tile slideshow: each .tile-slide is a full product (image + brand/price/buy link) toggled
   as one unit via [hidden] — display:flex below is an author rule and would otherwise beat
   the browser's default [hidden]{display:none} regardless of specificity, so that override is
   spelled out explicitly rather than assumed (bit me twice already elsewhere in this file).
   The whole slide — image, brand, price — is one link straight to Amazon; "View guide" on the
   card's footer below is the only way back to the guide page itself, kept deliberately separate. */
.tile-carousel { position: relative; }
.tile-slide { display: flex; flex-direction: column; }
.tile-slide[hidden] { display: none; }
.tile-slide-link { display: flex; flex-direction: column; color: inherit; text-decoration: none; }
.tile-slide-image { display: block; background: var(--bg); }
.tile-slide-image img { display: block; width: 100%; height: 150px; object-fit: contain; }
.tile-slide-image-empty { display: block; height: 150px; }
.tile-slide-info { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.7rem 1.1rem; border-top: 1px solid var(--border); }
.tile-slide-text { display: flex; flex-direction: column; min-width: 0; }
.tile-slide-brand { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-slide-price { font-weight: 700; font-size: 0.95rem; }
.tile-slide-cta {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
}
.tile-slide-link:hover .tile-slide-cta { filter: brightness(1.08); }

.tile-dots { position: absolute; top: 0.6rem; right: 0.6rem; display: flex; gap: 0.3rem; }
.tile-dot { width: 0.45rem; height: 0.45rem; padding: 0; border: none; border-radius: 999px; background: rgba(255, 255, 255, 0.6); box-shadow: 0 0 0 1px rgba(20, 32, 26, 0.25); cursor: pointer; }
.tile-dot.active { background: var(--accent); }

.ranking-header h1 { font-family: var(--font-display); font-size: 2rem; margin: 0.3rem 0; }
.ranking-header .intro { color: var(--ink-muted); max-width: 65ch; }

.ranking-list { list-style: none; margin: 2rem 0; padding: 0; display: flex; flex-direction: column; gap: 1.8rem; }
.ranking-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.6rem;
}

/* Top zone: media + the decision-critical summary (title, price, buy button), side by side
   and only as tall as this content needs — the old single grid row forced the image column
   to match the height of *everything* below it (specs, sentiment, etc.), which is what left
   a wall of empty space under a short image next to a tall text column. */
.ranking-top { display: flex; gap: 1.6rem; align-items: flex-start; flex-wrap: wrap; }

.ranking-media { position: relative; width: 220px; flex-shrink: 0; }
.ranking-number {
  position: absolute;
  top: -0.6rem;
  left: -0.6rem;
  z-index: 1;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.ranking-image-main {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  border-radius: 8px;
  overflow: hidden;
}
.ranking-image-main img { display: block; width: 100%; height: 220px; object-fit: contain; background: var(--bg); }
.ranking-image { width: 220px; height: 220px; object-fit: contain; background: var(--bg); border-radius: 8px; }
/* Reserves the image slot even with no photo — omitting the element entirely would collapse
   the space the summary column expects it to occupy. */
.ranking-image-empty { display: block; border: 1px dashed var(--border); }

.ranking-thumbs { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }
.ranking-thumb { padding: 0; border: 2px solid transparent; border-radius: 6px; background: none; cursor: pointer; line-height: 0; }
.ranking-thumb img { width: 42px; height: 42px; object-fit: contain; background: var(--bg); border-radius: 4px; }
.ranking-thumb.active { border-color: var(--accent); }

.ranking-summary { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 0.3rem; }
.ranking-summary h2 { margin: 0; font-size: 1.35rem; }
.ranking-summary .brand { color: var(--ink-muted); margin: 0 0 0.3rem; font-size: 0.9rem; }
.price-range { font-weight: 700; font-size: 1.4rem; color: var(--ink); margin: 0.3rem 0 0.6rem; }
.buy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  align-self: flex-start;
  padding: 0.85rem 1.6rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(31, 122, 92, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.buy-button:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(31, 122, 92, 0.38); }

/* Full-width zone below the top row — pros/cons lead since they're the fastest way to decide,
   the narrative fields (why it ranks here, caveats, sentiment) follow, and specs — reference
   material, not decision-driving — comes last. */
.ranking-details { margin-top: 1.4rem; padding-top: 1.4rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 1.1rem; }
.ranking-details h3 {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}
.ranking-note { color: var(--ink); }

.specs-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.specs-table tr + tr { border-top: 1px solid var(--border); }
.specs-table th, .specs-table td { text-align: left; padding: 0.35rem 0; }
.specs-table th { width: 40%; font-weight: 600; color: var(--ink-muted); padding-right: 1rem; }

.pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; background: var(--bg); border-radius: 8px; padding: 1rem 1.2rem; }
.pros-cons ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.pros-cons li { padding-left: 1.3rem; position: relative; font-size: 0.94rem; }
.pros-list li::before { content: "+"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.cons-list li::before { content: "–"; position: absolute; left: 0; color: var(--danger); font-weight: 700; }

.sentiment-summary { font-size: 0.94rem; color: var(--ink); margin: 0; }

.caveat-box {
  background: var(--caveat-bg);
  border-left: 3px solid var(--caveat);
  border-radius: 0 8px 8px 0;
  padding: 0.7rem 0.9rem;
  font-size: 0.92rem;
  color: var(--caveat-ink);
}
.caveat-box strong { color: var(--caveat); }

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 12, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 300;
}
/* Own display:flex above is an author rule and beats the browser's default
   [hidden]{display:none} regardless of specificity — has to be spelled out explicitly. */
.lightbox-backdrop[hidden] { display: none; }
.lightbox-image { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lightbox-close {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.28); }

.empty-state { color: var(--ink-muted); padding: 2rem 0; }

.site-footer { border-top: 1px solid var(--border); }
.site-footer p { max-width: 960px; margin: 0 auto; padding: 0.85rem 2rem; color: var(--ink-muted); font-size: 0.78rem; line-height: 1.5; }
.site-footer p + p { padding-top: 0; }
.site-footer a { color: inherit; text-decoration: underline; }

.legal-page { max-width: 70ch; }
.legal-page h1 { font-family: var(--font-display); font-size: 2rem; margin: 0 0 0.3rem; }
.legal-page .updated { color: var(--ink-muted); font-size: 0.85rem; margin: 0 0 1.8rem; }
.legal-page h2 { font-family: var(--font-display); font-size: 1.35rem; margin: 2.2rem 0 0.7rem; padding-top: 1.4rem; border-top: 1px solid var(--border); }
.legal-page h2:first-of-type { padding-top: 0; border-top: none; }
.legal-page p, .legal-page ul { margin: 0 0 1rem; }
.legal-page ul { padding-left: 1.3rem; }
.legal-page li { margin-bottom: 0.4rem; }
.legal-page .toc { color: var(--ink-muted); font-size: 0.9rem; margin: 0 0 2rem; }
.legal-page .toc a { margin-right: 1.2rem; }

/* --- Admin --- */
.admin-table { width: 100%; border-collapse: collapse; margin: 1rem 0 2rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.admin-table .actions { display: flex; align-items: center; gap: 0.6rem; }
.admin-table .actions a { margin-right: 0.8rem; }
.admin-table .actions form { margin: 0; }

.commission-form { max-width: 640px; }
.commission-import-form { max-width: 640px; }
.commission-import-form textarea { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.82rem; }
.commission-rates { border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem 0.3rem; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.7rem 1rem; }
.commission-rates legend { padding: 0 0.4rem; font-size: 0.85rem; color: var(--ink-muted); }
.commission-rate-field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--ink-muted); }

.commission-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin: 1rem 0 1.2rem; }
.commission-toolbar-actions { display: flex; gap: 0.6rem; }
.country-select-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--ink-muted); min-width: 280px; }
.country-select-form select { padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; color: var(--ink); background: var(--surface); }

.rate-fallback { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; }

/* Condensed country/rate view — one row per distinct rate rather than one row per category,
   the same "6.00%: category, category, category" shape Amazon's own rate sheets use, instead
   of a giant per-category table. */
.rate-tiers { display: flex; flex-direction: column; margin: 1rem 0 1.5rem; }
.rate-tier { display: grid; grid-template-columns: 4.5rem 1fr; gap: 0.8rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.rate-tier-rate { font-weight: 600; color: var(--ink); white-space: nowrap; }
.rate-tier-groups { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.rate-tier-excluded { margin-top: 0.6rem; border-top: 1px dashed var(--border); }
.rate-tier-excluded .rate-tier-rate { color: var(--ink-muted); font-weight: 400; }

.rate-chip {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  cursor: pointer;
}
.rate-chip:hover { border-color: var(--accent); color: var(--accent); }
.rate-tier-excluded .rate-chip { color: var(--ink-muted); }

.status-pill { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.status-draft { background: var(--caveat-bg); color: var(--caveat-ink); }
.status-published { background: var(--accent-soft); color: var(--accent); }

.item-edit-header { display: flex; gap: 1.2rem; align-items: center; margin: 0.8rem 0 1.8rem; }
.item-edit-header h1 { font-size: 1.4rem; margin: 0 0 0.3rem; }
.item-edit-form { max-width: 720px; }

.image-manager { max-width: 720px; margin-bottom: 2rem; padding-bottom: 1.8rem; border-bottom: 1px solid var(--border); }
.image-manager h2 { font-size: 1.05rem; margin: 0 0 0.3rem; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.9rem; margin: 1rem 0; }
.image-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  background: var(--surface);
}
.image-tile-primary { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.image-tile img { width: 100%; height: 96px; object-fit: contain; background: var(--bg); border-radius: 4px; }
.image-tile form { margin: 0; }
.image-tile .button-secondary, .image-tile .button-danger { width: 100%; padding: 0.3rem 0.5rem; font-size: 0.78rem; }
.image-primary-badge {
  align-self: flex-start;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.image-add-form { flex-direction: row; align-items: flex-end; max-width: none; margin-bottom: 0; }
.image-add-form label { flex: 1; }

.save-confirmation {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-size: 0.88rem;
  margin: 0 0 1rem;
}

.admin-form { display: flex; flex-direction: column; gap: 0.9rem; max-width: 480px; margin-bottom: 1.5rem; }
.admin-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--ink-muted); }
.admin-form input, .admin-form textarea { padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; color: var(--ink); }

/* Self-drawn suggestion list — see combobox.js for why this replaces <input list>/<datalist>. */
.combobox { position: relative; }
.combobox-input { width: 100%; box-sizing: border-box; }
.combobox-options {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.combobox-options[hidden] { display: none; }
/* .combobox-options .combobox-option (two classes) deliberately outranks ".admin-form button"
   (class + type) above — same fix as .rich-toolbar .rich-btn elsewhere in this file. Without
   it every option rendered as a solid accent-filled block instead of a quiet list row, since
   these buttons live inside .admin-form. */
.combobox-options .combobox-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.7rem;
  border: none;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.3;
  font-weight: 400;
  cursor: pointer;
}
.combobox-options .combobox-option:hover { background: var(--accent-soft); }
.combobox-group-label {
  padding: 0.5rem 0.7rem 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
}
.combobox-group-label:first-child { padding-top: 0.4rem; }

/* Chip/tag input — a comma-delimited list of keywords, each of which may itself contain
   spaces or hyphens (e.g. "pine-apple pizza" is one tag), so commas are the only real
   delimiter and Enter just commits whatever's currently typed. */
.tag-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.tag-editor:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.2rem 0.4rem 0.2rem 0.7rem;
  font-size: 0.82rem;
  white-space: nowrap;
}
.tag-chip-remove { background: none; border: none; cursor: pointer; color: var(--ink-muted); font-size: 0.95rem; line-height: 1; padding: 0 0.15rem; }
.tag-chip-remove:hover { color: var(--danger); }
/* .tag-editor .tag-editor-input (two classes) deliberately outranks ".admin-form input"
   above (class + type) so the boxed/bordered look stays on the outer .tag-editor container
   only — without it the text input would render as a second nested box. */
.tag-editor .tag-editor-input { flex: 1; min-width: 10ch; border: none; outline: none; background: transparent; padding: 0.2rem 0; font: inherit; color: var(--ink); }
/* font-family/font-size/line-height explicitly set — <button> doesn't inherit the page's type
   the way other elements do; without this every button on the site rendered in the browser's
   raw UA default (13.3px Arial, "normal" line-height) instead of the site's own font, which is
   what made a button sitting directly next to a same-row input (like the search bar below) end
   up visibly taller and differently-set than its neighbor. */
.admin-form button, .button-primary, .button-secondary, .button-danger {
  align-self: flex-start;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  font-weight: 600;
}
.button-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.button-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }

.rich-field { display: flex; flex-direction: column; max-width: 100%; }
.rich-field-label { font-size: 0.85rem; color: var(--ink-muted); margin-bottom: 0.35rem; }

/* Toolbar sits flush on top of the editable box — its own bottom border is the only line
   between them, and only the outer corners are rounded, so the two read as one control. Uses
   the .rich-toolbar .rich-btn compound selector (0,2,0) specifically to outrank the generic
   ".admin-form button" rule (0,1,1) above: without it, that rule's specificity wins over a
   bare ".rich-btn" (0,1,0) despite this block appearing later in the file, which is what made
   every toolbar button render as a solid accent-filled block instead of a quiet toolbar icon. */
.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
  padding: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}
.rich-toolbar-spacer { flex: 1; }
.rich-toolbar .rich-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.28rem 0.42rem;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  font-size: 0.72rem;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
}
/* SVG is an inline element by default and reserves a few px of descender space below its own
   baseline, same as a line of text would — with icon buttons sitting right next to each other
   that shows up as one icon looking a hair lower than its neighbor. display:block removes that
   reserved space so every icon centers on the same line regardless of what's next to it. */
.rich-toolbar .rich-btn svg { display: block; }
.rich-toolbar .rich-btn:hover:not(:disabled) { background: var(--surface); border-color: var(--border); color: var(--ink); }
.rich-toolbar .rich-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.rich-toolbar .rich-btn.rich-code-toggle { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
.rich-toolbar .rich-btn.rich-code-toggle.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.rich-editable {
  min-height: 4.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
}
.rich-editable:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.rich-editable p { margin: 0 0 0.6rem; }
.rich-editable p:last-child { margin-bottom: 0; }
.rich-editable ul, .rich-editable ol { margin: 0.3rem 0; padding-left: 1.3rem; }

.rich-code-mount .cm-editor {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  font-size: 0.85rem;
  min-height: 4.5rem;
  max-height: 22rem;
}
.rich-code-mount .cm-scroller { overflow: auto; }

.hint { color: var(--ink-muted); font-size: 0.85rem; }
.form-error, .form-errors { color: var(--danger); }
.form-errors { padding-left: 1.2rem; }
.callout { background: var(--caveat-bg); border: 1px solid var(--caveat); border-radius: 8px; padding: 0.8rem 1rem; margin: 1rem 0; font-size: 0.9rem; }

.builder-column { margin-bottom: 2.5rem; }
.builder-column h2 { font-size: 1.1rem; margin-top: 2rem; }
.builder-column h2:first-child { margin-top: 0; }

.ranked-section > h2 { font-size: 1.1rem; margin: 0 0 1rem; }

.add-product-bar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 1.2rem 0; }
.add-product-search { display: flex; gap: 0.6rem; flex: 1; min-width: 240px; margin: 0; }
.add-product-search input { flex: 1; padding: 0.55rem 0.8rem; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 0.9rem; line-height: 1.2; color: var(--ink); background: var(--surface); }

.search-result-row { display: flex; gap: 0.8rem; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.search-result-row img { width: 48px; height: 48px; object-fit: contain; }
.search-result-row div { flex: 1; display: flex; flex-direction: column; }
.search-result-row form { margin: 0; }

#manual-image-preview { width: 96px; height: 96px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; margin: -0.4rem 0 0.2rem; }

.ranked-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.ranked-item {
  display: grid;
  grid-template-columns: 1.2rem 1.5rem 48px 1fr auto auto;
  gap: 0.9rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 1rem;
}
.ranked-item form { margin: 0; }
/* Cursor lives on the handle alone, not the row — dragging is opt-in per gesture (see the
   mousedown/mouseup pair in edit.php's script) precisely so the rest of the row, including the
   title link, behaves like normal clickable/selectable content instead of a drag source. */
.drag-handle { color: var(--ink-muted); cursor: grab; }
.ranked-number { font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.ranked-thumb { width: 48px; height: 48px; object-fit: contain; background: var(--bg); border-radius: 6px; }
/* Reserves the same grid column as a real <img> — omitting the element entirely when a
   product has no image shifts every column after it into the wrong slot. */
.ranked-thumb-empty { display: block; border: 1px dashed var(--border); }
.ranked-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.ranked-meta strong { overflow-wrap: break-word; color: var(--ink); }
.ranked-meta:hover strong { color: var(--accent); }

.details-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.8rem;
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.details-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--ink-muted); }
.details-form textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; resize: vertical; }
.details-form > button { align-self: flex-start; }

.product-research { border: 1px solid var(--border); border-radius: 6px; padding: 0.8rem 1rem; }
.product-research summary { cursor: pointer; font-size: 0.88rem; font-weight: 600; color: var(--ink); }
.product-research > .hint { margin: 0.4rem 0 0.9rem; }

.research-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.research-card { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.research-card-wide { grid-column: 1 / -1; }
.research-card h4 { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted); font-weight: 600; }
.research-card textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; resize: vertical; }

.spec-rows, .list-rows { display: flex; flex-direction: column; gap: 0.4rem; }
.spec-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.4rem; }
.list-row { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; }
.spec-row input, .list-row input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 0.88rem; min-width: 0; }
.remove-row {
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.remove-row:hover { color: var(--danger); border-color: var(--danger); }
.add-row {
  align-self: flex-start;
  padding: 0.3rem 0.7rem;
  border: 1px dashed var(--border);
  background: none;
  border-radius: 6px;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 0.82rem;
}
.add-row:hover { color: var(--accent); border-color: var(--accent); }

.stat-row { display: flex; gap: 1rem; margin: 1.5rem 0; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.4rem; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--ink-muted); font-size: 0.82rem; }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-form { display: flex; flex-direction: column; gap: 1rem; width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; }
.login-form h1 { font-size: 1.3rem; margin: 0; }
.login-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--ink-muted); }
.login-form input { padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; }
.login-form button { padding: 0.6rem; border-radius: 6px; border: none; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }

.session-timer {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 100;
  font-variant-numeric: tabular-nums;
}
.session-timer-warning { border-color: var(--caveat); color: var(--caveat); font-weight: 600; }

/* Own display:flex here is an author-stylesheet rule, which beats the browser's default
   `[hidden] { display: none }` (a user-agent rule) regardless of selector specificity — so
   the [hidden] variant below has to be spelled out explicitly, or toggling .hidden in JS does
   nothing and the modal just stays visible always. */
.session-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 26, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.session-modal-backdrop[hidden] { display: none; }
.session-modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.6rem;
  max-width: 380px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}
.session-modal h2 { margin: 0 0 0.6rem; font-size: 1.15rem; }
.session-modal-body { color: var(--ink-muted); margin: 0 0 1.2rem; }
.session-modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }
.session-modal-extend {
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}

/* Generic modal, same [hidden]-override reasoning as .session-modal-backdrop above — own
   display:flex is an author rule and beats the browser's default [hidden] { display: none }
   regardless of specificity, so the [hidden] variant has to be spelled out here too. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 26, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 200;
  padding: 3rem 1rem;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 1.6rem;
  max-width: 640px;
  width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.3rem;
}
.modal-close:hover { color: var(--ink); }
.modal .admin-form, .modal .commission-import-form { max-width: none; }
.modal-actions { display: flex; gap: 0.6rem; align-items: center; }

@media (max-width: 720px) {
  .ranking-top { flex-direction: column; }
  .ranking-media { width: 100%; }
  .ranking-image-main img, .ranking-image { width: 100%; height: auto; max-height: 280px; }
  .buy-button { align-self: stretch; }
  .pros-cons { grid-template-columns: 1fr; }

  .ranked-item { grid-template-columns: 1.2rem 1.5rem 1fr; }
  .ranked-item .button-secondary, .ranked-item form { grid-column: 2 / -1; justify-self: start; }
  .spec-row { grid-template-columns: 1fr; }
  .research-grid { grid-template-columns: 1fr; }
  .item-edit-header { flex-direction: column; align-items: flex-start; }
}
