@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url('/fonts/inter-var.woff2') format('woff2');
}

:root {
  --ground: #0a0c11;
  --panel: #12151c;
  --panel-raised: #191d27;
  --topbar: #0d0f15;
  --line: #232734;
  --paper: #e7e9ee;
  --paper-dim: #a2a8b8;
  --muted: #676d80;
  --accent: #4c7dff;
  --accent-dim: #3a5fcc;
  --accent-soft: rgba(76, 125, 255, 0.12);
  --ok: #2fbf71;
  --warn: #d9a441;
  --bad: #e5484d;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --ground: #f7f8fa;
  --panel: #ffffff;
  --panel-raised: #f3f4f7;
  --topbar: #ffffff;
  --line: #e3e5ea;
  --paper: #14161c;
  --paper-dim: #565c6d;
  --muted: #8a8f9e;
  --accent: #3563e9;
  --accent-dim: #2648b8;
  --accent-soft: rgba(53, 99, 233, 0.08);
  --ok: #17915a;
  --warn: #a86f1e;
  --bad: #cf2f34;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #f7f8fa;
    --panel: #ffffff;
    --panel-raised: #f3f4f7;
    --topbar: #ffffff;
    --line: #e3e5ea;
    --paper: #14161c;
    --paper-dim: #565c6d;
    --muted: #8a8f9e;
    --accent: #3563e9;
    --accent-dim: #2648b8;
    --accent-soft: rgba(53, 99, 233, 0.08);
    --ok: #17915a;
    --warn: #a86f1e;
    --bad: #cf2f34;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--paper);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code, .mono {
  font-family: 'SF Mono', 'Cascadia Mono', Consolas, 'IBM Plex Mono', monospace;
}

::selection { background: var(--accent); color: #fff; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */

.topbar-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 56px;
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-shrink: 0;
}

.wordmark .mark {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--accent);
  display: inline-block;
  margin-right: 1px;
}

.wordmark .name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--paper);
}

.wordmark .tag {
  font-size: 11.5px;
  color: var(--muted);
  display: none;
}
@media (min-width: 760px) {
  .wordmark .tag { display: inline; }
}

nav.nav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}
nav.nav::-webkit-scrollbar { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 56px;
  color: var(--paper-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  white-space: nowrap;
  font-family: inherit;
}

.nav-item:hover { color: var(--paper); }
.nav-item.active {
  color: var(--paper);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
/* Anchor-style nav items (real links to server-rendered pages, e.g. Genres)
   inherit the button look but must shed the default anchor underline/color. */
a.nav-item { text-decoration: none; }
a.nav-item:hover { text-decoration: none; }

/* Hamburger toggle: hidden on desktop, shown on mobile via the media query
   below. Three bars that morph into an X when the menu is open. */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle-bar {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--paper);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.nav-count {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}

.crawl-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--paper-dim);
  flex-shrink: 0;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.status-dot.stale { background: var(--warn); }
.status-dot.error { background: var(--bad); }

@media (prefers-reduced-motion: no-preference) {
  .status-dot.live { animation: pulse 2.2s ease-in-out infinite; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- main ---------- */

main {
  padding: 28px 32px 60px;
  max-width: 1240px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar .sub {
  font-size: 12px;
  color: var(--muted);
}

.view { display: none; }
.view.active { display: block; }

/* ---------- kpi tiles ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 15px 17px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.tile-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
  line-height: 1.2;
}

.tile-value .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.tile-value.accent-sonar { color: var(--accent); }
.tile-value.accent-gold { color: var(--warn); }
.tile-value.accent-bad { color: var(--bad); }
.tile-note { font-size: 11.5px; color: var(--paper-dim); }

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0 0 3px;
  letter-spacing: -0.005em;
}

.panel .panel-sub {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px;
  max-width: 68ch;
}

/* ---------- intro banner ---------- */

.intro-banner {
  background: linear-gradient(135deg, var(--accent-soft), transparent 65%);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 22px;
  position: relative;
}
.intro-banner h2 {
  font-size: 16.5px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  max-width: 62ch;
}
.intro-banner p {
  font-size: 12.5px;
  color: var(--paper-dim);
  margin: 0;
  max-width: 62ch;
  line-height: 1.6;
}
.intro-banner strong { color: var(--paper); font-weight: 600; }
.intro-dismiss {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.intro-dismiss:hover { color: var(--paper); }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-head .titles { margin-bottom: 0; }

/* ---------- controls ---------- */

.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--panel-raised); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }

.tab-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--paper-dim);
  cursor: pointer;
  border-radius: 6px;
}

.tab-btn:hover { color: var(--paper); }
.tab-btn.active {
  background: var(--panel);
  color: var(--paper);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-ghost {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-raised);
  color: var(--paper-dim);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--paper); border-color: var(--muted); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

select,
input[type="search"], input[type="text"], input[type="email"], input[type="password"] {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-raised);
  color: var(--paper);
  font-size: 13px;
  font-family: inherit;
}
input::placeholder { color: var(--muted); }
input[type="search"]:focus, input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-hero {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.filter-row .chip-active {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-dim);
  color: var(--paper);
}
.filter-row .chip-active button {
  background: none;
  border: none;
  color: var(--paper-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tag-chip-btn {
  font-family: inherit;
  font-size: 11.5px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-raised);
  color: var(--paper-dim);
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.tag-chip-btn:hover { border-color: var(--accent); color: var(--paper); }
.tag-chip-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tag-chip-btn .n { color: var(--muted); font-family: 'SF Mono', Consolas, monospace; }
.tag-chip-btn.active .n { color: rgba(255,255,255,0.75); }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

table { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--panel); }

thead th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-raised); }

td.rank {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  width: 26px;
}

td.island .title { color: var(--paper); font-weight: 500; }
td.island .sub {
  display: block;
  font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
}

td.value { width: 180px; }

.bar-cell { display: flex; align-items: center; gap: 9px; }
.bar-num {
  font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
  min-width: 56px;
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}
.bar-track { flex: 1; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.bar-fill.sonar { background: var(--accent); opacity: 0.8; }

.delta-up { color: var(--ok); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }
.delta-pct { color: var(--muted); font-size: 11px; margin-left: 4px; }

.empty-state {
  padding: 26px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.mono-cell { font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace; font-size: 12px; color: var(--paper-dim); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--paper-dim);
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 10%, transparent); }

.creator-link { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 500; }
.creator-link:hover { text-decoration: underline; }

/* ---------- pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- charts ---------- */

.chart-box { margin-top: 4px; }
.chart-caption { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }

/* ---------- detail drawer ---------- */

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 8, 0.5);
  z-index: 20;
}
.drawer-backdrop.open { display: block; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px -20px rgba(0,0,0,0.4);
  z-index: 21;
  padding: 22px 22px 32px;
  overflow-y: auto;
  transform: translateX(100%);
}
.drawer.open { transform: translateX(0); }
@media (prefers-reduced-motion: no-preference) {
  .drawer { transition: transform 0.2s ease; }
}

.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.drawer h3 { font-size: 16px; font-weight: 700; margin: 0 0 4px; text-wrap: balance; }
.drawer .meta { font-size: 11.5px; color: var(--muted); line-height: 1.6; }

.close-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 11px;
  flex-shrink: 0;
  font-weight: 500;
}
.close-btn:hover { color: var(--paper); border-color: var(--muted); }

.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 12px 0; }
.tag-chip {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--paper-dim);
  text-decoration: none;
  transition: border-color 0.12s ease, color 0.12s ease;
}
/* Chips are now links to the genre page - give them an interactive affordance. */
a.tag-chip:hover { border-color: var(--accent); color: var(--paper); text-decoration: none; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 14px 0 18px;
}
.metric-tile {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
.metric-tile .label { font-size: 10.5px; color: var(--muted); }
.metric-tile .value { font-size: 17px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- compare ---------- */

.compare-results { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.compare-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  gap: 12px;
}
.compare-result-item:hover { background: var(--panel-raised); }
.compare-result-item .name { font-size: 12.5px; }
.compare-result-item .name .code { color: var(--muted); font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace; font-size: 10.5px; margin-left: 6px; }
.compare-result-item .add-hint { font-size: 11px; color: var(--accent); flex-shrink: 0; }
.compare-result-item.disabled { cursor: default; opacity: 0.5; }
.compare-result-item.disabled .add-hint { color: var(--muted); }

.creator-summary { border-left: 3px solid var(--accent); }
.creator-summary h2 { font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace; }

#compare-table th { vertical-align: top; }
.compare-col-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.compare-col-code { font-size: 10.5px; color: var(--muted); font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace; margin-bottom: 6px; }
.compare-winner { color: var(--ok); font-weight: 700; }
.compare-row-label { color: var(--muted); white-space: nowrap; }

/* ---------- top bar right / auth ---------- */

.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--paper-dim);
  cursor: pointer;
  white-space: nowrap;
}
.check-label input { cursor: pointer; }

/* ---------- pro / upgrade ---------- */

.pro-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #1b1200;
  background: linear-gradient(135deg, #ffd76e, #f5a623);
  padding: 2px 7px;
  border-radius: 5px;
  flex-shrink: 0;
}
.nav-item.locked::after {
  content: '★';
  font-size: 9px;
  color: var(--warn);
  margin-left: 4px;
  vertical-align: super;
}
.upgrade-gate {
  text-align: center;
  padding: 34px 24px;
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%);
}
.upgrade-gate h2 { font-size: 18px; margin-bottom: 8px; }
.upgrade-gate .panel-sub { margin: 0 auto 16px; max-width: 46ch; }
.upgrade-perks {
  list-style: none;
  padding: 0;
  margin: 4px 0 18px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--paper-dim);
}
.upgrade-perks li::before { content: '✓ '; color: var(--ok); font-weight: 700; }
.upgrade-perks strong { color: var(--paper); }

.billing-toggle { display: flex; gap: 6px; margin: 12px 0 10px; }
.billing-opt {
  flex: 1;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.billing-opt.active { color: var(--paper); border-color: var(--accent); background: var(--accent-soft); }
.billing-save { font-size: 10px; color: var(--ok); font-weight: 700; margin-left: 3px; }
.upgrade-price { text-align: center; margin: 4px 0 14px; }
.price-num { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.price-unit { font-size: 14px; color: var(--muted); }
.price-sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ---------- homepage ---------- */

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

.hero {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 40px 34px;
  margin-bottom: 20px;
  overflow: hidden;
  background:
    radial-gradient(1200px 400px at 80% -20%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, var(--panel), var(--ground));
}
.hero-eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.hero-title {
  font-size: 34px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  max-width: 18ch;
  text-wrap: balance;
}
.hero-sub {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--paper-dim);
  max-width: 60ch;
  margin: 0 0 22px;
}
.hero-sub strong { color: var(--paper); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 28px; }
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.hero-stats > div { display: flex; flex-direction: column; gap: 2px; }
.hero-stat-num {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hero-stat-label { font-size: 11.5px; color: var(--muted); }

@media (min-width: 720px) {
  .hero-title { font-size: 42px; }
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 4px;
}
@media (min-width: 900px) {
  .home-grid { grid-template-columns: 1fr 1fr; }
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.feature-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  font: inherit;
  color: inherit;
}
.feature-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.feature-ico { font-size: 22px; margin-bottom: 8px; }
.feature-title { font-size: 14.5px; font-weight: 700; margin-bottom: 5px; }
.feature-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.pro-tag {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #1b1200;
  background: linear-gradient(135deg, #ffd76e, #f5a623);
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 4px;
}

.drawer-insight {
  margin: 12px 0 4px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-soft), transparent 80%);
  font-size: 13px;
  line-height: 1.6;
  color: var(--paper-dim);
  white-space: pre-wrap;
}
.drawer-insight.loading { color: var(--muted); font-style: italic; }
.drawer-insight.error { border-left-color: var(--bad); color: var(--bad); }
.drawer-insight::before {
  content: '✨ AI insight';
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.drawer-insight.loading::before, .drawer-insight.error::before { color: var(--muted); }

/* ---------- drawer action buttons ---------- */

#drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.drawer-action-btn {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--paper);
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.drawer-action-btn:hover { border-color: var(--muted); background: var(--panel); }
.drawer-action-btn:active { transform: translateY(1px); }
.drawer-action-btn:disabled { opacity: 0.5; cursor: default; }

/* AI insights: the hero action. Gradient, larger, unmistakable. */
.drawer-ai-btn {
  background: linear-gradient(135deg, #7c5cff, #a855f7 55%, #f5a623);
  border: none;
  border-radius: 9px;
  color: #fff;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px -4px rgba(124,92,255,0.5);
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.drawer-ai-btn:hover { filter: brightness(1.08); box-shadow: 0 6px 22px -4px rgba(124,92,255,0.65); }
.drawer-ai-btn:active { transform: translateY(1px); }
.drawer-ai-btn:disabled { opacity: 0.7; cursor: default; }
.ai-spark { filter: drop-shadow(0 0 4px rgba(255,255,255,0.6)); }

/* Secondary AI action (e.g. competitor compare): same family, quieter than the
   filled primary so "AI insights" stays the hero button. Outlined gradient. */
.drawer-ai-btn.secondary {
  background: rgba(124, 92, 255, 0.10);
  border: 1px solid rgba(124, 92, 255, 0.55);
  color: var(--paper);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.drawer-ai-btn.secondary:hover { background: rgba(124, 92, 255, 0.18); filter: none; box-shadow: none; }
.pro-pill {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 20px;
  background: linear-gradient(135deg, #7c5cff, #f5a623);
  color: #fff;
}

/* ---------- Pro page ---------- */

.nav-pro {
  color: #f5a623 !important;
  font-weight: 700;
}
.pro-page { max-width: 760px; margin: 0 auto; }
/* ---- account settings ---- */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.account-row:last-of-type { border-bottom: none; }
.account-label { color: var(--muted); }

.pro-hero {
  text-align: center;
  padding: 40px 24px 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 22px;
  background:
    radial-gradient(900px 300px at 50% -30%, rgba(245,166,35,0.12), transparent 60%),
    linear-gradient(180deg, var(--panel), var(--ground));
}
.pro-eyebrow {
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  color: #f5a623; margin-bottom: 12px;
}
.pro-title {
  font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 12px;
  text-wrap: balance;
}
@media (min-width: 720px) { .pro-title { font-size: 38px; } }
.pro-sub { font-size: 14.5px; line-height: 1.6; color: var(--paper-dim); max-width: 54ch; margin: 0 auto; }
.pro-price { margin: 6px 0 4px; }
.pro-price-num { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; }
.pro-price-unit { font-size: 16px; color: var(--muted); margin-left: 2px; }
.pro-price-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pro-cta-note { font-size: 11.5px; color: var(--muted); margin-top: 10px; min-height: 14px; }

.pro-compare {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.plan-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.plan-table th, .plan-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.plan-table thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.plan-table th:not(:first-child), .plan-table td:not(:first-child) { text-align: center; width: 110px; }
.plan-table tbody tr:last-child td { border-bottom: none; }
.plan-pro-col, .plan-table td.pro-col { color: var(--paper); font-weight: 600; background: rgba(245,166,35,0.06); }
.plan-table th.plan-pro-col { color: #f5a623; }
.plan-table td.chk { font-weight: 700; }
.plan-table td.chk:not(.muted) { color: var(--ok); }
.plan-table td.muted { color: var(--muted); }
.pro-footnote { text-align: center; font-size: 11.5px; color: var(--muted); margin: 18px 0 0; }

/* ---------- toast ---------- */

#toast-host {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--paper);
  box-shadow: 0 12px 40px -12px rgba(0,0,0,0.5);
}
.toast.error { border-left-color: var(--bad); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 0.2s ease; }
  .toast.leaving { animation: toast-out 0.3s ease forwards; }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- modal (auth) ---------- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 8, 0.6);
  z-index: 30;
}
.modal-backdrop.open { display: block; }
.modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 30px 90px -20px rgba(0,0,0,0.65);
  z-index: 31;
  padding: 28px 26px 24px;
}
.modal.open { display: block; }
@media (prefers-reduced-motion: no-preference) {
  .modal.open { animation: modal-in 0.16s ease; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.98); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-head h3 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }

/* Auth form: full-width, comfortable inputs, clear primary action. */
#auth-modal .panel-sub { margin: 6px 0 18px; font-size: 12.5px; line-height: 1.5; }
#auth-form input {
  width: 100%;
  padding: 11px 13px;
  font-size: 14px;
  margin-bottom: 10px;
  box-sizing: border-box;
}
#auth-submit, #upgrade-checkout {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  margin-top: 2px;
}
.auth-msg { font-size: 12.5px; margin-top: 12px; min-height: 16px; }
.auth-msg.error { color: var(--bad); }
.auth-msg.success { color: var(--ok); }
.auth-toggle { font-size: 12.5px; color: var(--muted); margin-top: 18px; text-align: center; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  text-decoration: underline;
}
.watchlist-remove {
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 3px 8px;
}
.watchlist-remove:hover { color: var(--bad); border-color: var(--bad); }

/* =========================================================================
   MOBILE  (<= 720px)
   The layout is desktop-first (min-width queries build upward). This block is
   the deliberate small-screen design: hamburger nav, no horizontal page
   scroll, and reflowed spacing.
   ========================================================================= */
@media (max-width: 720px) {
  /* Nothing should ever push the page wider than the viewport. Wide content
     (tables, tag rows) scrolls inside its own container, set up below. */
  html, body { max-width: 100%; overflow-x: hidden; }

  main { padding: 18px 16px 48px; max-width: 100%; }

  /* Belt-and-braces: no view/panel/hero may exceed the viewport, and long
     unbroken strings (island codes, URLs) wrap instead of pushing width. */
  .view, .panel, .hero, .hero-sub, .topbar { max-width: 100%; }
  .hero-sub, .panel, td, .creator-code, .mono { overflow-wrap: anywhere; }

  /* --- top bar --- */
  .topbar-nav { gap: 12px; padding: 0 14px; height: 52px; }
  .nav-toggle { display: flex; }
  .wordmark { flex: 1; min-width: 0; }
  .wordmark .name { font-size: 14px; }

  /* The nav collapses to a dropdown panel toggled by the hamburger. It's taken
     out of the flex row and absolutely positioned under the bar. */
  nav.nav {
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    background: var(--topbar);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.22s ease;
  }
  nav.nav.open { max-height: 80vh; overflow-y: auto; }

  .nav-item {
    height: auto;
    padding: 13px 18px;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    font-size: 14px;
    width: 100%;
  }
  .nav-item.active {
    border-bottom-color: var(--line);
    border-left-color: var(--accent);
    background: var(--panel);
  }

  /* Trim the top-right cluster so it fits: hide the crawl-status chip on very
     small screens (it's non-essential), keep the auth button + pro badge. */
  .topbar-right { gap: 8px; }
  .crawl-status { display: none; }
  .btn-ghost { padding: 6px 12px; font-size: 12px; }

  /* --- content reflow --- */
  /* Any horizontal strip of controls (metric tabs, filters, tag rows) scrolls
     inside itself rather than stretching the page. */
  .tab-row, .filter-row, .tag-row, .billing-toggle, #pro-billing-toggle {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-row::-webkit-scrollbar, .filter-row::-webkit-scrollbar { display: none; }

  /* Tables: never widen the page; scroll within their wrapper. The .table-wrap
     is the scroll container; if a table isn't wrapped, it still won't overflow
     the body because of overflow-x:hidden above, but wrapping is preferred. */
  .table-wrap, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }

  /* Topbars within views (page title + right-side action) stack. */
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Hero: less padding (40px 34px is huge on a phone), smaller type, full-width
     CTAs. The oversized horizontal padding was the main cause of content
     appearing to run off the right edge. */
  .hero { padding: 26px 18px; }
  .hero h1, h1 { font-size: 26px; line-height: 1.15; }
  .hero-cta { flex-direction: column; align-items: stretch; }
  .hero-cta .btn-primary, .hero-cta .btn-ghost { width: 100%; text-align: center; }

  /* Panels also carry generous desktop padding; trim it so their contents have
     room on narrow screens. */
  .panel { padding: 16px; }

  /* Two-column stat/card grids collapse to one. */
  .account-grid, .kpi-row, .stat-grid { grid-template-columns: 1fr; }

  /* The hero stat strip uses a big 30px gap that forces 4 columns wider than a
     phone before they wrap; shrink it so they wrap cleanly to 2 rows. */
  .hero-stats { gap: 16px 22px; }
  .hero-stat-num { font-size: 22px; }

  /* Drawer takes the full width on a phone. */
  .drawer { width: 100%; max-width: 100%; }

  /* Modals fit the viewport with margin. */
  .modal, .auth-modal, .upgrade-modal { width: calc(100% - 28px); max-width: 100%; }
}
