:root {
  --bg0: #0b0d10;
  --bg1: #12161b;
  --panel: #171c22;
  --line: #2a323b;
  --ink: #e8ecef;
  --dim: #8ea0ad;
  --accent: #7ee3c3;
  --accent2: #ff9f6b;
  --paper: #f4ecd8;
  --paper-ink: #241f14;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --disp: "Space Grotesk", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 800px at 15% -10%, #16241f 0%, transparent 60%),
              radial-gradient(1000px 700px at 100% 0%, #241a2c 0%, transparent 55%),
              var(--bg0);
  color: var(--ink);
  font-family: var(--mono);
  min-height: 100vh;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.top { margin-bottom: 22px; }
.brand { display: flex; align-items: flex-start; gap: 14px; }
.glyph { font-size: 2.4rem; line-height: 1; filter: saturate(1.2); }
h1 {
  font-family: var(--disp);
  font-size: 2.1rem;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tag { margin: 0; color: var(--dim); max-width: 62ch; font-size: 0.92rem; line-height: 1.5; }

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 880px) {
  .board { grid-template-columns: 1fr; }
}

.editor, .output {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.tool-group { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-group.modes { margin-left: 4px; }
.tool-group.actions { margin-left: auto; }

.el-btn, .tool-btn {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: #1d242b;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.el-btn { min-width: 40px; font-weight: 700; }
.el-btn:hover, .tool-btn:hover { border-color: var(--accent); }
.el-btn.active, .tool-btn.active {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
.el-btn:active, .tool-btn:active { transform: scale(0.96); }
.tool-icon { display: inline-block; width: 1em; }

.canvas-wrap { position: relative; }
#board {
  width: 100%;
  aspect-ratio: 4 / 3;
  background:
    radial-gradient(circle at 1px 1px, #263038 1px, transparent 1px) 0 0 / 22px 22px,
    #0e1216;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
}
.hint {
  color: var(--dim);
  font-size: 0.78rem;
  margin: 8px 2px 0;
  line-height: 1.5;
}

.formula-bar {
  margin-top: 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  background: #0e1216;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.formula-bar .label { color: var(--dim); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.formula { font-family: var(--disp); font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.atom-count { color: var(--dim); font-size: 0.78rem; margin-left: auto; }

.output { display: flex; flex-direction: column; }
.paper {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 8px;
  padding: 22px 22px 18px;
  min-height: 420px;
  max-height: 560px;
  overflow-y: auto;
  box-shadow: inset 0 0 0 1px #00000012;
  font-family: var(--mono);
}
.paper-empty { color: #7a6f56; padding: 30px 6px; text-align: center; }
.paper-empty .small { font-size: 0.85rem; margin-top: 8px; }

.writeup h2 {
  font-family: var(--disp);
  font-size: 1.15rem;
  margin: 0 0 2px;
  color: #1b1710;
}
.writeup .subtitle { font-style: italic; color: #6b5f45; margin: 0 0 14px; font-size: 0.88rem; }
.writeup .retro {
  font-size: 0.88rem;
  color: #3a3324;
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #eadfc4;
  border-left: 3px solid #b89b52;
  border-radius: 3px;
}
.writeup ol {
  padding-left: 1.3em;
  margin: 0 0 16px;
}
.writeup li {
  margin-bottom: 10px;
  font-size: 0.88rem;
  line-height: 1.55;
}
.writeup li.theorem {
  background: #e4ecdf;
  border-left: 3px solid #5c8a5a;
  padding: 6px 8px;
  border-radius: 3px;
  list-style: none;
  margin-left: -1.3em;
  padding-left: calc(1.3em + 8px);
}
.writeup li.theorem::before {
  content: "∴ ";
  color: #3f6b3f;
  font-weight: 700;
}
.writeup .yield {
  font-size: 0.88rem;
  margin: 12px 0;
  font-weight: 700;
}
.writeup .spectra {
  font-size: 0.78rem;
  color: #4a4230;
  border-top: 1px dashed #b6a97e;
  padding-top: 10px;
  margin-top: 10px;
  line-height: 1.7;
  white-space: pre-wrap;
}
.writeup .footnote {
  font-size: 0.76rem;
  color: #7a6f56;
  margin-top: 14px;
  font-style: italic;
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
button.primary, button.secondary {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
button.primary {
  background: linear-gradient(90deg, var(--accent), #61c9a8);
  color: #06110d;
  flex: 1;
}
button.primary:hover { filter: brightness(1.08); }
button.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
button.secondary:hover { border-color: var(--accent); }

.share-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.share-btn {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  background: #1d242b;
}
.share-btn.bsky { background: #0a84ff22; border-color: #0a84ff66; color: #7ec3ff; }
.share-btn:hover { filter: brightness(1.15); }

.foot {
  margin-top: 30px;
  color: var(--dim);
  font-size: 0.78rem;
  line-height: 1.7;
  text-align: center;
}
.foot a { color: var(--accent); text-decoration: none; }
.foot a:hover { text-decoration: underline; }
