:root {
  --bg: #f8fafc;
  --bg-accent: #eef4ff;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --line: rgba(148, 163, 184, 0.2);
  --line-strong: rgba(71, 85, 105, 0.22);
  --text: #1e293b;
  --muted: #64748b;
  --muted-strong: #475569;
  --primary: #3b82f6;
  --primary-soft: #60a5fa;
  --accent: #f97316;
  --accent-soft: #fdba74;
  --emerald: #10b981;
  --indigo: #6366f1;
  --violet: #8b5cf6;
  --rose: #f43f5e;
  --slate: #94a3b8;
  --shadow: 0 20px 48px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.05);
  --radius-lg: 32px;
  --radius-md: 24px;
  --radius-sm: 18px;
  --sans: "Fira Sans", "Segoe UI", sans-serif;
  --mono: "Fira Code", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.13), transparent 32%),
    radial-gradient(circle at top right, rgba(249, 115, 22, 0.1), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 56%, #edf2f7 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
select,
a {
  font: inherit;
}

.page-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.hero,
.panel,
.stat-card,
.control-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.85fr);
  gap: 20px;
  padding: 28px;
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: auto -10% -30% auto;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(96, 165, 250, 0.25), transparent 66%);
  pointer-events: none;
}

.hero-copy,
.control-card {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero h1,
.panel h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.hero h1 {
  max-width: 12ch;
  font-size: clamp(2.2rem, 4vw, 4.1rem);
  line-height: 0.98;
}

.hero-text {
  max-width: 64ch;
  margin: 14px 0 0;
  color: var(--muted-strong);
  line-height: 1.7;
  font-size: 1.02rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.meta-chip {
  min-width: 220px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 6px;
}

.meta-chip span,
.stat-meta,
.control-note,
.legend-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.meta-chip strong {
  font-weight: 700;
}

.control-card {
  padding: 20px;
  border-radius: var(--radius-md);
  display: grid;
  gap: 14px;
  align-content: start;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 249, 255, 0.92));
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  color: var(--muted-strong);
  font-size: 0.86rem;
  font-weight: 700;
}

select,
.button {
  min-height: 48px;
  border-radius: 16px;
}

select {
  width: 100%;
  padding: 0 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: var(--panel-strong);
  color: var(--text);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  font-weight: 700;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
  cursor: pointer;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.24);
  outline-offset: 2px;
}

.button-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #2563eb);
  box-shadow: 0 14px 26px rgba(37, 99, 235, 0.2);
}

.button-secondary {
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}

.button[aria-disabled="true"],
.button.disabled {
  opacity: 0.55;
  pointer-events: none;
}

.error-banner {
  margin: 0 0 18px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(244, 63, 94, 0.18);
  background: rgba(255, 241, 242, 0.96);
  color: #9f1239;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.stats-grid,
.charts-grid,
.lists-grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 18px;
}

.stat-card {
  min-height: 138px;
  padding: 20px;
  border-radius: 24px;
  display: grid;
  gap: 10px;
  align-content: start;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.92));
}

.stat-label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.stat-card strong {
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1;
}

.charts-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.panel {
  border-radius: var(--radius-md);
  padding: 22px;
}

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

.panel-head h2 {
  font-size: 1.42rem;
  line-height: 1.1;
}

.chart-layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 20px;
  align-items: center;
}

.donut-chart {
  width: 220px;
  aspect-ratio: 1;
  border-radius: 999px;
  position: relative;
  background:
    conic-gradient(
      var(--slate) 0turn,
      rgba(148, 163, 184, 0.18) 0turn 1turn
    );
  margin: 0 auto;
  cursor: default;
}

.donut-chart::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.12);
}

.donut-center {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  padding: 20px;
}

.donut-center strong {
  font-family: var(--mono);
  font-size: 1.9rem;
}

.donut-center span {
  color: var(--muted);
  font-size: 0.92rem;
}

.donut-tooltip {
  position: fixed;
  z-index: 40;
  max-width: 280px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.22);
  pointer-events: none;
  display: grid;
  gap: 4px;
  transform: translate(14px, -50%);
}

.donut-tooltip strong {
  font-size: 0.94rem;
  line-height: 1.35;
}

.donut-tooltip span {
  color: rgba(241, 245, 249, 0.86);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.legend-list,
.ranked-list {
  display: grid;
  gap: 10px;
}

.legend-row,
.ranked-row {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(248, 250, 252, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.legend-row {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.legend-main,
.ranked-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex: 0 0 auto;
  margin-top: 3px;
}

.legend-name,
.ranked-name {
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.4;
  font-weight: 600;
}

.legend-value,
.ranked-value {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--muted-strong);
}

.legend-value {
  justify-self: start;
  padding-left: 22px;
  white-space: nowrap;
}

.lists-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.list-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 92px;
  gap: 12px;
  padding: 0 14px 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ranked-list {
  max-height: 720px;
  overflow: auto;
  padding-right: 4px;
}

.ranked-row {
  grid-template-columns: minmax(0, 1fr) 96px 92px;
  align-items: center;
}

.ranked-progress {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.ranked-progress-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--primary-soft));
}

.empty-state {
  padding: 18px;
  border-radius: 18px;
  background: rgba(248, 250, 252, 0.92);
  border: 1px dashed rgba(148, 163, 184, 0.3);
  color: var(--muted);
}

@media (max-width: 1240px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .charts-grid,
  .lists-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding-top: 18px;
  }

  .hero,
  .panel,
  .stat-card {
    border-radius: 24px;
  }

  .hero {
    padding: 20px;
  }

  .hero h1 {
    max-width: 100%;
    font-size: 2.2rem;
  }

  .hero-text {
    font-size: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-layout {
    grid-template-columns: 1fr;
  }

  .donut-chart {
    width: min(220px, 100%);
  }

  .list-head {
    display: none;
  }

  .ranked-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .meta-chip {
    min-width: 0;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
