.q38,
.q38-m {
  --q38-gold-ink: #7a5717;
  --q38-gen-bg: #fbf3e2;
  --q38-check-bg: #edf3f9;
  color: var(--ink);
  font-family: var(--font-sans);
}

.q38 {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 52px 64px 26px;
  background: var(--paper);
}

.q38 *,
.q38-m * {
  box-sizing: border-box;
}

.q38 [hidden],
.q38-m [hidden] {
  display: none !important;
}

.q38-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.q38-heading {
  min-width: 0;
}

.q38-title {
  margin: 0;
  font-size: 40px;
  line-height: 1.32;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--navy);
}

.q38-sub {
  margin: 6px 0 0;
  font-size: 20px;
  line-height: 1.6;
  color: var(--muted);
}

.q38-head-meta {
  flex: 0 0 auto;
  padding-bottom: 2px;
  text-align: right;
}

.q38-state {
  margin: 0;
  font-size: 18px;
  line-height: 1.6;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.q38-tag {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: var(--q38-gold-ink);
  white-space: nowrap;
}

.q38-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 0 12px;
}

.q38-panel {
  height: 100%;
  min-height: 0;
}

.q38-panel[hidden] {
  display: none !important;
}

/* b0 */

.q38-b0 {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 48px;
  align-items: center;
}

.q38-candidates {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.q38-cand {
  display: grid;
  grid-template-columns: 64px 260px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  min-width: 0;
}

.q38-cand-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--navy);
  border-radius: 8px;
  background: var(--white);
  font-size: 24px;
  line-height: 1;
  font-weight: 600;
  color: var(--navy);
}

.q38-gen {
  height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 0 22px;
  border: 1px solid var(--gold);
  border-radius: 10px;
  background: var(--q38-gen-bg);
}

.q38-gen-k {
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: var(--q38-gold-ink);
}

.q38-gen-v {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 600;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.q38-gap {
  position: relative;
  height: 76px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--white);
}

.q38-gap::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 2px;
  margin: -1px 0 0 -22px;
  background: var(--line);
}

.q38-b0-side {
  min-width: 0;
  border-top: 2px solid var(--gold);
  padding-top: 14px;
}

.q38-b0-count {
  margin: 0;
  font-size: 34px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.q38-b0-count strong {
  font-weight: 600;
  color: var(--q38-gold-ink);
}

.q38-b0-note {
  margin: 10px 0 0;
  font-size: 19px;
  line-height: 1.65;
  color: var(--muted);
}

.q38-b0-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.q38-b0-list li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  font-size: 19px;
  line-height: 1.62;
  color: var(--ink);
}

.q38-b0-list li::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: 11px;
  border-radius: 50%;
  background: var(--gold);
}

/* b1 */

.q38-b1 {
  height: 100%;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 36px;
  align-items: stretch;
}

.q38-ledger {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-top: 2px solid var(--gold);
  padding-top: 16px;
}

.q38-ledger-k {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.q38-ledger-rows {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.q38-ledger-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 22px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.q38-ledger-row > [data-q38-reveal] {
  display: block;
  min-width: 0;
}

.q38-ledger-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--navy);
  border-radius: 7px;
  background: var(--white);
  font-size: 18px;
  line-height: 1;
  font-weight: 600;
  color: var(--navy);
}

.q38-ledger-select {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.q38-ledger-note {
  margin: 14px 0 0;
  font-size: 17px;
  line-height: 1.6;
  color: var(--muted);
}

.q38-arrangements {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}

.q38-arrange {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.q38-arrange-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.q38-arrange-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--navy);
}

.q38-arrange-head span {
  font-size: 17px;
  line-height: 1.5;
  color: var(--muted);
}

.q38-track {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  min-width: 0;
}

.q38-work {
  flex: 1 1 0;
  min-width: 0;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  text-align: center;
}

.q38-work-gen {
  border-color: var(--gold);
  background: var(--q38-gen-bg);
}

.q38-work-check {
  border-color: var(--navy);
  background: var(--q38-check-bg);
}

.q38-work-k {
  font-size: 15px;
  line-height: 1.15;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.q38-work-gen .q38-work-k {
  color: var(--q38-gold-ink);
}

.q38-work-check .q38-work-k {
  color: var(--navy);
}

.q38-work-v {
  font-size: 20px;
  line-height: 1.15;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

.q38-arrow {
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  color: var(--gold);
}

.q38-arrow svg {
  display: block;
  width: 24px;
  height: 14px;
}

.q38-arrow path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.q38-arrow-small {
  flex-basis: 22px;
  width: 22px;
}

.q38-arrow-small svg {
  width: 22px;
  height: 13px;
}

.q38-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  border: 1px solid var(--gold);
  border-radius: 9px;
  background: var(--navy);
  color: var(--white);
  font-size: 23px;
  line-height: 1;
  font-weight: 600;
  white-space: nowrap;
}

.q38-select-ledger {
  flex: 0 0 132px;
  width: 132px;
}

.q38-select-track {
  flex: 0 0 150px;
  width: 150px;
}

.q38-select-parallel {
  flex: 0 0 150px;
  width: 150px;
  height: 64px;
}

.q38-arrange-note {
  margin: 10px 0 0;
  font-size: 16px;
  line-height: 1.6;
  color: var(--muted);
}

.q38-lanes {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  min-width: 0;
}

.q38-lane-stack {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 9px;
}

.q38-lane {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.q38-lane-key {
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--navy);
  border-radius: 6px;
  background: var(--white);
  font-size: 16px;
  line-height: 1;
  font-weight: 600;
  color: var(--navy);
}

.q38-merge {
  flex: 0 0 56px;
  width: 56px;
  height: 196px;
  overflow: visible;
}

.q38-merge path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.q38-scroll-hint {
  display: none;
}

/* b2 */

.q38-b2 {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.9fr);
  gap: 48px;
  align-items: center;
}

.q38-chain-wrap {
  min-width: 0;
}

.q38-chain-k {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.q38-chain {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  min-width: 0;
}

.q38-step {
  flex: 1 1 0;
  min-width: 0;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

.q38-step-first {
  border-color: var(--gold);
  background: var(--q38-gen-bg);
}

.q38-step-k {
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.q38-step-first .q38-step-k {
  color: var(--q38-gold-ink);
}

.q38-step-v {
  font-size: 25px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

.q38-step-note {
  font-size: 16px;
  line-height: 1.45;
  color: var(--muted);
}

.q38-link {
  flex: 0 0 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.q38-link-label {
  font-size: 14px;
  line-height: 1.35;
  letter-spacing: 0.01em;
  color: var(--q38-gold-ink);
  white-space: nowrap;
}

.q38-link .q38-arrow {
  flex-basis: 30px;
  width: 30px;
}

.q38-link .q38-arrow svg {
  width: 30px;
  height: 16px;
}

.q38-chain-rule {
  margin: 20px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 18px;
  line-height: 1.6;
  color: var(--navy);
}

.q38-align {
  min-width: 0;
  border-top: 2px solid var(--gold);
  padding-top: 16px;
}

.q38-align-k {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.q38-align-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.q38-align-list li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  font-size: 20px;
  line-height: 1.55;
  color: var(--ink);
}

.q38-align-list li::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: 11px;
  border-radius: 50%;
  background: var(--gold);
}

.q38-align-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 18px;
  line-height: 1.65;
  color: var(--navy);
}

/* footer */

.q38-foot {
  flex: 0 0 auto;
  min-height: 84px;
  display: flex;
  align-items: center;
  padding-top: 12px;
  border-top: 2px solid var(--gold);
}

.q38-question {
  margin: 0;
  font-size: 30px;
  line-height: 1.45;
  font-weight: 600;
  color: var(--navy);
}

.q38-foot-text {
  margin: 0;
  font-size: 26px;
  line-height: 1.45;
  font-weight: 600;
  color: var(--navy);
}

/* authored reveal motion */

@keyframes q38-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes q38-slide {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes q38-check-in {
  0% {
    opacity: 0;
    transform: scale(0.96);
    box-shadow: 0 0 0 0 rgba(164, 118, 36, 0);
  }
  60% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 4px rgba(164, 118, 36, 0.16);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(164, 118, 36, 0);
  }
}

.q38 [data-q38-reveal].q38-in {
  animation: q38-rise 340ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.q38 .q38-arrange.q38-in {
  animation: q38-slide 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.q38 [data-q38-reveal^="check"].q38-in .q38-work-check {
  animation: q38-check-in 460ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* mobile document flow */

.q38.q38-m {
  position: static;
  inset: auto;
  display: block;
  height: auto;
  padding: 0;
  background: transparent;
}

.q38-m {
  min-width: 0;
}

.q38-m .q38-head {
  display: block;
  padding-bottom: 14px;
  margin-bottom: 20px;
}

.q38-m .q38-title {
  font-size: 28px;
  line-height: 1.38;
}

.q38-m .q38-sub {
  font-size: 16px;
  line-height: 1.6;
}

.q38-m .q38-head-meta {
  margin-top: 10px;
  text-align: left;
}

.q38-m .q38-state {
  font-size: 15px;
  line-height: 1.6;
  white-space: normal;
}

.q38-m .q38-tag {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.5;
  white-space: normal;
}

.q38-m .q38-body {
  padding: 0;
}

.q38-m .q38-panel {
  height: auto;
}

.q38-m .q38-b0 {
  display: block;
  height: auto;
}

.q38-m .q38-candidates {
  gap: 12px;
}

.q38-m .q38-cand {
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px 10px;
  align-items: stretch;
}

.q38-m .q38-cand-key {
  grid-row: 1 / span 2;
  align-self: start;
  width: 38px;
  height: 38px;
  font-size: 17px;
}

.q38-m .q38-gen {
  grid-column: 2;
  height: 62px;
  padding: 0 14px;
}

.q38-m .q38-gen-k {
  font-size: 14px;
}

.q38-m .q38-gen-v {
  font-size: 19px;
}

.q38-m .q38-gap {
  grid-column: 2;
  height: 52px;
}

.q38-m .q38-b0-side {
  margin-top: 26px;
  padding-top: 12px;
}

.q38-m .q38-b0-count {
  font-size: 28px;
}

.q38-m .q38-b0-note {
  font-size: 16px;
  line-height: 1.7;
}

.q38-m .q38-b0-list {
  gap: 10px;
  margin-top: 16px;
}

.q38-m .q38-b0-list li {
  font-size: 16px;
  line-height: 1.7;
}

.q38-m .q38-b0-list li::before {
  margin-top: 9px;
}

.q38-m .q38-b1 {
  display: block;
  height: auto;
}

.q38-m .q38-ledger {
  display: block;
  padding-top: 12px;
}

.q38-m .q38-ledger-k {
  font-size: 14px;
}

.q38-m .q38-ledger-row {
  grid-template-columns: 36px minmax(0, 1fr) 18px minmax(0, 1fr);
  gap: 6px;
}

.q38-m .q38-ledger-key {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

.q38-m .q38-ledger-select {
  justify-content: flex-end;
  margin-top: 14px;
}

.q38-m .q38-select-ledger {
  flex-basis: 112px;
  width: 112px;
  height: 52px;
  font-size: 20px;
}

.q38-m .q38-ledger-note {
  font-size: 15px;
  line-height: 1.7;
}

.q38-m .q38-arrangements {
  display: block;
  margin-top: 28px;
}

.q38-m .q38-arrange {
  margin-top: 22px;
}

.q38-m .q38-arrange-head h2 {
  font-size: 19px;
}

.q38-m .q38-arrange-head span {
  font-size: 14px;
}

.q38-m .q38-track {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-color: var(--line) transparent;
}

.q38-m .q38-track > .q38-work {
  flex: 0 0 92px;
}

.q38-m .q38-track > .q38-select-track {
  flex: 0 0 108px;
  width: 108px;
}

.q38-m .q38-work {
  height: 52px;
}

.q38-m .q38-work-k {
  font-size: 12px;
}

.q38-m .q38-work-v {
  font-size: 16px;
}

.q38-m .q38-arrow {
  flex-basis: 20px;
  width: 20px;
}

.q38-m .q38-arrow svg {
  width: 20px;
  height: 12px;
}

.q38-m .q38-arrange-note {
  font-size: 14px;
  line-height: 1.7;
}

.q38-m .q38-lanes {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-color: var(--line) transparent;
}

.q38-m .q38-lane-stack {
  flex: 0 0 430px;
}

.q38-m .q38-merge {
  flex: 0 0 40px;
  width: 40px;
}

.q38-m .q38-select-parallel {
  flex: 0 0 104px;
  width: 104px;
  height: 56px;
  font-size: 20px;
}

.q38-m .q38-scroll-hint {
  display: block;
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.q38-m .q38-b2 {
  display: block;
  height: auto;
}

.q38-m .q38-chain-k {
  font-size: 14px;
}

.q38-m .q38-chain {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-color: var(--line) transparent;
}

.q38-m .q38-step {
  flex: 0 0 186px;
  min-height: 124px;
  padding: 12px 13px;
}

.q38-m .q38-step-v {
  font-size: 22px;
}

.q38-m .q38-step-note {
  font-size: 14px;
}

.q38-m .q38-link {
  flex-basis: 76px;
}

.q38-m .q38-link-label {
  font-size: 12px;
}

.q38-m .q38-chain-rule {
  font-size: 16px;
  line-height: 1.7;
}

.q38-m .q38-align {
  margin-top: 28px;
  padding-top: 12px;
}

.q38-m .q38-align-k {
  font-size: 14px;
}

.q38-m .q38-align-list li {
  font-size: 17px;
  line-height: 1.6;
}

.q38-m .q38-align-list li::before {
  margin-top: 9px;
}

.q38-m .q38-align-note {
  font-size: 16px;
  line-height: 1.75;
}

.q38-m .q38-foot {
  display: block;
  min-height: 0;
  margin-top: 24px;
  padding-top: 14px;
}

.q38-m .q38-question {
  font-size: 23px;
  line-height: 1.55;
}

.q38-m .q38-foot-text {
  font-size: 20px;
  line-height: 1.55;
}

.q38-m-link {
  margin: 24px 0 0;
  font-size: 15px;
  line-height: 1.6;
}

/* instant and reduced motion */

.is-instant .q38 *,
.is-instant .q38-m * {
  transition: none !important;
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .q38 *,
  .q38-m * {
    transition: none !important;
    animation: none !important;
  }
}

/* Coordinator repair: fixed source positions and keyed, measured rearrangement.
   The ledger is a reference view of the SAME batch, never extra generated work. */
.q38:not(.q38-m) .q38-b0 { grid-template-columns:360px minmax(0,1fr); gap:36px; align-items:stretch; }
.q38:not(.q38-m) .q38-candidates { display:flex; flex-direction:column; justify-content:center; gap:0; border-top:2px solid var(--gold); padding-top:16px; }
.q38:not(.q38-m) .q38-cand { grid-template-columns:42px minmax(0,1fr) 22px minmax(0,1fr); gap:8px; }
.q38:not(.q38-m) .q38-cand .q38-gap { height:56px; }
.q38:not(.q38-m) .q38-ledger-note { height:54.4px; flex-shrink:0; }
.q38-neutral-space { visibility:hidden; }
.q38:not(.q38-m) .q38-b0-side { align-self:center; border-top:0; padding:0 20px 0 30px; }
.q38-motion .q38-arrange.q38-in { animation:none; }
.q38-motion [data-q38-reveal="select"].q38-in { animation:none; }
.q38-motion .q38-ledger .q38-work { will-change:transform; }
.q38-motion .q38-ledger [data-q38-reveal^="check"].q38-in .q38-work-check { animation:none; }
.q38-m .q38-candidates { gap:0; }
.q38-m .q38-cand { grid-template-columns:36px minmax(0,1fr) 18px minmax(0,1fr); gap:6px; }
.q38-m .q38-cand .q38-gap { grid-column:auto; height:52px; }
.q38-m .q38-candidates .q38-neutral-space { display:none; }

/* Keep explanatory captions clear while the same keyed boxes cross their area.
   Stable/reduced-motion states have no moving phase and show both captions. */
.q38[data-q38-phase="move-to-serial"] .q38-arrange-note,
.q38[data-q38-phase="move-to-parallel"] .q38-arrange-note,
.q38[data-q38-phase="move-to-parallel"] .q38-lane-key {
  visibility: hidden;
}
