/* PuckQL viz: the data components in chat answers, the share page and Storybook (public/viz.js draws them).
   Native to The Rink (DESIGN.md): needs rink.css for its tokens, inside the .rink scope.
   A figure is a board on the ice: 2px rule border, Display title, Hanken for reading, Display for the numbers
   painted on it. Blue is the data, red marks the one entity the answer is about, team colour is a small square.
   Text sizes here are mirrored in viz.js (FONT), which measures labels to lay them out: change both together. */

/* ---------- the figure: a board ---------- */
.pqv { position: relative; margin: var(--s5) 0; padding: var(--s5) var(--s5) var(--s4); background: var(--board); border: 2px solid var(--rule); border-radius: 16px; color: var(--ink); font-family: var(--text); }
.pqv-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); }
.pqv-titles { min-width: 0; }
.pqv-title { margin: 0; font: 800 24px/1 var(--display); letter-spacing: .005em; text-transform: uppercase; text-wrap: balance; color: var(--ink); }
.pqv-sub { margin-top: 6px; font-size: var(--fs-tiny); line-height: 1.45; color: var(--ink-2); text-wrap: pretty; }
.pqv-count { flex: none; padding-top: 4px; font: 700 var(--fs-tiny)/1 var(--text); color: var(--ink-2); }

/* Chart | Table: a small segmented pill */
.pqv-toggle { flex: none; display: inline-flex; gap: 2px; padding: 3px; border: 2px solid var(--rule); border-radius: var(--r-pill); background: var(--ice); }
.pqv-toggle button { min-height: 30px; padding: 0 12px; border: 0; border-radius: var(--r-pill); background: none; color: var(--ink-2); font: 700 var(--fs-tiny)/1 var(--text); cursor: pointer; transition: color var(--t-menu) var(--ease), background-color var(--t-menu) var(--ease); }
.pqv-toggle button:hover { color: var(--ink); }
.pqv-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--ice); }
.pqv-toggle button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* legend: keys are the same marks the chart draws */
.pqv-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: -6px 0 var(--s3); font-size: var(--fs-tiny); color: var(--ink); }
.pqv-legend[hidden] { display: none; }
.pqv-key { display: inline-flex; align-items: center; gap: 8px; }
.pqv-key i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.pqv-key i.line { width: 16px; height: 3px; border-radius: 2px; }
.pqv-key i.dot { border-radius: 50%; }
.pqv-key i.ring { border-radius: 50%; background: none; box-shadow: inset 0 0 0 2px var(--c); }
.pqv-key em { font: 700 var(--fs-tiny)/1 var(--text); font-style: normal; color: var(--ink-2); }

.pqv-body { position: relative; min-height: 40px; }
.pqv-body svg { display: block; overflow: visible; }
.pqv-note { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--rule); font-size: var(--fs-tiny); line-height: 1.45; color: var(--ink-2); }
.pqv-note a { color: var(--blue); }
.pqv-err { padding: 14px 16px; border: 2px dashed var(--rule); border-radius: 12px; color: var(--ink-2); font-size: var(--fs-small); }
/* while the answer streams: the chart's place, dashed like any empty state */
.pqv-slot:not(.pqv-ready) { display: grid; place-items: center; min-height: 160px; margin: var(--s5) 0; border: 2px dashed var(--rule); border-radius: 16px; background: var(--board); color: var(--ink-2); font: 700 var(--fs-tiny)/1 var(--text); }
.pqv-slot:not(.pqv-ready):empty::before { content: "Building chart…"; }

/* ---------- svg text ---------- */
.pqv svg text { font-family: var(--text); font-variant-numeric: tabular-nums; }
.pqv-tick, .pqv-xlab, .pqv-reflab { font-size: 12px; font-weight: 500; fill: var(--ink-2); }
.pqv-xlab.now { fill: var(--ink); font-weight: 800; }
.pqv-axlab, .pqv-quad { font-size: 12px; font-weight: 700; fill: var(--ink-2); }
.pqv-section { font: 800 15px var(--display) !important; text-transform: uppercase; letter-spacing: .01em; fill: var(--ink); }
.pqv-lab { font-size: 14px; font-weight: 500; fill: var(--ink); }
.pqv-lab.hl { font-weight: 700; }
.pqv-rank { font: 800 16px var(--display) !important; fill: var(--ink-2); }
/* values: numbers painted on the board */
.pqv-val { font: 800 17px var(--display) !important; fill: var(--ink); }
.pqv-val.hl { fill: var(--red); }
.pqv-val.muted, .pqv-val.lose { fill: var(--ink-2); }
.pqv-val.win { fill: var(--ink); }
.pqv-mid { font-size: 13px; font-weight: 600; fill: var(--ink-2); }
.pqv-endlab .n { font-size: 13px; font-weight: 500; fill: var(--ink-2); }
.pqv-endlab .v { font: 800 17px var(--display); fill: var(--ink); }
.pqv-ptlab { font-size: 13px; font-weight: 500; fill: var(--ink); paint-order: stroke; stroke: var(--board); stroke-width: 4px; stroke-linejoin: round; }
.pqv-ptlab.hl { font-weight: 700; }
.pqv-chipv { font: 800 14px var(--display) !important; fill: var(--ink); }
.pqv-cellv { font-size: 12px; font-weight: 700; fill: #FFFFFF; pointer-events: none; }
.pqv-cellv.on-light { fill: #0E1B26; }

/* ---------- svg marks ---------- */
.pqv-grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.pqv-base { stroke: var(--viz-axis); stroke-width: 2; shape-rendering: crispEdges; }
.pqv-ref { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.pqv-mark { transition: opacity var(--t-tip) var(--ease); }
.pqv-hit { fill: transparent; cursor: default; outline: none; }
.pqv-row .pqv-hit:focus-visible { stroke: var(--blue); stroke-width: 2; }
.pqv svg.has-hover .pqv-row:not(.is-hover) :is(.pqv-mark, text) { opacity: .4; }
.pqv svg.has-hover .pqv-row.is-hover .pqv-hit { fill: color-mix(in oklab, var(--crease), transparent 40%); }
/* team colour: a 10px square with 3px corners and a faint ink ring (The Small Mark Rule) */
.pqv-team { stroke: color-mix(in oklab, var(--ink), transparent 65%); stroke-width: 1.5; }
.pqv-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.pqv-area { opacity: .1; }
.pqv-dot, .pqv-cross circle { stroke: var(--board); stroke-width: 2; }
.pqv-cross line { stroke: var(--ink); stroke-width: 1; opacity: .35; }
.pqv-overlay { fill: transparent; outline: none; cursor: crosshair; }
.pqv-overlay:focus-visible { stroke: var(--blue); stroke-width: 2; }
.pqv-pt { stroke: var(--board); stroke-width: 2; transition: opacity var(--t-tip) var(--ease); }
.pqv svg.has-hover .pqv-pt:not(.is-hover) { opacity: .3; }
.pqv-pt.is-hover { r: 7; }
.pqv-track { stroke: var(--ice-2); stroke-width: 8; stroke-linecap: round; }
.pqv-median { stroke: var(--ink-2); stroke-width: 1.5; }
.pqv-chip { fill: var(--board); stroke-width: 2.5; }
.pqv-cell { transition: opacity var(--t-tip) var(--ease); }
.pqv svg.has-hover .pqv-cell:not(.is-hover) { opacity: .5; }

/* shot map: the real rink, painted in the system's own lines on ice */
.rk-ice { fill: var(--ice); }
.rk-boards { fill: none; stroke: var(--ink-2); stroke-width: 2; }
.rk-blue { stroke: var(--blue); stroke-opacity: .8; stroke-width: 4; }
.rk-red { stroke: var(--red); stroke-opacity: .6; stroke-width: 1.5; }
.rk-red.thin { stroke-width: 1; }
.rk-circle { fill: none; stroke: var(--red); stroke-opacity: .45; stroke-width: 1.5; }
circle.rk-dot { fill: var(--red); fill-opacity: .6; }
.rk-crease { fill: var(--crease); stroke: var(--red); stroke-opacity: .6; stroke-width: 1; }
.rk-net { fill: var(--board); stroke: var(--red); stroke-opacity: .8; stroke-width: 1.2; }
.pqv-shot { stroke: var(--board); stroke-width: 2; transition: opacity var(--t-tip) var(--ease); }
.pqv-shot.hollow { fill: none; stroke-width: 1.75; }
.pqv svg.has-hover .pqv-shot:not(.is-hover) { opacity: .3; }

/* ---------- tooltip: a small board that floats (popover lift) ---------- */
.pqv-tip { position: fixed; left: 0; top: 0; z-index: 90; min-width: 150px; max-width: 280px; padding: 10px 12px; border: 2px solid var(--rule); border-radius: 12px; background: var(--board); box-shadow: 0 18px 40px -18px rgba(8, 18, 30, .45); font: 400 var(--fs-tiny)/1.4 var(--text); font-variant-numeric: tabular-nums; color: var(--ink); pointer-events: none; opacity: 0; transition: opacity var(--t-tip) var(--ease); }
.pqv-tip.on { opacity: 1; }
.pqv-tip-h { margin-bottom: 6px; font-weight: 700; color: var(--ink); }
.pqv-tip-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.pqv-tip-row i { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.pqv-tip-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.pqv-tip-row b { font-weight: 700; color: var(--ink-2); }
.pqv-tip-row b.hl { color: var(--ink); font-weight: 800; }
.pqv-tip-d { margin-top: 4px; color: var(--ink-2); }

/* ---------- tiles: numbers painted on one board, split by rule lines ---------- */
.pqv-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: var(--s5) 0; border: 2px solid var(--rule); border-radius: 16px; overflow: hidden; background: var(--board); }
.pqv-tile { display: flex; flex-direction: column; gap: 4px; padding: var(--s4) var(--s5); background: var(--board); box-shadow: inset 1px 0 0 var(--rule), inset 0 1px 0 var(--rule); }
.pqv-tile-l { font: 700 var(--fs-tiny)/1.3 var(--text); color: var(--ink-2); }
.pqv-tile-v { font: 900 48px/.95 var(--display); letter-spacing: -.005em; color: var(--blue); }
.pqv-tile:first-child .pqv-tile-v { color: var(--ink); }
.pqv-tile-d { display: inline-flex; align-items: center; gap: 6px; font: 700 var(--fs-tiny)/1.2 var(--text); color: var(--ink-2); }
.pqv-tile-d.good { color: var(--viz-good); }
.pqv-tile-d.bad { color: var(--red); }
.pqv-tile-d svg { fill: currentColor; }
.pqv-tile-d em { font-weight: 500; font-style: normal; color: var(--ink-2); }
.pqv-tile-c { font-size: var(--fs-tiny); color: var(--ink-2); }
.pqv-spark { width: 100%; height: 34px; margin-top: auto; overflow: visible; }
.pqv-spark .ln { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.pqv-spark .area { fill: var(--blue); opacity: .1; }
.pqv-spark circle { fill: var(--blue); stroke: var(--board); stroke-width: 2; vector-effect: non-scaling-stroke; }

/* ---------- tables: a board, ice-2 head on the red line ---------- */
.tablewrap { position: relative; max-width: 100%; overflow-x: auto; margin: var(--s5) 0; background: var(--board); border: 2px solid var(--rule); border-radius: 14px; }
.pqv .tablewrap { margin: 0; border-radius: 10px; }
.tablewrap table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-small); font-variant-numeric: tabular-nums; }
.tablewrap th, .tablewrap td { font-family: var(--text); white-space: nowrap; color: var(--ink); }
.tablewrap thead th { position: sticky; top: 0; z-index: 1; padding: 0; background: var(--ice-2); font: 700 var(--fs-tiny)/1.3 var(--text); text-align: left; border-bottom: var(--line-red) solid var(--red); }
.tablewrap thead th button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 6px; width: 100%; cursor: pointer; transition: color var(--t-menu) var(--ease); }
.tablewrap thead th:not(:has(button)), .tablewrap thead th button { padding: 12px 16px 10px; } /* after the button's all: unset, which would wipe it */
.tablewrap thead th.num button { justify-content: flex-end; }
.tablewrap thead th button:hover { color: var(--blue); }
.tablewrap thead th button:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.tablewrap thead th .caret { flex: none; fill: currentColor; opacity: 0; transition: opacity var(--t-menu) var(--ease); }
.tablewrap thead th button:hover .caret { opacity: .5; }
.tablewrap thead th.sorted .caret { opacity: 1; color: var(--red); }
.tablewrap tbody td { padding: 12px 16px; border-bottom: 1px solid var(--rule); background: var(--board); vertical-align: middle; transition: background-color var(--t-menu) var(--ease); }
.tablewrap tbody tr:last-child td { border-bottom: 0; }
.tablewrap tbody tr:hover td { background: var(--crease); }
.tablewrap td.num, .tablewrap th.num { text-align: right; }
.tablewrap th.num { font-size: var(--fs-tiny); }
.tablewrap td:first-child { font-weight: 600; }
/* the first column stays put while wide tables scroll sideways */
.tablewrap.pqt tbody td:first-child, .tablewrap.pqt thead th:first-child { position: sticky; left: 0; z-index: 1; }
.tablewrap.pqt thead th:first-child { z-index: 2; }
.tablewrap .t-rank { width: 1%; color: var(--ink-2) !important; font: 800 16px var(--display); }
.tablewrap tbody tr:nth-child(-n+3) .t-rank { color: var(--blue) !important; }
.tablewrap.dense tbody td { padding-top: 8px; padding-bottom: 8px; }
/* the row the answer is about: a red tint, set bold */
.tablewrap tr.hl td { background: color-mix(in oklab, var(--red), var(--board) 88%); font-weight: 700; }
/* in-cell magnitude bars */
.pqt-cell { display: inline-grid; grid-template-columns: minmax(48px, 88px) auto; align-items: center; justify-content: end; gap: 10px; width: 100%; }
.pqt-bar { position: relative; height: 6px; border-radius: 3px; background: var(--ice-2); overflow: hidden; }
.pqt-bar i { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--blue); }
.pqt-v.lead { font-weight: 800; }
.pqt-team { display: inline-flex; align-items: center; gap: 8px; font: 700 var(--fs-tiny) var(--text); }
.pqt-team i, .pqc-chip i { background: var(--tc, var(--muted)); width: 10px; height: 10px; border-radius: 3px; box-shadow: 0 0 0 1.5px color-mix(in oklab, var(--ink), transparent 65%); }
.pqt-player { display: inline-flex; align-items: baseline; gap: 8px; font-weight: 600; }
.pqt-player em { font: 700 12px var(--text); font-style: normal; color: var(--ink-2); }
.pqt-rank { font: 800 16px var(--display); }
.pqt-delta { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: var(--ink-2); }
.pqt-delta svg { fill: currentColor; }
.pqt-delta.good { color: var(--viz-good); }
.pqt-delta.bad { color: var(--red); }
.pqt-expiry { display: inline-block; padding: 3px 8px 2px; border: 2px solid var(--rule); border-radius: var(--r-pill); font: 700 12px/1 var(--text); }
.pqv-table { padding-bottom: var(--s4); }
.pqv-table .pqv-head { margin-bottom: var(--s3); }

/* ---------- contract card ---------- */
.pqc-lead { margin: -2px 0 var(--s4); }
.pqc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s4); }
.pqc-chip { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px; border: 2px solid var(--rule); border-radius: var(--r-pill); font: 700 var(--fs-tiny)/1.2 var(--text); color: var(--ink); }
.pqc-chip.warn { color: var(--viz-warn); border-color: var(--viz-warn); }
.pqc-chip.warn svg { fill: currentColor; }
.pqc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.pqc-stat { padding: 13px 14px 12px; }
.pqc-stat:first-child { padding-left: 0; }
.pqc-stat + .pqc-stat { border-left: 1px solid var(--rule); }
.pqc-stat .l { font: 700 var(--fs-tiny)/1.2 var(--text); color: var(--ink-2); }
.pqc-stat .v { margin-top: 7px; font: 900 30px/1 var(--display); white-space: nowrap; color: var(--ink); }
.pqc-stat .s { margin-top: 5px; font-size: var(--fs-tiny); color: var(--ink-2); }
.pqc-next { margin-top: var(--s3); font-size: var(--fs-small); color: var(--ink); }
.pqc-next b { font-weight: 700; }
.pqc-none { padding: 14px 0; font-size: var(--fs-small); color: var(--ink-2); }
.pqv-mark.past { opacity: .4; }

@media (max-width: 640px) {
  .pqv { padding: var(--s4) var(--s3) var(--s3); border-radius: 14px; }
  .pqt-cell { grid-template-columns: minmax(28px, 48px) auto; gap: 8px; }
  .pqv-tile-v { font-size: 40px; }
  .pqc-stats { grid-template-columns: 1fr 1fr; }
  .pqc-stat:nth-child(3) { padding-left: 0; border-left: 0; }
  .pqc-stat:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .pqc-stat .v { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { .pqv *, .pqv-tip { transition: none !important; } }
