/* The play-insights page: Material 3 cards on the site's dark theme (/styles.css).
   Chart colours: the categorical slots and the stage ramp (one blue, light → dark for Baby → Grown-up)
   were checked for colour-vision separation and contrast against the card surface (#202420). */
:root {
  --chart-surface: var(--surface);
  --ink: var(--text);
  --ink-secondary: #c3c2b7;
  --ink-muted: #9a9890;
  --grid: #343a33;
  --baseline: #4a5248;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-error: #e66767;
  --stage-0: #9ec5f4;
  --stage-1: #5598e7;
  --stage-2: #1c5cab;
  --stage-unknown: #6b6f68;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.insights-main { max-width: 1360px; }
.insights-heading { margin-bottom: 24px; }
.insights-heading > p:last-child { color: var(--muted); max-width: 70ch; }
#insights-gate h2 { font-size: 26px; margin-bottom: 8px; }
#insights-gate p { color: var(--muted); margin-bottom: 16px; }

/* The range (a segmented button), refresh and status: one row above everything they scope. */
.insights-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 8px 0 20px; }
.segmented { display: inline-flex; border: 1px solid #71836a; border-radius: 24px; overflow: hidden; }
.segmented button { min-height: 44px; min-width: 64px; padding: 8px 16px; border: 0; background: transparent; color: var(--text); font-weight: 600; }
.segmented button + button { border-left: 1px solid #71836a; }
.segmented button[aria-pressed="true"] { background: #35412f; color: var(--green); }
.segmented button[aria-pressed="true"]::before { content: "✓ "; font-weight: 700; }
.segmented button:hover { background: #2c3628; }
#insights-status { color: var(--muted); font-size: 13px; }
#insights { transition: opacity .2s; }
#insights.busy { opacity: .55; }

/* Stat tiles: one hero figure (players), then the rest. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { padding: 16px 18px; border: 1px solid var(--outline); border-radius: 20px; background: var(--chart-surface); }
.tile dt { color: var(--ink-secondary); font-size: 13px; }
.tile dd { margin: 4px 0 0; font-size: 28px; font-weight: 600; line-height: 1.2; }
.tile.hero dd { font-size: 48px; }

/* Cards. */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 16px; align-items: start; }
.insight-card { min-width: 0; padding: 20px 22px; border: 1px solid var(--outline); border-radius: 24px; background: var(--chart-surface); }
.insight-card h2 { font-size: 22px; letter-spacing: -0.03em; }
.insight-card h3 { font-size: 15px; letter-spacing: 0; margin: 0 0 6px; color: var(--ink-secondary); font-family: inherit; }
.insight-sub { margin-top: 4px; color: var(--ink-secondary); font-size: 13px; }
.insight-empty { margin-top: 12px; color: var(--ink-muted); font-size: 14px; }
.insight-card > :is(.legend, .columns, .bar-list, .table-scroll, .share-grid, .error-list) { margin-top: 14px; }

/* Legend: a swatch that mirrors the mark (a box for bars, a stroke for lines). */
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; list-style: none; font-size: 13px; color: var(--ink-secondary); }
.legend li { display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; flex: none; }
.key-box { width: 12px; height: 12px; border-radius: 3px; background: var(--key); }
.key-line { width: 16px; height: 2px; border-radius: 1px; background: var(--key); }
.series-1 { --key: var(--series-1); }
.series-2 { --key: var(--series-2); }
.series-error { --key: var(--series-error); }
.stage-0 { --key: var(--stage-0); }
.stage-1 { --key: var(--stage-1); }
.stage-2 { --key: var(--stage-2); }
.stage-unknown { --key: var(--stage-unknown); }

/* Columns per day, with an optional line in the same unit. */
.columns { --plot-h: 160px; }
.plot { position: relative; height: var(--plot-h); margin-left: 52px; border-bottom: 1px solid var(--baseline); }
.tick { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--grid); }
.tick span { position: absolute; right: calc(100% + 8px); top: -9px; font-size: 11px; color: var(--ink-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
/* (Each day gets an equal slot, the same slots the line's points sit in; the bar is centred in it.) */
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.col { flex: 1 1 0; min-width: 0; height: 100%; padding: 0 1px; display: flex; align-items: flex-end; justify-content: center; }
.col:hover .bar { filter: brightness(1.25); }
.bar { width: 100%; max-width: 24px; min-height: 0; border-radius: 4px 4px 0 0; background: var(--key); }
.bars.dense .bar { border-radius: 2px 2px 0 0; }
.line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.line polyline { fill: none; stroke: var(--key); stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
.x-labels { display: flex; justify-content: space-between; margin: 6px 0 0 52px; font-size: 11px; color: var(--ink-muted); }

/* Horizontal bars: label, bar from a shared baseline, value at the tip. */
.bar-list { display: grid; gap: 6px; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; min-height: 32px; }
.bar-row:hover .fill, .bar-row:hover .seg { filter: brightness(1.2); }
.bar-label { display: grid; min-width: 0; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.bar-label small { color: var(--ink-muted); font-size: 12px; }
.track { display: block; height: 16px; border-left: 1px solid var(--baseline); }
.fill, .stack { display: flex; height: 16px; min-width: 0; }
.fill { border-radius: 0 4px 4px 0; background: var(--key); }
.stack { gap: 2px; }
.seg { flex-basis: 0; min-width: 2px; background: var(--key); }
.seg:last-child { border-radius: 0 4px 4px 0; }
.bar-value { font-size: 13px; color: var(--ink-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 18px 24px; }
.share .bar-row { grid-template-columns: minmax(80px, 40%) minmax(0, 1fr) auto; }

/* Tables (and the table view behind each chart). */
.table-view { margin-top: 12px; }
.table-view summary { min-height: 44px; display: inline-flex; align-items: center; cursor: pointer; color: var(--green); font-size: 14px; }
.table-scroll { overflow-x: auto; }
.insight-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.insight-card th, .insight-card td { padding: 7px 8px; border-bottom: 1px solid var(--grid); text-align: left; font-weight: 400; }
.insight-card thead th { color: var(--ink-secondary); font-weight: 600; white-space: nowrap; }
.insight-card .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Errors: newest first, each opening to its stack. */
.error-list { display: grid; gap: 8px; padding: 0; list-style: none; }
.error { border: 1px solid var(--outline); border-radius: 16px; background: #1b1f1b; }
.error summary { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; padding: 12px 14px; cursor: pointer; list-style: none; }
.error summary::-webkit-details-marker { display: none; }
.error-count { min-width: 44px; padding: 2px 10px; border-radius: 12px; background: #4a2323; color: #ffd9d6; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.error-text { display: grid; min-width: 0; }
.error-message { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.error-meta { color: var(--ink-muted); font-size: 12px; }
.error-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 16px; margin: 0; padding: 0 14px 10px; font-size: 13px; }
.error-facts dt { color: var(--ink-muted); font-size: 12px; }
.error-facts dd { margin: 0; overflow-wrap: anywhere; }
.error-stack { margin: 0 14px 14px; max-height: 320px; overflow: auto; padding: 12px; border-radius: 12px; background: #111311; color: var(--ink-secondary); font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.insights-retention { margin-top: 24px; color: var(--muted); font-size: 12px; }
.insights-retention a { text-decoration: underline; }

.insights-tip { position: fixed; z-index: 10; max-width: min(320px, calc(100vw - 16px)); padding: 6px 10px; border-radius: 8px; background: #f1f3e8; color: #151716; font-size: 13px; font-weight: 600; line-height: 1.4; pointer-events: none; box-shadow: 0 4px 16px rgba(0,0,0,.4); }

@media (max-width: 640px) {
  .insights-main { padding: 24px 16px 40px; }
  .insight-card { padding: 16px; border-radius: 20px; }
  .tile { padding: 12px 14px; }
  .tile dd { font-size: 22px; }
  .tile.hero dd { font-size: 40px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles .hero { grid-column: 1 / -1; }
  .plot, .x-labels { margin-left: 44px; }
  .segmented button { min-width: 0; padding: 8px 12px; }
  .bar-row { grid-template-columns: minmax(84px, 38%) minmax(0, 1fr) auto; gap: 2px 8px; }
}
