:root {
  color-scheme: light;
  --bg: #fff;
  --fg: #0b0b0b;
  --line: #d8d8d8;
  --panel: rgba(255, 255, 255, 0.88);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
}

#molecule-canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  cursor: crosshair;
}

body[data-tool="erase"] #molecule-canvas {
  cursor: cell;
}

body[data-tool="translate"] #molecule-canvas {
  cursor: grab;
}

body.is-dragging #molecule-canvas {
  cursor: grabbing;
}

.toolbar {
  position: fixed;
  right: 4px;
  top: 50%;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transform: translateY(-50%);
}

.tool-button,
.icon-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tool-button:hover,
.tool-button:focus-visible,
.icon-close:hover,
.icon-close:focus-visible {
  outline: none;
  background: #f4f4f4;
}

.tool-button.is-active {
  background: var(--fg);
  color: var(--bg);
}

.tool-button svg,
.icon-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button[data-tool="draw"] svg circle {
  fill: none;
}

.energy-panel {
  position: fixed;
  left: 4px;
  top: 50%;
  z-index: 4;
  width: 84px;
  height: 58vh;
  min-height: 300px;
  max-height: 560px;
  transform: translateY(-50%);
  pointer-events: none;
}

.energy-ladder {
  position: absolute;
  inset: 0;
  outline: none;
  pointer-events: auto;
  touch-action: none;
}

.energy-level {
  position: absolute;
  left: 0;
  width: 44px;
  height: 26px;
  margin-top: -13px;
  border: 0;
  background: transparent;
  cursor: pointer;
  --level-width: 34px;
}

.energy-level::before {
  position: absolute;
  left: 50%;
  top: 12px;
  width: var(--level-width);
  height: 2px;
  background: rgba(0, 0, 0, 0.24);
  transform: translateX(-50%);
  content: "";
}

.energy-level.is-occupied::before {
  height: 4px;
  top: 11px;
  background: var(--fg);
}

.energy-level.is-selected::before {
  height: 5px;
  top: 10px;
  width: var(--level-width);
  background: rgba(237, 47, 47, 0.72);
}

.energy-level.is-degenerate::before {
  width: var(--level-width);
}

.energy-level.is-degenerate.is-selected::before {
  width: var(--level-width);
}

.energy-level:focus-visible::after {
  position: absolute;
  left: -5px;
  top: 4px;
  width: 42px;
  height: 18px;
  border: 1px solid var(--fg);
  border-radius: 18px;
  content: "";
}

.energy-empty {
  position: absolute;
  left: 0;
  top: 50%;
  width: 48px;
  height: 2px;
  background: var(--line);
}

.signature {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 4;
  color: #808080;
  font-size: 13px;
  text-decoration: none;
  transform: translateX(-50%);
  pointer-events: auto;
}

.signature:hover,
.signature:focus-visible {
  color: var(--fg);
  outline: none;
}

.info-modal {
  width: min(820px, calc(100vw - 32px));
  height: min(720px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--fg);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

.info-modal::backdrop {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.modal-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.icon-close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.icon-close svg {
  width: 19px;
  height: 19px;
}

.modal-body {
  height: calc(100% - 67px);
  overflow: auto;
  padding: 18px 20px 22px;
}

.modal-body h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
}

.modal-body p {
  margin: 0 0 14px;
  color: #333;
  line-height: 1.55;
}

.modal-note {
  color: #666;
  font-size: 12px;
}

.atom-map {
  display: block;
  width: 100%;
  height: auto;
  max-height: 300px;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.atom-map-bonds line {
  stroke: #111;
  stroke-linecap: round;
  stroke-width: 3;
}

.atom-map-atoms circle {
  fill: #050505;
}

.atom-map-atoms text {
  fill: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  font-weight: 750;
  text-anchor: middle;
  dominant-baseline: middle;
}

.orbital-table {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.orbital-row {
  display: grid;
  grid-template-columns: 84px minmax(130px, 1fr) minmax(180px, 1.4fr);
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.orbital-row.is-selected {
  background: rgba(237, 47, 47, 0.06);
  box-shadow: -10px 0 0 rgba(237, 47, 47, 0.06), 10px 0 0 rgba(237, 47, 47, 0.06);
}

.orbital-label {
  font-weight: 700;
}

.orbital-meta {
  color: #333;
  line-height: 1.45;
}

.coefficient-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 5px;
}

.coefficient-chip {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: baseline;
  min-width: 0;
  padding: 4px 7px;
  border-left: 3px solid transparent;
  border-radius: 0;
  background: #f5f5f5;
  color: #1b1b1b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.coefficient-index {
  color: #777;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  font-weight: 700;
}

.coefficient-value {
  justify-self: end;
}

.coefficient-chip.is-positive {
  background: rgba(237, 47, 47, 0.11);
  border-left-color: rgba(237, 47, 47, 0.55);
}

.coefficient-chip.is-negative {
  background: rgba(31, 100, 255, 0.11);
  border-left-color: rgba(31, 100, 255, 0.55);
}

.coefficient-chip.is-zero {
  color: #777;
  background: #f7f7f7;
}

@media (max-width: 720px) {
  .toolbar {
    right: 4px;
    gap: 8px;
  }

  .tool-button {
    width: 40px;
    height: 40px;
  }

  .energy-panel {
    left: 4px;
    width: 80px;
    height: 42vh;
    min-height: 220px;
    max-height: 290px;
  }

  .orbital-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .signature {
    bottom: 10px;
    font-size: 12px;
  }
}
