:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #182230;
  --muted: #64748b;
  --line: #dbe4ee;
  --blue: #0b6fb8;
  --blue-dark: #07598f;
  --cyan: #0e9fbb;
  --orange: #f59e0b;
  --orange-dark: #c97700;
  --green: #14805e;
  --red: #c94343;
  --shadow: 0 10px 28px rgba(30, 55, 80, .08);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -15%, rgba(14,159,187,.10), transparent 32rem),
    radial-gradient(circle at 100% 0%, rgba(11,111,184,.08), transparent 28rem),
    var(--bg);
}
button, input { font: inherit; }
button { cursor: pointer; }
.lab-shell { max-width: 1450px; margin: 0 auto; padding: 18px 20px 10px; }
.lab-header {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-bottom: 14px; padding: 2px 2px 0;
}
.eyebrow { margin: 0 0 3px; color: var(--blue); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
h1 { margin: 0; font-size: clamp(1.65rem, 2.3vw, 2.35rem); line-height: 1.05; letter-spacing: -.035em; }
.subtitle { margin: 5px 0 0; color: var(--muted); font-size: .94rem; }
.regime-box {
  min-width: 218px; padding: 10px 16px; border: 1px solid var(--line); border-left: 5px solid var(--blue);
  border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); text-align: right;
}
.regime-label { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
.regime-box strong { display: block; margin-top: 1px; color: var(--blue-dark); font-size: 1.18rem; }
.regime-box small { color: var(--muted); font-weight: 700; }
.regime-box.critical { border-left-color: var(--orange); }
.regime-box.critical strong { color: var(--orange-dark); }
.regime-box.over { border-left-color: var(--red); }
.regime-box.over strong { color: var(--red); }
.regime-box.undamped { border-left-color: var(--green); }
.regime-box.undamped strong { color: var(--green); }
.workspace { display: grid; grid-template-columns: minmax(285px, 335px) minmax(0, 1fr); gap: 14px; align-items: start; }
.main-panel { display: grid; gap: 12px; min-width: 0; }
.card { background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.controls { padding: 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-heading > div { display: flex; align-items: center; gap: 8px; }
.section-heading.compact { margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: .98rem; letter-spacing: -.01em; }
.step-dot { width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; background: var(--blue); font-size: .72rem; font-weight: 900; }
.control-group { padding: 9px 0 8px; border-bottom: 1px solid #edf1f5; }
.control-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.control-top label { font-size: .84rem; font-weight: 750; }
.number-wrap { display: flex; align-items: center; height: 31px; border: 1px solid #cfd9e4; border-radius: 8px; background: #fff; overflow: hidden; }
.number-wrap input { width: 71px; border: 0; outline: 0; padding: 5px 5px 5px 8px; text-align: right; color: var(--text); background: transparent; font-size: .82rem; font-weight: 750; }
.number-wrap span { height: 100%; display: grid; place-items: center; min-width: 31px; padding: 0 6px; color: var(--muted); background: #f3f6f9; border-left: 1px solid #dbe3eb; font-size: .75rem; font-weight: 800; }
input[type="range"] { width: 100%; height: 5px; accent-color: var(--blue); cursor: pointer; }
.preset-title { margin: 13px 0 7px; color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.preset { min-height: 37px; padding: 6px 4px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: .72rem; font-weight: 850; transition: .16s ease; }
.preset:hover, .preset:focus-visible { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(20,45,70,.09); outline: none; }
.preset.under { border-color: #9cc8e6; }
.preset.critical { border-color: #f7c76a; }
.preset.over { border-color: #eab2b2; }
.ghost-btn, .primary-btn { border-radius: 9px; padding: 7px 11px; font-size: .76rem; font-weight: 850; }
.ghost-btn { border: 1px solid #cfdbe7; background: #fff; color: #43556a; }
.ghost-btn:hover { background: #f5f8fb; }
.primary-btn { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.primary-btn:hover { background: var(--blue-dark); }
.schematic { margin-top: 12px; padding: 7px 8px 8px; border-radius: 11px; border: 1px solid #e0e8ef; background: var(--surface-soft); }
.schematic svg { width: 100%; display: block; max-height: 95px; color: var(--blue); }
.schematic .wire, .schematic .resistor, .schematic .coil, .schematic .capacitor { fill: none; stroke: #384b5e; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.schematic .resistor { stroke: var(--orange-dark); }
.schematic .coil { stroke: var(--blue); }
.schematic .capacitor { stroke: var(--cyan); }
.schematic .current-arrow { fill: none; stroke: currentColor; stroke-width: 2.4; }
.schematic text { fill: #4a5c6e; font-size: 16px; font-weight: 800; }
.schematic .current-label { fill: var(--blue); font-size: 12px; }
.schematic .initial-label { fill: var(--muted); font-size: 13px; }
.schematic p { margin: 1px 4px 0; color: var(--muted); font-size: .73rem; line-height: 1.35; }
.metrics { padding: 12px 14px 13px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.metric { min-width: 0; padding: 9px 10px; border: 1px solid #e2e9f0; border-radius: 11px; background: var(--surface-soft); }
.metric.emphasis { border-color: #bcd7ea; background: #f2f9fd; }
.metric span { display: block; color: var(--muted); font-size: .69rem; font-weight: 800; white-space: nowrap; }
.metric strong { display: block; margin: 2px 0 1px; font-size: 1.05rem; letter-spacing: -.015em; }
.metric small { display: block; color: #7c8b9a; font-size: .65rem; white-space: nowrap; }
.chart-card { padding: 12px 14px 10px; }
.chart-toolbar, .energy-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.chart-toolbar .section-heading, .energy-header .section-heading { margin-bottom: 6px; }
.time-controls { display: flex; align-items: center; gap: 6px; }
.time-readout { min-width: 105px; color: #3d4f62; background: #f2f6fa; border: 1px solid #dde5ec; border-radius: 8px; padding: 7px 9px; font-size: .73rem; font-variant-numeric: tabular-nums; font-weight: 800; text-align: center; }
.chart-wrap { position: relative; height: clamp(245px, 36vh, 390px); min-height: 230px; border: 1px solid #e1e8ef; border-radius: 12px; overflow: hidden; background: #fff; }
#responseChart { display: block; width: 100%; height: 100%; }
.chart-legend { position: absolute; top: 8px; left: 56px; display: flex; gap: 14px; padding: 5px 8px; background: rgba(255,255,255,.9); border: 1px solid rgba(219,228,238,.9); border-radius: 8px; color: #4c5d6f; font-size: .68rem; font-weight: 800; }
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.chart-legend i { width: 17px; height: 3px; border-radius: 4px; display: inline-block; }
.legend-v { background: var(--orange); }
.legend-i { background: var(--blue); }
.instant-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 7px; }
.instant-values > div { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 5px 7px; border-radius: 8px; background: #f7f9fb; }
.instant-values span { color: var(--muted); font-size: .68rem; font-weight: 800; }
.instant-values strong { font-size: .77rem; font-variant-numeric: tabular-nums; }
.energy-card { padding: 11px 14px 10px; }
.conservation { color: #496073; border: 1px solid #dce5ed; background: #f7fafc; border-radius: 8px; padding: 5px 9px; font-size: .72rem; font-weight: 850; white-space: nowrap; }
.energy-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.energy-values > div { padding: 7px 9px; border-radius: 9px; background: #f7f9fb; border: 1px solid #e5ebf1; }
.energy-values span { display: block; color: var(--muted); font-size: .65rem; font-weight: 800; }
.energy-values strong { display: block; margin-top: 1px; font-size: .88rem; font-variant-numeric: tabular-nums; }
.energy-bar { display: flex; height: 13px; margin-top: 9px; border-radius: 999px; overflow: hidden; background: #edf1f5; box-shadow: inset 0 0 0 1px rgba(0,0,0,.03); }
.energy-segment { min-width: 0; transition: width .08s linear; }
.energy-segment.cap, .energy-legend i.cap { background: var(--orange); }
.energy-segment.ind, .energy-legend i.ind { background: var(--blue); }
.energy-segment.res, .energy-legend i.res { background: #7d8b99; }
.energy-legend { display: flex; justify-content: flex-end; gap: 12px; margin-top: 4px; color: var(--muted); font-size: .62rem; font-weight: 800; }
.energy-legend span { display: flex; align-items: center; gap: 4px; }
.energy-legend i { width: 8px; height: 8px; border-radius: 50%; }
@media (max-width: 1050px) {
  .workspace { grid-template-columns: 300px minmax(0,1fr); }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .chart-wrap { height: 330px; }
}
@media (max-width: 780px) {
  .lab-shell { padding: 12px; }
  .lab-header { align-items: stretch; flex-direction: column; gap: 10px; }
  .regime-box { text-align: left; min-width: 0; }
  .workspace { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .controls .section-heading, .controls .preset-title, .controls .preset-grid, .controls .schematic { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .chart-toolbar, .energy-header { flex-direction: column; }
  .time-controls { width: 100%; flex-wrap: wrap; }
  .chart-wrap { height: 310px; }
  .energy-values { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 520px) {
  .controls { display: block; }
  .preset-grid { grid-template-columns: 1fr; }
  .metric-grid, .energy-values { grid-template-columns: 1fr 1fr; }
  .metric strong { font-size: .92rem; }
  .metric small { white-space: normal; }
  .time-controls .primary-btn, .time-controls .ghost-btn { flex: 1; }
  .time-readout { flex-basis: 100%; }
  .chart-wrap { height: 285px; }
  .chart-legend { left: 43px; }
  .instant-values { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

/* Rifinitura schema RLC */
.schematic { padding: 8px 8px 9px; }
.schematic svg { max-height: 168px; }
.schematic .wire { fill: none; stroke: #43576a; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.schematic .coil { fill: none; stroke: var(--blue); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.schematic .capacitor { fill: none; stroke: #0b90b6; stroke-width: 4; stroke-linecap: round; }
.schematic .current-arrow { fill: none; stroke: var(--blue); stroke-width: 2; }
.schematic .current-label { fill: var(--blue); font-size: 11.5px; font-weight: 800; }
.schematic .component-value { fill: #485d70; font-size: 12.5px; font-weight: 800; }
.schematic .initial-label { fill: var(--muted); font-size: 11.5px; font-weight: 700; }
.schematic .resistor-graphic .resistor-body { fill: url(#resBodyGrad); stroke: #a87d3d; stroke-width: 1.3; }
.schematic .resistor-graphic .resistor-gloss { fill: rgba(255,255,255,.28); }
.schematic .resistor-graphic .resistor-lead-fill { fill: url(#leadGrad); stroke: #b8c2ca; stroke-width: .7; }
.schematic .resistor-graphic .resistor-band { stroke: rgba(0,0,0,.14); stroke-width: .6; }

/* Cursore temporale mobile */
.time-scrubber {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 102px;
  align-items: center;
  gap: 10px;
  margin: 7px 3px 5px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 800;
}
.time-scrubber .scrubber-label { color: #536679; }
.time-input-wrap {
  min-width: 100px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.time-input-wrap input {
  width: 76px;
  min-width: 0;
  padding: 4px 3px 4px 7px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.time-input-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(11,111,184,.12);
}
.time-input-wrap span { padding: 0 7px 0 2px; color: var(--muted); }
.time-scrubber input[type=range] {
  width: 100%;
  height: 5px;
  margin: 0;
  accent-color: var(--blue);
}
.time-scrubber input[type=range]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
}
@media (max-width: 520px) {
  .time-scrubber { grid-template-columns: 1fr 102px; }
  .time-scrubber .scrubber-label { grid-column: 1 / -1; }
}
