/* Navigazione dei passaggi */

.step-toolbar {
  justify-content: center;
  margin-bottom: 14px;
}

.step-counter {
  min-width: 130px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

/* Passaggi e riepiloghi */

.step-card,
.summary-card {
  padding: 16px;
  margin-bottom: 16px;
  animation: cardFadeIn 0.3s ease;
  min-width: 0;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.step-title h3 {
  margin: 0;
}

/* Spiegazioni */

.explanation {
  color: var(--ink);
  line-height: 1.55;
  opacity: 0.85;
}

.explanation p {
  margin: 0 0 10px;
}

.explanation ul,
.notes-list {
  margin: 0;
  padding-left: 18px;
}

.notes-list li {
  margin-bottom: 6px;
}

/* Calcoli da copiare */

.calculation-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  min-width: 0;
  overflow: hidden;
}

.calculation-panel h3 {
  margin-bottom: 14px;
}

.calculation-section + .calculation-section {
  margin-top: 18px;
}

.calculation-section {
  min-width: 0;
}

.calculation-section h4 {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-size: 16px;
  font-weight: 900;
}

.certificate-section {
  margin-top: 14px;
  min-width: 0;
}

.certificate-section + .certificate-section {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.certificate-section h4 {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-size: 16px;
  font-weight: 900;
}

.calculation-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 32px;
  min-width: 0;
}

.calculation-list li {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.75;
  padding-left: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.calculation-list li::marker {
  color: var(--muted);
  font-weight: 800;
}

.calculation-list code {
  color: var(--ink);
  font-family: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas,
    monospace;
  font-size: 15px;
  line-height: 1.7;
  white-space: normal;
  overflow-wrap: anywhere;
}

.calculation-text {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.55;
}

.math-line {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  color: var(--ink);
  line-height: 2.1;
  min-height: 58px;
  padding: 10px 0 14px;
  scrollbar-width: thin;
}

.math-line .katex {
  font-size: 1.16em;
  line-height: 1.55;
  white-space: nowrap;
}

.math-line .katex-display {
  margin: 0;
  text-align: left;
  width: max-content;
  min-width: 100%;
  max-width: none;
  overflow: visible;
  padding: 4px 0 8px;
}

.math-line .katex-display > .katex {
  display: inline-block;
  padding: 2px 0 4px;
}

.math-line .katex-mathml,
.math-line .katex-mathml * {
  display: none;
  max-width: 1px;
  overflow: hidden;
}

.math-line code {
  display: inline-block;
}

/* Trasformazione in forma standard */

.standard-transform-panel {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  min-width: 0;
  overflow: hidden;
}

/* Summary (clickable header) */
.standard-transform-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  cursor: pointer;
  list-style: none; /* remove default triangle on Firefox */
  border-radius: 8px;
  transition: background 0.15s;
  user-select: none;
}

/* Remove default Safari/Chrome marker */
.standard-transform-summary::-webkit-details-marker {
  display: none;
}

.standard-transform-summary:hover {
  background: color-mix(in srgb, var(--accent-2) 6%, var(--code-bg));
}

.standard-transform-summary h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
  flex: 1;
}

/* Animated chevron */
.standard-transform-chevron {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: var(--accent-2);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 7l5 5 5-5' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 7l5 5 5-5' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 0.22s ease;
}

.standard-transform-panel[open] .standard-transform-chevron {
  transform: rotate(180deg);
}

/* Content area */
.standard-transform-panel[open] .standard-transform-grid {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.standard-transform-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.standard-transform-block {
  min-width: 0;
}

.standard-transform-wide {
  grid-column: 1 / -1;
}

.standard-transform-block h4 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 15px;
  font-weight: 900;
}

.standard-equation-list {
  display: grid;
  gap: 8px;
}

.standard-equation {
  min-width: 0;
}

.constraint-transform-list {
  display: grid;
  gap: 12px;
}

.constraint-transform-row {
  min-width: 0;
  padding: 10px 0 12px;
  border-top: 1px solid var(--line);
}

.constraint-transform-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.constraint-transform-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  color: var(--ink);
}

.constraint-transform-math {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.constraint-transform-math .math-line {
  min-height: 44px;
  padding: 6px 0 10px;
}

.transform-arrow {
  color: var(--accent-2);
  font-family: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-weight: 900;
}

.standard-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.standard-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 48%, transparent);
  border-radius: 999px;
  color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 12%, transparent);
  font-size: 12px;
  font-weight: 900;
}

.phase-label {
  margin-top: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
  border-left: 3px solid var(--accent-2);
}

.phase-label p {
  margin: 0;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.phase-sublabel {
  margin-top: 4px;
  padding: 3px 10px;
}

.phase-sublabel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* Tableau */

.tableau-frame {
  margin-top: 12px;
}

.tableau-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 0 2px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tableau-caption strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  transition: background var(--speed), border-color var(--speed);
}

.tableau {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-family: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas,
    monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tableau-canonical {
  min-width: 100%;
}

.tableau th,
.tableau td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 7px 7px;
  text-align: right;
  white-space: nowrap;
}

.tableau th:first-child,
.tableau td:first-child {
  text-align: left;
}

.tableau th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--code-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.tableau tr:last-child td {
  border-bottom: 0;
}

.tableau-groups th {
  text-align: center;
  color: var(--accent-2);
  background: var(--surface-2);
  letter-spacing: 0;
}

.tableau-vars th {
  text-align: center;
}

.tableau-exercise-head th {
  color: var(--ink);
  background: var(--surface-2);
}

.row-head,
.row-label,
.row-zero-label {
  min-width: 68px;
}

.tableau-canonical td:not(:first-child) {
  text-align: right;
}

.base-head,
.basis-label {
  color: var(--accent-2);
  font-weight: 900;
}

.basis-var {
  color: var(--muted);
}

.free-var {
  color: var(--ink);
}

.variable-head.basic-column {
  color: var(--muted);
}

.variable-head.nonbasic-column {
  color: var(--ink);
}

.row-zero-label span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.row-label {
  color: var(--muted);
  font-weight: 800;
}

.tableau td.basic-column,
.tableau th.basic-column {
  background: color-mix(in srgb, var(--surface-2) 68%, transparent);
}

.tableau td.nonbasic-column,
.tableau th.nonbasic-column {
  background: var(--input-bg);
}

.block-start {
  border-left: 2px solid color-mix(in srgb, var(--ink) 32%, var(--line)) !important;
}

.rhs-head,
.rhs-cell {
  min-width: 64px;
}

.basis-eq-head,
.basis-eq-cell {
  min-width: 62px;
  text-align: left !important;
}

.basis-eq-cell {
  color: var(--accent-2);
  font-weight: 900;
}

.tableau td.entering-cell,
.tableau th.entering-cell {
  background: var(--entering);
}

.tableau tr.leaving-row td {
  background: var(--leaving);
}

.tableau td.pivot-cell {
  background: var(--pivot) !important;
  color: #3b2f00;
  font-weight: 900;
}

.tableau .reduced-row td {
  background: var(--reduced-bg);
  color: var(--reduced-ink);
  font-weight: 900;
}

.reduced-row td.basic-column {
  color: var(--muted);
}

/* Rapporti e metriche */

.ratio-grid,
.solution-grid {
  display: grid;
  gap: 8px;
}

.ratio-grid {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin-top: 12px;
}

.solution-grid {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
  transition: background var(--speed), border-color var(--speed);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-value {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 900;
  word-break: break-word;
}

/* Vista compatta */

.compact-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

/* Testo del problema */

.problem-text {
  display: grid;
  gap: 6px;
  color: var(--ink);
  opacity: 0.85;
  font-family: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas,
    monospace;
  font-size: 13px;
  line-height: 1.55;
  overflow-x: auto;
}
