.battle-replay {
  --replay-bar: 8px;
  --compact-name-height: 40px;
  --compact-fixed-height: 66.5px;
  position: fixed; inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: none;
  box-sizing: border-box; margin: 0; border: 0; border-radius: 0;
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
  overflow: hidden; color: var(--parchment); background: radial-gradient(ellipse at 50% 43%, #20263a, #121622 45%, #0a0d14 85%);
  overscroll-behavior: contain;
}
.battle-replay::backdrop { background: #0b0e16; }
.battle-replay .language-control { top: calc(10px + env(safe-area-inset-top, 0px)); left: calc(10px + env(safe-area-inset-left, 0px)); bottom: auto; }
.battle-replay button { min-height: 36px; padding: 5px 9px; font-size: 12px; white-space: nowrap; }
.battle-replay button:hover { transform: none; }
/* Layout containment turns transient motion inside the stage (the FX entrance slide, lunges,
   dodges) into ink overflow: it is still drawn and still clipped by the dialog at the screen
   edge, but it no longer widens the dialog's scrollable area at phone widths. The stage is
   already positioned and isolated, so positions and stacking are unchanged. */
.replay-stage { position: relative; z-index: 0; isolation: isolate; contain: layout; height: 100%; max-width: 1000px; margin: auto; display: grid; grid-template-rows: 52px minmax(0, 1fr) 28px minmax(0, 1fr) 24px; gap: 6px; }
.replay-stage:focus { outline: none; }
.replay-caption { display: flex; justify-content: center; align-items: center; gap: 3px; margin: 0; line-height: 28px; text-align: center; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.replay-caption-name { min-width: 0; max-width: 22%; overflow: hidden; text-overflow: ellipsis; }
.replay-caption-detail { flex-shrink: 0; max-width: 65%; overflow: hidden; text-overflow: ellipsis; }
[data-phase="intro"] .replay-caption { font: bold 24px var(--serif); color: var(--gold); }
.replay-top, .replay-bottom { max-width: none; width: 100%; margin: 0; padding: 0; border: 0; min-width: 0; }
.replay-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 6px; padding-left: 50px; }
.replay-opponent { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.replay-round { grid-column: 1; font-size: 12px; color: var(--gold); }
.replay-controls { grid-column: 2; grid-row: 1 / 3; display: flex; gap: 4px; }
.replay-controls [aria-pressed="true"] { color: var(--gold-hi); border-color: var(--gold); background: #e7c88a24; }
.replay-row { display: grid; min-height: 0; grid-template-rows: auto minmax(0, 1fr); gap: 4px; }
.replay-bonuses { display: flex; flex-wrap: wrap; align-items: center; align-content: center; justify-content: center; gap: 2px 6px; min-height: 20px; }
.replay-badge { color: var(--gold); font-size: 11px; line-height: 16px; border: 1px solid #e7c88a55; padding: 0 6px; border-radius: 20px; white-space: nowrap; }
[data-phase="intro"] .replay-badge { background: #e7c88a26; box-shadow: 0 0 12px #e7c88a44; }
.replay-lineup { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(6px, 2vw, 22px); min-height: 0; justify-items: center; }
.replay-unit {
  --replay-accent: #c3c9d3; --unit-info-height: 75px;
  position: relative; container-type: size; box-sizing: border-box;
  width: 100%; max-width: 270px; height: 100%; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 2px;
  font-size: 12px;
}
.replay-unit[data-rarity="R"] { --replay-accent: #83b5e8; }
.replay-unit[data-rarity="SR"] { --replay-accent: #b493f1; }
.replay-unit[data-rarity="SSR"] { --replay-accent: #ffbf52; }
.replay-unit[data-rarity="UR"] { --replay-accent: #ffd27f; }
.replay-unit.is-acting { z-index: 3; }
.replay-unit.is-target { z-index: 3; }
.replay-unit[data-ko="true"] :is(.card-portrait, .replay-name, .replay-class, .replay-meter, .replay-hp) { filter: grayscale(1); opacity: .5; }
.replay-art, .battle-replay .prepare-face {
  position: relative; container-type: normal; flex: none; align-self: center;
  width: min(100%, calc((100cqh - var(--unit-info-height) - var(--compact-fixed-height)) / .75));
}
:is(.replay-art, .prepare-face) .card-compact { width: 100%; }
.battle-replay .card-compact .card-visual { --card-name-height: var(--compact-name-height); }
.battle-replay .card-compact .card-portrait { aspect-ratio: 4 / 3; }
.replay-name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.2; overflow: hidden; overflow-wrap: anywhere; text-align: center; }
.replay-class { display: flex; align-items: center; justify-content: center; gap: 3px; min-width: 0; font-size: 11px; color: var(--muted); }
.replay-class span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-class .card-class-icon { position: static; width: 14px; height: 14px; flex: 0 0 14px; }
.replay-meter { position: relative; height: var(--replay-bar); overflow: hidden; background: #060a12; border-radius: 3px; }
.replay-fill, .replay-ghost { position: absolute; inset: 0; transform-origin: left; background: #76c9a3; }
.replay-ghost { background: #f0dba4; }
[data-health="mid"] .replay-fill { background: #e7c88a; }
[data-health="low"] .replay-fill { background: #e68484; }
.replay-hp-static { display: none; width: 100%; height: var(--replay-bar); border: 0; appearance: none; }
.replay-hp-static::-webkit-progress-bar { background: #060a12; }
.replay-hp-static::-webkit-progress-value { background: #76c9a3; }
.replay-hp-static::-moz-progress-bar { background: #76c9a3; }
[data-health="mid"] .replay-hp-static { accent-color: #e7c88a; }
[data-health="low"] .replay-hp-static { accent-color: #e68484; }
[data-health="mid"] .replay-hp-static::-webkit-progress-value { background: #e7c88a; }
[data-health="low"] .replay-hp-static::-webkit-progress-value { background: #e68484; }
[data-health="mid"] .replay-hp-static::-moz-progress-bar { background: #e7c88a; }
[data-health="low"] .replay-hp-static::-moz-progress-bar { background: #e68484; }
[data-reduced="true"] :is(.replay-fill, .replay-ghost) { display: none; }
[data-reduced="true"] .replay-hp-static { display: block; }
.replay-hp { line-height: 17px; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.replay-status { grid-row: 6; display: flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; }
.replay-ko { position: relative; z-index: 4; background: #641b27ed; color: #fff; font-size: 9px; font-weight: 800; line-height: 13px; padding: 0 2px; }
.replay-flash { position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; }
.replay-flash[data-variant="damage"] { background: #ff4d4d; }
.replay-flash[data-variant="heal"] { background: #39df8d; }
.replay-flash[data-variant="buff"] { background: #ffd15c; }
.replay-number, .replay-banner { position: absolute; z-index: 5; text-align: center; pointer-events: none; font-weight: 800; }
.replay-photo-window { container-type: size; position: relative; aspect-ratio: 4 / 3; margin: 2px; min-width: 0; }
.card[data-rarity] .replay-photo-window .card-portrait { position: absolute; inset: 0; margin: 0; width: 100%; height: 100%; }
.replay-number-lanes { position: absolute; z-index: 6; inset: calc(60% + 1px) 0 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); min-width: 0; overflow: hidden; }
.replay-number {
  --number-rise: clamp(1px, calc(40cqh - 1em - 2px), 12px);
  position: relative; left: auto; top: auto; width: 100%; max-width: 100%; min-width: 0;
  align-self: end; color: #fff; font-size: clamp(20px, 28cqh, 34px); line-height: 1;
  white-space: nowrap;
  text-shadow: -1px -1px 0 #10121b, 1px -1px 0 #10121b, -1px 1px 0 #10121b, 1px 1px 0 #10121b, 0 2px 4px #000;
}
.replay-number[data-slot="0"] { grid-column: 1; grid-row: 1; }
.replay-number[data-slot="1"] { grid-column: 2; grid-row: 1; }
.replay-number[data-slot="2"] { grid-column: 3; grid-row: 1; }
.replay-number:only-child { grid-column: 1 / -1; }
.replay-number-lanes[data-crowded="true"] .replay-number { font-size: clamp(14px, 17cqw, 26px); }
.replay-number small { position: absolute; bottom: 100%; left: 0; right: 0; font-size: 7px; line-height: 8px; }
.replay-number[data-variant="counter"] { color: #ffda70; }
.replay-number[data-variant="dodge"] { color: #80caff; }
.replay-number:is([data-variant="heal"], [data-variant="buff"]) { color: #65f7a6; }
.replay-number[data-variant="buff"] { font-size: clamp(12px, 20cqh, 20px); }
.replay-skill-row { position: relative; flex: none; height: 14px; }
.replay-banner { inset: 0; height: 14px; overflow: hidden; font-size: 10px; line-height: 14px; white-space: nowrap; text-overflow: ellipsis; color: var(--gold-hi); background: #111827ee; }
.replay-bottom { text-align: center; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-live { position: absolute; top: 0; left: 0; margin: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.replay-result { position: absolute; z-index: 6; top: 50%; left: 50%; transform: translate(-50%, -50%); box-sizing: border-box; width: min(94%, 620px); padding: clamp(12px, 3vw, 24px); border: 1px solid #e7c88a70; border-radius: 12px; background: #171d2b; box-shadow: 0 16px 80px #000b; }
.replay-result:focus { outline: none; }
[data-phase="result"] .replay-stage { opacity: .15; }
.replay-result h2 { margin: 0 0 4px; text-align: center; font-size: clamp(24px, 4vw, 36px); color: var(--gold-hi); }
.replay-result p { margin: 4px 0; text-align: center; font-size: 12px; }
.replay-result-strategy > * { display: block; font-size: 11px; line-height: 16px; color: var(--gold); }
.replay-close-win { display: block; text-align: center; color: #8fefba; font-size: 12px; }
.replay-mvp { display: flex; gap: 12px; align-items: center; margin: 12px 0; }
.replay-mvp .card-portrait { width: 64px; height: 48px; aspect-ratio: 4 / 3; flex: 0 0 64px; margin: 0; }
.replay-mvp > div:last-child { display: grid; gap: 5px; min-width: 0; font-size: 12px; }
.replay-mvp .replay-name { text-align: left; font-size: 16px; }
.replay-mvp small { color: var(--gold); }
.replay-stats { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 11px; }
.replay-stats :is(th, td) { padding: 6px 2px; border-bottom: 1px solid var(--line); text-align: center; overflow-wrap: anywhere; }
.replay-stats th { font-weight: 400; color: var(--muted); }
.replay-stats th:first-child { width: 31%; text-align: left; }
.replay-stats tbody th { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.replay-result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 14px; }
#battle-log { max-height: 360px; }
@media (min-width: 1000px) {
  .battle-replay { --replay-bar: 10px; }
  .replay-caption { font-size: 16px; }
}
@media (max-height: 480px) {
  .replay-stage { grid-template-rows: 38px minmax(0, 1fr) 22px minmax(0, 1fr) 18px; gap: 3px; }
  .replay-top { grid-template-columns: minmax(0, 1fr) auto auto; }
  .replay-round { grid-column: 2; grid-row: 1; }
  .replay-controls { grid-column: 3; grid-row: 1; }
  .replay-row { grid-template-rows: auto minmax(0, 1fr); gap: 2px; }
  .replay-caption { line-height: 22px; }
  .replay-result { display: grid; grid-template-columns: 1fr 1.4fr; column-gap: 18px; padding: 14px; }
  .replay-result[hidden] { display: none; }
  .replay-result > :is(h2, p, .replay-close-win, .replay-mvp) { grid-column: 1; }
  .replay-stats { grid-column: 2; grid-row: 1 / 6; align-self: center; }
  .replay-result-actions { grid-column: 1 / 3; margin-top: 8px; }
  .replay-mvp { margin: 8px 0 0; }
}

/* Strategy details occupy fixed tracks; portraits take the remaining space. */
:is([data-version="battle-v3"],[data-version="battle-v4"],[data-version="battle-v5"],[data-version="battle-v6"]) .replay-stage { grid-template-rows: 52px 42px minmax(0,1fr) 28px minmax(0,1fr) 24px; }
.replay-strategy { grid-row: 2; display: grid; align-content: center; gap: 3px; text-align: center; font-size: 11px; line-height: 15px; color: var(--gold); }
.replay-strategy > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-position { grid-row: 1; text-align: center; color: var(--gold); font-size: 10px; line-height: 15px; }
.replay-era { grid-row: 5; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 10px; line-height: 11px; overflow-wrap: anywhere; color: var(--gold); overflow: hidden; }
[data-legacy="true"] .replay-stage { grid-template-rows: 52px minmax(0,1fr) 28px minmax(0,1fr) 48px; }
[data-legacy="true"] .replay-bottom { display: grid; grid-template-rows: 18px auto; align-content: center; gap: 3px; white-space: normal; }
[data-legacy="true"] .replay-bottom > strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-legacy { display: block; color: var(--muted); font-size: 11px; line-height: 12px; }
.prepare-stage { max-width: 900px; height: 100%; margin: auto; display: grid; grid-template-rows: 36px minmax(0,1fr) 14px minmax(0,1fr) 40px 64px 16px 36px; gap: 4px; }
.prepare-stage:focus { outline: none; }
.prepare-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap; gap: 8px; box-sizing: border-box; min-width: 0; padding: 0 0 0 48px; margin: 0; width: 100%; }
.prepare-top h2 { margin: 0; font-size: 17px; }
.prepare-side { min-height: 0; display: grid; grid-template-rows: 17px minmax(0,1fr); gap: 3px; }
.prepare-side[data-bonus="true"] { grid-template-columns: auto minmax(0,1fr); grid-template-rows: 17px minmax(0,1fr); column-gap: 4px; }
.prepare-side[data-bonus="true"] .prepare-lineup { grid-column: 1 / -1; }
.prepare-side[data-bonus="true"] .prepare-bonus { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.prepare-bonus { align-self: center; text-align: center; font-size: 10px; line-height: 12px; color: var(--gold); }
.replay-team-bonus { max-width: 100%; white-space: normal; text-align: center; line-height: 13px; }
.prepare-side-name { font-size: 11px; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.prepare-lineup { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; min-height: 0; }
.prepare-unit { --unit-info-height: 62px; container-type: size; min-height: 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.prepare-position { font-size: 10px; line-height: 12px; color: var(--gold); text-align: center; }
.battle-replay .prepare-face { display: block; min-width: 0; min-height: 0; padding: 0; border: 0; background: none; white-space: normal; font-size: 11px; }
.battle-replay .prepare-face:disabled { opacity: 1; cursor: default; }
.prepare-face.is-draggable { touch-action: none; cursor: grab; user-select: none; }
.prepare-face.is-dragging { position: relative; z-index: 4; cursor: grabbing; box-shadow: 0 0 0 2px var(--gold); }
.prepare-unit.is-drop-target { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.prepare-face .card-portrait { min-height: 0; }
.prepare-face[aria-pressed="true"],.prepare-tactic[aria-pressed="true"] { border-color: var(--gold); background: #e7c88a25; box-shadow: inset 0 0 0 1px var(--gold); }
.battle-replay .prepare-era { min-height: 28px; padding: 1px 3px; color: var(--gold); font-size: 10px; line-height: 11px; white-space: normal; overflow-wrap: anywhere; }
.prepare-description,.prepare-scout,.prepare-cycle { margin: 0; align-self: center; text-align: center; font-size: 11px; line-height: 13px; }
.prepare-description { color: var(--muted); align-self: stretch; min-height: 0; overflow-y: auto; overflow-wrap: anywhere; padding: 2px; }
.prepare-scout { color: var(--gold); }
.prepare-tactics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
.battle-replay .prepare-tactic { white-space: normal; min-width: 0; display: grid; align-content: center; gap: 3px; padding: 4px; }
.prepare-tactic strong { font-size: 12px; }
.prepare-tactic span { font-size: 10px; line-height: 12px; }
.prepare-cycle { font-size: 10px; line-height: 12px; color: var(--gold); }
.prepare-start { justify-self: center; min-width: 150px; color: var(--gold-hi); border-color: var(--gold); }
@media (max-height: 480px) {
  [data-legacy="true"] .replay-stage { grid-template-rows: 38px minmax(0,1fr) 22px minmax(0,1fr) 38px; }
  :is([data-version="battle-v3"],[data-version="battle-v4"],[data-version="battle-v5"],[data-version="battle-v6"]) .replay-stage { grid-template-rows: 36px 32px minmax(0,1fr) 22px minmax(0,1fr) 18px; }
  :is([data-version="battle-v3"],[data-version="battle-v4"],[data-version="battle-v5"],[data-version="battle-v6"]) .replay-position { grid-column: 2; grid-row: 1; line-height: 12px; }
  .prepare-stage { grid-template-columns: 1fr 1fr; grid-template-rows: 34px minmax(0,1fr) 24px 54px 16px 34px; gap: 4px 16px; }
  .prepare-top { grid-column: 1 / 3; }
  .prepare-side { grid-row: 2; }
  .prepare-scout { grid-column: 1; grid-row: 3; }
  .prepare-description { grid-column: 2; grid-row: 3; font-size: 10px; line-height: 11px; }
  .prepare-tactics { grid-column: 1 / 3; grid-row: 4; }
  .prepare-cycle { grid-column: 1 / 3; grid-row: 5; }
  .prepare-start { grid-column: 1 / 3; grid-row: 6; }
}

/* Each unit is one centred group; spare height stays outside its labels/card. */
.replay-position { order: 0; flex: none; height: 12px; line-height: 12px; }
.replay-art { order: 1; }
.replay-era { order: 2; flex: none; height: 16px; }
.replay-skill-row { order: 3; }
.replay-meter { order: 4; flex: none; }
.replay-status { order: 5; flex: none; height: 15px; }
.replay-hp { line-height: 15px; }
.replay-unit.is-acting .card-face { box-shadow: 0 0 15px #e7c88a88; }
.replay-unit.is-target .card-face { box-shadow: 0 0 0 2px #ff4d4dbb, 0 0 22px #ff4d4d99; }
.prepare-position { flex: none; height: 12px; }
.prepare-skills { display: grid; flex: none; grid-template-columns: repeat(2,minmax(0,1fr)); grid-auto-rows: 22px; gap: 2px; height: 46px; min-width: 0; }
.battle-replay .prepare-skills .prepare-era {
  min-width: 0; min-height: 0; padding: 0 1px; font-size: 8.5px; line-height: 10px;
  white-space: normal; overflow-wrap: anywhere; text-overflow: clip;
}
.prepare-skill-label { display: block; min-width: 0; }
.prepare-skills > :only-child { grid-column: 1 / -1; }
.replay-result { max-height: calc(100dvh - 20px); overflow-y: auto; }
.battle-replay .card-compact .card-name { font-size: clamp(10px, 6.5cqi, 18px); text-align: left; }
.battle-replay .card-compact .card-class { font-size: clamp(7px, 3.6cqi, 11px); justify-self: start; text-align: left; }
@media (min-width: 700px) and (min-height: 481px) {
  .battle-replay { --compact-name-height: 60px; --compact-fixed-height: 86.5px; }
  .prepare-unit { --unit-info-height: 78px; }
  .prepare-skills { grid-auto-rows: 30px; height: 62px; }
  .battle-replay .prepare-skills .prepare-era { font-size: 11px; line-height: 13px; }
}
@media (min-width: 380px) and (min-height: 481px) {
  .replay-number { font-size: clamp(20px, 28cqh, 34px); }
  .replay-number-lanes[data-crowded="true"] .replay-number { font-size: clamp(16px, 17cqw, 26px); }
}
@media (min-width: 1000px) {
  .replay-number { font-size: clamp(26px, 28cqh, 34px); }
}
@media (min-width: 700px) and (min-height: 481px) and (max-height: 800px) {
  .battle-replay { --compact-name-height: 52px; --compact-fixed-height: 78.5px; }
}
@media (max-width: 400px) and (min-height: 481px) and (max-height: 700px) {
  :is([data-version="battle-v3"],[data-version="battle-v4"],[data-version="battle-v5"],[data-version="battle-v6"]) .replay-stage { grid-template-rows: 44px 34px minmax(0,1fr) 24px minmax(0,1fr) 20px; gap: 5px; }
  .replay-row { gap: 3px; }
  .replay-bonuses { min-height: 18px; }
}
@media (max-height: 480px) {
  .battle-replay { --compact-name-height: 32px; --compact-fixed-height: 58.5px; }
  .battle-replay .card-compact .card-namebar { padding-block: 1px; }
  .battle-replay .card-compact .card-name { font-size: 9px; }
  .battle-replay .card-compact .card-class { font-size: 7px; }
  .replay-bonuses { min-height: 18px; }
  .replay-unit { display: grid; grid-template-columns: 48% minmax(0,1fr); grid-template-rows: 12px 16px 14px var(--replay-bar) 15px; align-content: center; gap: 2px; }
  .replay-unit .replay-art { grid-column: 1; grid-row: 1 / 6; width: min(100%, calc((100cqh - var(--compact-fixed-height)) / .75)); }
  .replay-unit > :is(.replay-position,.replay-era,.replay-skill-row,.replay-meter,.replay-status) { grid-column: 2; }
  .replay-position { grid-row: 1; }
  .replay-era { grid-row: 2; }
  .replay-skill-row { grid-row: 3; }
  .replay-meter { grid-row: 4; }
  .replay-status { grid-row: 5; }
  .replay-number, .replay-number-lanes[data-crowded="true"] .replay-number { font-size: 12px; }
  .replay-number small { font-size: 5px; }
}

/* PK batch 1: archive difficulty and challenge reports. */
#archive-difficulty-control { margin-block: 1rem; }
#archive-difficulty-control label { display: block; margin-bottom: .5rem; font-weight: 600; }
#archive-difficulty {
  appearance: none;
  width: 240px; max-width: 100%; padding: 8px 28px 8px 12px; min-height: 44px;
  border: 1px solid #ffffff24; border-radius: var(--radius); background: var(--panel);
  color: #f4efe5; font: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23f4efe5' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
#archive-difficulty:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
#archive-difficulty-rule, #my-challenges-note { color: var(--muted); line-height: 1.6; }
#my-challenges { margin-top: 2rem; }
.pk-challenge { border-top: 1px solid var(--line); padding-block: 1rem; overflow-wrap: anywhere; }
.pk-sent, .pk-team { line-height: 1.6; }
.pk-count, .pk-report-result, .pk-counter-result { color: var(--muted); }
.pk-report { border-inline-start: 3px solid var(--line); padding: .5rem 1rem; margin-block: 1rem; }
.pk-report h3 { margin-block: 0 .5rem; }
.pk-report[data-result="win"] { border-color: #7a9c67; }
.pk-report[data-result="loss"] { border-color: #bb7167; }
.pk-counter-result[data-result="win"] { color: #7a9c67; }
.pk-counter-result[data-result="loss"] { color: #bb7167; }
@media (max-width: 480px) {
  #archive-difficulty-control label { display: block; margin-bottom: .5rem; }
  #archive-difficulty { width: 100%; }
  .pk-report { padding-inline: .75rem; }
}

/* Settlement shares the preparation layout and keeps the battle controls fixed. */
.prepare-scouting { min-height: 0; align-self: center; }
.prepare-note { margin: 3px 0 0; text-align: center; color: var(--muted); font-size: 11px; line-height: 14px; overflow-wrap: anywhere; }
.prepare-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.prepare-actions button { min-width: 0; white-space: normal; }
.prepare-actions .prepare-start { min-width: 150px; }
.prepare-stage[data-extra="true"] { grid-template-rows: 36px minmax(0,1fr) minmax(14px,auto) minmax(0,1fr) 40px 64px 16px auto; }
.prepare-error { color: var(--gold-hi); }
.battle-preparation [aria-busy="true"] { cursor: wait; }
@media (max-height: 480px) {
  .prepare-scouting { grid-column: 1; grid-row: 3; }
  .prepare-actions { grid-column: 1 / 3; grid-row: 6; }
  .prepare-stage[data-extra="true"] { grid-template-rows: 34px minmax(0,1fr) auto 54px 16px auto; }
}

/* The optional FX layer never changes the formal card face or 2D replay layout. */
.battle-replay[data-fx="webgl"] .replay-fx-canvas { position: absolute; inset: 0; z-index: 5; width: 100%; height: 100%; pointer-events: none; }
.battle-replay[data-fx="webgl"] .language-control { z-index: 10; }
.battle-replay[data-fx="webgl"] .replay-result { z-index: 7; background: #171d2bf2; }
.battle-replay[data-fx="webgl"] .replay-fx-title { position: absolute; z-index: 6; inset: 46% 4% auto; pointer-events: none; text-align: center; font: 700 clamp(20px, 5vw, 46px)/1.15 var(--serif); color: #f4e6c2; letter-spacing: .04em; text-shadow: 0 2px 0 #1a0f05, 0 0 2px #000, 0 0 10px #c8962a77; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.battle-replay[data-fx="webgl"] .replay-fx-title[data-kind="heal"] { color: #c3ecd0; text-shadow: 0 2px 0 #06180b, 0 0 2px #000, 0 0 8px #2e9c5f77; }
.battle-replay[data-fx="webgl"] .replay-fx-title[data-kind="defense"] { color: #dbe5ef; text-shadow: 0 2px 0 #0b1420, 0 0 2px #000, 0 0 8px #6f8fb077; }
.battle-replay[data-fx="webgl"] .replay-unit.is-acting .card-face { box-shadow: 0 0 20px #e7c88aaa; }
.battle-replay[data-fx="webgl"] .replay-number { font-size: clamp(24px, 32cqh, 42px); text-shadow: -1px -1px 0 #111, 1px 1px 0 #111, 0 2px 4px #000, 0 0 8px #fff6; }
.battle-replay[data-fx="webgl"] .replay-number-lanes[data-crowded="true"] .replay-number { font-size: clamp(16px, 19cqw, 30px); }
.battle-replay[data-fx="webgl"] .replay-number[data-variant="heavy"] { color: #ffb94e; text-shadow: -1px -1px 0 #2b1405, 1px 1px 0 #2b1405, 0 0 10px #ff962a; }
.battle-replay[data-fx="webgl"] .replay-number[data-variant="counter"] { color: #ffe096; text-shadow: -1px -1px 0 #43111d, 1px 1px 0 #43111d, 0 0 10px #ff506d; }
.battle-replay[data-fx="webgl"][data-fx-effect="victory"] .replay-result h2 { color: #f3d17a; letter-spacing: .06em; text-shadow: 0 1px 0 #fff6d8, 0 3px 0 #5a3a0e, 0 5px 6px #000, 0 0 14px #c8962a55; }
.battle-replay[data-fx="webgl"][data-fx-effect="defeat"] .replay-result h2 { color: #b9c5d6; letter-spacing: .06em; text-shadow: 0 1px 0 #e6edf3, 0 3px 0 #1d2633, 0 5px 6px #000; }
.battle-replay[data-fx="webgl"][data-fx-effect="draw"] .replay-result h2 { color: #d8dee6; letter-spacing: .06em; text-shadow: 0 1px 0 #fff, 0 3px 0 #2a3240, 0 5px 6px #000; }
.battle-replay .replay-controls { gap: 3px; }
.battle-replay .replay-controls button { padding-inline: 6px; }

.replay-fx-notice { position: absolute; z-index: 9; top: calc(64px + env(safe-area-inset-top, 0px)); right: 10px; left: 10px; margin: 0; padding: 4px 8px; border-radius: 4px; background: #121622ed; color: #e8d7b3; text-align: center; font-size: 10px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.replay-fx-debug { position: absolute; z-index: 9; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); padding: 4px 7px; border-radius: 4px; color: #d6f7ff; background: #08101dec; font: 10px/16px monospace; pointer-events: none; }

/* Small 2D class cues share existing artwork and never participate in layout. */
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Warrior"] { --class-fx: #ff713d; --class-fx-alt: #ed304d; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Ruler"] { --class-fx: #ffd34a; --class-fx-alt: #9b57ed; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Religious"] { --class-fx: #c2eaff; --class-fx-alt: #fff1bf; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Artist"] { --class-fx: #ff3dbf; --class-fx-alt: #35e9ed; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Scholar"] { --class-fx: #38cfff; --class-fx-alt: #7657ef; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Sports"] { --class-fx: #b1ff39; --class-fx-alt: #26cda3; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Civic"] { --class-fx: #adc9d9; --class-fx-alt: #309caa; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Business"] { --class-fx: #ffbc28; --class-fx-alt: #25de8d; }
.battle-replay :is(.replay-flash,.replay-class-mark,.replay-banner)[data-class="Other"] { --class-fx: #91baff; --class-fx-alt: #a675ff; }
.battle-replay:not([data-fx="webgl"]) .replay-flash[data-variant="damage"][data-class] { background: radial-gradient(ellipse at center, #fff8, var(--class-fx) 35%, var(--class-fx-alt) 85%); }
.battle-replay:not([data-fx="webgl"]) .replay-banner[data-class] { color: var(--class-fx); border-bottom: 1px solid var(--class-fx-alt); box-sizing: border-box; }
.replay-class-mark { position: absolute; z-index: 7; inset: 12% auto auto 50%; margin-left: -19px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--class-fx); background: radial-gradient(circle, #10192cf2 45%, var(--class-fx-alt)); box-shadow: 0 0 12px var(--class-fx); pointer-events: none; }
.replay-class-mark .card-class-icon { position: static; width: 30px; height: 30px; filter: brightness(1.5); }
.replay-class-mark[data-class="Warrior"] { border-radius: 2px 16px; }
.replay-class-mark[data-class="Ruler"] { border-style: double; border-width: 3px; }
.replay-class-mark[data-class="Religious"] { border-color: #fff; box-shadow: 0 0 6px #fff, 0 0 14px var(--class-fx); }
.replay-class-mark[data-class="Artist"] { border-radius: 40% 65% 30% 55%; background: conic-gradient(#fa39bd, #33eced, #ffe359, #fa39bd); }
.replay-class-mark[data-class="Scholar"] { border-style: dotted; }
.replay-class-mark[data-class="Sports"] { border-inline-width: 5px; }
.replay-class-mark[data-class="Civic"] { border-radius: 8px; }
.replay-class-mark[data-class="Business"] { border-style: double; border-width: 4px; background: radial-gradient(circle, #5e4618, #b78c29); }
.battle-replay[data-fx="webgl"] .replay-class-mark { display: none; }

/* Expedition and duel screens sit outside the full-screen battle overlays. */
.battle-panels>#expedition { border-color: var(--line-gold); background: linear-gradient(128deg,#d9b46c17,transparent 65%),var(--panel-fill); }
.battle-panels>#wager { border-color: #d3505f55; background: linear-gradient(128deg,#a8303f22,transparent 65%),var(--panel-fill); }
.pk-entry { overflow-wrap: anywhere; }
.pk-entry>p { margin-block: 6px 12px; }
.pk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-block: 10px; }
.pk-actions button { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.pk-entry-actions { display: grid; justify-items: start; min-block-size: var(--control); margin-block: 10px 0; }
.pk-entry-actions>button,.wager-entry-status>button { padding: 6px 14px; font-size: var(--text-sm); line-height: 1.25; }
.pk-entry>p.expedition-entry-progress { min-block-size: 1.7em; margin-block: 6px; white-space: nowrap; color: var(--gold-hi); }
html[data-session] #wager .wager-guest-shell,html:not([data-session]) #wager .wager-account-shell { display: none; }
.wager-entry-status { display: flex; align-items: flex-start; gap: 8px; block-size: 88px; }
.wager-entry-text { flex: 1; min-inline-size: 0; max-block-size: 100%; overflow-y: auto; scrollbar-width: thin; }
.wager-entry-text :is(p,ul) { margin: 0; }
.wager-entry-status>button { flex: none; max-width: 48%; }
.pk-status { color: var(--gold-hi); overflow-wrap: anywhere; }
.pk-status:empty { display: none; }
.account-dialog:is(.expedition-dialog,.wager-dialog) { width: min(760px,calc(100vw - 24px)); }
:is(.expedition-dialog,.wager-dialog) .dialog-heading { flex-wrap: nowrap; }
:is(.expedition-dialog,.wager-dialog) .dialog-heading h2 { min-width: 0; margin: 4px 0 8px; }
:is(.expedition-dialog,.wager-dialog) .dialog-heading button { flex: none; white-space: nowrap; }
.pk-card-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; align-items: start; }
.pk-card-grid>* { min-width: 0; max-width: 100%; }
.pk-card-grid .card-compact { width: 100%; }
.pk-card-grid .card-compact .card-visual { --card-name-height: clamp(30px,6vw,42px); }
.pk-card-grid .card-compact .card-portrait { aspect-ratio: 4/3; }

.expedition-map-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 16px; color: var(--gold-hi); }
.expedition-dialog .expedition-map-head p { margin: 4px 0; }
.expedition-chapters { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 6px; margin: 14px 0; }
.expedition-chapters button { padding: 8px 6px; line-height: 1.3; font-size: var(--text-sm); overflow-wrap: anywhere; }
.expedition-chapters button[aria-pressed="true"],.expedition-node[aria-current="step"] { border-color: var(--gold); color: var(--gold-hi); background: #32281d; }
.expedition-chapters small { display: block; margin-top: 4px; color: var(--muted); }
.expedition-path { position: relative; display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); grid-template-rows: repeat(2,minmax(62px,auto)); gap: 9px; margin: 14px 0; }
.expedition-path::before { content: ""; position: absolute; inset: 30px 9%; border: 1px solid var(--line-gold); border-inline-start: 0; border-radius: 0 12px 12px 0; pointer-events: none; }
.expedition-node { position: relative; display: grid; align-content: center; justify-items: center; gap: 3px; min-width: 0; padding: 5px 2px; line-height: 1.15; }
.expedition-node:nth-child(n+6) { grid-row: 2; }
.expedition-node:nth-child(6) { grid-column: 5; }
.expedition-node:nth-child(7) { grid-column: 4; }
.expedition-node:nth-child(8) { grid-column: 3; }
.expedition-node:nth-child(9) { grid-column: 2; }
.expedition-node:nth-child(10) { grid-column: 1; }
.expedition-node[data-state="locked"] { color: var(--muted); background: #10141b; border-style: dashed; }
.expedition-node[data-state="open"] { border-color: var(--gold); }
.expedition-node[data-state="cleared"] { color: var(--gold-hi); border-color: var(--line-gold); }
.expedition-node-stars,.expedition-pending { color: var(--gold-hi); font-size: var(--text-xs); }
.expedition-pending { position: absolute; inset: 5px 5px auto auto; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px #d9b46c30; }
.expedition-stage,.expedition-codex { border-top: 1px solid var(--line-2); padding-top: 12px; margin-top: 14px; }
.expedition-codex summary { color: var(--gold-hi); cursor: pointer; padding-block: 6px; }
.expedition-lineup { max-width: 540px; }
.expedition-lineup>div { display: grid; gap: 5px; text-align: center; font-size: var(--text-xs); }
.expedition-conditions { padding-inline-start: 20px; line-height: 1.55; }
.expedition-conditions li[data-met="true"] { color: #b7dcaa; }
.expedition-conditions li[data-met="false"] { color: #f4a2a3; }
.expedition-result { border-inline-start: 2px solid var(--gold); padding-inline-start: 12px; }

.pk-entry-actions>.wager-panel { width: 100%; }
#battle #wager .wager-panel>summary { display: flex; width: fit-content; min-height: var(--control); max-width: 100%; overflow-wrap: anywhere; line-height: 1.25; }
.wager-gate { padding-inline-start: 20px; color: var(--muted); line-height: 1.65; }
.wager-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px 10px; border-top: 1px solid var(--line-2); padding-block: 8px; overflow-wrap: anywhere; }
.wager-row> * { min-width: 0; }
.wager-countdown { color: var(--gold-hi); font-variant-numeric: tabular-nums; }
.wager-warning { background: #a8303f20; color: #f8ded9; border: 1px solid #d3505f66; border-radius: var(--radius-sm); padding: 12px; line-height: 1.6; }
.wager-consent { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 8px; align-items: start; line-height: 1.5; overflow-wrap: anywhere; }
:is(.wager-dialog,#settings-wager) .wager-consent input { width: 18px; height: 18px; margin-top: 3px; padding: 0; accent-color: var(--gold); }
.wager-dialog-content { min-width: 0; }
.wager-card { display: grid; min-width: 0; gap: 4px; }
.wager-card>button,.pk-card-grid>button { width: 100%; min-width: 0; max-width: 100%; padding: 4px; overflow-wrap: anywhere; }
.wager-card-count { color: var(--muted); font-size: var(--text-xs); text-align: center; font-variant-numeric: tabular-nums; }
.wager-card [aria-pressed="true"],.pk-card-grid>button[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
/* The loading caption is removed when the portrait settles; let presses land on the stable frame. */
.wager-dialog .card-portrait-note { pointer-events: none; }
.wager-lock-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; }
.wager-lock-controls button { width: 30px; min-height: 36px; padding: 2px; }
#wager-consent-modal .wager-pool { max-height: min(44dvh,400px); overflow: auto; overscroll-behavior: contain; padding: 3px; }
body:has(> dialog.battle-replay[open])>:is(.expedition-dialog,.wager-dialog) :is(.card-sweep,.card-particle) { animation-play-state: paused; }
@media (min-width: 601px) {
  .wager-pool.pk-card-grid { grid-template-columns: repeat(5,minmax(0,1fr)); }
}
@media (max-width: 600px) {
  .expedition-chapters { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .expedition-path { gap: 6px; }
  .pk-card-grid { gap: 5px; }
}
