:root {
  --bg: #0d1015;
  --panel: rgba(18, 22, 30, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e6e9ef;
  --dim: #8b93a3;
  --accent: #ffd34d;
  --accent2: #4cc9f0;
  --ax: #ff8a3d;
  --eq: #3db8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
canvas#view, canvas#labels { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
canvas#labels { pointer-events: none; }

kbd { display: inline-block; min-width: 1.5em; padding: 0 4px; margin: 0 1px; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; background: rgba(255,255,255,0.06); font: 11px/1.5 ui-monospace, monospace;
  color: var(--text); text-align: center; }

.panel { position: fixed; top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; backdrop-filter: blur(8px); max-height: calc(100vh - 24px); overflow-y: auto; transition: opacity .2s; }
#left { left: 12px; width: 244px; }
#right { right: 12px; width: 268px; }
.hidden { display: none !important; }
body.locked .panel { opacity: 0.72; pointer-events: none; }

h1 { font-size: 16px; margin: 0 0 8px; letter-spacing: .02em; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 12px 0 6px; font-weight: 600; }
section:first-of-type h2 { margin-top: 4px; }

button, select { font: inherit; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 6px; cursor: pointer; }
button:hover, select:hover { background: rgba(255,255,255,0.12); }
button.on { background: rgba(255, 211, 77, 0.18); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { background: rgba(255,255,255,0.06); }
button.primary { background: rgba(255, 211, 77, 0.2); border-color: rgba(255, 211, 77, 0.55); }
button.primary:hover:not(:disabled) { background: rgba(255, 211, 77, 0.32); }
button.danger:hover { background: rgba(255, 93, 108, 0.18); border-color: #ff5d6c; }
button.icon { width: 24px; height: 24px; padding: 0; border-radius: 50%; font-weight: 700; line-height: 1; flex: none; }
button.link { background: none; border: none; padding: 0; color: var(--accent2); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }
button kbd { font-size: 10px; opacity: .7; }
select { width: 100%; margin-top: 8px; }
select option { background: #1a1f29; }

.grid2, .grid3, .grid4, .grid6 { display: grid; gap: 5px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }
.grid4 { grid-template-columns: 1fr 1fr; }
.grid6 { grid-template-columns: repeat(5, 1fr); }
.grid6 button { padding: 6px 0 3px; display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: 14px; }
.grid6 button small { font-size: 10px; font-weight: 400; color: var(--dim); }
.grid6 button .dot { width: 10px; height: 10px; border-radius: 50%; margin-bottom: 3px; }
.grid4 button { text-align: left; }

.toggle { display: flex; align-items: center; gap: 6px; margin: 4px 0; cursor: pointer; }
.toggle kbd { margin-left: auto; }
.stats { margin-top: 10px; color: var(--dim); font-size: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.stats b { color: var(--text); font-weight: 600; }

.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sub { color: var(--dim); font-size: 12px; margin: 4px 0 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 6px 0; }
.ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--dim); margin: -4px 0 8px; }
#newman, #scan { display: block; width: 240px; margin: 6px auto; border-radius: 8px; background: rgba(0,0,0,0.25); }
#newman { height: 240px; }
#scan { height: 110px; }

#crosshair { position: fixed; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none; display: none; }
body.locked #crosshair { display: block; }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: rgba(255,255,255,0.85); box-shadow: 0 0 2px #000; }
#crosshair::before { left: 10px; top: 2px; width: 2px; height: 18px; }
#crosshair::after { top: 10px; left: 2px; height: 2px; width: 18px; }
#crosshair span { position: absolute; inset: 7px; border-radius: 50%; border: 2px solid transparent; }
#crosshair.target span { border-color: var(--accent); }

#hover { position: fixed; left: 50%; top: calc(50% + 22px); transform: translateX(-50%); pointer-events: none;
  background: rgba(0,0,0,0.7); padding: 3px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; display: none; z-index: 5; }
#hover.show { display: block; }
#hover .act { color: var(--accent); }
#toast { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); background: rgba(20,24,32,0.95);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .25s; pointer-events: none;
  max-width: min(640px, 80vw); text-align: center; z-index: 6; }
#toast.show { opacity: 1; }
#toast.err { border-color: rgba(255, 93, 108, 0.7); background: rgba(48, 18, 24, 0.95); }
#toast.err::before { content: "⚠ "; color: #ff8080; }

/* status bar: what a click will do right now, and how to move */
#hud { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none; z-index: 4; max-width: calc(100vw - 24px); }
#hud-state { background: rgba(18, 22, 30, 0.9); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; white-space: nowrap;
  display: flex; align-items: center; gap: 8px; }
#hud-state .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
#hud-state .pending { color: var(--accent); }
#hud-state .sep { color: var(--dim); }
#hud-mode { color: var(--dim); font-size: 11.5px; white-space: nowrap; }
#hud-mode kbd { font-size: 10px; }
#empty { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; color: var(--dim);
  background: rgba(18, 22, 30, 0.75); padding: 10px 16px; border-radius: 10px; border: 1px dashed var(--line); }

/* modal overlays: intro, shortcut sheet, command palette */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(5,7,10,0.62); backdrop-filter: blur(3px); z-index: 10; padding: 16px; }
.card { max-width: 620px; max-height: calc(100vh - 32px); overflow-y: auto; background: rgba(18, 22, 30, 0.97); border: 1px solid var(--line); border-radius: 16px; padding: 24px 28px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.head h1 { margin: 0; }
#intro h1 { font-size: 26px; margin-bottom: 4px; }
#intro .lead { color: #c5cbd6; font-size: 14px; margin: 0 0 14px; }
#intro .steps { margin: 0 0 12px; padding-left: 20px; color: #c5cbd6; line-height: 1.6; }
#intro .steps li { margin: 6px 0; }
#intro .steps b { color: var(--text); }
.intro-actions { display: flex; gap: 8px; margin-top: 18px; }
.intro-actions button { padding: 11px 14px; font-size: 14px; }
#start { flex: 1; background: var(--accent); color: #111; border: none; font-weight: 700; }
#start:hover { background: #ffdf7a; }
#start kbd { color: #111; border-color: rgba(0,0,0,0.25); background: rgba(0,0,0,0.08); }
.help-card { max-width: 820px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
.help-card h3 { margin: 14px 0 6px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.help-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.help-card dt { text-align: right; white-space: nowrap; color: var(--text); }
.help-card dd { margin: 0; color: #c5cbd6; }
.help-card > .sub { margin-top: 16px; }

#palette { place-items: start center; padding-top: 14vh; }
.pal-card { width: min(560px, 100%); background: rgba(18, 22, 30, 0.98); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
#pal-input { width: 100%; font: 15px ui-sans-serif, system-ui; color: var(--text); background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 14px 16px; outline: none; }
#pal-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
#pal-list li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; cursor: pointer; }
#pal-list li.on { background: rgba(255, 211, 77, 0.16); }
#pal-list li .grp { color: var(--dim); font-size: 11px; width: 70px; flex: none; }
#pal-list li .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pal-list li .lbl small { color: var(--dim); margin-left: 6px; }
#pal-list li.empty { color: var(--dim); cursor: default; }
.pal-foot { border-top: 1px solid var(--line); padding: 6px 12px; color: var(--dim); font-size: 11px; }

#demo-bar { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); width: min(460px, calc(100vw - 560px));
  min-width: 260px; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 14px;
  backdrop-filter: blur(8px); box-shadow: 0 6px 24px rgba(0,0,0,0.35); }
#demo-bar .demo-head { display: flex; align-items: center; gap: 8px; }
#demo-bar .demo-head b { flex: 1; font-size: 14px; }
#demo-step { color: var(--accent); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
#demo-text { color: var(--text); margin: 6px 0; }
#demo-key { color: var(--dim); font-size: 12px; }
#demo-key .go { color: var(--accent); font-weight: 600; }
@media (max-width: 1040px) { #demo-bar { width: calc(100vw - 32px); z-index: 5; } }
#sk { --sk-bg: #12161e; top: auto; bottom: 58px; left: 50%; right: auto; transform: translateX(-50%); width: min(500px, calc(100vw - 580px));
  min-width: 260px; height: 124px; padding: 2px 4px; overflow: hidden; background: rgba(18, 22, 30, 0.92); display: flex; flex-direction: column; }
#sk .sk-head { position: absolute; top: 4px; right: 4px; left: 8px; display: flex; align-items: center; gap: 8px; pointer-events: none; }
#sk .sk-head h2 { display: none; }
#sk .sk-head button { pointer-events: auto; width: 18px; height: 18px; font-size: 11px; margin-left: auto; opacity: 0.7; }
#sk .sk-msg { color: var(--dim); font-size: 11px; }
#sk[data-state=loading] .sk-msg::before { content: "Loading 2D drawing…"; }
#sk[data-state=error] .sk-msg::before { content: "2D drawing unavailable (couldn't load RDKit)"; }
#sk .sk-svg { flex: 1; width: 100%; min-height: 0; display: block; font-family: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; }
#sk-open { position: fixed; bottom: 58px; left: 50%; transform: translateX(-50%); }
body.sk-on #toast { bottom: 194px; }
@media (max-width: 1040px) { #sk { width: calc(100vw - 24px); } }
@media (max-width: 720px) { .help-cols { grid-template-columns: 1fr; } #right { top: auto; bottom: 12px; } .intro-actions { flex-direction: column; } }

.row { display: flex; align-items: center; gap: 6px; margin: 8px 0 2px; }
.row select { margin: 0 0 0 auto; width: auto; flex: 1; min-width: 0; }
.smiles { display: flex; gap: 5px; }
.smiles input { flex: 1; min-width: 0; font: 12px ui-monospace, monospace; color: var(--text); background: rgba(0,0,0,0.3);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 7px; }
.smiles input:focus { outline: 1px solid var(--accent); }

.grid7 { display: grid; gap: 4px; grid-template-columns: repeat(7, 1fr); margin-top: 5px; }
.grid7 button { padding: 4px 0; font-size: 11px; font-weight: 700; display: flex; flex-direction: column; align-items: center; }
.grid7 button .dot { width: 7px; height: 7px; border-radius: 50%; margin-bottom: 2px; }
.bonds button { display: flex; flex-direction: column; align-items: center; font-size: 11px; padding: 4px 0; }
.bond-glyph { font-size: 18px; line-height: 1; font-weight: 700; }
#tool-help { margin-top: 6px; }
#rx-steps { margin: 8px 0; padding-left: 20px; }
#rx-steps li { margin: 4px 0; font-size: 12px; }
#rx-steps li.sub { list-style: none; margin-left: -20px; }
#rx-steps li button { float: right; padding: 0 6px; font-size: 11px; }
#rx-result { font-size: 12px; margin: 6px 0 10px; }
#rx-result .err { color: #ff8080; }
#rx-result .ok { color: #9be89b; }
#rx-result .warn { color: #ffd34d; margin-top: 4px; }
#rx-result ul { margin: 4px 0; padding-left: 16px; color: var(--dim); }

.search { width: 100%; display: flex; align-items: center; justify-content: space-between; margin: 10px 0 2px; color: var(--dim); text-align: left; background: rgba(0,0,0,0.3); }
.search:hover { color: var(--text); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { display: inline-block; }
#opts > summary h2::after, #rx-howto > summary::after { content: " ▸"; }
#opts[open] > summary h2::after, #rx-howto[open] > summary::after { content: " ▾"; }
#rx-howto > summary { color: var(--accent2); font-size: 12px; margin: 2px 0 4px; }
.guide { background: rgba(76, 201, 240, 0.08); border: 1px solid rgba(76, 201, 240, 0.35); border-radius: 8px; padding: 8px 10px; margin: 4px 0 8px; font-size: 12px; line-height: 1.5; }
.guide-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 4px; color: var(--accent2); }
.guide-head .icon { width: 20px; height: 20px; }
#templates { margin: 0 0 6px; }
canvas#view.can-click { cursor: pointer; }
canvas#view.dragging { cursor: grabbing; }

.grid8 { display: grid; gap: 4px; grid-template-columns: repeat(8, 1fr); }
.grid8 button { padding: 4px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grid8 button small { font-size: 9px; color: var(--dim); }
.grid8 .swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,0.4); }
.grid8 button.on { background: rgba(255,255,255,0.14); border-color: var(--text); }
button.wide { width: 100%; margin-top: 6px; }
