.viewer {
  min-width: 0;
  color: var(--ink);
  background: #211e26;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: clip;
  container: frame-viewer / inline-size;
}
.viewer .scenario-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 17px;
  min-height: 47px;
  padding: 7px 15px;
  border-bottom: 1px solid #423942;
  background: #26222b;
}
.viewer .scenario-outcome {
  display: flex;
  flex: 1 1 90px;
  align-items: center;
  gap: 8px;
  margin: 0;
  font: 650 .82rem/1.2 var(--sans);
}
.scenario-outcome::before {
  content: "";
  flex: 0 0 7px;
  height: 7px;
  border-radius: 50%;
  background: #a89eaf;
}
.scenario-outcome[data-outcome]::before { background: #c8ade4; }
.scenario-outcome:is([data-outcome=hit],[data-outcome=throw])::before { background: var(--accent); }
.scenario-outcome:is([data-outcome=parry],[data-outcome=block])::before { background: #84d4d6; }
.viewer .box-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 0;
  cursor: pointer;
  color: #e4dfe5;
  font: 600 .76rem/1.25 var(--sans);
}
.box-toggle input {
  appearance: none;
  position: relative;
  width: 23px;
  height: 13px;
  margin: 0;
  padding: 0;
  border-radius: 9px;
  border: 1px solid #93879a;
  background: #322c38;
  cursor: pointer;
}
.box-toggle input::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e9e1ee;
}
.box-toggle input:checked { background: #bda5db; border-color: #bda5db; }
.box-toggle input:checked::after { left: 12px; background: #2a1f32; }
.viewer-button, .viewer-controls select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 30px;
  min-height: 30px;
  border: 1px solid #504852;
  border-radius: 4px;
  padding: 4px 9px;
  color: #f6f0e9;
  background: #2f2933;
  cursor: pointer;
  font: 650 .76rem/1.1 var(--sans);
}
.viewer-button:hover, .viewer-controls select:hover { background: #403546; border-color: #8d7b93; }
.viewer-button:active { background: #48374a; }
.viewer :is(button, select, input):focus-visible { outline: 2px solid #e9b6ff; outline-offset: 2px; }
.setup-button::before {
  content: "";
  width: 12px;
  height: 12px;
  background:
    linear-gradient(currentColor 0 0) 3px 1px / 2px 4px,
    linear-gradient(currentColor 0 0) 8px 7px / 2px 4px,
    linear-gradient(currentColor 0 0) 0 2px / 100% 2px,
    linear-gradient(currentColor 0 0) 0 8px / 100% 2px;
  background-repeat: no-repeat;
}
.setup-button[aria-expanded=true] { border-color: #b599c8; color: #edcef7; background: #48374a; }
.scenario-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px),1fr));
  gap: 14px 20px;
  align-items: end;
  margin: 0;
  padding: 15px;
  min-inline-size: 0;
  background: #302933;
  border: 0;
  border-bottom: 1px solid #4c404e;
}
.scenario-controls legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.viewer .scenario-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: #e7dee8;
  font: 600 .76rem/1.3 var(--sans);
}
.scenario-field select {
  width: 100%;
  min-width: 0;
  min-height: 33px;
  padding: 4px 6px;
  border: 1px solid #675a6c;
  border-radius: 3px;
  background: #242026;
  color: var(--ink);
  font: inherit;
}
.scenario-field > span { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.scenario-value { color: #dfbbea; font: 500 .69rem/1.25 var(--mono); }
.scenario-field input[type=range] { width: 100%; height: 26px; margin: 0; accent-color: #d5afe0; cursor: pointer; }
.viewer .scenario-toggle { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.scenario-toggle input { width: 16px; height: 16px; order: -1; margin: 0; accent-color: #d5afe0; }

.aerial-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 20px;
  min-inline-size: 0;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 14px;
  background: #2a232d;
}
.aerial-controls legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.viewer .aerial-direction { display: flex; align-items: center; gap: 9px; }
.aerial-direction select { width: auto; min-height: 30px; }
.viewer .aerial-delay { flex: 1 1 150px; max-width: 260px; gap: 0; }
.aerial-delay input[type=range] { height: 18px; }
.aerial-toggle input { order: -1; }
.aerial-markers { display: flex; flex-wrap: wrap; gap: 4px; }
.viewer .aerial-marker { min-height: 24px; padding: 3px 6px; color: #e3c9ef; font: 600 10px/1 var(--mono); }

.viewer .scenario-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: clamp(180px, 28vh, 310px);
  height: clamp(180px, 28dvh, 310px);
  background:
    radial-gradient(ellipse at 50% 78%, #5d405c5c, transparent 53%),
    radial-gradient(ellipse at 0% 95%, #7c443327, transparent 60%),
    linear-gradient(#1c1a23, #332735 65%, #3c3040 66%, #322a38 100%);
}
.scenario-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background-image:
    linear-gradient(#b29bba12 1px,transparent 1px),
    linear-gradient(90deg,#b29bba12 1px,transparent 1px);
  background-size: 28px 28px;
  background-position: center;
  mask-image: linear-gradient(to bottom,#0006 0%,#000 62%,transparent 66%);
}
.scenario-stage::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 65%;
  left: -60%;
  right: -60%;
  height: 110%;
  border-top: 1px solid #b395b84f;
  background-image:
    linear-gradient(#c39bc03b 1px,transparent 1px),
    linear-gradient(90deg,#c39bc033 1px,transparent 1px);
  background-size: 35px 12px;
  background-position: center top;
  transform: perspective(110px) rotateX(62deg);
  transform-origin: center top;
}
.aerial-stage::after { top: 84%; }
.aerial-stage::before {
  mask-image: linear-gradient(to bottom, #0007, #000 78%, transparent 84%);
}
.viewer .aerial-stage {
  background: radial-gradient(ellipse at 52% 88%, #59425c69, transparent 60%),
    linear-gradient(#1c1a23, #362a3a 84%, #392c3c 84%, #2c2530);
}
.viewer .viewer-stage {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  image-rendering: pixelated;
}
.stage-fighter {
  position: absolute;
  left: 13px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ece4e4;
  font: 700 11px/1 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  pointer-events: none;
}
.stage-fighter.opponent { left: auto; right: 13px; flex-direction: row-reverse; }
.player-side {
  padding: 3px 5px;
  background: #e4a17c;
  color: #291d23;
  font: 800 10px/1 var(--mono);
  clip-path: polygon(0 0,100% 0,100% 69%,84% 100%,0 100%);
}
.opponent .player-side { background: #bda7dd; }
.viewer .viewer-controls {
  display: grid;
  grid-template-columns: auto auto auto minmax(24px,1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid #514351;
  background: #28232c;
}
.viewer .playback-button {
  width: 77px;
  color: #26170f;
  background: var(--accent);
  border-color: var(--accent);
}
.viewer .playback-button:hover { background: #ffa47d; border-color: #ffa47d; }
.playback-button::before, .step-button::before {
  content: "";
  width: 9px;
  height: 10px;
  background: currentColor;
  clip-path: polygon(0 0,100% 50%,0 100%);
}
.playback-button.playing::before {
  clip-path: none;
  background: linear-gradient(to right,currentColor 0 32%,transparent 32% 64%,currentColor 64%);
}
.viewer .step-button { padding: 4px; }
.step-button::before {
  width: 10px;
  clip-path: polygon(0 0,77% 44%,77% 0,100% 0,100% 100%,77% 100%,77% 56%,0 100%);
}
.step-button.previous::before { transform: rotate(180deg); }
.viewer .viewer-slider { width: calc(100% - 8px); min-width: 0; margin: 0 4px; accent-color: var(--accent); cursor: pointer; }
.viewer-controls select { display: block; width: auto; min-width: 0; padding: 4px; font: 600 11px/1.2 var(--mono); }
.viewer-controls .viewer-frame { max-width: 134px; }
.viewer-controls :disabled { opacity: .6; cursor: default; }
.viewer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  min-height: 30px;
  padding: 6px 14px;
  border-top: 1px solid #3f3741;
  color: #c9beca;
  font: 500 10px/1.35 var(--sans);
}
.box-legends { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; }
.box-key { display: inline-flex; align-items: center; gap: 4px; }
.box-key::before { content: ""; width: 7px; height: 7px; border: 1px solid var(--box-color); background: color-mix(in srgb,var(--box-color) 24%,transparent); }
.viewer .scenario-source { margin: 0 0 0 auto; color: #afa5b5; font-size: 10px; }
.viewer .viewer-note { margin: 0; padding: 1px 14px 9px; color: #d4c8d6; font: .75rem/1.45 var(--sans); }
.viewer .viewer-note:empty { display: none; }

@container frame-viewer (max-width: 480px) {
  .viewer .scenario-head { gap: 5px 10px; padding-inline: 10px; }
  .viewer .viewer-controls { gap: 5px; padding-inline: 9px; }
  .viewer .playback-button { width: 32px; font-size: 0; gap: 0; }
  .viewer .viewer-frame { max-width: 88px; }
  .box-legends { gap: 4px 7px; }
  .viewer .scenario-source { margin-left: 0; }
}
@container frame-viewer (max-width: 335px) {
  .viewer .scenario-head { gap: 3px 7px; }
  .viewer .scenario-outcome { flex-basis: 68px; font-size: .73rem; }
  .viewer .setup-button { padding-inline: 5px; }
  .viewer .viewer-controls { grid-template-columns: auto auto auto 1fr auto; }
  .viewer .viewer-slider { grid-area: 1/1/2/-1; min-height: 22px; }
  .viewer-controls .viewer-frame { max-width: 100%; }
}
@media (forced-colors: active) {
  .box-toggle input { appearance: auto; }
  .box-toggle input::after { display: none; }
  .step-button::before, .playback-button::before { forced-color-adjust: none; color: ButtonText; }
}
