:root {
  --navy: #2c3e50;
  --softgray: #e9ecef;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --slate: #556366;
  --coral: #e74c3c;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --max-width: 1120px;
  --container-pad: 16px;
  --radius: 10px;
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.06);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body{
  margin:0;
  font-family:"Montserrat",system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial;
  color:var(--navy);
  background:linear-gradient(135deg,#ecf0f1 0%,#d6dbdf 100%);
  padding:16px;
}

.container{
  max-width:var(--max-width);
  margin:0 auto;
  min-height:100vh;
  display:flex;
  flex-direction:column;
  gap:18px;
  padding:18px;
}

.page-header{ text-align:center; padding:1rem; }
.header-grid{
  display:grid;
  grid-template-columns:1fr auto 1fr;
  align-items:center;
  gap:12px;
  padding:8px 0;
}
.page-title{
  margin:0;
  justify-self:center;
  font-size:2rem;
  font-weight:700;
}
.header-actions{ justify-self:end; }

@media (max-width: 767px){
  .header-grid{ grid-template-columns:1fr; text-align:left; }
  .page-title{ justify-self:start; }
  .header-actions{ justify-self:start; }
}

.cols{ display:flex; flex-direction:column; gap:24px; }

.experiment-area{
  background:var(--gray-100);
  border-radius:10px;
  padding:20px;
  margin-bottom:24px;
}

.sim-area{
  background:var(--softgray);
  border-radius:8px;
  padding:12px;
  position:relative;
  overflow:hidden;
  height:460px;
}

.controls{
  background:white;
  border-radius:8px;
  padding:16px;
  box-shadow:var(--shadow-sm);
}

.control-group{ margin-bottom:18px; }
.label{
  display:block;
  margin-bottom:6px;
  font-size:14px;
  color:var(--slate);
  font-weight:600;
}

.range-row{ display:flex; align-items:center; gap:12px; }
.range{ flex:1; }

.value{
  display:inline-block;
  padding:6px 8px;
  border-radius:6px;
  background:rgba(26,188,156,0.12);
  color:var(--teal);
  min-width:74px;
  text-align:center;
  font-weight:700;
}

.segmented{
  display:flex;
  width:100%;
  gap:0;
  background:var(--gray-200);
  border-radius:8px;
  padding:4px;
  border:1px solid var(--gray-300);
}
.seg-btn{
  flex:1;
  border:0;
  background:transparent;
  padding:8px 6px;
  border-radius:6px;
  font:inherit;
  font-size:13px;
  font-weight:600;
  color:var(--slate);
  cursor:pointer;
  transition:background 0.2s,color 0.2s;
}
.seg-btn.active{
  background:var(--navy);
  color:white;
  box-shadow:0 2px 6px rgba(0,0,0,0.14);
}
.seg-btn:hover:not(.active){ background:rgba(44,62,80,0.06); }

.btn{
  display:inline-block;
  border-radius:0.375rem;
  font-weight:600;
  cursor:pointer;
  border:1px solid transparent;
  font-size:16px;
  padding:12px 24px;
  transition:all 0.2s;
}

.navy-btn{ background-color: rgba(44,62,80,0.8); color:white; }
.navy-btn:hover{ background-color: rgba(44,62,80,0.7); transform: translateY(-2px); }

.teal-btn{ background-color: rgba(26,188,156,0.9); color:white; }
.teal-btn:hover{ background-color: rgba(26,188,156,0.75); transform: translateY(-2px); }

.gold-btn{ background-color: rgba(241,196,15,1); color: var(--navy); opacity:0.9; }
.gold-btn:hover{ background-color: rgba(241,196,15,0.5); transform: translateY(-2px); }

.coral-btn{ background-color: rgba(231,76,60,0.8); color:white; }
.coral-btn:hover{ background-color: rgba(231,76,60,0.7); transform: translateY(-2px); }

.button-stack{ display:flex; flex-direction:column; gap:10px; margin-top:18px; }

.panel{
  margin-top:24px;
  background:white;
  border-radius:8px;
  padding:16px;
  box-shadow:var(--shadow-sm);
}
.panel h3{ margin:0 0 12px 0; font-size:18px; }
.panel .panel-body{ color:var(--navy); }
.panel ol{ margin:8px 0 0 20px; }

.table-wrap{ overflow-x:auto; }
.results-table{
  width:100%;
  border-collapse:collapse;
  background:white;
  border:1px solid var(--softgray);
}
.results-table th, .results-table td{
  border:1px solid var(--softgray);
  padding:8px;
  text-align:left;
}
.results-table thead tr{ background:var(--softgray); }
.results-table th{ font-weight:700; }

.row-delete{ background:none; border:0; cursor:pointer; color:#e53e3e; font-size:16px; }

.table-input{
  width:100%;
  max-width:160px;
  padding:8px;
  border-radius:6px;
  border:1px solid var(--gray-300);
  background:white;
  font:inherit;
  color:var(--navy);
  text-align:center;
}
.table-input:focus{
  outline:3px solid rgba(26, 188, 156, 0.18);
  outline-offset:2px;
}

/* range styling */
input[type="range"]{ -webkit-appearance:none; appearance:none; height:6px; background:transparent; }
input[type="range"]::-webkit-slider-runnable-track{
  height:6px;
  background:linear-gradient(90deg,#d0d0d0,#bdbdbd);
  border-radius:6px;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:18px;height:18px;border-radius:50%;
  background:var(--navy);
  margin-top:-6px;
  box-shadow:0 2px 6px rgba(0,0,0,0.2);
}

/* Responsive */
@media (min-width: 768px){
  .cols{ flex-direction:row; }
  .sim-area{ flex:2; margin-right:24px; }
  .controls{ flex:1; }
}

/* --------------------------------
   Rig
----------------------------------- */
.rig{
  position:relative;
  width:100%;
  height:100%;
  border-radius:10px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255,255,255,0.65), rgba(255,255,255,0) 58%),
    radial-gradient(circle at 90% 15%, rgba(255,255,255,0.40), rgba(255,255,255,0) 55%),
    linear-gradient(180deg, #ffffff 0%, #f2f4f7 100%);
  border:1px solid rgba(44,62,80,0.12);
  box-shadow:var(--shadow-xs);
  overflow:hidden;
}

.wires{ position:absolute; inset:0; width:100%; height:100%; pointer-events:none; z-index:2; }
.wire{ fill:none; stroke-linecap:round; stroke-linejoin:round; opacity:0.95; }
.wire-red{ stroke: rgba(231, 76, 60, 0.95); stroke-width: 5; }
.wire-black{ stroke: rgba(20, 25, 35, 0.92); stroke-width: 5; }

/* --------------------------------
   Power pack
----------------------------------- */
.power-pack{
  position:absolute;
  left:2.5%;
  top:50%;
  transform:translateY(-50%);
  width:25%;
  min-height:230px;
  border-radius:12px;
  background: linear-gradient(180deg, #2f3b49 0%, #1f2834 100%);
  border:1px solid rgba(0,0,0,0.35);
  box-shadow: 0 10px 22px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.08);
  padding:10px;
  z-index:5;
  color:#fff;
  display:flex;
  flex-direction:column;
  gap:6px;
}
.pp-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.pp-name{
  font-weight:800;
  letter-spacing:0.6px;
  font-size:10px;
  color:rgba(255,255,255,0.9);
}
.pp-led{
  width:10px;height:10px;border-radius:50%;
  background: rgba(231,76,60,0.25);
  box-shadow: 0 0 4px rgba(231,76,60,0.4);
  transition: background 160ms ease, box-shadow 160ms ease;
}
.pp-led.on{
  background: rgba(26,188,156,0.95);
  box-shadow: 0 0 12px rgba(26,188,156,0.8);
}

.pp-dial-wrap{
  display:flex;
  justify-content:center;
  align-items:center;
  flex:1;
  padding:4px 0;
}
.pp-dial{
  position:relative;
  width:110px;
  height:110px;
  border-radius:50%;
  background:
    radial-gradient(circle at 30% 30%, #4a5868 0%, #2c3847 60%, #1a222d 100%);
  border:2px solid rgba(255,255,255,0.1);
  box-shadow: inset 0 4px 12px rgba(0,0,0,0.4), 0 4px 8px rgba(0,0,0,0.3);
  cursor: grab;
  touch-action:none;
  user-select:none;
}
.pp-dial:active{ cursor:grabbing; }
.pp-dial:focus{ outline:3px solid rgba(26,188,156,0.4); outline-offset:2px; }

.pp-dial-ticks{
  position:absolute; inset:0;
  border-radius:50%;
  background:
    conic-gradient(
      from 135deg,
      rgba(255,255,255,0.14) 0deg,
      rgba(255,255,255,0.14) 1deg,
      transparent 1deg,
      transparent 18deg,
      rgba(255,255,255,0.14) 18deg,
      rgba(255,255,255,0.14) 19deg,
      transparent 19deg,
      transparent 36deg,
      rgba(255,255,255,0.14) 36deg,
      rgba(255,255,255,0.14) 37deg,
      transparent 37deg,
      transparent 54deg,
      rgba(255,255,255,0.14) 54deg,
      rgba(255,255,255,0.14) 55deg,
      transparent 55deg,
      transparent 72deg,
      rgba(255,255,255,0.14) 72deg,
      rgba(255,255,255,0.14) 73deg,
      transparent 73deg,
      transparent 90deg,
      rgba(255,255,255,0.14) 90deg,
      rgba(255,255,255,0.14) 91deg,
      transparent 91deg,
      transparent 270deg,
      rgba(255,255,255,0.14) 270deg
    );
  -webkit-mask: radial-gradient(circle, transparent 46%, black 47%, black 49%, transparent 50%);
          mask: radial-gradient(circle, transparent 46%, black 47%, black 49%, transparent 50%);
  pointer-events:none;
}

.pp-knob{
  position:absolute;
  left:50%; top:50%;
  width:78%;
  height:78%;
  border-radius:50%;
  transform: translate(-50%, -50%) rotate(0deg);
  background:
    radial-gradient(circle at 35% 30%, #6d7988 0%, #3e4a5a 55%, #22303c 100%);
  border:1px solid rgba(255,255,255,0.08);
  box-shadow: 0 2px 6px rgba(0,0,0,0.55), inset 0 2px 4px rgba(255,255,255,0.12);
  transition: transform 120ms ease-out;
  pointer-events:none;
}
.pp-knob-indicator{
  position:absolute;
  left:50%;
  top:8%;
  width:4px;
  height:30%;
  background: linear-gradient(180deg, #f1c40f 0%, #e67e22 100%);
  border-radius:999px;
  transform:translateX(-50%);
  box-shadow:0 0 6px rgba(241,196,15,0.45);
}

.pp-dial-labels{
  position:absolute; inset:0; pointer-events:none;
}
.pp-lbl{
  position:absolute;
  font-size:10px;
  font-weight:700;
  color: rgba(255,255,255,0.75);
}
.pp-lbl-min{ left:-2px; bottom:18%; }
.pp-lbl-zero{ left:50%; top:-4px; transform:translateX(-50%); }
.pp-lbl-max{ right:-2px; bottom:18%; }

.pp-terminals{
  display:flex;
  justify-content:space-around;
  align-items:center;
  padding:4px 10px 2px;
}
.pp-term{
  width:22px;height:22px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-weight:900;
  font-size:12px;
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}
.pp-term-pos{ background: rgba(231,76,60,0.9); color:white; }
.pp-term-neg{ background: rgba(20,25,35,0.9); color:white; }

/* --------------------------------
   Meters
----------------------------------- */
.meter{
  position:absolute;
  border-radius:10px;
  background:#101a24;
  border:1px solid rgba(44,62,80,0.20);
  box-shadow:var(--shadow-sm);
  padding:10px;
  z-index:4;
  color:white;
}
.meter-amm{
  left:32%;
  top:10%;
  width:20%;
  min-width:140px;
}
.meter-volt{
  left:60%;
  top:64%;
  width:34%;
  min-width:150px;
}
.component-box{
  position:absolute;
  left:60%;
  top:12%;
  width:34%;
  min-height:110px;
  border-radius:10px;
  background: white;
  border:1px solid rgba(44,62,80,0.18);
  box-shadow:var(--shadow-sm);
  padding:10px;
  z-index:4;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
}
.component-label{
  font-size:11px;
  font-weight:700;
  letter-spacing:0.6px;
  color:var(--slate);
  text-transform:uppercase;
}
.component-visual{
  width:100%;
  height:56px;
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
}
.component-visual svg{ width:90%; height:100%; }
.component-jacks{
  width:100%;
  display:flex;
  justify-content:space-between;
  padding:0 8px;
}

.meter-topbar{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px; }
.meter-name{ font-weight:800; letter-spacing:0.6px; font-size:10px; color:rgba(255,255,255,0.90); }
.meter-mode{
  font-weight:900;
  font-size:0.9rem;
  padding:2px 8px;
  border-radius:999px;
  background: rgba(26,188,156,0.18);
  border:1px solid rgba(26,188,156,0.30);
}

.meter-jacks{ display:flex; justify-content:space-between; padding:6px 4px 0; }
.meter-jacks-top{ padding:0 4px 6px; }
.jack{
  width:12px;height:12px;border-radius:50%;
  border:2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.30);
}
.component-box .jack{
  background: rgba(44,62,80,0.1);
  border:2px solid rgba(44,62,80,0.35);
}
.jack-red{ outline:3px solid rgba(231,76,60,0.35); outline-offset:1px; }
.jack-black{ outline:3px solid rgba(20,25,35,0.35); outline-offset:1px; }

/* LCD */
.lcd{
  position:relative;
  border-radius:8px;
  padding:10px 10px;
  background: linear-gradient(180deg, rgba(214,232,210,0.95), rgba(182,210,178,0.92));
  border:1px solid rgba(255,255,255,0.18);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.18), inset 0 -2px 10px rgba(255,255,255,0.18);
  overflow:hidden;
}
.lcd::before{
  content:"";
  position:absolute; inset:0;
  background: repeating-linear-gradient(180deg, rgba(0,0,0,0.05), rgba(0,0,0,0.05) 1px, rgba(255,255,255,0) 1px, rgba(255,255,255,0) 4px);
  opacity:0.28; pointer-events:none;
}
.lcd::after{
  content:"";
  position:absolute; inset:0;
  background: radial-gradient(circle at 20% 20%, rgba(255,255,255,0.35), rgba(255,255,255,0) 55%);
  opacity:0.55; pointer-events:none;
}
.lcd-live{
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
}
.lcd-digits{
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1ch;
  justify-content: end;
  align-items: baseline;
  width: 6ch;
  overflow: hidden;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
  color: rgba(10, 22, 14, 0.95);
  text-shadow: 0 1px 0 rgba(255,255,255,0.22);
}
.lcd-digit{
  display: inline-block;
  width: 1ch;
  text-align: center;
}
.lcd-digit.decimal{ transform: translateY(1px); }
.lcd-unit{
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  font-size: 14px;
  color: rgba(10, 22, 14, 0.80);
}

/* --------------------------------
   Component visuals
----------------------------------- */
.resistor-symbol{
  fill: #ffffff;
  stroke: #222;
  stroke-width:2;
}
.lamp-glass{
  fill: rgba(255,255,255,0.15);
  stroke: rgba(0,0,0,0.45);
  stroke-width:1.4;
}
.lamp-filament{
  fill:none;
  stroke: #222;
  stroke-width:1.5;
  stroke-linecap:round;
  transition: stroke 180ms ease, filter 180ms ease;
}
.lamp-glow{
  fill: rgba(255,204,0,0);
  transition: fill 180ms ease, filter 180ms ease;
}
.diode-body{
  fill: rgba(44,62,80,0.12);
  stroke: rgba(0,0,0,0.5);
  stroke-width:1.2;
}
.diode-triangle{ fill: rgba(44,62,80,0.85); stroke:none; }
.diode-bar{ stroke: rgba(44,62,80,0.85); stroke-width:3; }
.diode-led{
  fill: rgba(231,76,60,0);
  stroke: rgba(231,76,60,0.7);
  stroke-width:1.2;
  transition: fill 180ms ease, filter 180ms ease;
}

/* --------------------------------
   Mobile adjustments
----------------------------------- */
@media (max-width: 767px){
  .header-actions{
    justify-self:start;
    width:100%;
    margin-top:8px;
  }

  body{ padding:8px; }
  .container{ padding:0 8px; }

  .btn{
    padding:14px 20px;
    font-size:16px;
    min-height:48px;
  }

  .sim-area{ height:520px; }

  .power-pack{
    left:2%;
    width:34%;
    min-height:220px;
  }
  .meter-amm{
    left:40%;
    top:6%;
    width:56%;
  }
  .component-box{
    left:40%;
    top:36%;
    width:56%;
  }
  .meter-volt{
    left:40%;
    top:72%;
    width:56%;
  }

  input[type="range"]::-webkit-slider-thumb{
    width:24px; height:24px; margin-top:-9px;
  }
  input[type="range"]::-moz-range-thumb{
    width:24px; height:24px;
  }
  input[type="range"]{ height:10px; }
}

@media (hover: none) and (pointer: coarse){
  .btn{
    min-height:50px;
    font-size:17px;
  }
  .control-group{ margin-bottom:20px; }
  .button-stack{ gap:12px; }
}

/* --------------------------------
   Footer
----------------------------------- */
.site-footer {
  background: #2c3e50;
  color: #fff;
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  margin: 32px -16px -16px;
}

.site-footer p {
  margin: 0;
}
