.pdca-intro,
.pdca-module {
  padding: 1rem;
  display: grid;
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.pdca-intro p,
.pdca-module-lead {
  margin: 0;
  color: var(--muted);
}

.pdca-aliases-title {
  margin: 0;
  color: var(--muted);
}

.pdca-aliases-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.26rem;
}

.pdca-aliases-list li {
  line-height: 1.35;
}

.pdca-counter {
  font-size: 0.9rem;
  color: var(--muted);
}

.definition-panel {
  display: grid;
  gap: 0.65rem;
}

.pdca-definition-text {
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  line-height: 1.45;
}

.pdca-actions {
  display: flex;
  gap: 0.5rem;
}

.pdca-actions button {
  flex: 1;
}

/* En el primer y el último paso se oculta uno de los dos botones. Con display:none
   el que queda se estira al doble y salta de sitio en cada avance: se le reserva el
   hueco para que "Adelante" no se mueva en todo el recorrido. */
.pdca-actions button[hidden] {
  display: block;
  visibility: hidden;
}

.cycle-layout {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.cycle-canvas {
  position: relative;
  /* Las cajas se colocan en %, el trazado del ciclo en unidades del viewBox.
     Fijar la proporción hace que ambos sistemas describan el mismo espacio a
     cualquier ancho; antes las flechas iban en px y se despegaban de las cajas. */
  aspect-ratio: 360 / 272;
  container-type: inline-size;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(12, 29, 44, 0.12);
  background:
    radial-gradient(16rem 12rem at 0% 0%, rgba(162, 217, 205, 0.2), transparent 62%),
    radial-gradient(16rem 12rem at 100% 100%, rgba(248, 208, 153, 0.2), transparent 62%),
    #fbfbf7;
}

.cycle-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* El anillo pasa por los centros de las cuatro cajas, no por un inset aproximado. */
.cycle-ring {
  fill: none;
  stroke: rgba(19, 44, 64, 0.15);
  stroke-width: 1.5;
  stroke-dasharray: 3 8;
}

/* Cada flecha arranca y termina en el borde de su caja, con aire a los dos lados.
   La punta va en el mismo trazo que la línea, así un solo `stroke` las tiñe juntas. */
.cycle-link {
  fill: none;
  stroke: rgba(11, 128, 120, 0.58);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 220ms ease, stroke 220ms ease, stroke-dasharray 220ms ease;
}

.cycle-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 30%;
  min-height: 19%;
  border-radius: 12px;
  border: 1px solid rgba(12, 29, 44, 0.18);
  background: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: clamp(0.7rem, 3.3cqw, 0.84rem);
  line-height: 1.2;
  padding: 0.32rem;
  color: var(--muted);
  transition:
    border-color 220ms ease,
    color 220ms ease,
    box-shadow 220ms ease,
    background-color 220ms ease,
    opacity 220ms ease;
}

.cycle-node strong {
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
}

.cycle-node[data-cycle-node="plan"] {
  left: 50%;
  top: 20%;
}

.cycle-node[data-cycle-node="do"] {
  left: 79%;
  top: 50%;
}

.cycle-node[data-cycle-node="check"] {
  left: 50%;
  top: 80%;
}

.cycle-node[data-cycle-node="act"] {
  left: 21%;
  top: 50%;
}

.cycle-node.is-active {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: rgba(11, 128, 120, 0.08);
  box-shadow: 0 0 0 4px rgba(11, 128, 120, 0.14);
}

.cycle-node.is-hidden,
.cycle-link.is-hidden,
.cycle-token.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* El paquete atraviesa las cajas al circular, que es justo lo que ilustra: pasa
   por las cuatro fases. Va como ficha —disco propio y sombra— para leerse
   por encima del texto en vez de ensuciarlo. */
.cycle-token {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 0 0 1px rgba(12, 29, 44, 0.1),
    0 3px 8px rgba(21, 43, 62, 0.16);
  transform: translate(-50%, -50%);
  transition:
    left 620ms cubic-bezier(0.2, 0.9, 0.2, 1),
    top 620ms cubic-bezier(0.2, 0.9, 0.2, 1),
    opacity 240ms ease;
}

.phase-detail {
  border: 1px solid rgba(12, 29, 44, 0.14);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 0.72rem 0.85rem;
  display: grid;
  gap: 0.45rem;
}

.phase-detail h3,
.malfunction-detail h3 {
  margin: 0;
}

.phase-detail p,
.malfunction-detail p {
  margin: 0;
}

.handoff-block {
  margin-top: 0.25rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(12, 29, 44, 0.12);
  display: grid;
  gap: 0.4rem;
}

.handoff-title,
.handoff-caption {
  margin: 0;
}

.handoff-caption {
  color: var(--muted);
  font-size: 0.88rem;
}

.handoff-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 0.45rem;
  align-items: center;
}

.handoff-chip {
  margin: 0;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  border: 1px solid rgba(12, 29, 44, 0.14);
  background: #fff;
  display: grid;
  gap: 0.15rem;
}

.handoff-chip small {
  color: var(--muted);
  font-size: 0.74rem;
}

.handoff-chip strong {
  font-size: 0.84rem;
  line-height: 1.35;
}

.handoff-arrow {
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 1.05rem;
}

/* Tipo 1: la información llega, pero incompleta. El traspaso se dibuja
   discontinuo para que se lea como un canal que gotea, no como uno cortado. */
.cycle-canvas.is-malfunction[data-malfunction-type="type1"] [data-cycle-link="do-check"] {
  stroke: rgba(169, 53, 42, 0.8);
  stroke-dasharray: 5 5;
}

/* Tipo 2: la fase de comprobación se salta; entra y sale en rojo. */
.cycle-canvas.is-malfunction[data-malfunction-type="type2"] [data-cycle-node="check"] {
  opacity: 0.35;
  text-decoration: line-through;
}

.cycle-canvas.is-malfunction[data-malfunction-type="type2"] [data-cycle-link="do-check"],
.cycle-canvas.is-malfunction[data-malfunction-type="type2"] [data-cycle-link="check-act"] {
  stroke: rgba(169, 53, 42, 0.7);
}

.cycle-canvas.is-malfunction[data-malfunction-type="type3"] [data-cycle-node] {
  opacity: 0.5;
}

.cycle-canvas.is-malfunction[data-malfunction-type="type3"] [data-cycle-node="do"] {
  opacity: 1;
  border-color: rgba(169, 53, 42, 0.72);
  background: rgba(169, 53, 42, 0.08);
}

.malfunction-detail {
  border: 1px solid rgba(12, 29, 44, 0.14);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 0.72rem 0.85rem;
  display: grid;
  gap: 0.52rem;
}

.potential-wrap {
  display: grid;
  gap: 0.32rem;
}

.potential-bar {
  height: 9px;
  border-radius: 999px;
  background: rgba(12, 29, 44, 0.16);
  overflow: hidden;
}

.potential-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #9f3f1f, #eb9d34, #5ea86f);
  transition: width 500ms ease;
}

.games-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.game-card {
  border: 1px solid rgba(12, 29, 44, 0.14);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 0.8rem;
  display: grid;
  gap: 0.6rem;
}

.game-card h3 {
  margin: 0;
}

.game-lead {
  margin: 0;
  color: var(--muted);
}

.order-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.order-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
  background: #fff;
  border: 1px solid rgba(12, 29, 44, 0.14);
  border-radius: 10px;
  padding: 0.48rem 0.55rem;
}

.order-name {
  font-size: 0.92rem;
}

.order-controls {
  display: flex;
  gap: 0.32rem;
}

.order-controls .btn-mini {
  flex: none;
  min-width: 2rem;
  padding: 0.26rem 0.5rem;
}

.match-list {
  display: grid;
  gap: 0.45rem;
}

.match-item {
  display: grid;
  gap: 0.35rem;
  background: #fff;
  border: 1px solid rgba(12, 29, 44, 0.14);
  border-radius: 10px;
  padding: 0.5rem 0.55rem;
}

.match-text {
  display: grid;
  gap: 0.18rem;
}

.match-text small {
  color: var(--muted);
  font-size: 0.75rem;
}

.match-text strong {
  font-size: 0.86rem;
}

.match-item select {
  width: 100%;
  border: 1px solid rgba(12, 29, 44, 0.2);
  border-radius: 8px;
  background: #fff;
  padding: 0.35rem 0.45rem;
  color: var(--text);
}

.game-actions button {
  flex: 1;
}

.game-feedback {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.game-feedback[data-status="success"] {
  color: #1c6b2f;
}

.game-feedback[data-status="warning"] {
  color: #8b4d1c;
}

@media (max-width: 980px) {
  .cycle-layout {
    grid-template-columns: 1fr;
  }

  .pdca-actions {
    flex-direction: column;
  }

  .pdca-actions button {
    width: 100%;
  }

  .games-grid {
    grid-template-columns: 1fr;
  }
}
