:root {
  color-scheme: dark;
  --bg: #0f1318;
  --bg-deep: #090d11;
  --panel: rgba(20, 27, 34, 0.88);
  --panel-strong: rgba(25, 34, 43, 0.96);
  --line: rgba(152, 176, 201, 0.17);
  --line-strong: rgba(152, 176, 201, 0.28);
  --text: #edf3f8;
  --muted: #9ba9b7;
  --muted-low: #70808f;
  --accent: #28b39a;
  --accent-bright: #52d4bb;
  --blue: #72a7ff;
  --orange: #f08a4b;
  --red: #ff7d7d;
  --green: #7ee0bf;
  --mono: "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --sans: "Avenir Next", Inter, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  min-height: 100%;
  background: var(--bg-deep);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 2%, rgba(40, 179, 154, 0.17), transparent 31rem),
    radial-gradient(circle at 95% 13%, rgba(240, 138, 75, 0.12), transparent 28rem),
    linear-gradient(180deg, var(--bg-deep), var(--bg) 58%, #141b22);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.021) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.017) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 72%);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 18rem;
  height: 18rem;
  border-radius: 999px;
  opacity: 0.28;
  filter: blur(90px);
  pointer-events: none;
}

.ambient-one {
  top: 20%;
  left: -11rem;
  background: var(--accent);
}

.ambient-two {
  right: -10rem;
  bottom: 8%;
  background: var(--blue);
}

.topbar {
  display: flex;
  position: sticky;
  z-index: 10;
  top: 0;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 17, 0.84);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark {
  color: var(--orange);
  filter: drop-shadow(0 0 10px rgba(240, 138, 75, 0.48));
}

.brand-slash {
  color: var(--muted-low);
}

.brand-section {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.live-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font: 0.72rem var(--mono);
}

.live-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 14px rgba(240, 138, 75, 0.75);
}

.live-state.ready i {
  background: var(--accent);
  box-shadow: 0 0 14px rgba(40, 179, 154, 0.8);
}

.live-state.error i {
  background: var(--red);
  box-shadow: 0 0 14px rgba(255, 125, 125, 0.72);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  transition: 160ms ease;
}

.icon-button:hover {
  border-color: rgba(40, 179, 154, 0.55);
  color: var(--accent-bright);
  transform: translateY(-1px);
}

.icon-button.loading span {
  animation: spin 0.8s linear infinite;
}

main {
  width: min(100% - 32px, 1180px);
  min-width: 0;
  margin: 0 auto;
  padding: 56px 0 42px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 30px;
}

.hero-main {
  min-width: 0;
}

.back-button {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
  color: var(--accent-bright);
  background: transparent;
  cursor: pointer;
  font: 700 0.75rem var(--mono);
}

.back-button:hover {
  color: var(--text);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font: 750 0.69rem var(--mono);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  overflow-wrap: anywhere;
  margin-bottom: 12px;
  font-family: var(--serif);
  font-size: clamp(2.8rem, 7vw, 5.8rem);
  font-weight: 560;
  line-height: 0.96;
  letter-spacing: -0.045em;
}

.hero-copy {
  max-width: 42rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
}

.hero-copy strong {
  color: var(--text);
  font-weight: 650;
}

.open-target {
  display: inline-flex;
  margin-top: 13px;
  color: var(--accent-bright);
  font: 700 0.74rem var(--mono);
  text-decoration: none;
}

.open-target:hover {
  color: var(--text);
}

.back-button[hidden],
.open-target[hidden],
#traffic-explorer[hidden],
#detail-sections[hidden],
#page-breakdown-panel[hidden] {
  display: none;
}

.range-picker {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(7, 10, 14, 0.58);
}

.range-picker button {
  min-height: 38px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.79rem;
  font-weight: 700;
}

.range-picker button:hover {
  color: var(--text);
}

.range-picker button.active {
  color: #06120f;
  background: var(--accent);
  box-shadow: 0 4px 18px rgba(40, 179, 154, 0.25);
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status-banner[hidden] {
  display: none;
}

.status-banner strong,
.status-banner span {
  display: block;
}

.status-banner strong {
  margin-bottom: 2px;
  font-size: 0.92rem;
}

.status-banner span {
  color: var(--muted);
  font-size: 0.78rem;
}

.status-banner.error {
  border-color: rgba(255, 125, 125, 0.35);
}

.loader {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  border: 2px solid rgba(40, 179, 154, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.status-banner.error .loader {
  border: 0;
  border-radius: 0;
  animation: none;
}

.status-banner.error .loader::before {
  color: var(--red);
  content: "!";
  font: 900 1.2rem var(--mono);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  display: flex;
  min-height: 188px;
  flex-direction: column;
  padding: 19px;
  border-radius: 14px;
}

.metric-primary {
  border-color: rgba(40, 179, 154, 0.33);
  background:
    linear-gradient(140deg, rgba(40, 179, 154, 0.13), transparent 64%),
    var(--panel-strong);
}

.metric-label {
  color: var(--muted);
  font: 0.73rem var(--mono);
}

.metric-value {
  margin: 13px 0 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.055em;
}

.metric-primary .metric-value {
  color: var(--accent-bright);
}

.metric-delta,
.metric-context {
  min-height: 19px;
  margin-bottom: 14px;
  color: var(--muted);
  font: 0.71rem var(--mono);
}

.metric-delta.up {
  color: var(--green);
}

.metric-delta.down {
  color: var(--orange);
}

.metric-note {
  margin-top: auto;
  color: var(--muted-low);
  font-size: 0.72rem;
  line-height: 1.35;
}

.panel {
  border-radius: 16px;
  padding: 22px;
}

.trend-panel {
  margin-bottom: 16px;
}

.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.panel-heading.compact {
  margin-bottom: 15px;
}

.panel h2 {
  margin-bottom: 0;
  font-family: var(--serif);
  font-size: 1.42rem;
  font-weight: 600;
  line-height: 1.15;
}

.chart-legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font: 0.69rem var(--mono);
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 15px;
  height: 3px;
  border-radius: 99px;
}

.legend-visits {
  background: var(--accent);
}

.legend-views {
  background: var(--blue);
}

.trend-chart {
  position: relative;
  width: 100%;
  height: 250px;
  overflow: hidden;
}

.trend-chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.trend-chart .grid-line {
  stroke: rgba(152, 176, 201, 0.13);
  stroke-width: 1;
}

.trend-chart .area {
  fill: url("#visits-area");
}

.trend-chart .line-visits,
.trend-chart .line-views {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.trend-chart .line-visits {
  stroke: var(--accent);
  stroke-width: 3;
}

.trend-chart .line-views {
  stroke: var(--blue);
  stroke-width: 2;
  stroke-dasharray: 5 6;
  opacity: 0.78;
}

.trend-chart .point {
  fill: var(--panel-strong);
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted-low);
  font: 0.65rem var(--mono);
}

.empty-chart {
  display: grid;
  height: 100%;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font: 0.76rem var(--mono);
}

.explorer-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.traffic-panel {
  align-self: start;
  padding: 0;
  overflow: hidden;
}

.traffic-panel .panel-heading {
  margin: 0;
  padding: 22px 22px 17px;
  border-bottom: 1px solid var(--line);
}

.row-count {
  color: var(--muted);
  font: 0.69rem var(--mono);
  white-space: nowrap;
}

.traffic-list {
  display: grid;
}

.traffic-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 76px 110px 12px;
  gap: 10px;
  min-width: 0;
  min-height: 70px;
  align-items: center;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid rgba(152, 176, 201, 0.1);
  color: var(--text);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: 150ms ease;
}

.traffic-row:last-child {
  border-bottom: 0;
}

.traffic-row:hover,
.traffic-row:focus-visible {
  position: relative;
  z-index: 1;
  outline: none;
  background: rgba(40, 179, 154, 0.085);
  box-shadow: inset 3px 0 var(--accent);
}

.traffic-row.quiet {
  opacity: 0.55;
}

.traffic-rank {
  color: var(--muted-low);
  font: 0.67rem var(--mono);
}

.traffic-identity,
.traffic-stat {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.traffic-title {
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.traffic-subtitle {
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted-low);
  font: 0.64rem var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.traffic-stat {
  align-items: flex-end;
}

.traffic-stat b {
  color: var(--accent-bright);
  font: 750 0.82rem var(--mono);
}

.traffic-stat span {
  margin-top: 2px;
  color: var(--muted-low);
  font: 0.58rem var(--mono);
  white-space: nowrap;
}

.sparkline {
  display: block;
  width: 100%;
  height: 38px;
  overflow: visible;
}

.sparkline path {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.traffic-chevron {
  color: var(--muted-low);
  font-size: 1.25rem;
  transition: transform 150ms ease;
}

.traffic-row:hover .traffic-chevron,
.traffic-row:focus-visible .traffic-chevron {
  color: var(--accent-bright);
  transform: translateX(2px);
}

.insight-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr 0.9fr;
  gap: 16px;
  margin-bottom: 16px;
}

.table-panel {
  min-width: 0;
}

.rank-list {
  display: grid;
  gap: 8px;
}

.rank-row {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(152, 176, 201, 0.11);
  border-radius: 10px;
  background: rgba(7, 10, 14, 0.46);
}

.rank-action {
  padding: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.rank-action:hover,
.rank-action:focus-visible {
  outline: none;
  border-color: rgba(40, 179, 154, 0.5);
}

.rank-action:hover .rank-name,
.rank-action:focus-visible .rank-name {
  color: var(--accent-bright);
}

.rank-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--share);
  background: linear-gradient(90deg, rgba(40, 179, 154, 0.15), rgba(114, 167, 255, 0.03));
  pointer-events: none;
}

.rank-content {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 8px 10px;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.rank-name {
  text-decoration: none;
}

a.rank-name:hover {
  color: var(--accent-bright);
}

.rank-value {
  color: var(--muted);
  font: 0.72rem var(--mono);
  white-space: nowrap;
}

.empty-list {
  padding: 24px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font: 0.72rem var(--mono);
  text-align: center;
}

.audience-panel {
  margin-bottom: 18px;
}

.audience-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
}

.audience-group {
  min-width: 0;
}

.audience-group h3 {
  margin-bottom: 11px;
  color: var(--muted);
  font: 0.72rem var(--mono);
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.audience-pill {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.032);
  font-size: 0.75rem;
}

.audience-pill b {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.data-footer {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  padding: 0 4px;
  color: var(--muted-low);
  font: 0.64rem var(--mono);
}

.data-footer p {
  margin-bottom: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .explorer-grid {
    grid-template-columns: 1fr;
  }

  .insight-grid {
    grid-template-columns: 1fr 1fr;
  }

  .insight-grid .table-panel:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .topbar {
    min-height: 58px;
    padding: 0 16px;
  }

  .live-state span {
    display: none;
  }

  main {
    width: min(100% - 24px, 1180px);
    padding-top: 34px;
  }

  .hero {
    align-items: stretch;
    flex-direction: column;
    gap: 20px;
  }

  .range-picker {
    align-self: start;
  }

  .range-picker button {
    padding: 0 11px;
  }

  h1 {
    font-size: clamp(2.55rem, 14vw, 4.6rem);
  }

  .metric-grid,
  .insight-grid,
  .audience-grid {
    grid-template-columns: 1fr;
  }

  .insight-grid .table-panel:first-child {
    grid-column: auto;
  }

  .metric-card {
    min-height: 160px;
  }

  .panel {
    padding: 18px;
  }

  .traffic-panel {
    padding: 0;
  }

  .traffic-panel .panel-heading {
    padding: 18px 16px 14px;
  }

  .panel-heading {
    align-items: start;
    flex-direction: column;
    gap: 10px;
  }

  .trend-chart {
    height: 210px;
  }

  .traffic-row {
    grid-template-columns: 24px minmax(0, 1fr) auto 12px;
    gap: 8px;
    padding: 11px 12px;
  }

  .traffic-row .sparkline {
    grid-column: 2 / 4;
    grid-row: 2;
    height: 28px;
  }

  .traffic-stat {
    grid-column: 3;
    grid-row: 1;
  }

  .traffic-chevron {
    grid-column: 4;
    grid-row: 1;
  }

  .traffic-title {
    font-size: 0.78rem;
  }

  .audience-grid {
    gap: 20px;
  }

  .data-footer {
    flex-direction: column;
    gap: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
