:root {
  color-scheme: dark;
  --bg: #091014;
  --panel: #101b21;
  --panel-2: #15242c;
  --line: #29414b;
  --line-soft: rgba(255, 255, 255, 0.09);
  --text: #edf6f7;
  --muted: #9fb4ba;
  --accent: #38c7b6;
  --amber: #f3b74f;
  --danger: #ff6b6b;
  --blue: #72a8ff;
  --green: #73d483;
  --radius: 8px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(56, 199, 182, 0.12), transparent 34%),
    linear-gradient(180deg, #071013, #0d171c 58%, #081014);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: var(--text);
  background: var(--accent);
  color: #062423;
  border-radius: 6px;
  padding: 0.72rem 0.95rem;
  font-weight: 750;
  cursor: pointer;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b151a;
  color: var(--text);
  padding: 0.62rem 0.7rem;
  outline: none;
}

button:hover {
  filter: brightness(1.06);
}

.app-shell {
  height: 100vh;
  overflow: hidden;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(4, 10, 12, 0.28), rgba(4, 10, 12, 0.78)),
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 88px),
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 72px);
}

.login-panel {
  width: min(460px, 100%);
  background: rgba(16, 27, 33, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.34);
}

.brand-mark {
  width: 72px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0;
  margin-bottom: 24px;
}

.login-panel h1,
.topbar h1,
.sidebar h2,
.schematic-stage h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-copy,
.topbar p {
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b151a;
  color: var(--text);
  padding: 0.78rem 0.85rem;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 199, 182, 0.15);
}

.login-error {
  min-height: 1.2em;
  color: var(--danger);
  margin: 0;
}

.demo-note {
  color: var(--muted);
  margin: 18px 0 0;
  font-size: 0.88rem;
}

.learning-view {
  height: 100vh;
  display: none;
  grid-template-columns: 318px minmax(0, 1fr);
  overflow: hidden;
}

.learning-view.active {
  display: grid;
}

.login-view.hidden {
  display: none;
}

.sidebar {
  height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(9, 16, 20, 0.96);
  padding: 16px;
  position: sticky;
  top: 0;
  overflow: hidden;
}

.sidebar-head,
.topbar,
.stage-toolbar,
.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  display: block;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 850;
  margin-bottom: 5px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  background: #1a2a32;
  color: var(--muted);
  border: 1px solid var(--line);
}

.search-label {
  margin: 16px 0 12px;
}

.topic-list {
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 146px);
  overflow: auto;
  padding-right: 4px;
}

.topic-button {
  width: 100%;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 9px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.topic-button.active,
.topic-button:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.topic-code {
  width: 38px;
  height: 34px;
  display: grid;
  place-items: center;
  background: #0d171c;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 850;
}

.topic-meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.done-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
}

.done-dot.done {
  background: var(--green);
}

.study-area {
  height: 100vh;
  padding: 14px;
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.topbar {
  align-items: flex-start;
  margin-bottom: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 2.1vw, 2rem);
}

.topbar p {
  margin: 6px 0 0;
  max-width: 76ch;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.progress-card {
  min-width: 136px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.topbar-tools {
  display: flex;
  align-items: stretch;
  gap: 12px;
}

.narration-card {
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.narration-card span,
.progress-card span {
  color: var(--muted);
  font-size: 0.8rem;
}

.narration-card select {
  margin: 6px 0 8px;
}

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

.narration-actions button:last-child {
  background: #1a2a32;
  border: 1px solid var(--line);
  color: var(--text);
}

.progress-card strong {
  display: block;
  font-size: 1.35rem;
  margin: 2px 0 7px;
}

.progress-track {
  height: 8px;
  background: #071013;
  border-radius: 99px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.35s ease;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.25fr) minmax(330px, 0.75fr);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.schematic-stage,
.study-panel,
.subtopic-strip {
  background: rgba(16, 27, 33, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.schematic-stage {
  padding: 12px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #091217;
  border: 1px solid var(--line);
  border-radius: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented button {
  background: transparent;
  color: var(--muted);
  padding: 0.42rem 0.58rem;
  font-size: 0.84rem;
}

.segmented button.active {
  background: var(--accent);
  color: #062423;
}

.schematic-canvas {
  margin-top: 10px;
  min-height: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(56, 199, 182, 0.11), transparent 30%),
    linear-gradient(180deg, rgba(255,255,255,.035), transparent),
    #071013;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}

.recreated-schematic {
  position: relative;
  height: 100%;
  min-height: 0;
}

.schematic-reference {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 12px;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(7, 16, 19, 0.78);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  padding: 6px 9px;
}

.real-schematic {
  position: relative;
  min-height: 440px;
  background:
    radial-gradient(circle at 18% 20%, rgba(56, 199, 182, 0.12), transparent 24%),
    linear-gradient(180deg, rgba(255,255,255,.05), transparent),
    #071013;
  display: grid;
  place-items: center;
}

.real-schematic img {
  width: 100%;
  height: 100%;
  min-height: 440px;
  object-fit: contain;
  display: block;
  padding: 16px;
  opacity: 0.74;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
}

.real-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.real-flow {
  fill: none;
  stroke: var(--accent);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 3 23;
  animation: flow 0.9s linear infinite;
  filter: drop-shadow(0 0 7px rgba(56, 199, 182, 0.85));
}

.real-flow.blue {
  stroke: var(--blue);
  filter: drop-shadow(0 0 7px rgba(114, 168, 255, 0.85));
}

.real-flow.green {
  stroke: var(--green);
  filter: drop-shadow(0 0 7px rgba(115, 212, 131, 0.85));
}

.real-flow.amber {
  stroke: var(--amber);
  filter: drop-shadow(0 0 7px rgba(243, 183, 79, 0.85));
}

.real-flow.red {
  stroke: var(--danger);
  filter: drop-shadow(0 0 7px rgba(255, 107, 107, 0.85));
}

.real-hotspot {
  fill: rgba(56, 199, 182, 0.18);
  stroke: var(--accent);
  stroke-width: 3;
  animation: pulse-hotspot 1.45s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(56, 199, 182, 0.62));
}

.real-hotspot.amber {
  fill: rgba(243, 183, 79, 0.18);
  stroke: var(--amber);
}

.real-callout {
  fill: rgba(7, 16, 19, 0.9);
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 1;
}

.real-callout-text {
  fill: var(--text);
  font-size: 20px;
  font-weight: 850;
}

.real-callout-sub {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@keyframes pulse-hotspot {
  0%, 100% {
    opacity: 0.55;
  }

  50% {
    opacity: 1;
  }
}

.narration-caption {
  display: none;
  margin-top: 8px;
  border: 1px solid rgba(56, 199, 182, 0.35);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: rgba(56, 199, 182, 0.1);
  color: var(--text);
  line-height: 1.5;
  padding: 9px 11px;
  max-height: 72px;
  overflow: auto;
}

.narration-caption.active {
  display: block;
}

.manual-figure {
  margin: 14px 0 0;
  background: #071013;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}

.manual-figure img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  background:
    radial-gradient(circle at 20% 18%, rgba(56, 199, 182, 0.1), transparent 25%),
    #071013;
  padding: 16px;
}

.manual-figure figcaption {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 10px 12px;
  border-top: 1px solid var(--line-soft);
}

.system-svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
}

.component {
  fill: rgba(19, 36, 44, 0.96);
  stroke: #7d9aa3;
  stroke-width: 1.4;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.26));
}

.component.hot {
  stroke: var(--amber);
}

.component.good {
  stroke: var(--green);
}

.label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.small-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.pipe {
  fill: none;
  stroke: #526d76;
  stroke-width: 7;
  stroke-linecap: round;
  opacity: 0.78;
}

.pipe.active {
  stroke: var(--accent);
  stroke-dasharray: 5 16;
  animation: flow 0.85s linear infinite;
  opacity: 1;
  filter: drop-shadow(0 0 8px rgba(56, 199, 182, 0.75));
}

.pipe.amber.active {
  stroke: var(--amber);
  filter: drop-shadow(0 0 8px rgba(243, 183, 79, 0.75));
}

.pipe.blue.active {
  stroke: var(--blue);
  filter: drop-shadow(0 0 8px rgba(114, 168, 255, 0.75));
}

.pipe.green.active {
  stroke: var(--green);
  filter: drop-shadow(0 0 8px rgba(115, 212, 131, 0.75));
}

.pipe.red.active {
  stroke: var(--danger);
  filter: drop-shadow(0 0 8px rgba(255, 107, 107, 0.75));
}

.status-light {
  fill: #3b4b51;
}

.status-light.on {
  fill: var(--green);
  filter: drop-shadow(0 0 8px rgba(115, 212, 131, 0.55));
}

.status-light.warn {
  fill: var(--amber);
  filter: drop-shadow(0 0 8px rgba(243, 183, 79, 0.5));
}

@keyframes flow {
  to {
    stroke-dashoffset: -25;
  }
}

.flow-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-swatch {
  width: 24px;
  height: 5px;
  border-radius: 99px;
  background: var(--accent);
}

.study-panel {
  min-width: 0;
  overflow: hidden;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.tab {
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  color: var(--text);
  background: var(--panel-2);
}

.tab-panel {
  display: none;
  padding: 12px;
  overflow: auto;
  min-height: 0;
}

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

.fact-list,
.flow-list,
.quiz-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fact-card,
.quiz-card,
.flow-step {
  background: #0b151a;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px;
  line-height: 1.42;
  font-size: 0.93rem;
}

.flow-step.sync-active {
  border-color: var(--accent);
  background: rgba(56, 199, 182, 0.12);
  box-shadow: inset 4px 0 0 var(--accent);
}

.fact-card strong,
.flow-step strong {
  display: block;
  margin-bottom: 5px;
}

.source-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.4;
}

.quiz-options {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.quiz-options button {
  text-align: left;
  background: #13242c;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 650;
}

.quiz-options button.correct {
  border-color: var(--green);
  background: rgba(115, 212, 131, 0.16);
}

.quiz-options button.incorrect {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.16);
}

.subtopic-strip {
  margin-top: 0;
  padding: 10px;
  overflow: hidden;
}

.subtopic-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 1fr);
  gap: 8px;
  margin-top: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.subtopic-card {
  background: #0b151a;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 9px;
}

.subtopic-card span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  margin-top: 4px;
}

@media (max-width: 1050px) {
  body,
  .app-shell,
  .learning-view {
    overflow: auto;
  }

  .learning-view.active {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    height: auto;
    min-height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topic-list {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    max-height: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .study-area {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    grid-template-rows: auto auto auto;
  }

  .schematic-canvas,
  .recreated-schematic,
  .system-svg {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .study-area,
  .sidebar,
  .login-panel {
    padding: 16px;
  }

  .topbar,
  .stage-toolbar {
    display: grid;
  }

  .progress-card {
    width: 100%;
  }

  .topbar-tools {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .narration-card {
    width: 100%;
  }

  .schematic-canvas,
  .system-svg {
    min-height: 360px;
  }
}
