.problem { background: var(--paper-2); padding: 7rem 0; }
.problem-title { margin: 1.1rem 0 2.4rem; max-width: 18ch; }

.bento {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(200px, auto);
    gap: 16px;
}

.cell {
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border-radius: var(--r-card);
    padding: 28px;
    transition: transform 200ms var(--ease);
}
.cell:hover { transform: translateY(-2px); }

.cell-tag {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--text-on-light-faint);
    margin-bottom: 0.7rem;
}
.cell h4 { margin-bottom: 1.6rem; }

.cell-anchor { grid-column: span 7; grid-row: span 2; background: var(--violet-tint); }
.cell-anchor h3 { font-weight: 480; max-width: 26ch; margin-bottom: 1.6rem; }
.cell-identity { grid-column: span 5; grid-row: span 2; }
.cell:nth-child(3) { grid-column: span 4; }
.cell:nth-child(4) { grid-column: span 4; }
.cell:nth-child(5) { grid-column: span 4; }
.cell-dispersion { grid-column: span 8; }
.cell:nth-child(7) { grid-column: span 4; }
.cell-trace {
    grid-column: span 12;
    flex-direction: row;
    align-items: center;
    gap: 2.5rem;
    flex-wrap: wrap;
}
.cell-trace .trace-head { flex: 1 1 280px; }
.cell-trace .cell-tag { margin-bottom: 0.5rem; }
.trace-note { flex: 1 1 340px; color: var(--text-on-light-soft); }

/* Cada visualización ocupa el espacio restante de su celda */
.cell-diagram, .entities, .pouches, .balance, .rules, .fan, .perms {
    margin-top: auto;
    width: 100%;
}

/* Diagrama ancla: lo que la conexión resuelve vs lo que queda pendiente */
.cell-diagram { height: auto; max-height: 240px; }
.d-label { font-family: var(--font-mono); font-size: 15px; fill: var(--text-on-light-soft); }
.d-label-center { text-anchor: middle; font-size: 13px; }
.d-line { stroke: var(--paper-line); stroke-width: 1.4; fill: none; }
.d-line.active { stroke: var(--violet-700); stroke-width: 2; }
.d-line.dashed { stroke: var(--text-on-light-faint); stroke-width: 1.4; stroke-dasharray: 5 5; opacity: 0.6; }
.d-node { fill: var(--text-on-light-faint); }
.d-node.violet { fill: var(--violet-700); }
.d-zone { stroke: var(--text-on-light-faint); stroke-width: 1.4; stroke-dasharray: 6 6; fill: none; opacity: 0.55; }
.d-zone-title {
    text-anchor: middle;
    font-family: var(--font-mono);
    font-size: 15px;
    letter-spacing: 0.06em;
    fill: var(--text-on-light-soft);
}
.d-zone-item {
    text-anchor: middle;
    font-family: var(--font-mono);
    font-size: 13px;
    fill: var(--text-on-light-faint);
}
.d-q {
    text-anchor: middle;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 30px;
    fill: var(--violet-700);
    opacity: 0.5;
}
.d-amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 15px;
    fill: var(--text-on-light-soft);
}

/* 01 Identidad: entidades de distinto tipo */
.entities {
    list-style: none;
    margin: auto 0 0;
    padding: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 0.7rem;
}
.entity {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--paper-2);
    border-radius: 10px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 420ms var(--ease), transform 420ms var(--ease);
}
.cell.in .entity { opacity: 1; transform: none; }
.cell.in .entity:nth-child(1) { transition-delay: 160ms; }
.cell.in .entity:nth-child(2) { transition-delay: 290ms; }
.cell.in .entity:nth-child(3) { transition-delay: 420ms; }
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--paper);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-on-light-soft);
}
.entity-name { flex: 1; font-size: 0.92rem; color: var(--text-on-light); }
.entity-kind {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-on-light-faint);
}

/* 02 Bolsas de dinero */
.pouches { list-style: none; margin: auto 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.85rem; }
.pouch { display: flex; flex-direction: column; gap: 0.4rem; }
.pouch-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; }
.pouch-name { font-size: 0.85rem; color: var(--text-on-light-soft); }
.pouch-amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.8rem;
    color: var(--text-on-light);
}
.pouch-track { display: block; height: 8px; border-radius: 4px; background: var(--paper-2); overflow: hidden; }
.pouch-fill {
    display: block;
    height: 100%;
    border-radius: 4px;
    background: var(--paper-line);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 640ms var(--ease-reveal);
}
.pouch-fill.violet { background: var(--violet-700); }
.cell.in .pouch-fill { transform: scaleX(1); }
.cell.in .pouch:nth-child(1) .pouch-fill { transition-delay: 180ms; }
.cell.in .pouch:nth-child(2) .pouch-fill { transition-delay: 320ms; }
.cell.in .pouch:nth-child(3) .pouch-fill { transition-delay: 460ms; }

/* 03 Balances */
.balance { display: flex; flex-direction: column; gap: 0.3rem; }
.balance-caption {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-on-light-faint);
}
.balance-figure {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.7rem;
    color: var(--text-on-light);
    letter-spacing: 0.01em;
}
.balance-split { list-style: none; margin: 0.75rem 0 0; padding: 0.75rem 0 0; border-top: 1px solid var(--paper-line); }
.balance-split li { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.2rem 0; }
.bs-key { font-size: 0.82rem; color: var(--text-on-light-soft); }
.bs-val {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    color: var(--text-on-light-soft);
}

/* 04 Reglas de distribución */
.rules { display: flex; flex-direction: column; gap: 0.9rem; }
.split { display: flex; gap: 4px; height: 12px; }
.split .seg {
    height: 100%;
    border-radius: 3px;
    background: var(--paper-line);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 520ms var(--ease-reveal);
}
.split .seg.violet { background: var(--violet-700); }
.cell.in .split .seg { transform: scaleX(1); }
.cell.in .split .seg:nth-child(1) { transition-delay: 200ms; }
.cell.in .split .seg:nth-child(2) { transition-delay: 360ms; }
.cell.in .split .seg:nth-child(3) { transition-delay: 500ms; }

.rule-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.rule-legend li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-on-light-soft);
}
.rule-legend b {
    margin-left: auto;
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.78rem;
    color: var(--text-on-light);
}
.rule-legend .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--paper-line); }
.rule-legend .dot.violet { background: var(--violet-700); }

/* 05 Dispersión */
.fan { height: auto; max-height: 200px; }
.fan-line {
    stroke: var(--violet-700);
    stroke-width: 1.6;
    fill: none;
    stroke-dasharray: 6 6;
    stroke-dashoffset: 0;
}
.cell-dispersion.in .fan-line { animation: fan-flow 1.8s linear infinite; }
.cell-dispersion.in .fan-line:nth-of-type(2) { animation-delay: 0.15s; }
.cell-dispersion.in .fan-line:nth-of-type(3) { animation-delay: 0.3s; }
.cell-dispersion.in .fan-line:nth-of-type(4) { animation-delay: 0.45s; }
.cell-dispersion:hover .fan-line { animation-duration: 0.9s; }
@keyframes fan-flow { to { stroke-dashoffset: -24; } }

/* 06 Control: matriz de permisos */
.perms { border-collapse: collapse; font-size: 0.8rem; }
.perms th, .perms td { padding: 0.5rem 0.3rem; text-align: center; }
.perms thead th {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-on-light-faint);
}
.perms tbody th {
    text-align: left;
    font-weight: 400;
    color: var(--text-on-light-soft);
    white-space: nowrap;
}
.perms tbody tr + tr th, .perms tbody tr + tr td { border-top: 1px solid var(--paper-2); }
.perms td::after {
    content: '';
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 340ms var(--ease), transform 340ms var(--ease);
}
.perms td.on::after { background: var(--violet-700); }
.perms td.off::after { background: var(--paper-line); }
.cell.in .perms td::after { opacity: 1; transform: none; }
.cell.in .perms tbody tr:nth-child(1) td::after { transition-delay: 200ms; }
.cell.in .perms tbody tr:nth-child(2) td::after { transition-delay: 330ms; }
.cell.in .perms tbody tr:nth-child(3) td::after { transition-delay: 460ms; }

@media (prefers-reduced-motion: reduce) {
    .cell-dispersion.in .fan-line,
    .cell-dispersion:hover .fan-line { animation: none; }
    .pouch-fill, .split .seg { transform: scaleX(1); transition: none; }
    .entity { opacity: 1; transform: none; transition: none; }
    .perms td::after { opacity: 1; transform: none; transition: none; }
}

@media (max-width: 768px) {
    .problem { padding: 4.5rem 0; }
    .bento { grid-template-columns: 1fr; grid-auto-rows: auto; }
    .cell-anchor, .cell-identity, .cell-dispersion, .cell-trace,
    .cell:nth-child(3), .cell:nth-child(4), .cell:nth-child(5), .cell:nth-child(7) {
        grid-column: 1 / -1;
        grid-row: auto;
    }
    .cell { padding: 24px; }
    .cell h4, .cell-anchor h3 { margin-bottom: 1.4rem; }
    .cell-trace { flex-direction: column; align-items: flex-start; gap: 1.2rem; }
    .entity-name { font-size: 0.86rem; }
    .perms { width: 100%; }
}
