:root {
  --bg: #f8f6ef;
  --surface: #fffefa;
  --ink: #1c2e30;
  --muted: #637175;
  --green: #1e6e52;
  --green-deep: #0f4e3f;
  --green-soft: #e7f3ed;
  --blue: #1f86b5;
  --blue-soft: #e5f3f8;
  --amber: #eda42a;
  --amber-soft: #fff2d8;
  --red: #b54944;
  --red-soft: #fae8e5;
  --line: #c2d0ca;
  --shadow: 0 18px 50px rgba(36, 54, 50, 0.12);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background:
    linear-gradient(120deg, rgba(30, 110, 82, 0.07), transparent 32%),
    radial-gradient(circle at 86% 14%, rgba(237, 164, 42, 0.12), transparent 24%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar,
.panel,
.data-section {
  background: rgba(255, 254, 250, 0.9);
  border: 1px solid rgba(194, 208, 202, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 108px;
  padding: 22px 28px;
  border-radius: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(23px, 3vw, 34px);
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  font-size: 20px;
}

.class-chip {
  min-width: 136px;
  padding: 14px 18px;
  color: #fff;
  text-align: right;
  background: var(--green-deep);
  border-radius: 16px;
}

.class-chip span,
.class-chip strong {
  display: block;
}

.class-chip span {
  margin-bottom: 4px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}

.class-chip strong {
  font-size: 24px;
}

.module-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 12px 16px;
  color: var(--muted);
  font-weight: 800;
  background: rgba(255, 254, 250, 0.72);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.tab.is-active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.tab-icon {
  display: inline-grid;
  width: 28px;
  height: 28px;
  margin-right: 9px;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 12px;
}

.panel {
  display: none;
  padding: 24px;
  border-radius: 24px;
}

.panel.is-active {
  display: block;
}

.panel-head,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.ghost-button {
  color: var(--green);
  background: #fff;
  border: 1px solid var(--line);
}

.primary-button {
  color: #fff;
  background: var(--green);
  border: 1px solid var(--green);
}

.ghost-button.small {
  min-height: 34px;
  padding: 0 12px;
}

.ghost-button.full {
  width: 100%;
  margin-top: 16px;
}

.sim-grid,
.relay-grid {
  display: grid;
  gap: 18px;
}

.sim-grid {
  grid-template-columns: 340px minmax(0, 1fr);
}

.control-board,
.visual-stage,
.relay-stage,
.step-board {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.control-board {
  padding: 18px;
}

.control-block {
  margin-bottom: 18px;
}

.control-block label,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

output {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--green-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 700;
}

input[type="range"] {
  accent-color: var(--green);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  background: #f1f4ee;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.segment {
  min-height: 36px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-weight: 800;
}

.segment.is-active {
  color: #fff;
  background: var(--green);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 18px 0;
}

.metric-strip div {
  padding: 12px;
  background: var(--green-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.metric-strip span,
.metric-strip strong {
  display: block;
}

.metric-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-strip strong {
  margin-top: 4px;
  color: var(--green);
  font-size: 28px;
  line-height: 1;
}

.feedback-card {
  min-height: 74px;
  padding: 13px 14px;
  color: var(--ink);
  background: var(--amber-soft);
  border: 1px solid rgba(237, 164, 42, 0.45);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
}

.control-board .primary-button {
  width: 100%;
  margin-top: 14px;
}

.visual-stage {
  min-height: 430px;
  padding: 12px;
  overflow: hidden;
}

svg {
  display: block;
  width: 100%;
  height: 100%;
}

.bench {
  fill: #d9d6c9;
}

#coreBar,
.core-cap,
.relay-core {
  fill: url(#coreGradient);
  stroke: #5d696a;
  stroke-width: 2;
}

.coil-turn,
.relay-turn {
  fill: none;
  stroke: url(#coilGradient);
  stroke-linecap: round;
}

.coil-turn {
  stroke-width: 6;
}

.relay-turn {
  stroke-width: 4;
}

.field-line {
  fill: none;
  stroke: rgba(31, 134, 181, 0.58);
  stroke-linecap: round;
}

.field-line.active {
  filter: url(#glow);
}

.pole-text {
  fill: var(--red);
  font-size: 28px;
  font-weight: 900;
}

.circuit-lines path,
.circuit-lines line {
  fill: none;
  stroke: #2a3334;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.pin {
  fill: #7e8989;
  stroke: #4f5b5c;
  stroke-width: 1.5;
  transition: transform 260ms ease, opacity 260ms ease;
}

.pin.is-attracted {
  fill: var(--green);
}

.meter rect {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 2;
}

.meter text {
  fill: var(--green);
  font-size: 19px;
  font-weight: 900;
  text-anchor: middle;
}

.data-section {
  margin-top: 18px;
  padding: 18px;
  border-radius: 20px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 14px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #e2e8e3;
  text-align: left;
  font-size: 13px;
}

th {
  color: #fff;
  background: var(--green);
  font-weight: 900;
}

td {
  background: rgba(255, 255, 255, 0.74);
}

td:first-child,
th:first-child {
  text-align: center;
}

.relay-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.relay-stage {
  min-height: 530px;
  padding: 12px;
  background:
    linear-gradient(90deg, rgba(232, 246, 250, 0.5), rgba(255, 244, 220, 0.55)),
    var(--surface);
  overflow: hidden;
}

.step-board,
.relay-lab-board {
  padding: 18px;
}

.relay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.control-zone {
  fill: rgba(229, 243, 248, 0.65);
  stroke: #9bc7d5;
  stroke-width: 2;
}

.work-zone {
  fill: rgba(255, 242, 216, 0.72);
  stroke: #e2c177;
  stroke-width: 2;
}

.zone-title {
  font-size: 24px;
  font-weight: 900;
}

.relay-drag-title {
  fill: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-anchor: middle;
}

.control-title {
  fill: var(--blue);
}

.work-title {
  fill: var(--amber);
}

.relay-shell rect {
  fill: rgba(255, 254, 250, 0.84);
  stroke: rgba(82, 100, 103, 0.52);
  stroke-width: 2.5;
}

.insulation-divider {
  stroke: rgba(99, 113, 117, 0.5);
  stroke-dasharray: 8 8;
  stroke-linecap: round;
  stroke-width: 4;
}

.relay-label,
.relay-main-note,
.isolation-note,
.mechanical-linkage text,
.contact-caption {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-anchor: middle;
}

.isolation-note {
  font-size: 13px;
}

.relay-main-note {
  fill: var(--green);
  font-size: 15px;
}

.battery-low line,
.switch-control line,
.control-wire,
.battery-high line,
.work-wire,
.contact-blade,
.contact-bridge,
.armature-post,
.switch-drag-rail {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.battery-low line,
.switch-control line,
.control-wire {
  stroke: #879a9a;
}

.battery-high line,
.work-wire,
.contact-bridge {
  stroke: #9c8a6b;
}

.control-wire.is-live,
.switch-control.is-live line,
.relay-coil.is-live .relay-turn {
  stroke: var(--blue);
  filter: url(#relayGlow);
  stroke-dasharray: 16 10;
  animation: relay-current-flow 0.85s linear infinite;
}

.work-wire.is-live,
.contact-group.is-live .work-wire,
.contact-group.is-live .contact-bridge,
.battery-high.is-live line,
.motor.is-live circle,
.motor.is-live path {
  stroke: var(--amber);
  filter: url(#relayGlow);
  stroke-dasharray: 16 10;
  animation: relay-current-flow 0.85s linear infinite;
}

.work-loop-trace {
  fill: none;
  stroke: rgba(237, 164, 42, 0.86);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 9;
  stroke-dasharray: 20 12;
  opacity: 0;
  pointer-events: none;
  filter: url(#relayGlow);
  transition: opacity 220ms ease;
}

#relaySvg.relay-is-working .work-loop-trace {
  opacity: 0.72;
  animation: relay-current-flow 0.8s linear infinite;
}

.work-join-note {
  fill: var(--amber);
  font-size: 15px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-anchor: middle;
  transition: opacity 220ms ease;
}

#relaySvg.relay-is-working .work-join-note {
  opacity: 1;
}

.switch-control circle,
.contact-group circle {
  fill: #fffefa;
  stroke: #4f5b5c;
  stroke-width: 3;
}

.static-contact {
  fill: #fffefa;
  stroke: #6f624c;
  stroke-width: 4;
}

.switch-control {
  cursor: pointer;
  outline: none;
  touch-action: none;
}

.switch-control:hover line,
.switch-control:focus-visible line {
  stroke-width: 7;
}

.switch-control.is-on text {
  fill: var(--blue);
}

.switch-hotspot {
  fill: transparent;
  fill-opacity: 0;
  stroke: none;
  pointer-events: all;
}

.switch-drag-rail {
  stroke: rgba(31, 134, 181, 0.28);
  stroke-width: 12;
}

.drag-note {
  fill: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-anchor: middle;
}

.draggable-part,
.armature {
  cursor: grab;
  touch-action: none;
}

#relaySvg.is-dragging,
#relaySvg.is-dragging .draggable-part,
#relaySvg.is-dragging .armature {
  cursor: grabbing;
}

.drag-knob {
  fill: #fffefa;
  stroke: var(--green);
  stroke-width: 5;
  filter: drop-shadow(0 5px 9px rgba(31, 134, 181, 0.28));
  pointer-events: all;
}

.switch-control.is-on .drag-knob,
.relay-coil.is-live ~ .armature .armature-knob {
  stroke: var(--blue);
}

.relay-core {
  fill: #a6b3b1;
  stroke: #5e6c6d;
  stroke-width: 2;
}

.relay-pole-face {
  fill: #687778;
  stroke: #fffefa;
  stroke-width: 2;
}

.relay-field-lines {
  opacity: 0;
  transition: opacity 220ms ease;
}

.relay-field-lines path {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-width: 3;
  stroke-dasharray: 9 7;
  animation: relay-current-flow 0.9s linear infinite;
}

#relaySvg.relay-is-magnetized .relay-field-lines {
  opacity: calc(0.25 + var(--relay-strength, 0) * 0.75);
}

.relay-coil text,
.switch-control text,
.battery-low text,
.battery-high text,
.armature text,
.contact-group text,
.motor text {
  fill: var(--muted);
  font-size: 18px;
  font-weight: 800;
  text-anchor: middle;
}

.armature-pivot {
  fill: #fffefa;
  stroke: #596768;
  stroke-width: 3;
}

#armatureBar,
#armatureHandle,
#insulatingPusher {
  fill: #738181;
  transition: transform 300ms ease;
}

#armatureHandle {
  fill: #fffefa;
  stroke: #596768;
  stroke-width: 4;
}

#relaySvg.relay-is-magnetized #armatureHandle {
  stroke: var(--blue);
}

.attract-arrow {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-width: 3;
  opacity: 0.65;
}

.relay-arrow-head {
  fill: var(--blue);
}

#springShape {
  fill: none;
  stroke: #768485;
  stroke-width: 4;
  transition: transform 300ms ease;
}

.moving-contact {
  transition: transform 300ms ease;
}

.mechanical-link {
  fill: none;
  stroke: #596768;
  stroke-dasharray: 7 6;
  stroke-linecap: round;
  stroke-width: 5;
  transition: d 300ms ease;
}

#relaySvg.relay-is-working .mechanical-link {
  stroke: var(--green);
  stroke-dasharray: none;
}

.insulating-pusher {
  fill: #fffefa;
  stroke: #596768;
  stroke-width: 2;
}

#switchBlade {
  transition:
    x2 220ms ease,
    y2 220ms ease,
    transform 300ms ease;
  transform-box: fill-box;
  transform-origin: left center;
}

#switchBridge,
#contactBridge,
#contactBridgeBar {
  opacity: 0.7;
  transition: opacity 220ms ease;
}

#switchBridge.is-visible,
#contactBridge.is-visible,
#contactBridgeBar.is-visible {
  opacity: 1;
}

#contactBridge {
  stroke-width: 7;
}

.contact-bridge-bar {
  fill: var(--amber);
  filter: url(#relayGlow);
}

.moving-contact:not(.is-closed) .contact-bridge-bar {
  fill: rgba(237, 164, 42, 0.62);
  filter: none;
}

.moving-contact-label {
  fill: var(--amber);
  font-size: 13px;
  font-weight: 900;
  text-anchor: middle;
}

.contact-gap-mark {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-width: 3;
  opacity: 0.75;
  transition: opacity 220ms ease;
}

.contact-gap-mark.is-closed {
  opacity: 0;
}

.contact-gap-label {
  fill: var(--red);
  font-size: 12px;
  font-weight: 900;
  opacity: 0.72;
  text-anchor: middle;
  transition: opacity 220ms ease;
}

#relaySvg.relay-is-working .contact-gap-label {
  opacity: 0;
}

#motorGroup circle {
  fill: #fffefa;
  stroke: #8c9797;
  stroke-width: 4;
}

#motorGroup text {
  fill: var(--green);
  font-size: 28px;
  font-weight: 900;
}

#motorFan {
  fill: rgba(237, 164, 42, 0.28);
  stroke: #8c9797;
  stroke-width: 2;
  transform-origin: 720px 300px;
  transition: transform 120ms linear;
}

.relay-lab-board {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.96), rgba(241, 248, 243, 0.9)),
    var(--surface);
}

.relay-readout {
  padding: 15px;
  background: var(--green-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.relay-readout span,
.relay-readout strong {
  display: block;
}

.relay-readout span {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.relay-readout strong {
  margin-top: 6px;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.15;
}

#relayHint {
  min-height: 88px;
  margin: 14px 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.relay-switch-panel {
  margin-bottom: 18px;
  padding: 14px;
  background: #fffefa;
  border: 1px solid rgba(68, 118, 108, 0.24);
  border-radius: 14px;
}

.relay-switch-panel output {
  min-width: 44px;
  text-align: right;
}

.relay-switch-panel input[type="range"] {
  height: 30px;
  margin-top: 6px;
  accent-color: var(--blue);
}

.relay-switch-caption {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.relay-status-grid {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.status-pill {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
}

.status-pill span {
  width: 10px;
  height: 10px;
  margin-right: 9px;
  border-radius: 999px;
  background: #aab7b1;
  box-shadow: 0 0 0 4px rgba(170, 183, 177, 0.16);
}

.status-pill.is-active {
  color: var(--ink);
  border-color: rgba(68, 118, 108, 0.42);
  background: var(--green-soft);
}

.status-pill.is-active span {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(68, 118, 108, 0.16);
}

@keyframes relay-current-flow {
  to {
    stroke-dashoffset: -26;
  }
}

.step-counter {
  padding: 15px;
  background: var(--green-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.step-counter span,
.step-counter strong {
  display: block;
}

.step-counter span {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.step-counter strong {
  margin-top: 6px;
  font-size: 22px;
}

#stepText {
  min-height: 78px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.step-list {
  display: grid;
  gap: 8px;
}

.step-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.step-item span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #fff;
  border-radius: 999px;
  background: #aab7b1;
  font-size: 12px;
  font-weight: 900;
}

.step-item.is-current {
  color: var(--ink);
  border-color: var(--green);
  background: var(--green-soft);
}

.step-item.is-current span {
  background: var(--green);
}

@media (max-width: 980px) {
  .sim-grid,
  .relay-grid {
    grid-template-columns: 1fr;
  }

  .control-board {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .control-block,
  .metric-strip,
  .feedback-card,
  .control-board .primary-button {
    margin: 0;
  }

  .metric-strip,
  .feedback-card,
  .control-board .primary-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1220px);
    padding-top: 10px;
  }

  .topbar,
  .panel-head,
  .section-title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .module-tabs {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
  }

  .control-board {
    grid-template-columns: 1fr;
  }

  .segment {
    font-size: 14px;
  }

  .metric-strip strong {
    font-size: 24px;
  }

  .visual-stage {
    min-height: 300px;
  }

  .relay-stage {
    min-height: 360px;
  }

  .relay-actions {
    width: 100%;
  }

  .relay-actions button {
    flex: 1;
  }
}
