/* =========================================================
   GABBRO — math-canvas.css
   Math Canvas (tools/math.html): serie di Fourier e di Taylor.
   Richiede base.css; l'intestazione usa gli stili di article.css.
   Riusa i token e le superfici del sito (niente palette propria).
   ========================================================= */

.wrap-wide { max-width: 1320px; }

.lab-page { padding-top: 40px; padding-bottom: 96px; }

/* =========================================================
   INTESTAZIONE
   ========================================================= */
.lab-head { max-width: 820px; margin-bottom: 28px; }
.lab-head .breadcrumb { margin-bottom: 24px; }
.lab-head h1 {
  margin: 16px 0 14px;
  font-size: clamp(30px, 4.4vw, 46px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.08;
}
.lab-head .lead {
  margin: 0 0 20px;
  font-family: var(--text-font);
  font-size: 16.5px;
  line-height: 1.7;
  color: var(--text-dim);
}

/* selettore argomento */
.tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--bg-1);
}
.tab {
  padding: 7px 20px;
  border: 0;
  border-radius: 5px;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--text-dim); }
.tab.active {
  background: var(--bg-3);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}
.tab:focus-visible { outline: 2px solid var(--accent-3); outline-offset: 2px; }

/* =========================================================
   LAYOUT
   ========================================================= */
.lab {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  max-height: calc(100vh - var(--nav-h) - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* =========================================================
   CONTROLLI
   ========================================================= */
.panel { display: none; flex-direction: column; padding: 20px; }
.panel.active { display: flex; }

.panel-head { margin-bottom: 18px; }
.panel-head h2 {
  margin: 0 0 5px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.panel-desc {
  margin: 0;
  font-family: var(--text-font);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-faint);
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.slider-head label { margin: 0; }
.slider-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* select */
select {
  width: 100%;
  height: 38px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--bg-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23a0a3ad' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 12px center;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  appearance: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
select:hover { border-color: rgba(255, 255, 255, 0.22); }
select:focus-visible { outline: 2px solid var(--accent-3); outline-offset: 2px; }
option { color: var(--text); background: var(--bg-2); }

/* slider */
input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6.5px;
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
  transition: transform 0.15s var(--ease);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--text);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent-3); outline-offset: 4px; border-radius: 2px; }

/* interruttori */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.toggle-row > label:first-child { margin: 0; }

.switch { position: relative; display: inline-block; width: 32px; height: 18px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s var(--ease);
}
.sw-track::before {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s var(--ease), background 0.2s;
}
.switch input:checked + .sw-track { background: rgba(var(--glow), 0.85); }
.switch input:checked + .sw-track::before { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + .sw-track { outline: 2px solid var(--accent-3); outline-offset: 2px; }

/* separatore */
.rule { height: 1px; background: var(--border); margin: 6px 0 16px; }

/* riquadro formula */
.info-box {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-3);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(34, 211, 238, 0.04);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  line-height: 1.65;
  word-break: break-word;
  min-height: 38px;
}
.formula-label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

/* scorciatoie da tastiera */
.kbd-hint {
  margin-top: 16px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.9;
}
.kbd-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin: 0 1px;
}

/* =========================================================
   GRAFICI
   ========================================================= */
.canvas-area { display: grid; gap: 14px; min-width: 0; }

.canvas-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(10, 11, 14, 0.92);
  overflow: hidden;
}

.canvas-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.canvas-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.canvas-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  background: rgba(7, 8, 10, 0.6);
}
.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* altezze fisse per ogni riquadro */
.h-main { height: 300px; }
.h-comp { height: 200px; }
.h-spec { height: 180px; }

/* legenda */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.leg-bar  { width: 2px;  height: 12px;  border-radius: 1px; flex-shrink: 0; }
.leg-line { width: 16px; height: 1.5px; border-radius: 1px; flex-shrink: 0; }

/* card nascoste finché il relativo grafico non è attivo */
.canvas-card.is-hidden { display: none; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1000px) {
  .lab { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .lab-page { padding-top: 20px; padding-bottom: 40px; }
  .h-main { height: 260px; }
  .h-comp { height: 180px; }
  .h-spec { height: 160px; }
  .canvas-card {
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
}
