dialog#match-history {
  box-sizing: border-box;
  width: min(860px, calc(100dvw - 22px));
  max-width: 860px;
  max-height: min(88dvh, 960px);
  margin: auto;
  padding: 0;
  overflow: auto;
  color: #f6eed4;
  background: #182a22;
  border: 1px solid #617858;
  border-radius: 16px;
  box-shadow: 0 14px 55px #0009;
  scroll-padding-top: 108px;
}
.side > #open-history { display: flex; width: 100%; margin-bottom: 8px; }
#match-history::backdrop { background: #09150fbd; }
#match-history .history-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  padding: 16px 20px 12px;
  background: #233b2f;
  border-bottom: 1px solid #4c654b;
}
#match-history .history-header h2 { margin: 0; color: #fff0cc; font: bold 1.8rem/1.14 Georgia, serif; }
#match-history .history-header p { margin: 0; }
#match-history .history-header [data-history-player] { color: #c7d9bf; margin-top: 4px; overflow-wrap: anywhere; }
#match-history .history-kicker { color: #a7d4a9; font: 800 .67rem/1.5 system-ui, sans-serif; letter-spacing: .13em; }
#match-history .history-content { padding: 14px 20px 18px; }
#match-history .history-button, #match-history select {
  min-height: 42px;
  color: #f4efd5;
  background: #1b3127;
  border: 1px solid #6d8769;
  border-radius: 8px;
  padding: 5px 10px;
  font: 700 .84rem/1.2 system-ui, sans-serif;
}
#match-history .history-button { cursor: pointer; }
#match-history .history-button:hover { background: #355442; }
#match-history :is(button, select, summary):focus-visible { outline: 3px solid #ffd481; outline-offset: 2px; }
#match-history .history-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
#match-history .history-stats div {
  min-height: 62px;
  display: flex;
  flex-direction: column-reverse;
  justify-content: center;
  padding: 7px 10px;
  background: #263e31;
  border: 1px solid #48674d;
  border-radius: 10px;
}
#match-history .history-stats dt { color: #d2dfc6; font-size: .78rem; line-height: 1.25; }
#match-history .history-stats dd { margin: 0 0 3px; color: #ffe6a9; font-size: 1.33rem; font-weight: 830; line-height: 1; font-variant-numeric: tabular-nums; }
#match-history .history-breakdown { margin: 18px 0; }
#match-history .history-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
#match-history h3 { color: #fff0cc; margin: 0; font: 700 1.17rem/1.2 Georgia, serif; }
#match-history .history-section-head p { margin: 0; color: #bacfb7; font-size: .82rem; }
#match-history .history-section-head label { display: flex; align-items: center; gap: 6px; color: #d8e4cd; font-size: .82rem; }
#match-history select { width: auto; min-width: 8em; }
#match-history table { width: 100%; border-collapse: collapse; font-size: .88rem; table-layout: fixed; }
#match-history th, #match-history td { padding: 6px 3px; border-bottom: 1px solid #445d49; text-align: center; }
#match-history th:first-child { text-align: left; width: 35%; }
#match-history thead { background: #294536; color: #e8f2d8; }
#match-history tbody th { font-weight: 600; }
#match-history td { font-variant-numeric: tabular-nums; }
#match-history .history-note { margin: 5px 0 10px; color: #bfceb6; font-size: .77rem; }
#match-history .history-timeline { padding: 0; margin: 0; list-style: none; }
#match-history .history-card { padding: 9px; margin: 0 0 7px; background: #21382c; border: 1px solid #45654b; border-radius: 10px; }
#match-history .history-preview { display: flex; align-items: center; gap: 10px; }
#match-history .history-card-copy { min-width: 0; }
#match-history .history-card-title { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 8px; }
#match-history .history-card-title :is(time, span) { color: #f3e4bd; font-size: .9rem; }
#match-history .history-card p { margin: 3px 0 0; color: #d9e5ce; font-size: .84rem; }
#match-history .history-card p.history-match-metrics { color: #bcd0b9; font-size: .77rem; }
#match-history .history-result { border-radius: 20px; padding: 2px 8px; color: #f4eed5; background: #485345; font-size: .78rem; }
#match-history .history-result[data-outcome="win"] { color: #e2ffe4; background: #275b42; }
#match-history .history-result[data-outcome="loss"] { color: #ffe4e0; background: #6f3d37; }
#match-history .history-result[data-outcome="draw"] { color: #fff0bb; background: #62552e; }
#match-history .history-final-board { margin: 3px 0 0; }
#match-history .history-final-board summary { min-height: 32px; width: fit-content; padding: 5px 4px; color: #f8d88c; cursor: pointer; font-size: .84rem; }
#match-history .record-board {
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  background: #cfad78;
  border: 2px solid #ae8550;
  border-radius: 4px;
}
#match-history .record-board-small { width: 76px; flex: 0 0 76px; }
#match-history .record-board-large { width: min(100%, 390px); margin: 3px auto 6px; border-width: 3px; }
#match-history .record-square { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
#match-history .record-dark { background: #416858; }
#match-history .record-piece { z-index: 1; font: 10px/1 "DejaVu Sans", "Segoe UI Symbol", serif; color: #f9e3b1; -webkit-text-stroke: .3px #3e3123; }
#match-history .record-piece[data-side="jade"] { color: #164939; -webkit-text-stroke: .3px #d2efd5; }
#match-history .record-board-large .record-piece { font-size: clamp(19px, 6vw, 39px); -webkit-text-stroke-width: .7px; }
#match-history .record-rank, #match-history .record-file { position: absolute; color: #232c20; font: 800 clamp(8px, 2vw, 11px)/1 system-ui, sans-serif; }
#match-history .record-rank { inset: 2px auto auto 2px; }
#match-history .record-file { inset: auto 2px 2px auto; }
#match-history .record-dark :is(.record-file,.record-rank) { color: #ebf6d5; }
#match-history .record-disc {
  display: grid; place-items: center; width: 76%; height: 76%; border-radius: 50%;
  border: 1px solid #ecd2a5; color: #ffebac; background: #c34d3c; -webkit-text-stroke-width: 0;
}
#match-history .record-disc[data-side="blue"] { background: #2672a0; }
#match-history .record-board-large .record-disc { font-size: clamp(15px, 5vw, 29px); border-width: 2px; }
@media (max-width: 580px) {
  #match-history .history-header, #match-history .history-content { padding: 10px 12px; }
  #match-history .history-header h2 { font-size: 1.42rem; }
  #match-history .history-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  #match-history .history-stats div { min-height: 50px; }
  #match-history .history-stats dd { font-size: 1.16rem; }
  #match-history table { font-size: .76rem; }
  #match-history .record-board-small { width: 61px; flex-basis: 61px; }
  #match-history .record-board-small .record-piece { font-size: 8px; }
}
