:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #0b1220;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --success-bg: #064e3b;
  --success-border: #34d399;
  --success-text: #ecfdf5;
  --warn-bg: #451a03;
  --warn-border: #fbbf24;
  --warn-text: #fef3c7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}

a:hover,
a:focus-visible {
  color: #bae6fd;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--accent);
  color: #0f172a;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 700;
  z-index: 100;
}

.skip-link:focus {
  left: 12px;
}

.page-header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 18px 6px;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: clamp(1.35rem, 2.3vw, 1.75rem);
  letter-spacing: -0.01em;
}

.lede {
  margin: 0;
  max-width: 940px;
  color: var(--text-muted);
  font-size: 0.94rem;
  line-height: 1.42;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 18px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(310px, 0.88fr);
  gap: 14px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.toolbar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.actions-row {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.toolbar-label {
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--text);
  margin-right: 2px;
}

button,
select {
  font: inherit;
  font-size: 0.82rem;
  border-radius: 7px;
  border: 1px solid #475569;
  background: #0f172a;
  color: var(--text);
  padding: 4px 8px;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: var(--accent);
  background: #172554;
}

.atom-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #334155;
  border: 2px solid var(--accent);
  color: #f8fafc;
  font-weight: 800;
  font-size: 0.72rem;
}

.badge-light {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

.badge-o {
  background: #dc2626;
  border-color: #fecaca;
}

.badge-n {
  background: #2563eb;
  border-color: #bfdbfe;
}

.badge-cl {
  background: #15803d;
  border-color: #bbf7d0;
}

.primary-tool {
  background: #0c4a6e;
  border-color: var(--accent);
  font-weight: 600;
}

.danger-tool:hover {
  background: #7f1d1d;
  border-color: #fca5a5;
}

.preset-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-left: auto;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: #1e293b;
  border: 1px solid #64748b;
  color: #f8fafc;
}

.how-to-line {
  margin: 6px 2px;
  font-size: 0.84rem;
  line-height: 1.38;
  color: var(--text-muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #1e293b;
  padding: 1px 5px;
  border-radius: 4px;
  color: #e2e8f0;
}

.canvas-wrap {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

#workbench-svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
}

.atom-node {
  cursor: grab;
}

.atom-node:active {
  cursor: grabbing;
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 12px;
  background: #111827;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--text-muted);
}

.dot-legend {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 2px;
}

.open-dot {
  background: #38bdf8;
  box-shadow: 0 0 6px #38bdf8;
}

.lone-dot {
  background: #e2e8f0;
}

.feedback-banner {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #172554;
  border: 1px solid #38bdf8;
  color: #f8fafc;
  font-size: 0.94rem;
}

.inspector-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card h2 {
  margin: 0;
  font-size: 1.12rem;
}

.pill {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.pill-stable {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.pill-open {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.stat-box {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.stat-box dt {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-box dd {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: 0.98rem;
}

.formula-value {
  font-size: 1.2rem !important;
  color: var(--accent);
}

.molecule-identity {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.molecule-identity h3 {
  margin: 0 0 4px;
  font-size: 1.06rem;
  color: #f8fafc;
}

.mol-meta {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mol-detail {
  margin: 0 0 6px;
  font-size: 0.9rem;
}

.mol-context {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.progress-count {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent);
}

.challenge-intro {
  margin: 0 0 10px;
  font-size: 0.89rem;
  color: var(--text-muted);
}

.challenge-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.ch-item-btn {
  text-align: left;
  padding: 7px 9px;
  font-size: 0.84rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.ch-item-btn.active {
  border-color: var(--accent);
  background: #0c4a6e;
}

.ch-item-btn.solved {
  border-color: var(--success-border);
}

.ch-check {
  font-weight: 800;
  color: #34d399;
}

.active-challenge {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
}

.active-ch-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.small-btn {
  padding: 4px 9px;
  font-size: 0.82rem;
}

.active-challenge p {
  margin: 4px 0;
  font-size: 0.89rem;
}

.ch-hint {
  color: var(--text-muted);
  font-size: 0.84rem !important;
}

.info-section {
  max-width: 1200px;
  margin: 8px auto 0;
  padding: 0 20px 20px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.clean-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.clean-list li {
  margin-bottom: 6px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.clean-list li strong {
  color: var(--text);
}

.page-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px 28px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.page-footer p {
  margin: 4px 0;
}

@media (max-width: 900px) {
  .layout,
  .info-grid {
    grid-template-columns: 1fr;
  }
  .preset-label {
    margin-left: 0;
  }
}

@media (max-width: 520px) {
  .challenge-list,
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
