: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; width: 100%; margin-top: 8px; }
}

.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: 560px;
}

.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; }

.select-input {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--gray-300);
  background: white;
  font: inherit;
  color: var(--navy);
}

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

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--slate);
  font-style: italic;
}

.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); }
.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: 8px; }

.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; }

/* 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);
}
input[type='range']::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--navy);
  border: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

@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: 4.5; }
.wire-black { stroke: rgba(20, 25, 35, 0.92); stroke-width: 4.5; }

/* --------------------------------
   Power supply
----------------------------------- */
.power-pack {
  position: absolute;
  left: 50%;
  top: 2.5%;
  transform: translateX(-50%);
  width: 44%;
  min-width: 220px;
  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 12px 20px;
  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: 13px; color: rgba(255, 255, 255, 0.95); }
.pp-led {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(26, 188, 156, 0.95);
  box-shadow: 0 0 8px rgba(26, 188, 156, 0.7);
}
.pp-lcd { padding: 6px 10px; }
.pp-terminals {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.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; }

/* --------------------------------
   Current indicator (between supply and resistors)
----------------------------------- */
.current-indicator {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(26, 188, 156, 0.10);
  border: 1px solid rgba(26, 188, 156, 0.3);
  color: var(--navy);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  z-index: 4;
  white-space: nowrap;
}
.current-arrow { color: var(--teal); font-weight: 800; font-size: 14px; }
.current-label { color: var(--slate); }
.current-value { color: var(--teal); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --------------------------------
   Component boxes (R1, R2)
----------------------------------- */
.component-box {
  position: absolute;
  width: 28%;
  min-width: 160px;
  border-radius: 10px;
  background: white;
  border: 1px solid rgba(44, 62, 80, 0.18);
  box-shadow: var(--shadow-sm);
  padding: 22px 10px 22px; /* top/bottom padding leaves room for pinned jacks */
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.component-box--r1 { left: 8%; top: 44%; }
.component-box--r2 { right: 8%; top: 44%; }

.component-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--navy);
  text-transform: none;
  text-align: center;
  line-height: 1.3;
}
.component-visual {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.component-visual svg { width: 100%; height: 100%; }
.r2-svg { position: absolute; inset: 0; }

/* Circuit-symbol primitives used inside component-visual svgs */
.cb-body { fill: white; stroke: var(--navy); stroke-width: 2; }
.cb-lead { stroke: var(--navy); stroke-width: 2.5; stroke-linecap: round; }
.cb-line { stroke: var(--navy); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.cb-arrow { stroke: var(--navy); stroke-width: 1.8; fill: none; color: var(--navy); }

.component-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--navy);
  background: rgba(26, 188, 156, 0.1);
  border-radius: 4px;
  padding: 2px 8px;
  margin-top: 2px;
}

/* Pin circuit jacks to the top edge and voltmeter jacks to the bottom edge. */
.component-jacks {
  position: absolute;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  top: -6px;
}
.component-jacks-bottom { top: auto; bottom: -6px; }

/* --------------------------------
   Meters (voltmeters)
----------------------------------- */
.meter {
  position: absolute;
  border-radius: 10px;
  background: #101a24;
  border: 1px solid rgba(44, 62, 80, 0.2);
  box-shadow: var(--shadow-sm);
  padding: 10px;
  z-index: 4;
  color: white;
  width: 28%;
  min-width: 160px;
}
.meter-volt--1 { left: 8%; top: 78%; }
.meter-volt--2 { right: 8%; top: 78%; }

.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: 12px; color: rgba(255, 255, 255, 0.95); }
.meter-name sub { font-size: 0.8em; }
.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.3);
}
.meter-jacks { display: flex; justify-content: space-between; padding: 6px 8px 0; }
/* Voltmeter top jacks are pinned so wires meet the top edge of the meter */
.meter-jacks-top {
  position: absolute;
  left: 12px;
  right: 12px;
  top: -6px;
  padding: 0;
  display: flex;
  justify-content: space-between;
}
.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.3);
}
.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 (shared with power supply)
----------------------------------- */
.lcd {
  position: relative;
  border-radius: 8px;
  padding: 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: 5ch;
  overflow: hidden;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-weight: 900;
  font-size: 24px;
  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: 13px;
  color: rgba(10, 22, 14, 0.8);
}
.pp-lcd .lcd-digits { font-size: 28px; width: 5ch; }
.pp-lcd .lcd-unit { font-size: 15px; }

/* --------------------------------
   Mobile layout
----------------------------------- */
@media (max-width: 767px) {
  body { padding: 8px; }
  .container { padding: 0 8px; }
  .sim-area { height: 620px; }

  .power-pack { left: 50%; top: 2%; width: 80%; }
  .current-indicator { top: 26%; }
  .component-box { width: 44%; min-width: 0; padding: 8px; }
  .component-box--r1 { left: 3%; top: 42%; }
  .component-box--r2 { right: 3%; top: 42%; }
  .meter { width: 44%; min-width: 0; }
  .meter-volt--1 { left: 3%; top: 76%; }
  .meter-volt--2 { right: 3%; top: 76%; }

  .btn { padding: 14px 20px; font-size: 16px; min-height: 48px; }
  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; }
