/* Stats modal: the cluster that holds the HUD, the modal shell, the rail, and the shared parts of the views inside.
   The modal works like the Settings modal (fade 300ms, dim, cutout title behind the box), see docs/DESIGN_LANGUAGE.md. */

/* Cluster: the HUD sits here, at the bottom right. */
.stats-cluster {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 110;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
  max-width: calc(100vw - 48px);
  pointer-events: none;
}

.stats-cluster .shape-hud {
  position: static;
  right: auto;
  bottom: auto;
  flex: 0 0 auto;
  z-index: auto;
}

/* Stats modal. It works like the Settings modal (fade 300ms, dim, cutout title behind the box), see docs/DESIGN_LANGUAGE.md.
   The title STATS is Passion One drawn as a path (no font has to load); redraw it from fonts/passion-one-latin-400-normal.woff2 if the word changes.
   The three layers are siblings of the overlay for the same reason as the notes title (a blend mode only mixes inside its own stacking context). */
.stats-overlay, .stats-title-invert, .stats-title-fade {
  --stats-w: min(800px, calc(100vw - 48px));
  --stats-h: min(680px, calc(100vh - 200px));
  --stats-title-width: min(88vw, 300vh);
  --stats-title-height: calc(var(--stats-title-width) * 0.2995);
  --stats-title-left: calc(50vw - var(--stats-title-width) / 2);
  --stats-title-top: calc(50vh - var(--stats-title-height) / 2);
  --stats-title-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 119.8'%3E%3Cpath d='M71 3.4 67.3 33.3Q48.8 29 41.9 29Q33.1 29 33.1 36.1Q33.1 38.9 37.3 41.5Q41.5 44.1 47.5 47Q53.5 49.9 59.4 53.9Q65.4 57.9 69.6 65.4Q73.8 72.9 73.8 82.6Q73.8 100.4 64.3 110.1Q54.8 119.8 37.3 119.8Q19.8 119.8 3.2 114.4L5.2 86.5Q25.2 92.3 33.1 92.3Q40.9 92.3 40.9 85.4Q40.9 81.9 36.7 78.9Q32.5 75.9 26.5 72.9Q20.6 69.9 14.5 66Q8.4 62.1 4.2 54.6Q0 47.1 0 36.8Q0 20.2 9.7 10.1Q19.4 0 36.4 0Q53.3 0 71 3.4ZM152.5 30.1H130.8V117.9H98.9V30.1H75.9L77.8 1.9H154.4ZM245 117.9H213.8L210.3 99.6H188.2L184.7 117.9H155L176.3 1.9H223.7ZM206.7 77.8 200.2 36.3H198.9L192.3 77.8ZM322.2 30.1H300.6V117.9H268.6V30.1H245.6L247.5 1.9H324.1ZM397.2 3.4 393.5 33.3Q375 29 368 29Q359.3 29 359.3 36.1Q359.3 38.9 363.5 41.5Q367.7 44.1 373.6 47Q379.6 49.9 385.6 53.9Q391.6 57.9 395.8 65.4Q400 72.9 400 82.6Q400 100.4 390.5 110.1Q380.9 119.8 363.5 119.8Q346 119.8 329.3 114.4L331.4 86.5Q351.4 92.3 359.3 92.3Q367.1 92.3 367.1 85.4Q367.1 81.9 362.9 78.9Q358.7 75.9 352.7 72.9Q346.7 69.9 340.7 66Q334.6 62.1 330.4 54.6Q326.2 47.1 326.2 36.8Q326.2 20.2 335.9 10.1Q345.6 0 362.5 0Q379.4 0 397.2 3.4Z'/%3E%3C/svg%3E");
}

.stats-overlay { position:fixed; inset:0; z-index:200; display:flex; align-items:center; justify-content:center; pointer-events:none; }
.stats-overlay[hidden] { display:none; }
.stats-dim { position:fixed; inset:0; z-index:197; pointer-events:none; background:var(--bg-color); opacity:0; transition:opacity 0.3s var(--ease-out-quart); }
.stats-overlay.is-open ~ .stats-dim { opacity:var(--opacity-dim-deep); }
.stats-overlay[hidden] ~ .stats-dim { display:none; }
.stats-title-invert { position:fixed; inset:0; z-index:198; pointer-events:none; background:var(--text-color); mix-blend-mode:difference; opacity:0; transition:opacity 0.3s var(--ease-out-quart);
  -webkit-mask-image: var(--stats-title-mask); mask-image: var(--stats-title-mask);
  -webkit-mask-repeat:no-repeat; mask-repeat:no-repeat;
  -webkit-mask-size:var(--stats-title-width) auto; mask-size:var(--stats-title-width) auto;
  -webkit-mask-position:var(--stats-title-left) var(--stats-title-top); mask-position:var(--stats-title-left) var(--stats-title-top); }
.stats-overlay.is-open ~ .stats-title-invert { opacity:1; }
.stats-overlay[hidden] ~ .stats-title-invert { display:none; }
.stats-title-fade { position:fixed; inset:0; z-index:199; pointer-events:none; background:var(--bg-color); opacity:0; transition:opacity 0.3s var(--ease-out-quart);
  -webkit-mask-image: var(--stats-title-mask); mask-image: var(--stats-title-mask);
  -webkit-mask-repeat:no-repeat; mask-repeat:no-repeat;
  -webkit-mask-size:var(--stats-title-width) auto; mask-size:var(--stats-title-width) auto;
  -webkit-mask-position:var(--stats-title-left) var(--stats-title-top); mask-position:var(--stats-title-left) var(--stats-title-top); }
.stats-overlay.is-open ~ .stats-title-fade { opacity:calc(1 - var(--opacity-dim-faint)); }
.stats-overlay[hidden] ~ .stats-title-fade { display:none; }

.stats-modal { position:relative; z-index:1; pointer-events:auto; display:flex; flex-direction:row; width:var(--stats-w); height:var(--stats-h); overflow:hidden; background:var(--panel-bg-solid); border:1px solid var(--panel-border); border-radius:12px; box-shadow:var(--shadow-panel); color:var(--text-color); outline:none; opacity:0; transition:opacity 0.3s var(--ease-out-quart); }
.stats-overlay.is-open .stats-modal { opacity:1; }
.stats-rail { flex:0 0 176px; box-sizing:border-box; padding:24px 12px 24px 16px; border-right:1px solid var(--divider); overflow-y:auto; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:var(--border-strong) transparent; }
.stats-rail-group + .stats-rail-group { margin-top:18px; }
.stats-rail-label { padding:0 8px 6px; font-family:var(--font-title); font-size:calc(var(--font-xs) * 2); font-weight:400; letter-spacing:0.1em; text-transform:uppercase; opacity:calc(var(--opacity-faint) / 2); }
.stats-rail-button { appearance:none; display:block; width:100%; box-sizing:border-box; margin:0 0 2px; padding:6px 8px; border:1px solid transparent; border-radius:6px; background:transparent; color:var(--text-color); font:inherit; font-size:var(--font-sm); text-align:left; opacity:var(--opacity-muted); cursor:pointer; transition:opacity 90ms var(--ease-out-quart), background-color 90ms var(--ease-out-quart); }
.stats-rail-button:hover, .stats-rail-button:focus-visible { opacity:1; background:var(--surface-2); }
.stats-rail-button.is-selected { opacity:1; background:var(--surface-3); }
.stats-rail-button:focus-visible { outline:1px solid var(--text-color); outline-offset:1px; }
.stats-main { flex:1 1 auto; min-width:0; display:flex; flex-direction:column; }
.stats-scroll { flex:1 1 auto; min-height:0; margin-top:0; padding:24px 20px 24px 24px; overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-gutter:stable; scrollbar-color:var(--border-strong) transparent; }
.stats-subnav:not([hidden]) + .stats-scroll { padding-top:16px; }
.stats-scroll > :first-child { margin-top:0; }
@media (max-width: 640px) {
  .stats-modal { flex-direction:column; }
  .stats-rail { flex:0 0 auto; display:flex; gap:4px; padding:12px 16px; border-right:0; border-bottom:1px solid var(--divider); overflow-x:auto; overflow-y:hidden; }
  .stats-rail-group { display:flex; gap:4px; flex:0 0 auto; }
  .stats-rail-group + .stats-rail-group { margin-top:0; }
  .stats-rail-label { display:none; }
  .stats-rail-button { width:auto; margin:0; white-space:nowrap; }
}

/* Strips: the one segmented control for every selector (subview strip, History range and metric, shape picker, map-mode picker). */
.stats-subnav, .history-range-selector, .history-metric-selector, .stats-map-modes { display:flex; flex-wrap:wrap; gap:2px; box-sizing:border-box; padding:3px; border:1px solid var(--panel-border); border-radius:8px; background:var(--surface-1); }
.stats-subnav { flex:0 0 auto; margin:24px 20px 0 24px; }
.stats-subnav[hidden] { display:none; }
.variation-section > .history-metric-selector, .variation-section > .stats-map-modes { margin-top:8px; }
.stats-subnav-button { appearance:none; flex:1 1 auto; min-width:0; min-height:26px; padding:4px 8px; border:0; border-radius:6px; background:transparent; color:var(--text-color); font:inherit; font-size:var(--font-sm); font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; opacity:var(--opacity-muted); cursor:pointer; transition:opacity 90ms var(--ease-out-quart), background-color 90ms var(--ease-out-quart); }
.stats-subnav-button:hover, .stats-subnav-button:focus-visible { opacity:1; background:var(--surface-2); }
.stats-subnav-button.is-selected { opacity:1; background:var(--surface-3); }
.stats-subnav-button:focus-visible { outline:1px solid var(--text-color); outline-offset:1px; }

/* List buttons: the pair rows (Relationships). */
.relationship-pair-row { appearance:none; box-sizing:border-box; width:100%; margin:0; padding:6px 8px; border:1px solid var(--panel-border); border-radius:6px; background:var(--surface-1); color:var(--text-color); font:inherit; font-size:var(--font-sm); line-height:1.35; text-align:left; opacity:var(--opacity-muted); cursor:pointer; transition:opacity 90ms var(--ease-out-quart), background-color 90ms var(--ease-out-quart); }
.relationship-pair-row { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.relationship-pair-row + .relationship-pair-row { margin-top:4px; }
.relationship-pair-row:hover, .relationship-pair-row:focus-visible { opacity:1; background:var(--surface-2); }
.relationship-pair-row.is-selected { opacity:1; background:var(--surface-3); }
.relationship-pair-row:focus-visible { outline:1px solid var(--text-color); outline-offset:1px; }

.stats-total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--divider);
  font-size: var(--font-sm);
}

.stats-total-label {
  opacity: var(--opacity-muted);
}

.stats-total-value {
  font-size: var(--font-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-total-row:last-child,
.coverage-row:last-child { border-bottom: 0; }

/* The headline figure of a view (e.g. recognized samples) is large and leads the page. */
.stats-total-row.is-hero {
  align-items: flex-end;
  padding: 0;
  border-bottom: 0;
}

.stats-total-row.is-hero .stats-total-value {
  font-size: var(--font-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Cards and section heads inside the views (same look as the Settings cards). */
.stats-scroll > .variation-section { margin-top:12px; padding:14px 16px; background:var(--surface-1); border:1px solid var(--panel-border); border-radius:8px; }
.stats-modal .variation-section-head { padding-bottom:8px; margin-bottom:4px; border-bottom:1px solid var(--divider); font-size:calc(var(--font-xs) * 2); letter-spacing:0.1em; text-transform:uppercase; }
.stats-modal .variation-section-head > :first-child { font-family:var(--font-title); font-weight:400; opacity:var(--opacity-muted); }
.stats-modal .variation-range { font-size:var(--font-xs); letter-spacing:0; text-transform:none; opacity:var(--opacity-faint); }
.stats-overview-grid { display:block; margin-top:0; }

.stats-overview-note {
  margin-top: 10px;
  font-size: var(--font-xs);
  line-height: 1.4;
  opacity: var(--opacity-faint);
}

.stats-map-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: var(--font-xs);
  opacity: var(--opacity-muted);
}

.stats-map-scroll {
  max-height: 292px;
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}

.stats-map-scroll .heatmap-grid {
  min-width: max-content;
}

@media (max-width: 720px) {
  .stats-cluster {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
  }

  .stats-map-scroll {
    max-height: 230px;
  }
}
