/* The Past games page (past.html, past.js). Loaded after style.css, so
   the tokens, buttons, and the board's own rules (#board-wrap > svg,
   #board ...) carry over unchanged; this only lays the page out. */

body.past-page {
  display: block;
  padding: 0.75rem 1rem 2rem;
}

#past-main {
  max-width: 1400px;
  margin: 0 auto;
  min-width: 0;
}

.past-nav {
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.past-nav a,
#past-main a {
  color: var(--accent);
}

.past-lede {
  color: var(--ink-soft);
  margin-top: 0;
}

.muted {
  color: var(--ink-soft);
}

#past-main h1 {
  margin: 0.4rem 0 0.25rem;
  overflow-wrap: anywhere;
}

/* --- the list ---------------------------------------------------------- */

#past-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: 0.75rem;
}

.past-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  color: var(--ink) !important;
  text-decoration: none;
}

.past-card:hover,
.past-card:focus-visible {
  border-color: var(--accent);
}

.past-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}

.past-card-facts {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.past-card-players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.75rem;
  font-size: 0.9rem;
}

.past-card-warn {
  color: var(--warn);
  font-size: 0.85rem;
}

/* A player's color chip beside their name; the name stays ink. */
.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.swatch {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 25%, transparent);
}

/* --- stats across every game, above the list ---------------------------- */

#archive-stats {
  margin: 1rem 0 1.5rem;
}

#archive-stats h2,
#past-list-title {
  margin: 0 0 0.6rem;
}

/* A short chart keeps its own height beside a tall one. */
#archive-stats-grid {
  align-items: start;
}

#archive-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  min-width: 0;
}

.stat-tile-label {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.stat-tile-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-tile-note {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* --- the replay --------------------------------------------------------- */

#replay-notice {
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  background: var(--info-bg);
  color: var(--ink);
  border-left: 3px solid var(--info);
}

#replay-notice.has-problems {
  background: var(--warn-bg);
  border-left-color: var(--warn);
}

#replay {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 26rem);
  gap: 1rem 1.5rem;
  align-items: start;
}

#replay-board-column {
  min-width: 0;
}

/* As big as the window's height allows under the page's heading, and
   never wider than its column. The controls sit in the side column
   beside it (under it below 900px), so they stay in view. */
#replay #board-wrap {
  width: min(100%, max(18rem, calc(100vh - 8.5rem)));
  max-width: 1100px;
  margin: 0 auto;
}

#replay-controls {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

#replay-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

#replay-buttons button {
  min-width: 2.75rem;
  min-height: 2.25rem;
  padding: 0.3rem 0.6rem;
}

#replay-play {
  min-width: 5rem !important;
}

#replay-speed-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

#replay-speed {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  padding: 0.2rem 0.3rem;
}

#replay-scrubber {
  width: 100%;
  accent-color: var(--accent);
  min-height: 1.75rem;
}

#replay-position {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 1rem;
  font-size: 0.95rem;
}

#replay-turn {
  font-weight: 600;
}

#replay-time {
  color: var(--ink-soft);
}

#replay-lines {
  margin: 0;
  padding: 0.4rem 0.6rem 0.4rem 1.6rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  max-height: 9.5rem;
  overflow-y: auto;
  font-size: 0.9rem;
}

#replay-lines li {
  padding: 0.05rem 0;
  overflow-wrap: anywhere;
}

#replay-lines li.inferred {
  color: var(--ink-soft);
  font-style: italic;
}

#replay-lines li.has-problem,
#past-problems li {
  color: var(--ink);
}

.line-problem {
  display: block;
  color: var(--warn);
  font-size: 0.85rem;
}

#replay-side h2 {
  font-size: 1.1rem;
  margin: 0 0 0.4rem;
}

#replay-players,
#past-standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

#replay-players th,
#replay-players td,
#past-standings th,
#past-standings td {
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

#replay-players th,
#past-standings th {
  color: var(--ink-soft);
  font-weight: 500;
}

#replay-players .num,
#past-standings .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#replay-players tr.is-out td {
  color: var(--ink-soft);
}

.player-status {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-left: 1.1rem;
}

#replay-pot {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

/* The board's own ring for the space a turn ended on. */
.replay-focus {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  pointer-events: none;
}

/* --- stats --------------------------------------------------------------- */

#past-stats {
  margin-top: 1.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr));
  gap: 1rem;
}

.chart-card {
  margin: 0;
  padding: 0.85rem 1rem 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  min-width: 0;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 1rem;
}

.chart-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.chart-sub {
  margin: 0.2rem 0 0.5rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.chart-body {
  min-width: 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.segmented {
  display: inline-flex;
}

.segmented button {
  padding: 0.25rem 0.7rem;
  min-height: 2rem;
  border-radius: 0;
}

.segmented button:first-child {
  border-radius: 0.35rem 0 0 0.35rem;
}

.segmented button:last-child {
  border-radius: 0 0.35rem 0.35rem 0;
  border-left: none;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

svg.chart {
  display: block;
  overflow: visible;
  font-family: var(--font-body);
}

svg.chart .grid,
svg.chart .axis {
  stroke: var(--rule);
  stroke-width: 1;
}

svg.chart .tick,
svg.chart .value {
  fill: var(--ink-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

svg.chart .label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

svg.chart .series {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* White and black lines and marks: a mid gray halo under them, so each
   reads on either theme's surface. */
svg.chart .series-halo,
svg.chart .lane-halo {
  fill: none;
  stroke: #8a8a8a;
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

svg.chart .lane-halo {
  stroke-width: 8;
}

svg.chart .dot-halo,
svg.chart .bar-halo {
  stroke: #8a8a8a;
  stroke-width: 1;
}

svg.chart .turn-cursor {
  stroke: var(--accent);
  stroke-width: 1.5;
  pointer-events: none;
}

svg.chart .crosshair {
  stroke: var(--ink-soft);
  stroke-width: 1;
  pointer-events: none;
}

svg.chart .hit {
  fill: transparent;
  cursor: pointer;
}

svg.chart .bar-paid {
  fill: var(--ink-soft);
}

svg.chart .bar-received {
  fill: var(--accent);
}

.swatch.key-paid {
  background: var(--ink-soft);
}

.swatch.key-received {
  background: var(--accent);
}

.swatch.key-expected {
  border-radius: 0;
  height: 2px;
  box-shadow: none;
  background: var(--ink);
}

/* The list's stats across every game (showArchiveStats). */
svg.chart .bar-track {
  fill: var(--surface-alt);
  stroke: var(--rule);
  stroke-width: 1;
}

.swatch.key-track {
  border-radius: 0.2rem;
  background: var(--surface-alt);
}

svg.chart .group-key,
svg.chart .group-held {
  stroke: color-mix(in srgb, var(--ink) 30%, transparent);
  stroke-width: 1;
}

svg.chart .group-first {
  fill: var(--ink);
}

.swatch.key-first {
  border-radius: 0.1rem;
  height: 0.35rem;
  box-shadow: none;
  background: var(--ink);
}

.swatch.key-held {
  border-radius: 0.2rem;
  background: color-mix(in srgb, var(--ink-soft) 60%, transparent);
}

svg.chart .median-mark {
  stroke: var(--ink-soft);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

svg.chart .length-dot {
  fill: var(--accent);
  cursor: pointer;
}

.chart-note {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
}

svg.chart .expected-mark {
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}

svg.chart .reference {
  stroke: var(--ink-soft);
  stroke-width: 1;
}

svg.chart .dot {
  stroke: var(--surface);
  stroke-width: 2;
  cursor: pointer;
}

svg.chart .dot.dot-halo {
  stroke: #8a8a8a;
}

svg.chart .lane {
  stroke-width: 6;
  stroke-linecap: round;
  cursor: pointer;
}

svg.chart .lane-end {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}

svg.chart .lane-win {
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}

svg.chart .heat-cell {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}

svg.chart .heat-count {
  fill: var(--ink);
  font-weight: 600;
  pointer-events: none;
}

svg.chart .heat-count.on-dark {
  fill: var(--accent-ink);
}

svg.chart .heat-title {
  fill: var(--ink);
  font-weight: 600;
}

svg.chart .heat-note {
  fill: var(--ink-soft);
}

.stat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 20rem;
  overflow-y: auto;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.6rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.4rem 0.2rem;
  font-weight: 400;
  font-size: 0.9rem;
  cursor: pointer;
}

.stat-row:hover {
  background: var(--surface-alt);
  filter: none !important;
}

.stat-main {
  font-weight: 600;
}

.set-swatch {
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 0.2rem;
  background: var(--ink-soft);
}

.trade-row {
  flex-direction: column;
  align-items: flex-start;
}

.trade-side {
  overflow-wrap: anywhere;
}

.trade-completes {
  color: var(--good);
  font-weight: 600;
}

#chart-tip {
  position: fixed;
  z-index: 50;
  max-width: 18rem;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
  pointer-events: none;
}

#chart-tip .tip-title {
  font-weight: 600;
}

#chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* --- details under the stats ------------------------------------------------ */

#past-details {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#past-details details {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  padding: 0.6rem 0.9rem;
}

#past-details summary {
  cursor: pointer;
  font-weight: 600;
}

#past-settings {
  columns: 2 16rem;
  font-size: 0.9rem;
  padding-left: 1.1rem;
}

#past-log {
  max-height: 28rem;
  overflow-y: auto;
  font-size: 0.88rem;
  padding-left: 2.6rem;
}

#past-log li,
#past-problems li {
  overflow-wrap: anywhere;
}

#past-problems li {
  margin-bottom: 0.5rem;
}

.problem-line {
  display: block;
}

.problem-text {
  display: block;
  color: var(--warn);
  font-size: 0.88rem;
}

button.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

#past-error {
  color: var(--bad);
}

@media (max-width: 520px) {
  .eliminated-time {
    display: none;
  }
}

/* One column under 900px: the board full width, the players under it. */
@media (max-width: 900px) {
  #replay {
    grid-template-columns: minmax(0, 1fr);
  }

  #replay #board-wrap {
    width: 100%;
  }
}
