.history { padding-block: 32px 40px; }
.history-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 21px; }
.history-heading h1 { font-size: clamp(2.65rem,5vw,4.35rem); line-height: 1; letter-spacing: -.054em; }
.history-heading p { color: var(--muted); margin-top: 8px; }
.import-control { flex: none; }
.history-notice { color: var(--teal); background: #1e2a21; border: 1px solid #3e584a; padding: 9px 12px; margin-bottom: 13px; border-radius: 5px; overflow-wrap: anywhere; }
.history-notice.error { color: var(--rust); background: #2c211d; border-color: #594036; }
.history-grid { display: grid; grid-template-columns: minmax(207px,.25fr) minmax(0,1fr); gap: 21px; align-items: start; }
.team-directory,.team-history,.matches { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); box-shadow: 0 6px 16px #0002; }
.team-directory { padding: 13px; }
.team-directory h2 { padding: 2px 6px 8px; font-size: 1.3rem; }
.team-directory p { padding: 11px 5px 2px; color: var(--muted); font-size: .79rem; }
#history-teams { display: grid; gap: 5px; }
.team-row {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  min-height: 44px; padding: 6px 7px; background: #191a15;
  border: 1px solid transparent; border-radius: 5px; color: var(--text);
}
.team-row:hover,.team-row[aria-pressed=true] { border-color: #7c6544; background: #352e22; }
.team-row-name { font-size: .875rem; font-weight: 680; }
.team-row-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; }
.team-emblem {
  --badge:#aeb6bd;
  display: inline-grid; place-items: center; flex: none; width: 20px; height: 26px;
  clip-path: polygon(0 0,100% 0,100% 71%,50% 100%,0 71%); background: var(--badge);
}
.team-emblem::after { content: ""; width: 36%; height: 46%; background: #1d211c; clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); }
.team-verdant { --badge:var(--teal); }
.team-ash { --badge:var(--rust); }
.team-thorn { --badge:#c7d98d; }
.team-crimson { --badge:#ef88a3; }
.team-history { padding: 18px; background: linear-gradient(142deg,#29271f,#1d1e1a 53%); }
.team-history-heading { display: flex; align-items: center; gap: 12px; padding-bottom: 15px; }
.history-emblem .team-emblem { width: 30px; height: 39px; }
.team-history h2 { font-size: clamp(1.65rem,3.5vw,2.65rem); line-height: 1.1; letter-spacing: -.025em; }
.team-history-heading p { color: var(--muted); font-size: .85rem; margin-top: 3px; }
.history-metrics { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 8px; margin: 0 0 16px; }
.history-metrics div { border: 1px solid var(--line); border-radius: 6px; background: #191a16; padding: 8px 9px; }
.history-metrics dt { color: var(--muted); font-size: .78rem; }
.history-metrics dd { color: var(--text); font-size: clamp(1.12rem,2.4vw,1.72rem); font-weight: 730; margin: 4px 0 0; font-variant-numeric: tabular-nums; line-height: 1.1; }
.history-metrics .metric-wins dd { color: var(--teal); }
.history-metrics .metric-losses dd { color: var(--rust); }
.matches { background: #1a1b16; }
.matches-header { display: flex; align-items: end; justify-content: space-between; gap: 9px; padding: 12px 13px; }
.matches-header h3,.history-review-grid h3 { font-family: var(--display); font-weight: 500; font-size: 1.28rem; }
.matches-header p { color: var(--muted); font-size: .78rem; }
.result-filter { display: grid; gap: 3px; min-width: 114px; color: var(--muted); font-size: .75rem; }
.games-overflow,.troop-overflow { overflow: auto; }
.games-table,.troop-table { width: 100%; border-collapse: collapse; text-align: left; }
.games-table { min-width: 521px; }
.games-table th,.games-table td { padding: 8px 11px; font-size: .85rem; border-top: 1px solid #3c392e; }
.games-table th,.troop-table th { color: var(--muted); font-weight: 650; background: #23231d; }
.games-table tbody tr:hover { background: #26251d; }
.games-table strong { display: block; font-weight: 620; }
.games-table td span:not(.outcome) { display: block; color: var(--muted); font-size: .75rem; }
.outcome { display: inline-flex; align-items: center; justify-content: center; min-width: 42px; padding: 2px 5px; border-radius: 4px; font-size: .75rem; font-weight: 760; }
.outcome-win { color: #91e3c4; background: #203629; }
.outcome-loss { color: #ffad95; background: #3b2620; }
.outcome-draw { color: #e8cb98; background: #3a3020; }
.view-battle,.troop-link { padding: 3px 0; border: 0; background: none; text-align: left; color: var(--gold); font-weight: 670; }
.view-battle:hover,.troop-link:hover { text-decoration: underline; }
.survivor-score,.battle-time-cell { font-variant-numeric: tabular-nums; }
.no-games { padding: 23px 13px; color: var(--muted); border-top: 1px solid var(--line); }

.battle-history-dialog { width: min(1090px,calc(100% - 25px)); max-height: calc(100% - 26px); overflow: auto; }
.battle-history-dialog h2 { padding-right: 38px; line-height: 1.13; font-size: clamp(1.65rem,3.3vw,2.4rem); }
.battle-history-status { margin: 7px 0 12px; color: var(--muted); font-size: .86rem; }
.battle-history-score { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.review-score {
  display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; align-items: start;
  background: #24261f; border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px;
}
.review-side-0 strong { color: var(--teal); }
.review-side-1 strong { color: var(--rust); }
.review-survivors { font-size: .85rem; font-weight: 670; }
.review-result,.battle-history-strategy { color: var(--muted); font-size: .8rem; grid-column: 1 / -1; }
.battle-history-strategy { padding-top: 7px; }
.history-review-grid { display: grid; grid-template-columns: minmax(0,1.24fr) minmax(0,1fr); gap: 14px; margin-top: 13px; }
.history-board,.history-timeline { width: 100%; max-width: none; }
.history-detail-actions { display: flex; flex-wrap: wrap; gap: 7px 10px; margin-top: 9px; }
.troop-header { display: flex; justify-content: space-between; align-items: center; gap: 7px; margin-bottom: 6px; }
.troop-header select { max-width: 151px; }
.troop-overflow { border: 1px solid var(--line); border-radius: 5px; max-height: 280px; }
.troop-table th,.troop-table td { padding: 5px 6px; font-size: .79rem; border-bottom: 1px solid var(--line); }
.troop-table th { position: sticky; top: 0; }
.troop-table tr:last-child td { border-bottom: 0; }
.troop-link[aria-pressed=true] { color: var(--teal); text-decoration: underline; }
.history-script { margin-top: 7px; border: 1px solid var(--line); border-radius: 5px; padding: 7px; }
.history-script h4 { font-size: .8rem; color: var(--gold); margin: 0; }
.history-script pre { margin: 4px 0 0; max-height: 140px; overflow: auto; font: .76rem/1.5 ui-monospace,Menlo,monospace; }

@media (max-width:1080px) {
  .history-metrics { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .history-grid { gap: 13px; }
}
@media (max-width:760px) {
  .history { padding-top: 23px; }
  .history-grid,.history-review-grid { grid-template-columns: minmax(0,1fr); }
  #history-teams { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .team-history { padding: 11px; }
  .history-heading { flex-wrap: wrap; gap: 8px; }
  .battle-history-dialog { padding: 15px; }
}
@media (max-width:440px) {
  .review-score { grid-template-columns: 1fr; }
  .matches-header { padding-inline: 9px; }
  .history-metrics { gap: 5px; }
  .history-metrics div { padding-inline: 5px; }
}
