* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #f0f2f5;
  margin: 0;
  padding: 30px 20px;
  color: #2c3e50;
}

h1 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 5px;
}

.subtitle {
  text-align: center;
  color: #7f8c8d;
  margin-top: 0;
  margin-bottom: 30px;
}

form {
  max-width: 1100px;
  margin: 0 auto;
}

/* Griglia a due pannelli (A e B) */
.griglia-pannelli {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 750px) {
  .griglia-pannelli { grid-template-columns: 1fr; }
}

.panel {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
  color: #2c3e50;
}

.badge {
  background: #3498db;
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

/* Controlli di dimensione (+ / −) */
.controlli-dim {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.controlli-dim button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  background: #3498db;
}

.controlli-dim button:hover:not(:disabled) {
  background: #2980b9;
  transform: scale(1.08);
}

.controlli-dim button:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
  opacity: 0.5;
}

.dim-label {
  font-weight: 700;
  font-size: 17px;
  color: #2c3e50;
  min-width: 60px;
  text-align: center;
}

/* Griglia matrici */
.matrice-input {
  display: inline-grid;
  gap: 6px;
  justify-content: center;
  width: 100%;
}

.matrice-input input {
  width: 60px;
  height: 52px;
  text-align: center;
  font-size: 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  transition: all 0.2s;
}

.matrice-input input:focus {
  outline: none;
  border-color: #3498db;
  background: #eaf4fc;
}

/* Pannello extra */
.panel.small {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.panel.small label {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.panel.small input {
  padding: 8px 12px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  width: 140px;
}

.panel.small input:focus {
  outline: none;
  border-color: #3498db;
}

button {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: #3498db;
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

button:hover:not(:disabled) {
  background: #2980b9;
  transform: translateY(-1px);
}

button:active:not(:disabled) { transform: translateY(0); }

button.reset {
  background: #e74c3c;
}

button.reset:hover {
  background: #c0392b;
}

/* Pannello azioni */
.panel.azioni {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.panel.azioni h3 {
  width: 100%;
  font-size: 13px;
  text-transform: uppercase;
  color: #7f8c8d;
  letter-spacing: 1px;
  margin: 0 0 8px;
}

/* Risultato */
.risultato-box {
  max-width: 1100px;
  margin: 25px auto 0;
  background: white;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-left: 6px solid #27ae60;
}

.risultato-box h2 {
  margin-top: 0;
  color: #27ae60;
}

.risultato-testo {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.risultato-html {
  margin-top: 15px;
  line-height: 1.8;
}

.risultato-html .blocco {
  margin-bottom: 15px;
}

.risultato-html .blocco strong {
  display: block;
  margin-bottom: 6px;
  color: #2c3e50;
}

/* Tabelle matrici risultato */
.matrice-tab {
  border-collapse: separate;
  border-spacing: 5px;
  margin: 10px 0;
}

.matrice-tab td {
  min-width: 60px;
  height: 50px;
  text-align: center;
  background: #ecf0f1;
  border: 2px solid #bdc3c7;
  border-radius: 8px;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 15px;
}

/* Errore */
.errore {
  max-width: 1100px;
  margin: 20px auto;
  background: #fdecea;
  border-left: 6px solid #e74c3c;
  color: #c0392b;
  padding: 15px 20px;
  border-radius: 8px;
  font-weight: 600;
}

/* Passaggi */
.passaggi {
  margin-top: 20px;
  background: #fdf6e3;
  border-left: 4px solid #e67e22;
  border-radius: 8px;
  padding: 12px 18px;
}

.passaggi summary {
  cursor: pointer;
  font-weight: 700;
  color: #b9651a;
  user-select: none;
}

.passaggi pre {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  white-space: pre-wrap;
  color: #4a3c1f;
  margin: 10px 0 0;
  line-height: 1.6;
  max-height: 450px;
  overflow-y: auto;
}