.duel-ceremony {
  --ceremony-ink: #080e17;
  --ceremony-navy: #111c2b;
  --ceremony-ivory: #f5e9cf;
  --ceremony-muted: #afbac5;
  --ceremony-gold: #edbd70;
  --ceremony-blue: #91d8e9;
  --ceremony-line: #8f704e73;
  --ceremony-heading: Cinzel, Georgia, serif;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  color: var(--ceremony-ivory);
  background:
    linear-gradient(0deg, #080e17 1%, #080e17aa 52%, #080e17e5),
    url("riftbound-stage.webp") center / cover,
    var(--ceremony-ink);
}

.duel-ceremony [hidden], .duel-ceremony[hidden] { display: none !important; }
.duel-ceremony button, .duel-ceremony select { font: inherit; }
.duel-ceremony button:focus-visible, .duel-ceremony select:focus-visible {
  outline: 2px solid var(--ceremony-gold);
  outline-offset: 4px;
}

.ceremony-header {
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 24px;
  padding: 14px clamp(15px, 4vw, 66px);
  border-bottom: 1px solid var(--ceremony-line);
  background: #080e17e8;
}

.ceremony-header > button { justify-self: start; }
.ceremony-header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.ceremony-match-label {
  margin: 0;
  color: var(--ceremony-ivory);
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.4;
}

.ceremony-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45em;
  min-height: 42px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ceremony-muted);
  cursor: pointer;
}

.ceremony-link:hover, .ceremony-link:focus-visible {
  color: var(--ceremony-ivory);
  background: #172535;
}

.ceremony-setup-frame {
  display: grid;
  grid-template-areas: "player center bot";
  grid-template-columns: minmax(170px, .74fr) minmax(430px, 1.8fr) minmax(170px, .74fr);
  align-items: center;
  gap: clamp(8px, 2.5vw, 40px);
  width: min(100%, 1510px);
  min-height: calc(100svh - 72px);
  margin: 0 auto;
  padding: clamp(18px, 5vh, 62px) clamp(16px, 4vw, 64px);
}

.ceremony-seat {
  --ceremony-seat-color: var(--ceremony-gold);
  grid-area: player;
  min-width: 0;
  min-height: 290px;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
}

.ceremony-seat--bot { --ceremony-seat-color: var(--ceremony-blue); grid-area: bot; }
.ceremony-seat-art {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  justify-content: center;
  padding: 18px 0 30px;
  filter: drop-shadow(0 14px 26px #000a);
}

.ceremony-portrait-card {
  grid-row: 1;
  grid-column: 1 / 6;
  z-index: 1;
  min-width: 0;
  margin: 0;
  transform: rotate(-8deg);
}

.ceremony-portrait-card:nth-child(2) {
  grid-column: 4 / -1;
  margin-bottom: -18px;
  transform: translateY(-10%) rotate(8deg) scale(.92);
}

.ceremony-seat--bot .ceremony-portrait-card:first-child { grid-column: 3 / -1; transform: rotate(8deg); }
.ceremony-seat--bot .ceremony-portrait-card:nth-child(2) { grid-column: 1 / 6; transform: translateY(-10%) rotate(-8deg) scale(.92); }
.ceremony-portrait-image, .ceremony-portrait-card > .card-fallback {
  display: block;
  width: 100%;
  aspect-ratio: 744 / 1039;
  object-fit: contain;
  border-radius: 6%;
  border: 1px solid color-mix(in srgb, var(--ceremony-seat-color) 65%, transparent);
  background: #0a1522;
}

.ceremony-portrait-card > figcaption {
  margin-top: 6px;
  color: var(--ceremony-muted);
  font-size: .65rem;
  text-align: center;
}

.ceremony-seat-caption {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  border-top: 1px solid color-mix(in srgb, var(--ceremony-seat-color) 65%, transparent);
  padding: 15px 0 0;
  text-align: center;
  overflow-wrap: anywhere;
}

.ceremony-seat-caption::before {
  content: "";
  position: absolute;
  top: -4px;
  left: calc(50% - 3px);
  width: 6px;
  height: 6px;
  background: var(--ceremony-seat-color);
  transform: rotate(45deg);
}

.ceremony-seat-caption p {
  margin: 0;
  color: var(--ceremony-seat-color);
  font-size: .73rem;
  font-weight: 700;
}

.ceremony-seat-caption h2 { margin: 0; font: 600 clamp(16px, 2vw, 25px)/1.16 var(--ceremony-heading); }

.ceremony-stage {
  grid-area: center;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: clamp(14px, 2.8vh, 29px);
  padding: clamp(17px, 3vw, 44px);
  border: 1px solid var(--ceremony-line);
  background: linear-gradient(155deg, #121e2ef0, #080e17f5);
  box-shadow: 0 25px 65px #0006, inset 0 0 35px #b4915410;
}

.ceremony-progress {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--ceremony-muted);
  font-size: .72rem;
  line-height: 1.25;
}

.ceremony-progress li { position: relative; padding-block: 3px; }
.ceremony-progress li + li::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -11px;
  width: 4px;
  height: 4px;
  background: #766449;
  transform: translateY(-50%) rotate(45deg);
}
.ceremony-progress li[aria-current] { color: var(--ceremony-gold); box-shadow: 0 1px var(--ceremony-gold); }
.ceremony-stage-copy { display: grid; justify-items: center; gap: 10px; text-align: center; }
.ceremony-stage-copy h1, .ceremony-overlay-content h1 {
  max-width: 100%;
  margin: 0;
  color: var(--ceremony-ivory);
  font: 650 clamp(2rem, 4vw, 4.25rem)/1.04 var(--ceremony-heading);
  text-wrap: balance;
}
.ceremony-stage-copy h1:focus, .ceremony-overlay-content h1:focus { outline: none; }
.ceremony-stage-copy p, .ceremony-overlay-prompt {
  max-width: 40rem;
  margin: 0;
  color: var(--ceremony-muted);
  font-size: clamp(.86rem, 1.2vw, 1rem);
  line-height: 1.45;
  text-align: center;
  text-wrap: balance;
}
.ceremony-overlay-prompt:empty { display: none; }

.duel-ceremony .btn {
  min-height: 44px;
  justify-content: center;
  border: 1px solid #7e8c9d70;
  border-radius: 5px;
  padding: 9px 17px;
  color: var(--ceremony-ivory);
  background: #142437;
  font-weight: 650;
}

.duel-ceremony .btn--primary {
  border-color: #f4cf8f;
  color: #241a0e;
  background: linear-gradient(145deg, #f8d68d, #d9a85e);
  box-shadow: 0 3px 10px #c298522e;
}

.duel-ceremony .btn:not(:disabled):hover { border-color: var(--ceremony-gold); }
.duel-ceremony .btn--primary:not(:disabled):hover { background: #f6d595; }
.ceremony-actions, .ceremony-choices { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 12px; }
.ceremony-actions:not(:has(button:not([hidden]))) { display: none; }
.ceremony-choices small { display: block; margin-top: 4px; font-size: .72rem; font-weight: 500; }
.ceremony-choices .btn { min-width: min(154px, 100%); text-align: center; }

.ceremony-dice {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: center;
  gap: clamp(16px, 4vw, 47px);
  width: min(100%, 360px);
}
.ceremony-die-seat {
  --die-color: var(--ceremony-gold);
  display: grid;
  justify-items: center;
  gap: 14px;
  color: var(--die-color);
}
.ceremony-die-seat:last-child { --die-color: var(--ceremony-blue); }
.ceremony-die-seat strong { font-size: .76rem; font-weight: 650; }
.ceremony-dice-divider { height: 75%; background: linear-gradient(transparent, #b5946799, transparent); }
.ceremony-die {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: min(100%, 108px);
  aspect-ratio: 1;
  font: 650 clamp(2.25rem, 5.8vw, 4rem)/1 var(--ceremony-heading);
  text-shadow: 0 0 16px color-mix(in srgb, var(--die-color) 45%, transparent);
}
.ceremony-die::before, .ceremony-die::after {
  position: absolute;
  z-index: -1;
  inset: 9%;
  content: "";
  border: 1px solid color-mix(in srgb, var(--die-color) 56%, transparent);
  background: color-mix(in srgb, var(--die-color) 7%, #0d1827);
  transform: rotate(45deg);
}
.ceremony-die::after { inset: 16%; border-color: #ac926541; background: transparent; }
.ceremony-die[data-winner="true"]::before { box-shadow: 0 0 22px color-mix(in srgb, var(--die-color) 28%, transparent); }
.duel-ceremony[data-motion="on"] .ceremony-die:has([data-rolling="true"]) { animation: ceremony-tumble .32s ease-out both; }
@keyframes ceremony-tumble {
  0% { transform: translateY(8px) rotate(-11deg) scale(.92); opacity: .6; }
  50% { transform: translateY(-6px) rotate(8deg) scale(1.08); }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}

.ceremony-field-picks, .ceremony-field-reveal {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.ceremony-field-reveal { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 305px; }
.ceremony-field-entry { display: grid; justify-items: center; gap: 3px; min-width: 0; }
.ceremony-field-picks .field-pick, .ceremony-field-reveal > div, .ceremony-opening-field {
  display: grid;
  align-content: start;
  justify-items: center;
  min-width: 0;
  gap: 5px;
  margin: 0;
  padding: 6px;
  border: 1px solid #967b5369;
  border-radius: 5px;
  color: var(--ceremony-ivory);
  background: #101c2b;
  font-size: .73rem;
  line-height: 1.25;
  text-align: center;
}
.ceremony-field-picks .field-pick { width: 100%; cursor: pointer; }
.ceremony-field-picks .field-pick:hover:not(:disabled) { border-color: var(--ceremony-gold); background: #1b3042; }
.ceremony-field-picks .field-image, .ceremony-field-image {
  display: block;
  width: 100%;
  aspect-ratio: 1039 / 744;
  object-fit: contain;
  border-radius: 5%;
}
.ceremony-field-reveal > div:nth-child(2) { border-color: #74aabd7a; }
.ceremony-field-reveal > div > span { color: var(--ceremony-muted); }
.ceremony-field-reveal > div > div { width: 100%; }
.ceremony-field-reveal .card-fallback, .ceremony-field-picks .card-fallback { min-height: 45px; }

.ceremony-notice { margin: 0; color: #ffbdb6; font-size: .82rem; text-align: center; }
.ceremony-notice:empty { display: none; }

.duel-ceremony--overlay {
  z-index: 100;
  position: fixed;
  inset: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse at 50% 4%, #39587966, transparent 61%),
    linear-gradient(0deg, #080e17 0%, #080e17b0 52%, #080e17d4),
    url("riftbound-stage.webp") center / cover,
    var(--ceremony-ink);
}

.duel-ceremony--overlay[data-outcome="win"] {
  background:
    radial-gradient(ellipse at 50% 0%, #ac763e57, transparent 61%),
    linear-gradient(0deg, #080e17 0%, #080e17a8 57%, #080e17d4),
    url("riftbound-stage.webp") center / cover,
    var(--ceremony-ink);
}
body:has(.duel-ceremony--overlay:not([hidden])) { overflow: hidden; }
#match-app[inert] { display: none; }
.ceremony-overlay-content {
  display: grid;
  justify-items: center;
  align-content: center;
  flex: 1;
  gap: clamp(10px, 1.8vh, 22px);
  width: min(100%, 980px);
  margin: 0 auto;
  padding: clamp(19px, 4vh, 50px) clamp(13px, 4vw, 55px);
}
.ceremony-overlay-content h1 { text-align: center; }
.ceremony-sigil { display: grid; place-items: center; width: 30px; height: 30px; transform: rotate(45deg); border: 1px solid var(--ceremony-gold); }
.ceremony-sigil > span { width: 13px; height: 13px; background: var(--ceremony-gold); box-shadow: 0 0 22px #e2ad6180; }
.duel-ceremony[data-outcome="loss"] .ceremony-sigil { border-color: var(--ceremony-blue); }
.duel-ceremony[data-outcome="loss"] .ceremony-sigil > span { background: var(--ceremony-blue); }
#ceremony-opening, #ceremony-result { display: grid; width: 100%; justify-items: center; gap: clamp(10px, 1.8vh, 22px); }
.ceremony-opening-fields {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  width: 100%;
}
.ceremony-opening-field { width: min(27%, 106px); font-size: .65rem !important; padding: 3px; cursor: pointer; }
.ceremony-opening-field:hover { border-color: var(--ceremony-gold); }
.ceremony-opening-field span { line-height: 1.25; }
.ceremony-opening-hand {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(100%, 1030px, 111svh);
  gap: clamp(10px, 1.7vw, 24px);
  padding: 0 clamp(12px, 2vw, 25px);
}
.ceremony-hand-entry { display: grid; align-content: start; justify-items: center; gap: 8px; min-width: 0; }
.ceremony-hand-entry:is(:hover, :focus-within) { z-index: 1; }
.ceremony-hand-card {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(2.2em, 1fr);
  width: 100%;
  padding: 3px;
  border: 1px solid #9eb2c080;
  border-radius: 9px;
  color: var(--ceremony-ivory);
  background: #0b101b;
  box-shadow: 0 10px 22px #0009;
  cursor: pointer;
  transform-origin: 50% 100%;
  transform: translateY(var(--opening-drop, 0px)) rotate(var(--opening-tilt, 0deg));
}
@media (min-width: 621px) {
  .ceremony-hand-entry:first-child { --opening-tilt: -5deg; --opening-drop: 8px; }
  .ceremony-hand-entry:nth-child(2) { --opening-tilt: -1.5deg; }
  .ceremony-hand-entry:nth-child(3) { --opening-tilt: 1.5deg; }
  .ceremony-hand-entry:last-child { --opening-tilt: 5deg; --opening-drop: 8px; }
  .ceremony-hand-card:is(:hover, :focus-visible) { transform: translateY(-7px); }
}
.ceremony-hand-card[aria-pressed="true"] {
  border-color: var(--ceremony-gold);
  box-shadow: 0 0 0 2px var(--ceremony-gold), 0 8px 25px #edb86963;
}
.ceremony-hand-card[aria-pressed="true"]::after {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  content: "↶";
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #221608;
  background: var(--ceremony-gold);
  box-shadow: 0 3px 10px #0008;
  font-weight: 800;
}
.ceremony-hand-card:hover { border-color: var(--ceremony-gold); }
.ceremony-hand-art {
  display: block;
  width: 100%;
  aspect-ratio: 744 / 1039;
  overflow: hidden;
  border-radius: 5%;
  background: url("rift-main-back.webp") center / 100% 100% no-repeat, #0c1825;
}
.ceremony-hand-art > .ceremony-hand-image, .ceremony-hand-art > .card-fallback {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ceremony-hand-art[data-loading] > img { opacity: 0; }
.duel-ceremony[data-motion="on"] .ceremony-hand-art > img { transition: opacity .2s ease-out; }
.ceremony-card-name {
  display: grid;
  place-items: center;
  min-height: 2.2em;
  padding: 3px 4px;
  font-size: clamp(.71rem, 1.25vw, .92rem);
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.ceremony-card-details { min-height: 36px; padding: 3px 8px; font-size: .73rem !important; }
.ceremony-mulligan-count { margin: 0; color: var(--ceremony-muted); font-size: .78rem; }
.ceremony-scoreline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(8px, 2.2vw, 28px);
  width: min(100%, 650px);
}
.ceremony-score-seat {
  --score-color: var(--ceremony-gold);
  display: grid;
  grid-template-columns: minmax(24px, 82px) minmax(0, 1fr);
  grid-template-rows: 1fr auto auto;
  align-items: end;
  gap: 2px clamp(6px, 1.2vw, 13px);
  min-width: 0;
  padding: clamp(7px, 1.4vw, 15px);
  border: 1px solid #7a84945c;
  background: #0c1725d9;
}
.ceremony-score-seat[data-seat="opponent"] { --score-color: var(--ceremony-blue); }
.ceremony-score-seat[data-winner="true"] { border-color: color-mix(in srgb, var(--score-color) 75%, transparent); }
.ceremony-score-art, .ceremony-score-seat > .card-fallback {
  grid-row: 1 / 4;
  align-self: center;
  width: 100%;
  aspect-ratio: 744 / 1039;
  object-fit: contain;
  border-radius: 5%;
}
.ceremony-score-seat strong { color: var(--score-color); font: 650 clamp(1.7rem, 5vw, 3.8rem)/1 var(--ceremony-heading); }
.ceremony-score-name { font-size: .79rem; font-weight: 700; }
.ceremony-score-deck { align-self: start; color: var(--ceremony-muted); font-size: .7rem; overflow-wrap: anywhere; }
.ceremony-score-vs { color: var(--ceremony-muted); font-size: .68rem; }
.ceremony-result-games {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--ceremony-muted);
  font-size: .78rem;
}
.ceremony-result-games li { padding: 6px 9px; border-bottom: 1px solid var(--ceremony-line); }
.duel-ceremony[data-motion="on"] .ceremony-seat {
  --ceremony-arrival: -16px;
  animation: ceremony-arrive .46s ease-out both;
}
.duel-ceremony[data-motion="on"] .ceremony-seat--bot { --ceremony-arrival: 16px; }
.duel-ceremony[data-motion="on"][data-scene="result"] .ceremony-scoreline { animation: ceremony-deal .4s ease-out both; }
.duel-ceremony[data-motion="on"][data-scene="result"] .ceremony-sigil > span { animation: ceremony-glint .65s ease-out both; }
@keyframes ceremony-arrive {
  from { opacity: 0; transform: translateX(var(--ceremony-arrival)); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes ceremony-glint {
  from { opacity: .25; transform: scale(.35); }
  60% { opacity: 1; transform: scale(1.18); }
  to { opacity: 1; transform: scale(1); }
}
.duel-ceremony[data-motion="on"]:not([hidden]) .ceremony-hand-entry { animation: ceremony-deal .38s ease-out both; }
.duel-ceremony[data-motion="on"] .ceremony-hand-entry:nth-child(2) { animation-delay: .05s; }
.duel-ceremony[data-motion="on"] .ceremony-hand-entry:nth-child(3) { animation-delay: .1s; }
.duel-ceremony[data-motion="on"] .ceremony-hand-entry:nth-child(4) { animation-delay: .15s; }
@keyframes ceremony-deal {
  from { opacity: 0; transform: translateY(17px) rotate(-3deg) scale(.96); }
  to { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}

@media (max-width: 850px) {
  .ceremony-setup-frame {
    grid-template-areas: "player bot" "center center";
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 13px;
    width: min(100%, 660px);
  }
  .ceremony-seat { min-height: 0; }
  .ceremony-seat-art { width: min(100%, 155px); margin: auto; padding-block: 7px 10px; }
  .ceremony-seat-caption { padding-top: 9px; }
  .ceremony-stage { width: 100%; align-self: start; }
}

@media (max-width: 470px) {
  .ceremony-header { grid-template-columns: auto minmax(0, 1fr); padding-block: 3px 7px; gap: 1px 4px; }
  .ceremony-header-actions { grid-column: 2; grid-row: 1; }
  .ceremony-header > p { grid-column: 1 / -1; grid-row: 2; font-size: .72rem; }
  .ceremony-setup-frame { padding: 10px 10px 18px; }
  .ceremony-seat-art { width: min(100%, 104px); padding-top: 4px; }
  .ceremony-portrait-card:nth-child(2) { margin-bottom: -10px; }
  .ceremony-portrait-card figcaption { display: none; }
  .ceremony-seat-caption h2 { font-size: clamp(14px, 4vw, 18px); }
  .ceremony-stage { gap: 13px; padding: 15px 9px; }
  .ceremony-field-picks { gap: 4px; }
  .ceremony-field-picks .field-pick { padding: 4px; font-size: .64rem; }
  .ceremony-overlay-content { justify-items: stretch; gap: 12px; }
  .ceremony-sigil { justify-self: center; }
  .ceremony-card-details { min-height: 44px; }
  .ceremony-score-seat { grid-template-columns: clamp(32px, 12vw, 56px) minmax(0, 1fr); }
}

@media (max-width: 620px) {
  .ceremony-opening-hand {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(100%, 328px, 47svh);
    gap: 8px 11px;
    padding: 0;
  }
  .ceremony-hand-entry { gap: 2px; }
}

@media (max-width: 350px) {
  .ceremony-score-seat { grid-template-columns: minmax(22px, 44px) minmax(0, 1fr); }
  .ceremony-score-deck { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .duel-ceremony :is(.ceremony-die, .ceremony-hand-entry, .ceremony-seat, .ceremony-scoreline, .ceremony-sigil > span) {
    animation: none !important;
  }
  .duel-ceremony .ceremony-hand-art > img { transition: none; }
}
