/* =================================================================
   Design tokens
   ================================================================= */
:root {
  /* Surfaces */
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* Text */
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  /* Brand (MSF orange, warmer & more vibrant) */
  --brand: #f97316;
  --brand-dark: #ea580c;
  --brand-darker: #c2410c;
  --brand-light: #ffedd5;
  --brand-tint: #fff7ed;

  /* Status */
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 18px -4px rgba(15, 23, 42, 0.08), 0 4px 8px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 32px -8px rgba(15, 23, 42, 0.10), 0 8px 16px -8px rgba(15, 23, 42, 0.06);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-2xl: 24px;

  /* Spacing scale (4px base) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
  font-feature-settings: "cv11", "ss01";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.container { max-width: 1320px; margin: 0 auto; padding: 0 var(--s-6); }

/* =================================================================
   Sticky toolbar
   ================================================================= */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: var(--s-4) 0;
  margin-bottom: var(--s-6);
}
.toolbar-inner {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--s-3);
  align-items: center;
}
@media (max-width: 760px) {
  .toolbar-inner { grid-template-columns: 1fr; }
}
.brand-line {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}
.brand-line .logo {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  border-radius: var(--r-sm);
  font-weight: 800;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.brand-line h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-line .tag {
  background: var(--brand-light);
  color: var(--brand-darker);
  padding: 3px var(--s-3);
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.region-picker {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s ease;
  color: var(--text);
}
.region-picker:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); }
.region-picker .label-icon { font-size: 16px; }
.region-picker select {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding-right: var(--s-1);
}
.region-picker select:focus { outline: none; }

.btn {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: var(--r-md);
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.btn:hover:not(:disabled) {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* =================================================================
   Input panel
   ================================================================= */
.input-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-bottom: var(--s-6);
  box-shadow: var(--shadow-sm);
}
.input-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--s-3);
}
.input-panel-head h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
textarea {
  width: 100%;
  min-height: 90px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
  resize: vertical;
  background: var(--surface-2);
  color: var(--text);
  line-height: 1.7;
  transition: all 0.15s ease;
}
textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1); }
.source-badges {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-top: var(--s-3);
}
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--info-bg);
  border: 1px solid #bfdbfe;
  color: var(--info);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
}

/* =================================================================
   Section card
   ================================================================= */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6) var(--s-8);
  margin-bottom: var(--s-5);
  box-shadow: var(--shadow-sm);
  animation: fadeUp 0.4s ease backwards;
}
.section:nth-child(2) { animation-delay: 0.05s; }
.section:nth-child(3) { animation-delay: 0.10s; }
.section:nth-child(4) { animation-delay: 0.15s; }
.section:nth-child(5) { animation-delay: 0.20s; }
.section:nth-child(6) { animation-delay: 0.25s; }
.section:nth-child(7) { animation-delay: 0.30s; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.section-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: 6px;
}
.section-num {
  font-size: 11px;
  font-weight: 700;
  background: var(--brand-light);
  color: var(--brand-darker);
  padding: 3px 8px;
  border-radius: var(--r-sm);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}
.section-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.section-desc {
  color: var(--text-2);
  font-size: 13px;
  margin-bottom: var(--s-5);
  line-height: 1.6;
  max-width: 720px;
}

/* =================================================================
   Hero / TL;DR
   ================================================================= */
.hero {
  position: relative;
  background: linear-gradient(135deg, #fff 0%, var(--brand-tint) 60%, #fff5e8 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-8) var(--s-10);
  margin-bottom: var(--s-6);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: fadeUp 0.4s ease;
}
.hero::after {
  content: "";
  position: absolute;
  top: -80px;
  right: -80px;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(249, 115, 22, 0.08) 0%, transparent 70%);
  pointer-events: none;
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--brand-darker);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--s-3);
  position: relative;
}
.hero-eyebrow::before {
  content: "";
  width: 24px;
  height: 2px;
  background: var(--brand);
  border-radius: 2px;
}
.hero-headline {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: var(--s-2);
  line-height: 1.15;
  position: relative;
}
.hero-headline .winner {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subline {
  color: var(--text-2);
  font-size: 15px;
  margin-bottom: var(--s-6);
  position: relative;
}
.hero-share-bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: var(--s-2);
  max-width: 480px;
  position: relative;
}
.hero-share-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-dark) 100%);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.hero-share-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: var(--s-6);
  font-weight: 600;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-5);
  position: relative;
  padding-top: var(--s-5);
  border-top: 1px solid rgba(226, 232, 240, 0.6);
}
.hero-stat .label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-3);
  font-weight: 700;
  margin-bottom: 6px;
}
.hero-stat .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-stat .sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

/* =================================================================
   Chart layout
   ================================================================= */
.split {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--s-6);
  align-items: start;
}
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.chart-wrap {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3);
  height: 400px;
  position: relative;
}
.chart-wrap.tall { height: 360px; }

/* =================================================================
   Domain ranking table
   ================================================================= */
.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.rank-table th {
  text-align: left;
  color: var(--text-3);
  font-weight: 700;
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.rank-table td {
  padding: 14px var(--s-3);
  border-bottom: 1px solid var(--surface-3);
  vertical-align: middle;
}
.rank-table tr:last-child td { border-bottom: none; }
.rank-table tr.winner td {
  background: linear-gradient(90deg, var(--brand-light) 0%, transparent 80%);
}
.rank-table tr.winner td:first-child::after { content: " 🏆"; }
.rank-num {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  text-align: center;
  line-height: 24px;
  font-size: 11px;
  font-weight: 700;
  margin-right: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.rank-table tr.winner .rank-num {
  background: var(--brand);
  color: #fff;
}
.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

/* =================================================================
   MoM pill + sparkline (used in MoM table & hero)
   ================================================================= */
.mom-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.mom-up { background: var(--good-bg); color: var(--good); }
.mom-down { background: var(--bad-bg); color: var(--bad); }
.mom-flat { background: var(--surface-3); color: var(--text-3); }
.spark {
  display: inline-block;
  vertical-align: middle;
  margin-right: var(--s-2);
}

/* =================================================================
   Confidence badges + delta arrows (used in hero & cross-source)
   ================================================================= */
.conf-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.conf-high { background: var(--good-bg); color: var(--good); }
.conf-mid  { background: var(--warn-bg); color: var(--warn); }
.conf-low  { background: var(--bad-bg);  color: var(--bad);  }
.conf-none { background: var(--surface-3); color: var(--text-3); }
.delta-up   { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad);  font-weight: 600; }
.delta-flat { color: var(--text-3); }

/* =================================================================
   Misc
   ================================================================= */
.approx-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--warn-bg);
  border: 1px solid #fcd34d;
  color: var(--warn);
  border-radius: var(--r-sm);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  margin-left: var(--s-2);
}
.loading {
  text-align: center;
  padding: var(--s-12) var(--s-5);
  color: var(--text-3);
  font-size: 14px;
}
.skeleton {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: var(--s-3);
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--bad); font-size: 13px; padding: 6px 0; }
.empty-prompt {
  text-align: center;
  padding: var(--s-12) var(--s-5);
  color: var(--text-3);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
}
.empty-prompt .icon { font-size: 36px; margin-bottom: var(--s-3); opacity: 0.4; }
