:root {
  --bg: #f5f5f0;
  --panel: #ffffff;
  --border: #c9c7bd;
  --text: #2c2c2a;
  --accent: #3c3489;
  --valid: #0f6e56;
  --valid-bg: #e1f5ee;
  --invalid: #a32d2d;
  --invalid-bg: #fcebeb;
  --mismatch-bg: #f0b429;
  --mismatch-text: #4a3306;
  --hint: #f0b429;
  --tier-easy: #4a8f2f;
  --tier-medium: #b9860a;
  --tier-hard: #a32d2d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

.smiles-form {
  display: flex;
  gap: 8px;
}

.smiles-form input {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 220px;
}

.smiles-form button {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.smiles-error {
  color: var(--invalid);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.loading-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--invalid);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.auto-connect-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--valid);
  background: var(--valid);
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.hidden {
  display: none;
}

.reset-btn,
.clean-up-btn,
.hint-btn,
.random-btn,
.set-checkpoint-btn,
.restore-checkpoint-btn,
.how-to-play-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.new-puzzle-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.checkpoint-select {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  max-width: 160px;
}

.reset-btn:disabled,
.random-btn:disabled,
.hint-btn:disabled,
.set-checkpoint-btn:disabled,
.restore-checkpoint-btn:disabled,
.checkpoint-select:disabled,
.smiles-form button:disabled {
  opacity: 0.6;
  cursor: default;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #2c2c2a;
  color: #fff;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2000;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 3000;
}

/* Higher specificity than the shared .hidden rule (which .help-overlay's
   own display:flex would otherwise win against by source order alone). */
.help-overlay.hidden {
  display: none;
}

.help-modal {
  position: relative;
  background: var(--panel);
  border-radius: 10px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.help-close-btn {
  position: sticky;
  float: right;
  top: 0;
  right: 0;
  margin-left: 12px;
  font-size: 22px;
  line-height: 1;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
}

.help-content h2 {
  margin-top: 0;
  font-size: 22px;
}

.help-content h3 {
  font-size: 17px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 28px;
}

.help-content h3:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 20px;
}

.help-content h4 {
  font-size: 14px;
  margin-bottom: 4px;
}

.help-content p,
.help-content li {
  font-size: 14px;
  line-height: 1.5;
}

.help-content code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

.help-table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0 16px;
  font-size: 13px;
}

.help-table th,
.help-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.help-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.help-credit {
  margin-top: 28px;
  font-size: 12px;
  color: #a8a49c;
  text-align: center;
}

.new-puzzle-modal .help-content h2 {
  margin-bottom: 16px;
}

.new-puzzle-action-btn {
  display: block;
  width: 100%;
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 8px;
}

.new-puzzle-action-btn:hover {
  border-color: var(--accent);
}

/* The revealed panel for whichever action button was last clicked sits
   directly under it rather than at the bottom, so it reads as "this
   button's own controls" instead of a separate unrelated section. */
.new-puzzle-panel {
  margin: -2px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.new-puzzle-panel select {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}

.new-puzzle-panel .smiles-form {
  margin: 0;
}

.new-puzzle-panel .smiles-form input {
  flex: 1;
}

/* Plain informational text, not a control — substitution rules were never
   player-adjustable to begin with (always on for Medium/Hard, always off
   and hidden entirely on Easy — see main.js's applyDifficulty), so this is
   just a label, never an interactive checkbox. Sets no display of its own,
   so the shared .hidden rule's display:none always applies cleanly with no
   specificity fight (unlike .help-overlay/.substitution-toggle before it —
   see those rules' comments for why that mattered there). */
.substitution-indicator {
  font-size: 14px;
  font-weight: 500;
  color: var(--valid);
  user-select: none;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 4px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: none;
  color: inherit;
  font-size: 11px;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

.info-btn:hover {
  background: currentColor;
  color: var(--panel);
}

/* Briefly flashes the linked section in the "How to play" modal when the
   substitution-rules info button jumps to it, so it's obvious what just
   scrolled into view instead of leaving the player to guess. */
@keyframes flash-highlight {
  from {
    background: var(--mismatch-bg);
  }
  to {
    background: transparent;
  }
}

.help-flash-highlight {
  animation: flash-highlight 1.5s ease-out;
  border-radius: 6px;
}

.difficulty-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.difficulty-badge.easy {
  background: var(--tier-easy);
}

.difficulty-badge.medium {
  background: var(--tier-medium);
}

.difficulty-badge.hard {
  background: var(--tier-hard);
}

.solution-count-badge {
  font-size: 13px;
  color: var(--text);
  opacity: 0.75;
}

.hint-info {
  flex-basis: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--accent);
}

.app-main {
  display: flex;
  gap: 16px;
  padding: 20px;
  align-items: flex-start;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 640px;
  overflow-y: auto;
}

.workspace {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 640px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}

.zoom-layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

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

.bond-line {
  stroke: var(--invalid);
  stroke-width: 2;
  pointer-events: none;
}

.bond-line.valid {
  stroke: var(--valid);
}

.bond-line.hint {
  stroke: var(--hint);
  stroke-width: 3;
}

.bond-line-hit {
  stroke: transparent;
  stroke-width: 10;
  pointer-events: stroke;
  cursor: pointer;
}

.temp-line {
  stroke: #888;
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.group {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  touch-action: none;
}

.group.sidebar-card {
  position: relative;
  left: auto;
  top: auto;
}

.hint-highlight {
  outline: 3px solid var(--hint);
  outline-offset: 3px;
  border-radius: 4px;
}

.drag-source-hidden {
  opacity: 0;
}

.drag-ghost {
  position: fixed;
  opacity: 0.9;
  z-index: 1000;
  pointer-events: none;
}

.group-strip {
  display: flex;
}

.cell {
  position: relative;
  width: 48px;
  height: 48px;
  border: 1.5px solid var(--element-color, var(--border));
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  margin-left: -1.5px;
}

.cell:first-child {
  margin-left: 0;
}

.cell-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cell-number {
  font-weight: 700;
}

.cell-substitution {
  display: flex;
  gap: 2px;
}

.substitution-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #404040;
}

.cell-valid {
  border-color: var(--valid);
  background: var(--valid-bg);
}

.cell-invalid {
  border-color: var(--invalid);
  background: var(--invalid-bg);
}

.dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--element-color, var(--accent));
  cursor: pointer;
  touch-action: none;
  pointer-events: auto;
}

.dot.side-bottom {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.dot.side-top {
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.dot.side-left {
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.dot.side-right {
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.win-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: 8px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: min(90vw, 640px);
  max-height: 80vh;
  overflow: auto;
}

.win-banner.match {
  background: var(--valid);
  color: white;
}

.win-banner.mismatch {
  background: var(--mismatch-bg);
  color: var(--mismatch-text);
}

.win-banner-handle {
  font-weight: 500;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.win-banner-handle:active {
  cursor: grabbing;
}

.solution-info {
  font-size: 13px;
  font-weight: 400;
  font-family: monospace;
  margin-top: 4px;
  opacity: 0.9;
  max-width: 220px;
  word-break: break-all;
}

.win-banner.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.structure-compare {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

.structure-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.structure-panel-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.structure-image {
  background: #ffffff;
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  display: inline-block;
  font-size: 13px;
}

.structure-image svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.source-name {
  font-size: 13px;
  font-weight: 700;
}

/* Capitalizes only the very first letter, not text-transform:capitalize's
   "every word" behavior, since Wikidata labels are often multi-word
   (e.g. "acetylsalicylic acid") and only the leading letter should change. */
.source-name::first-letter {
  text-transform: uppercase;
}
