.realm-repair {
  --repair-gold: #e4be82;
  --repair-ink: #f1e3c9;
  --repair-field: #0e2328;
  scroll-margin-top: 4rem;
  color: var(--repair-ink);
  padding: clamp(3.5rem, 8vw, 7rem) clamp(1rem, 5vw, 4rem);
  background: linear-gradient(180deg, var(--repair-field), #10272ae6), var(--static-scenery) center / cover;
  border-top: 1px solid #e4be8255;
}
.realm-human .realm-repair { --repair-field: #30241c; }
.realm-underworld .realm-repair { --repair-field: #0a1b27; }
.realm-gate .realm-repair { --repair-field: #152823; }
.realm-heaven .realm-repair { --repair-field: #20242e; }

.repair-inner { width: min(100%, 48rem); margin-inline: auto; }
.repair-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: .6rem .8rem;
  margin-bottom: 1.3rem;
}
.repair-heading > p { grid-column: 1 / -1; max-width: 36rem; opacity: .91; }
.repair-kicker { color: var(--repair-gold); font-size: .78rem; letter-spacing: .14em; }
.repair-heading h2 {
  margin-top: .15em;
  font: 400 clamp(1.9rem, 6vw, 3.25rem)/1.2 Painting, "Songti SC", serif;
}
.repair-reset, .repair-jigsaw, .repair-footer a {
  padding: .45rem .7rem;
  color: var(--repair-gold);
  background: transparent;
  border: 1px solid #e4be8270;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.repair-workbench {
  display: grid;
  gap: .8rem;
  position: relative;
  padding: clamp(.6rem, 2.5vw, 1.2rem);
  border: 1px solid #e4be8255;
  background: #0b1b20a0;
}
.repair-surface {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: .45rem;
  min-width: 0;
  padding: clamp(.35rem, 1.4vw, .8rem);
  background: radial-gradient(ellipse, #e4be821c, transparent 76%);
}
.repair-surface img { user-select: none; object-fit: contain; height: 100%; width: 100%; min-height: 0; }
.repair-surface figure { margin: 0; min-height: 0; min-width: 0; }
.repair-picker { display: flex; justify-content: center; gap: .55rem; }
.repair-switch {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: .25rem;
  min-height: 2.75rem;
  min-width: 0;
  padding: .35rem .55rem;
  border: 1px solid #e4be8266;
  color: var(--repair-ink);
  background: #172b30;
  text-align: center;
  line-height: 1.3;
  cursor: pointer;
}
.repair-switch > input, .repair-person-slot > input {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.repair-switch:has(input:checked) { border-color: var(--repair-gold); background: #3a372b; }
.repair-switch:has(input:focus-visible), .repair-person-slot:has(input:focus-visible),
.repair-footer a:focus-visible, .repair-jigsaw:focus-visible, .repair-reset:focus-visible {
  outline: 2px solid #ffe3a3;
  outline-offset: 3px;
}
.repair-picker .repair-switch img { width: 4.9rem; height: 3rem; object-fit: contain; }

.repair-complete {
  display: none;
  align-items: center;
  grid-template-columns: minmax(5.5rem, 1fr) minmax(0, 2.5fr);
  gap: clamp(.75rem, 3vw, 1.55rem);
  margin-top: 1.15rem;
  padding: clamp(.65rem, 2.5vw, 1.25rem);
  background: #203934;
  border: 1px solid #e4be82aa;
}
.repair-complete figure { margin: 0; display: grid; place-items: center; min-height: 5rem; }
.repair-complete img { width: 100%; max-height: 8.5rem; object-fit: contain; }
.repair-complete figure { overflow: clip; }
.repair-human .repair-complete img,
.repair-underworld .repair-complete img { scale: 1.5; }
.repair-complete h3 { color: var(--repair-gold); margin: 0; font-size: 1rem; }
.repair-complete p { margin: .25rem 0 .7rem; font-size: .88rem; line-height: 1.6; }
.repair-jigsaw { display: inline-block; font-size: .83rem; }
.repair-footer { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: .65rem; margin-top: 1.15rem; }
.repair-footer a { font-size: .8rem; }
.repair-inner:has(#seat-xinzhui:checked):has(#seat-envoys:checked) .repair-complete,
.repair-inner:has(#dust-vessel:checked):has(#dust-offering:checked):has(#dust-observer:checked) .repair-complete,
.repair-inner:has(#stack-fit-fish:checked):has(#stack-fit-giant:checked):has(#stack-fit-earth:checked) .repair-complete,
.repair-inner:has(#light-left:checked):has(#light-right:checked) .repair-complete,
.repair-inner:has(#paint-moon:checked):has(#paint-sun:checked):has(#paint-deity:checked) .repair-complete { display: grid; }

/* 相迎：两组人物入画。 */
.repair-people { grid-template: 3.3rem minmax(6.5rem, 22vw) / repeat(2, minmax(0, 1fr)); }
.repair-people .repair-canopy { grid-column: 1 / -1; }
.repair-person-slot {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  border: 1px dashed #e4be8266;
  padding: .25rem;
  font-size: .78rem;
  text-align: center;
}
.repair-person-slot img { opacity: 0; }
.repair-person-slot:has(.repair-seat:checked) { border-color: #e4be82; }
.repair-person-slot:has(.repair-seat:checked) img { opacity: 1; }
.repair-person-slot > input { visibility: hidden; }
.repair-encounter:has(#select-xinzhui:checked) #seat-xinzhui:not(:checked),
.repair-encounter:has(#select-envoys:checked) #seat-envoys:not(:checked),
.repair-encounter:has(#select-xinzhui:checked):not(:has(#seat-xinzhui:checked)) #wrong-left,
.repair-encounter:has(#select-envoys:checked):not(:has(#seat-envoys:checked)) #wrong-right { visibility: visible; }
.repair-miss-note { display: none; color: #ffd0b5; font-size: .83rem; margin: 0; }
.repair-encounter:has(.repair-wrong:focus) .repair-miss-note { display: block; }

/* 祭祀：薄沙保留轮廓，三条线索依次开放。 */
.repair-dust-panel {
  display: block;
  width: min(100%, 38rem);
  margin-inline: auto;
  padding: 0;
  overflow: hidden;
  background-color: #211b14;
}
.repair-dust-panel > img { display: block; width: 100%; height: auto; }
.repair-dust-tracks {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
}
.dust-tile, .paint-tile, .stack-slot {
  position: relative;
  min-width: 0;
  border: 1px solid #e4be8260;
  overflow: hidden;
}
.dust-tile input, .paint-tile input, .stack-slot input {
  position: absolute;
  z-index: 3;
  inset: 0;
  height: 100%;
  width: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dust-tile:has(input:focus-visible), .paint-tile:has(input:focus-visible), .stack-slot:has(input:focus-visible) {
  outline: 2px solid #ffe3a3;
  outline-offset: -2px;
  z-index: 1;
}
.dust-tile::before, .dust-grains {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.dust-tile::before {
  background:
    radial-gradient(ellipse at 2px 8px, #f0ce958c .55px, transparent 1.45px) 2px 3px / 11px 13px,
    radial-gradient(circle at 6px 3px, #4c3319a1 .72px, transparent 1.65px) 0 0 / 17px 19px,
    radial-gradient(ellipse at 7px 5px, #fff0ca71 .75px, transparent 1.8px) 5px 0 / 13px 23px,
    linear-gradient(120deg, #746043b2, #b4925b7d 60%, #6d50367c);
}
.dust-grains {
  opacity: 0;
  background:
    radial-gradient(ellipse at 3px 2px, #efd4a3 1px, transparent 1.65px) 0 0 / 17px 13px,
    radial-gradient(circle at 5px 5px, #d49f62 .8px, transparent 1.45px) 1px 0 / 11px 17px,
    radial-gradient(circle at 9px 1px, #fff0c4 .45px, transparent 1.1px) 3px 7px / 19px 11px;
}
.dust-clue, .repair-trial-error { display: none; margin: 0; font-size: .86rem; line-height: 1.55; }
.repair-human:not(:has(#dust-vessel:checked)) .clue-vessel,
.repair-human:has(#dust-vessel:checked):not(:has(#dust-offering:checked)) .clue-offering,
.repair-human:has(#dust-offering:checked):not(:has(#dust-observer:checked)) .clue-observer,
.repair-human:has(#dust-observer:checked) .clue-done { display: block; }

.dust-clear, .paint-apply { visibility: hidden; }
.repair-human:not(:has(.dust-miss:checked)) #dust-vessel:not(:checked),
.repair-human:has(#dust-vessel:checked):not(:has(.dust-miss:checked)) #dust-offering:not(:checked),
.repair-human:has(#dust-offering:checked):not(:has(.dust-miss:checked)) #dust-observer:not(:checked) {
  visibility: visible;
  z-index: 4;
}
.repair-human:not(:has(.dust-miss:checked)) .dust-tile:has(#dust-vessel:not(:checked)) .dust-miss,
.repair-human:has(#dust-vessel:checked):not(:has(.dust-miss:checked)) .dust-tile:has(#dust-offering:not(:checked)) .dust-miss,
.repair-human:has(#dust-offering:checked):not(:has(.dust-miss:checked)) .dust-tile:has(#dust-observer:not(:checked)) .dust-miss,
.dust-tile:has(.dust-clear:checked) .dust-miss,
.repair-human:has(#dust-observer:checked) .dust-miss { visibility: hidden; }
.dust-tile:has(.dust-clear:checked)::before,
.repair-human:has(#dust-observer:checked) .dust-tile::before { opacity: 0; }
.repair-human:has(.dust-miss:checked) .dust-miss:not(:checked),
.repair-heaven:has(.paint-miss:checked) .paint-miss:not(:checked) { visibility: hidden; }
.repair-inner:has(.repair-undo:checked) .repair-trial-error { display: block; color: #ffceac; }
.repair-undo-label { display: none; }
.repair-undo:checked ~ .repair-undo-label {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  padding: .2rem;
  text-align: center;
  font-size: .77rem;
  color: #ffe1c9;
  background: #593321dc;
  cursor: pointer;
  pointer-events: none;
  z-index: 2;
}

/* 地下：横板、巨人与双鱼可以按任意顺序尝试归位。 */
.stack-picker .repair-switch { flex: 1 1 0; }
.repair-stack {
  height: clamp(15rem, 47vw, 23rem);
  grid-template-rows: minmax(0, .7fr) repeat(2, minmax(0, 1fr));
}
.stack-slot {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: .25rem;
  border-style: dashed;
}
.stack-slot-name { color: var(--repair-gold); font-size: .85rem; }
.stack-slot img { display: none; }
.stack-fit, .stack-miss { visibility: hidden; }
.stack-slot:has(.stack-fit:checked) { border-style: solid; }
.stack-slot:has(.stack-fit:checked) .stack-slot-name { display: none; }
.stack-slot:has(.stack-fit:checked) img { display: block; }

.repair-underworld:has(.stack-picker input:checked):not(:has(.stack-miss:checked)) .stack-slot:has(.stack-fit:not(:checked)) .stack-miss,
.stack-miss:checked { visibility: visible; }
.repair-underworld:has(#stack-pick-earth:checked):not(:has(.stack-miss:checked)) #stack-fit-earth:not(:checked),
.repair-underworld:has(#stack-pick-giant:checked):not(:has(.stack-miss:checked)) #stack-fit-giant:not(:checked),
.repair-underworld:has(#stack-pick-fish:checked):not(:has(.stack-miss:checked)) #stack-fit-fish:not(:checked) {
  visibility: visible;
  z-index: 4;
}
.repair-underworld:has(#stack-pick-earth:checked) .stack-slot:has(#stack-fit-earth:not(:checked)) .stack-miss,
.repair-underworld:has(#stack-pick-giant:checked) .stack-slot:has(#stack-fit-giant:not(:checked)) .stack-miss,
.repair-underworld:has(#stack-pick-fish:checked) .stack-slot:has(#stack-fit-fish:not(:checked)) .stack-miss { visibility: hidden; }
.repair-underworld:has(.stack-miss:checked) .stack-picker { pointer-events: none; opacity: .55; }
.repair-underworld:has(.stack-miss:checked) .stack-picker input { visibility: hidden; }

/* 天门：分别点灯，找出两阙留出的入口。 */
.repair-lanterns { height: clamp(12rem, 44vw, 22rem); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.repair-lanterns > div { min-width: 0; min-height: 0; position: relative; display: grid; isolation: isolate; }
.repair-lanterns > div::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -10%;
  background: radial-gradient(ellipse, #edbe7066, #edbe7018 52%, transparent 72%);
  opacity: 0;
}
.repair-lanterns img { filter: brightness(.19) saturate(.5); }
.repair-gate:has(#light-left:checked) .repair-gate-left::before,
.repair-gate:has(#light-right:checked) .repair-gate-right::before { opacity: 1; }
.repair-gate:has(#light-left:checked) .repair-gate-left img,
.repair-gate:has(#light-right:checked) .repair-gate-right img { filter: none; }

/* 日月：取色，再把指定部位和颜料对应。 */
.paint-note { color: #d4cbb7; font-size: .86rem; line-height: 1.55; }
.paint-palette { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.paint-swatch { min-height: 3.25rem; font-size: .79rem; }
.paint-swatch:has(#pigment-pale) { --swatch: #91abb0; }
.paint-swatch:has(#pigment-ochre) { --swatch: #c69e62; }
.paint-swatch:has(#pigment-red) { --swatch: #bc543c; }
.paint-swatch:has(#pigment-blue) { --swatch: #477b94; }
.paint-swatch::before {
  content: "";
  width: 1rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--swatch);
  border: 1px solid #fff6db70;
}
.repair-pigments { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(7.5rem, 23vw) minmax(5.8rem, 14vw); }
.paint-tile {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  padding: .3rem;
  background: #19282c;
  color: var(--repair-ink);
  font-size: .75rem;
  text-align: center;
  line-height: 1.3;
}
.paint-tile:last-child { grid-column: 1 / -1; }
.paint-tile img { filter: grayscale(1) contrast(.75) brightness(.76); }
.paint-tile:has(.paint-apply:checked) img { filter: none; }
.paint-tile:has(.paint-apply:checked) { border-color: var(--repair-gold); }
.paint-miss { visibility: var(--trial-visible, hidden); }
.repair-heaven:has(.paint-swatch input:checked) { --trial-visible: visible; }
.repair-heaven:has(#pigment-pale:checked) { --trial-ink: #91abb0; }
.repair-heaven:has(#pigment-ochre:checked) { --trial-ink: #c69e62; }
.repair-heaven:has(#pigment-red:checked) { --trial-ink: #bc543c; }
.repair-heaven:has(#pigment-blue:checked) { --trial-ink: #477b94; }

.repair-heaven:has(#pigment-blue:checked):not(:has(.paint-miss:checked)) #paint-moon:not(:checked),
.repair-heaven:has(#pigment-red:checked):not(:has(.paint-miss:checked)) #paint-sun:not(:checked),
.repair-heaven:has(#pigment-pale:checked):not(:has(.paint-miss:checked)) #paint-deity:not(:checked) {
  visibility: visible;
  z-index: 4;
}
.repair-heaven:has(#pigment-blue:checked):not(:has(.paint-miss:checked)) .paint-tile:has(#paint-moon:not(:checked)) .paint-miss,
.repair-heaven:has(#pigment-red:checked):not(:has(.paint-miss:checked)) .paint-tile:has(#paint-sun:not(:checked)) .paint-miss,
.repair-heaven:has(#pigment-pale:checked):not(:has(.paint-miss:checked)) .paint-tile:has(#paint-deity:not(:checked)) .paint-miss,
.paint-tile:has(.paint-apply:checked) .paint-miss { visibility: hidden; }
.repair-heaven:has(.paint-miss:checked) .paint-swatch { pointer-events: none; opacity: .55; }
.repair-heaven:has(.paint-miss:checked) .paint-swatch input { visibility: hidden; }
.paint-miss:checked ~ .repair-undo-label {
  background: color-mix(in srgb, var(--trial-ink) 32%, #201811bd);
  box-shadow: inset 0 0 0 2px #e7a573;
  font-weight: 600;
  text-shadow: 0 1px 5px #080c0e;
}

@media (prefers-reduced-motion: no-preference) {
  .repair-person-slot:has(.repair-seat:checked) img { animation: repair-seat .54s cubic-bezier(.18,.72,.3,1) both; }
  .dust-tile::before { transition: opacity .52s ease-out; }
  .dust-tile:has(.dust-clear:checked) .dust-grains { animation: dust-scatter .66s cubic-bezier(.15,.65,.35,1) both; }
  .stack-slot:has(.stack-fit:checked) img { animation: repair-seat .54s cubic-bezier(.18,.72,.3,1) both; }
  .repair-lanterns img, .repair-pigments img { transition: filter .55s ease; }
  .repair-lanterns > div::before { transition: opacity .6s ease; }
  .repair-complete figure { animation: repair-finish .45s ease-out both; }
}

@keyframes dust-scatter {
  0% { opacity: 0; transform: translate(0, 0) scale(.86); }
  22% { opacity: .88; }
  100% { opacity: 0; transform: translate(19%, -29%) scale(1.22) rotate(-5deg); }
}
@keyframes repair-seat {
  from { opacity: .1; transform: translateY(-1.25rem) scale(.92); }
  78% { opacity: 1; transform: translateY(.1rem) scale(1.015); }
  to { opacity: 1; transform: none; }
}
@keyframes repair-finish {
  from { opacity: 0; transform: translateY(.45rem); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 520px) {
  .repair-heading > p { font-size: .9rem; line-height: 1.65; }
  .repair-picker .repair-switch { font-size: .79rem; }
  .repair-reset { font-size: .78rem; }
  .repair-complete { grid-template-columns: minmax(4.3rem, .65fr) minmax(0, 2fr); }
  .repair-complete p { font-size: .8rem; }
}
