figure:is(#settle-n-loop, .settle-n-loop) {
  --f-ground: #0B1226;
  --f-ink: #FFFFFF;
  --f-dim: #AEB9CC;
  --f-blue: #427BFF;
  --f-line: #27345A;
  width: 100%;
  margin: 0;
  container: settle-n / inline-size;
  color: var(--f-ink);
}

.on-paper figure:is(#settle-n-loop, .settle-n-loop) {
  --f-ground: var(--paper, #D4DEF0);
  --f-ink: #0A1020;
  --f-dim: #35435E;
  --f-line: #AEBDD8;
}

:root[data-theme="dark"] .on-paper figure:is(#settle-n-loop, .settle-n-loop) {
  --f-ground: #0B1226;
  --f-ink: #FFFFFF;
  --f-dim: #AEB9CC;
  --f-line: #27345A;
}

.sn-stage {
  --layout-width: 1280;
  --sn-unit: clamp(1px, .078125cqi, 1.25px);
  --sn-body: calc(15 * var(--sn-unit));
  --sn-title: calc(17 * var(--sn-unit));
  --sn-quote: calc(21 * var(--sn-unit));
  --sn-fill: var(--f-ground);
  --sn-best: color-mix(in srgb, var(--f-ground) 89%, var(--f-blue));
  position: relative;
  isolation: isolate;
  height: calc(384 * var(--sn-unit));
  font: 500 var(--sn-body)/1.2 var(--font-body, sans-serif);
}

.sn-stage :is(.sn-request, .sn-board, .sn-contract, .sn-outcome) {
  position: absolute;
  left: calc(var(--x) / var(--layout-width) * 100%);
  top: calc(var(--y) * var(--sn-unit));
  width: calc(var(--w) / var(--layout-width) * 100%);
  z-index: 1;
}

.sn-stage .sn-node {
  border: 1px solid var(--f-line);
  border-radius: 12px;
  background: var(--sn-fill);
}

.sn-label {
  font: 600 var(--sn-title)/1.15 var(--font-display, sans-serif);
}

.sn-request {
  --x: 0; --y: 140; --w: 294;
  display: grid;
  gap: 14px;
  padding: 20px;
}

.sn-pair,
.sn-pair .sn-value {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sn-pair .sn-value {
  font-size: var(--sn-body);
}

.sn-pair img {
  width: 32px;
}

.sn-pair-label {
  display: none;
}

.sn-arrow {
  color: var(--f-dim);
}

.sn-value {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font: 500 var(--sn-body)/1 var(--font-mono, monospace);
  font-variant-numeric: tabular-nums;
}

.sn-value img, .sn-seat img {
  flex: none;
  max-width: none;
}

.sn-board {
  --x: 366; --y: 48; --w: 318;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: calc(8 * var(--sn-unit));
}

.sn-stage .sn-bid {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  height: calc(44 * var(--sn-unit));
  white-space: nowrap;
  padding-inline: 10px;
  color: var(--f-dim);
}

.sn-bid .sn-value {
  color: var(--f-ink);
}

.sn-bid [data-sn-quote], .sn-amount {
  font-size: var(--sn-quote);
  letter-spacing: -.03em;
}

.sn-stage .sn-bid[data-best] {
  background: var(--sn-best);
  border-color: color-mix(in srgb, var(--f-line) 72%, var(--f-blue));
  color: var(--f-ink);
}

.sn-bid[data-best]::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 3px;
  border-radius: 999px;
  background: var(--f-blue);
}

.sn-badge {
  display: none;
  width: max-content;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--f-line) 65%, var(--f-blue));
  border-radius: 999px;
  padding: 2px 5px;
  font-size: clamp(13px, var(--sn-body) - 2px, 16px);
  line-height: 1;
}

.sn-bid[data-best] .sn-badge {
  display: flex;
}

.sn-bid:not([data-best]) .sn-value {
  grid-column: 3;
}

.sn-taken {
  display: none;
}

.sn-bid[data-taken] .sn-taken {
  display: inline;
  margin-inline-start: 4px;
  padding-inline-start: 4px;
  border-inline-start: 1px solid var(--f-line);
}

.sn-contract {
  --x: 754; --y: 110; --w: 252;
  height: calc(164 * var(--sn-unit));
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  padding-inline: 5px;
  text-align: center;
}

.sn-seat {
  display: grid;
  place-items: center;
  width: calc(48 * var(--sn-unit));
  height: calc(48 * var(--sn-unit));
  border: 1px solid var(--f-line);
  border-radius: 50%;
  background: var(--f-ground);
}

.sn-seat img {
  width: calc(36 * var(--sn-unit));
  opacity: var(--sn-locked, 1);
}

.sn-locked {
  opacity: var(--sn-lock-label, 1);
  color: var(--f-dim);
}

.sn-transaction {
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--f-dim);
}

.sn-stage:not([data-animated]) .sn-transaction,
.sn-stage[data-paying] .sn-transaction {
  color: var(--f-ink);
  background: var(--sn-best);
}

.sn-refund {
  margin: 0;
  color: var(--f-dim);
}

.sn-outcome {
  --x: 1066; --w: 202;
  height: calc(88 * var(--sn-unit));
  display: grid;
  justify-items: center;
  align-content: center;
  gap: calc(8 * var(--sn-unit));
  padding: 10px 4px;
  text-align: center;
}

.sn-you { --y: 74; }
.sn-solver { --y: 222; }

.sn-outcome .sn-value {
  opacity: var(--sn-result, 1);
}

.sn-outcome .sn-value > span {
  width: max-content;
  display: flex;
  align-items: baseline;
  gap: 4px;
  text-align: left;
}

.sn-outcome img {
  width: calc(32 * var(--sn-unit));
  opacity: var(--sn-paid, 1);
}

.sn-routes, .sn-motion {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sn-routes {
  display: block;
  fill: none;
  stroke: color-mix(in srgb, var(--f-line) 88%, var(--f-dim));
  stroke-width: 1.5px;
  stroke-linecap: round;
}

.sn-routes path {
  vector-effect: non-scaling-stroke;
}

.sn-routes [data-offer]:not([data-selected]) {
  visibility: hidden;
}

.sn-routes [data-selected] {
  stroke: color-mix(in srgb, var(--f-line) 26%, var(--f-blue));
}

.sn-routes .sn-trace {
  stroke: var(--f-blue);
  opacity: 0;
}

.sn-motion {
  /* Travellers enter and leave behind the face of each card. */
  z-index: 0;
}

.sn-motion > * {
  position: absolute;
  transform: translate(-50%, -50%);
  opacity: 0;
}

.sn-motion img {
  width: calc(32 * var(--sn-unit));
  height: calc(32 * var(--sn-unit));
}

.sn-motion i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--f-blue);
}

.sn-tall {
  display: none;
}

.sn-wide [data-open] {
  d: path("M147 140C147 50 294 22 497 22C718 22 880 45 880 110");
}

@container settle-n (1130px <= width < 1240px) {
  .sn-request .sn-pair,
  .sn-pair .sn-value {
    gap: 4px;
    font-size: 14px;
  }

  .sn-pair img { width: 28px; }
}

@container settle-n (700px <= width < 1130px) {
  .sn-request { --y: 117; }

  .sn-contract {
    --y: 92;
    height: 200px;
    gap: 4px;
    font-size: 13px;
  }

  .sn-wide [data-open] {
    d: path("M147 117C147 50 294 22 497 22C718 22 880 45 880 92");
  }
}

@container settle-n (700px <= width < 1130px) or (width < 278px) {
  .sn-request .sn-pair {
    display: grid;
    gap: 6px;
  }

  .sn-pair .sn-value {
    display: grid;
    grid-template-columns: 28px 1fr;
    grid-template-rows: 1fr 1fr;
    column-gap: 6px;
    row-gap: 0;
    height: 34px;
    font-size: 13px;
  }

  .sn-pair img {
    grid-row: 1 / -1;
    align-self: center;
    width: 28px;
  }

  .sn-pair-label {
    display: block;
    color: var(--f-dim);
    font: 500 13px/1 var(--font-body, sans-serif);
  }

  .sn-arrow { display: none; }
}

@container settle-n (700px <= width < 1280px) {
  .sn-stage { --sn-quote: 17px; }

  .sn-stage .sn-bid {
    grid-template-columns: 1fr auto;
    grid-template-rows: 1fr 1fr;
    gap: 0 4px;
    padding-inline: 9px;
    font-size: 13px;
  }

  .sn-bid .sn-badge {
    justify-self: end;
    grid-column: 2;
    grid-row: 1;
  }

  .sn-stage .sn-bid .sn-value {
    justify-self: end;
    grid-row: 2;
    grid-column: 1 / -1;
    gap: 4px;
  }

  .sn-bid .sn-value img {
    width: 20px;
  }

  .sn-outcome .sn-value {
    gap: 4px;
  }
}

@container settle-n (700px <= width < 950px) {
  .sn-stage {
    --sn-title: 15px;
    --sn-body: 13px;
  }

  .sn-outcome .sn-value {
    flex-direction: column;
    gap: 3px;
  }

  .sn-outcome img { width: 24px; }

  .sn-outcome {
    gap: 4px;
    padding: 5px;
  }
}

@container settle-n (width < 700px) {
  .sn-stage {
    --layout-width: 350;
    --sn-unit: 1px;
    --sn-title: 15px;
    --sn-body: 13px;
    --sn-quote: 17px;
    --sn-phone-offset: 0px;
    height: calc(560px + var(--sn-phone-offset));
  }

  .sn-request {
    --x: 22; --y: 51; --w: 306;
    justify-items: center;
    transform: translateY(-50%);
  }

  .sn-pair img { width: 28px; }

  .sn-board {
    --x: 45; --y: 122; --w: 260;
    gap: 5px;
  }

  .sn-stage .sn-bid {
    height: 36px;
    gap: 3px;
    padding-inline: 6px;
  }

  .sn-bid .sn-value {
    gap: 4px;
  }

  .sn-bid .sn-badge {
    padding: 2px 4px;
  }

  .sn-bid .sn-value img { width: 20px; }

  .sn-bid[data-taken] .sn-taken {
    margin-inline-start: 3px;
    padding-inline-start: 3px;
  }

  .sn-stage .sn-contract {
    --y: 374; --w: 222;
    left: 50%;
    min-width: min(204px, 100%);
    height: 112px;
    gap: 2px;
    transform: translateX(-50%);
  }

  .sn-seat {
    width: 32px;
    height: 32px;
  }

  .sn-seat img {
    width: 26px;
  }

  .sn-transaction {
    padding-block: 2px;
  }

  .sn-outcome {
    --y: 510; --w: 168;
    height: 50px;
    gap: 2px;
    padding: 4px;
  }

  .sn-outcome img { width: 24px; }
  .sn-you { --x: 0; }
  .sn-solver { --x: 182; }

  .sn-stage :is(.sn-board, .sn-contract, .sn-outcome) {
    top: calc(var(--y) * 1px + var(--sn-phone-offset));
  }

  .sn-motion img {
    width: 26px;
    height: 26px;
  }

  .sn-routes {
    top: var(--sn-phone-offset);
    height: 560px;
  }

  .sn-wide { display: none; }
  .sn-tall { display: block; }

  .sn-tall [data-open] {
    d: path("M22 51C13 51 16 168 16 237C16 346 19 425 64 425");
  }

  .sn-tall [data-pay="ada"] {
    d: path("M64 453C28 453 38 486 62 487C76 488 84 496 84 510");
  }

  .sn-tall [data-pay="night"] {
    d: path("M286 453C322 453 312 486 288 487C274 488 266 496 266 510");
  }
}

@container settle-n (width < 347px) {
  .sn-stage .sn-bid {
    grid-template-columns: auto 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 0 4px;
    line-height: 1;
  }

  .sn-stage .sn-bid .sn-value {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: end;
  }

  .sn-bid .sn-badge {
    justify-self: end;
    padding-block: 0;
  }
}

@container settle-n (width < 305px) {
  .sn-outcome { padding-inline: 3px; }
  .sn-outcome .sn-value { gap: 3px; }
  .sn-outcome img { width: 20px; }
  .sn-outcome .sn-amount { font-size: 15px; }
}

@container settle-n (width < 278px) {
  .sn-stage { --sn-phone-offset: 46px; }
  .sn-request { --y: 81; }
}
