:root {
  --bg-0: #081523;
  --bg-1: #0f2436;
  --bg-2: #163149;
  --panel: rgba(11, 28, 45, 0.88);
  --panel-strong: rgba(8, 21, 34, 0.96);
  --line: rgba(144, 188, 215, 0.25);
  --accent: #2ea6de;
  --accent-2: #1bd0b5;
  --warn: #f3a64d;
  --text: #e8f3ff;
  --muted: #8eb0cb;
  --glow: 0 0 0 1px rgba(56, 161, 214, 0.25), 0 10px 35px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: radial-gradient(1400px 900px at 10% -10%, #244867 0%, transparent 55%),
    radial-gradient(1200px 800px at 95% 0%, #2f3b5f 0%, transparent 50%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 48%, var(--bg-2));
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.23;
  background-image: linear-gradient(rgba(160, 192, 216, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(160, 192, 216, 0.09) 1px, transparent 1px);
  background-size: 28px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  background: rgba(5, 16, 28, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font: 700 1.1rem "Source Serif 4", serif;
  background: linear-gradient(140deg, #1f8dc8, #1dd2b4);
  color: #03111d;
}

h1 {
  margin: 0;
  font: 700 1.2rem "Source Serif 4", serif;
  letter-spacing: 0.4px;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.top-metrics {
  display: flex;
  gap: 12px;
}

.top-metrics div {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 118px;
}

.top-metrics span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-metrics strong {
  font-size: 1.06rem;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  gap: 14px;
  padding: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--glow);
  padding: 14px;
}

h2 {
  margin: 0 0 10px;
  font: 700 1.03rem "Source Serif 4", serif;
  letter-spacing: 0.2px;
}

h3 {
  margin: 0 0 6px;
  color: #b7d5eb;
  font-size: 0.86rem;
  font-weight: 600;
}

.left-panel,
.right-panel {
  height: calc(100vh - 94px);
  overflow: auto;
}

.chapter-matrix {
  display: grid;
  gap: 8px;
}

.circuit-module {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(151, 194, 222, 0.3);
}

.knowledge-tree-module {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(151, 194, 222, 0.3);
}

#leftKnowledgeTree {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(20, 20, 20, 0.45);
  background: #f7f7f4;
}

.circuit-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid rgba(149, 192, 219, 0.35);
  background: rgba(255, 255, 255, 0.94);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.circuit-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#circuitCaption {
  display: none;
}

.chapter-item {
  border: 1px solid rgba(151, 194, 222, 0.28);
  background: rgba(7, 21, 35, 0.9);
  border-radius: 10px;
  padding: 9px;
  transition: 0.2s ease;
}

.chapter-item:hover {
  transform: translateY(-1px);
  border-color: rgba(46, 166, 222, 0.6);
}

.chapter-item b {
  display: block;
  font-size: 0.9rem;
}

.chapter-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.center-panel {
  display: grid;
  gap: 12px;
}

.panel-row {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.instrument-card {
  min-height: 500px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border-radius: 999px;
  border: 1px solid rgba(159, 203, 229, 0.36);
  padding: 3px 9px;
  font-size: 0.74rem;
  color: #b8d8ef;
}

.pill.ok {
  color: #8ff0e0;
  border-color: rgba(27, 208, 181, 0.52);
}

.instrument-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 280px;
  gap: 12px;
  align-items: stretch;
}

.instrument-left {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  gap: 8px;
}

.knobs-wrap {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 5px;
  align-content: start;
  align-items: start;
  grid-auto-rows: min-content;
}

.knob-block {
  padding: 4px;
  border: 1px solid rgba(154, 196, 223, 0.25);
  border-radius: 8px;
  background: rgba(7, 19, 33, 0.94);
  align-self: start;
  height: auto;
  min-height: 0;
}

.knob {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  margin: 0 auto 4px;
  position: relative;
  background: radial-gradient(circle at 35% 28%, #567a98 0%, #1a3349 32%, #0a1a2b 100%);
  border: 1px solid rgba(159, 203, 230, 0.34);
  cursor: grab;
  touch-action: none;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.65);
}

.knob::before {
  content: "";
  position: absolute;
  width: 4px;
  height: 17px;
  border-radius: 999px;
  background: linear-gradient(#d8ebff, #7dc8f1);
  left: 50%;
  top: 7px;
  transform: translateX(-50%) rotate(var(--angle, 0deg));
  transform-origin: 50% 22px;
}

.knob::after {
  content: attr(data-label);
  position: absolute;
  width: 84px;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: #99bbd2;
}

.readout {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(4, 13, 22, 0.8);
  border-radius: 6px;
  padding: 2px 5px;
  border: 1px solid rgba(142, 180, 202, 0.22);
}

.readout span {
  font-size: 0.66rem;
  color: var(--muted);
}

.readout strong {
  font: 600 0.72rem "Source Serif 4", serif;
}

.control-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-content: start;
}

#toggleSim {
  margin-top: auto;
}

.mini-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mini-actions .btn {
  margin-top: 0;
  padding: 6px;
  font-size: 0.76rem;
}

label {
  color: #9bc2dd;
  font-size: 0.74rem;
}

input[type="range"] {
  width: 100%;
  accent-color: #3bb8df;
}

select,
textarea,
.btn {
  font: 500 0.85rem "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

select,
textarea {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(148, 188, 215, 0.34);
  background: rgba(4, 15, 25, 0.9);
  color: #d9ecfb;
  padding: 7px 9px;
}

.btn {
  margin-top: 6px;
  border: 1px solid rgba(46, 166, 222, 0.52);
  color: #dbf2ff;
  background: linear-gradient(130deg, rgba(37, 112, 174, 0.7), rgba(22, 82, 139, 0.8));
  border-radius: 9px;
  padding: 8px;
  cursor: pointer;
}

.btn.secondary {
  background: rgba(7, 30, 50, 0.95);
  border-color: rgba(142, 181, 205, 0.36);
}

.btn:hover {
  filter: brightness(1.12);
}

.display-card canvas {
  width: 100%;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(7, 20, 33, 0.93), rgba(4, 13, 24, 0.96));
  border: 1px solid rgba(138, 181, 208, 0.27);
}

.canvas-stack {
  display: grid;
  gap: 9px;
}

.scope-layout {
  gap: 10px;
}

.scope-row {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 260px;
  gap: 10px;
  align-items: start;
}

.wave-under-knobs {
  margin-top: 2px;
}

.instrument-scopes {
  margin-top: auto;
}

.spectrum-panel,
.iq-panel {
  align-self: end;
}

.wave-under-knobs canvas {
  width: 100%;
}

.iq-panel canvas {
  aspect-ratio: 1 / 1;
  height: auto;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 8px;
  max-height: 310px;
  overflow: auto;
  padding-right: 4px;
}

.case-item {
  border: 1px solid rgba(149, 192, 219, 0.34);
  background: rgba(8, 24, 39, 0.96);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  transition: 0.2s ease;
}

.case-item:hover {
  border-color: rgba(27, 208, 181, 0.66);
  transform: translateY(-1px);
}

.case-item b {
  display: block;
  font-size: 0.84rem;
  line-height: 1.35;
}

.case-item small {
  display: block;
  margin-top: 5px;
  color: #9ec2db;
  font-size: 0.73rem;
  line-height: 1.35;
}

.tip {
  color: #9bc0d7;
  font-size: 0.76rem;
}

.tutor-box {
  border: 1px solid rgba(145, 188, 213, 0.33);
  border-radius: 10px;
  background: rgba(5, 17, 29, 0.94);
  padding: 9px;
  min-height: 108px;
  line-height: 1.58;
  font-size: 0.82rem;
}

.progress-wrap {
  margin-top: 8px;
}

.progress {
  margin-top: 6px;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(13, 37, 57, 0.85);
  border: 1px solid rgba(121, 165, 194, 0.3);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 70%;
  background: linear-gradient(90deg, #1db7c9, #f3a64d);
}

.progress-wrap p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.action-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #b5d4e8;
  font-size: 0.78rem;
  line-height: 1.45;
}

#codeEditor {
  height: 360px;
  resize: vertical;
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
}

.code-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.code-status {
  margin: 8px 0 0;
  font-size: 0.74rem;
  color: #a0cbdf;
  background: rgba(4, 15, 25, 0.92);
  border-radius: 8px;
  border: 1px solid rgba(142, 181, 205, 0.32);
  padding: 7px;
  white-space: pre-wrap;
}

@media (max-width: 1500px) {
  .layout {
    grid-template-columns: 290px 1fr;
  }

  .right-panel {
    grid-column: span 2;
    height: auto;
  }
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .left-panel,
  .right-panel {
    height: auto;
  }

  .instrument-grid {
    grid-template-columns: 1fr;
  }

  .knobs-wrap {
    grid-template-columns: repeat(4, minmax(70px, 1fr));
  }

  .scope-row {
    grid-template-columns: 1fr;
  }

  .case-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: flex-start;
  }

  .top-metrics {
    width: 100%;
    overflow-x: auto;
  }

  .knobs-wrap {
    grid-template-columns: repeat(3, minmax(76px, 1fr));
  }

  .case-grid {
    grid-template-columns: 1fr;
  }
}
