body {
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
  background:
    radial-gradient(900px 420px at 50% -60px, rgba(var(--spark-rgb), 0.12) 0%, transparent 60%),
    linear-gradient(180deg, var(--board) 0%, var(--neutral-bg) 100%);
  user-select: none;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--board);
  border-bottom: 1px solid var(--board-line);
}

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

.hub-back {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.hub-back svg { width: 17px; height: 17px; }
.hub-back:hover { background: var(--board-soft); color: var(--ink); }
.hub-back:focus-visible { outline: 3px solid var(--spark); outline-offset: 2px; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--spark);
  border: none;
  border-radius: 10px;
}

.brand-mark svg { width: 26px; height: 26px; }

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--ink);
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }

.top-divider {
  width: 1px;
  align-self: stretch;
  margin: 4px 6px;
  background: var(--board-line);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  border: none;
  background: transparent;
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14.5px;
}

.btn-icon { width: 16px; height: 16px; flex: none; }
.btn-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:hover { background: var(--board-soft); }

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}

.btn.primary {
  background: var(--spark);
  color: var(--ink);
}

.btn.primary:hover { background: var(--spark-hover); }

.btn.quiet { color: var(--muted); }

.btn.quiet:hover { background: var(--board-soft); }

.btn.quiet.danger:hover { background: rgba(var(--warn-rgb), 0.1); color: var(--warn); }

.btn:focus-visible {
  outline: 3px solid var(--spark);
  outline-offset: 2px;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
}

aside {
  width: 292px;
  flex: none;
  padding: 18px 16px 20px;
  overflow: auto;
  background: var(--board);
  border-right: 1px solid var(--board-line);
}

aside h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--spark);
  padding-left: 12px;
  border-left: 3px solid var(--spark);
}

.palette { display: flex; flex-direction: column; gap: 8px; }

.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: var(--paper);
  cursor: grab;
}

.tool:hover { border-color: var(--accent); }

.tool.armed {
  border-color: var(--spark);
  box-shadow: inset 0 0 0 1px var(--spark), 0 0 0 4px rgba(var(--spark-rgb), 0.22);
}

.tool svg { width: 118px; height: 64px; flex: none; }

.tool span {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.steps {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  counter-reset: step;
}

.steps li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.35;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--paper);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.legend {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--board-line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.legend div {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.legend svg {
  width: 54px;
  height: 28px;
  background: var(--paper);
  border-radius: 6px;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 14px;
  gap: 10px;
}

.context-menu {
  position: absolute;
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--board-line);
  box-shadow: var(--shadow-pop);
  transform: translateX(-50%);
  z-index: 5;
}

.context-menu[hidden] { display: none; }

.context-menu button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.context-menu button svg {
  width: 19px;
  height: 19px;
  display: block;
}

.context-menu button:hover { background: var(--board-soft); }

.context-menu button.danger { color: var(--warn); }
.context-menu button.danger:hover { background: rgba(var(--warn-rgb), 0.12); }

.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background:
    radial-gradient(1000px 460px at 50% -8%, rgba(var(--spark-rgb), 0.08) 0%, transparent 60%),
    var(--board-soft);
}

#sheet {
  position: relative;
}

#circuit {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
}

#sheet.hot #circuit {
  box-shadow: inset 0 0 0 3px var(--spark), var(--shadow-card);
}

.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.corner.tl { top: 8px; left: 8px; border-top: 2.5px solid var(--accent); border-left: 2.5px solid var(--accent); border-radius: 4px 0 0 0; }
.corner.tr { top: 8px; right: 8px; border-top: 2.5px solid var(--accent); border-right: 2.5px solid var(--accent); border-radius: 0 4px 0 0; }
.corner.bl { bottom: 8px; left: 8px; border-bottom: 2.5px solid var(--accent); border-left: 2.5px solid var(--accent); border-radius: 0 0 0 4px; }
.corner.br { bottom: 8px; right: 8px; border-bottom: 2.5px solid var(--accent); border-right: 2.5px solid var(--accent); border-radius: 0 0 4px 0; }

.empty-hint {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
}

.empty-hint.hidden { display: none; }

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 5px solid var(--muted);
  box-shadow: var(--shadow-status);
}

.status p {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--ink);
}

.mascot { width: 38px; height: 44px; flex: none; overflow: visible; }
.mascot-bulb { fill: var(--glass); stroke: var(--ink); stroke-width: 1.6; }
.mascot-base { fill: var(--glass-base); stroke: var(--ink); stroke-width: 1.4; }
.mascot-thread { stroke: var(--ink); stroke-width: 1; opacity: 0.45; }
.mascot-face { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; }
.mascot-face.fill { fill: var(--ink); stroke: none; }
.mascot-glow { fill: var(--spark); opacity: 0.3; }
.mascot.ok .mascot-bulb { fill: var(--spark); }

.status.ok { border-left-color: var(--spark); }
.status.ok p { color: var(--ok); }

.status.info { border-left-color: var(--spark); }
.status.info p { color: var(--ink); }

.status.warn { border-left-color: var(--warn); }
.status.warn p { color: var(--warn); }

#ghost {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  opacity: 0.9;
  filter: drop-shadow(0 8px 16px rgba(10, 22, 16, 0.3));
}

#ghost[hidden] { display: none; }

#ghost svg { display: block; }

.wire { stroke: var(--ink); fill: none; stroke-width: 2.5; stroke-linecap: butt; stroke-linejoin: miter; }
.wire.selected { stroke: var(--accent); stroke-width: 4.5; }
.wire.preview { stroke: var(--ink); }
.wire.preview.loose { stroke: var(--preview-loose); stroke-dasharray: 7 6; }

.flow {
  fill: none;
  stroke: var(--spark);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 3 9;
  opacity: 0.85;
  animation: flow-move 0.6s linear infinite;
}

@keyframes flow-move {
  to { stroke-dashoffset: -24; }
}

.symbol line,
.symbol path {
  stroke: var(--ink);
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: butt;
}

.plate-long { stroke-width: 2.2; stroke-linecap: round; }
.plate-short { stroke-width: 6.5; stroke-linecap: round; }
.sign { stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.junction, .contact { fill: var(--ink); stroke: none; }

.bulb { stroke: var(--ink); stroke-width: 2.5; }
.bulb.off { fill: var(--paper); }

.bulb-glow { stroke: none; fill: var(--spark); }

.label {
  font-family: "Inter", Arial, Helvetica, sans-serif;
  font-size: 15px;
  font-weight: 600;
  fill: var(--ink);
}

.sel {
  fill: rgba(var(--accent-rgb), 0.1);
  stroke: var(--accent);
  stroke-width: 2;
  rx: 10;
}

.snap-ring { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.arm-ring { fill: rgba(var(--spark-rgb), 0.22); stroke: var(--spark); stroke-width: 2.5; }

.drop-rect {
  fill: rgba(var(--accent-rgb), 0.12);
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
}

.port-ring { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.port-core { fill: var(--ink); stroke: none; }

.grid-line.minor { stroke: var(--grid-minor); stroke-width: 1; }
.grid-line.major { stroke: rgba(var(--accent-rgb), 0.18); stroke-width: 1; }

.drop-zone { fill: none; stroke: var(--line); stroke-width: 2; stroke-dasharray: 10 8; }

.short-halo { fill: none; stroke: var(--warn); stroke-width: 2; stroke-dasharray: 5 4; }

@media (max-width: 980px) {
  main { flex-direction: column; }
  aside {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--board-line);
  }
  .palette { display: grid; grid-template-columns: repeat(3, 1fr); }
  .tool { flex-direction: column; align-items: center; padding: 8px 6px; }
  .tool span { font-size: 15px; }
  .tool svg { width: 100%; height: 52px; }
  .steps { display: none; }
  h1 { font-size: 21px; }
  .status p { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .bulb-glow { display: none; }
  .flow { animation: none; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 22px 24px;
  width: min(380px, 100%);
  box-shadow: 0 24px 60px rgba(20, 14, 22, 0.4);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
}

.modal-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.modal-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  margin-bottom: 16px;
}

.modal-card input[type="text"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  font-family: var(--font-display);
  font-weight: 600;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.modal-btn:hover { background: var(--board-soft); }

.modal-btn.primary {
  background: var(--spark);
  border-color: var(--spark);
  color: var(--ink);
}

.modal-btn.primary:hover { background: var(--spark-hover); }

.modal-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.tutorial-overlay[hidden] { display: none; }

.tutorial-card {
  position: relative;
  background: var(--paper);
  border-radius: 20px;
  padding: 30px 28px 24px;
  width: min(420px, 100%);
  box-shadow: 0 24px 60px rgba(20, 14, 22, 0.4);
  text-align: center;
}

.tutorial-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.tutorial-close svg { width: 15px; height: 15px; }
.tutorial-close:hover { background: var(--board-soft); }

.tutorial-art {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.tutorial-art svg { height: 88px; width: auto; }

.tutorial-card h2 {
  margin: 6px 0 8px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.tutorial-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}

.tutorial-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--board-line);
}

.tutorial-dots span.active { background: var(--spark); }

.tutorial-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.tutorial-actions .modal-btn { flex: 1; }

.tasks-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.tasks-overlay[hidden] { display: none; }

.tasks-card:focus { outline: none; }

.tasks-card {
  position: relative;
  background: var(--paper);
  border-radius: 20px;
  padding: 28px;
  width: min(480px, 100%);
  max-height: min(640px, 86vh);
  overflow: auto;
  box-shadow: 0 24px 60px rgba(20, 14, 22, 0.4);
  scrollbar-width: thin;
  scrollbar-color: var(--board-line) transparent;
}

.tasks-card::-webkit-scrollbar { width: 8px; }
.tasks-card::-webkit-scrollbar-track { background: transparent; }
.tasks-card::-webkit-scrollbar-thumb { background: var(--board-line); border-radius: 999px; }
.tasks-card::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.tasks-card h2 {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-list[hidden] { display: none; }

.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
  font-family: var(--font-body);
}

.task-row:hover { border-color: var(--accent); background: var(--neutral-bg); }

.task-num {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--board-soft);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.task-title {
  flex: 1;
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 600;
}

.task-diff {
  flex: none;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 999px;
}

.task-diff.easy { background: rgba(62, 125, 92, 0.16); color: var(--ok); }
.task-diff.medium { background: rgba(var(--spark-rgb), 0.2); color: var(--accent); }
.task-diff.hard { background: rgba(var(--warn-rgb), 0.16); color: var(--warn); }

.task-sticky {
  position: fixed;
  top: 84px;
  right: 24px;
  width: 280px;
  max-width: calc(100vw - 32px);
  background: var(--paper);
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  z-index: 40;
  overflow: hidden;
}

.task-sticky[hidden] { display: none; }

.task-sticky-handle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 9px 9px 10px;
  background: var(--board);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.task-sticky-handle:active { cursor: grabbing; }

.task-sticky-grip { width: 16px; height: 16px; flex: none; color: var(--muted); fill: currentColor; }

.task-sticky-title {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-sticky-close {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.task-sticky-close svg { width: 13px; height: 13px; }
.task-sticky-close:hover { background: var(--board-soft); color: var(--ink); }

.task-sticky-body { padding: 12px 14px 14px; }
.task-sticky-body .task-diff { margin-bottom: 8px; }

.task-sticky-body p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
}
