:root {
  --bg: #f4f7f4;
  --ink: #17221d;
  --muted: #607067;
  --line: #c9d8cf;
  --panel: #ffffff;
  --metal: #d58936;
  --nonmetal: #327b77;
  --noble: #6d5bd0;
  --accent: #1c6f57;
  --accent-2: #c44f34;
  --shell: rgba(28, 111, 87, 0.22);
  --shadow: 0 14px 38px rgba(26, 45, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  min-height: 100vh;
  padding: 20px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 4vw, 40px);
  line-height: 1.12;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.summary {
  min-width: 168px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfffc;
  text-align: right;
}

.summary span,
.summary strong {
  display: block;
}

.summary span {
  color: var(--muted);
  font-size: 13px;
}

.summary strong {
  margin-top: 4px;
  font-size: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(360px, 1fr) minmax(260px, 340px);
  gap: 16px;
  padding: 16px 0 0;
}

.panel,
.atom-card,
.reaction-state-card,
.concept {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.periodic-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(40px, 1fr));
  gap: 8px;
}

.element-btn {
  min-height: 52px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.element-btn:hover,
.element-btn.active {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(28, 111, 87, 0.18);
}

.element-btn strong,
.element-btn span {
  display: block;
}

.element-btn strong {
  font-size: 18px;
}

.element-btn span {
  color: var(--muted);
  font-size: 11px;
}

.metal {
  border-left: 5px solid var(--metal);
}

.nonmetal {
  border-left: 5px solid var(--nonmetal);
}

.noble {
  border-left: 5px solid var(--noble);
}

.field {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.toggle-row,
.reaction-buttons {
  display: grid;
  gap: 8px;
}

.primary-action {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.left-reaction-head {
  margin-top: 18px;
}

.toggle-row {
  grid-template-columns: 1fr 1fr;
}

.pill,
.reaction-buttons button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  cursor: pointer;
}

.pill.active,
.reaction-buttons button.active {
  border-color: var(--accent);
  background: #e8f3ee;
  color: var(--accent);
  font-weight: 700;
}

.reaction-buttons {
  grid-template-columns: repeat(2, 1fr);
}

.stage {
  display: grid;
  gap: 16px;
}

.atom-card {
  padding: 18px;
}

.reaction-state-card {
  padding: 18px;
}

.atom-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef5f1;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.atom-canvas {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1 / 1;
  margin: 8px auto 0;
}

.shell-model {
  position: relative;
  width: 100%;
  height: 100%;
}

.atom-canvas > .shell-model {
  position: absolute;
  inset: 0;
}

.small-shell-model {
  width: min(100%, 360px);
  height: 320px;
  margin: 0 auto;
}

.small-shell-model .nucleus {
  width: 58px;
  height: 58px;
  font-size: 15px;
}

.small-shell-model .nucleus small {
  font-size: 9px;
}

.small-shell-model .electron {
  width: 10px;
  height: 10px;
  margin: -5px;
}

.small-shell-model .shell-label {
  font-size: 10px;
}

.nucleus {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #ffdf7f, #d95235 58%, #8d2e2a);
  color: #fff;
  box-shadow: 0 8px 24px rgba(141, 46, 42, 0.28);
  text-align: center;
  font-weight: 800;
}

.nucleus small {
  display: block;
  font-size: 11px;
  font-weight: 600;
}

.shell {
  position: absolute;
  left: 50%;
  top: 50%;
  border: 2px solid var(--shell);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.shell-label {
  position: absolute;
  left: 50%;
  top: -11px;
  padding: 2px 7px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.electron {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px;
  border-radius: 50%;
  background: #183c8f;
  box-shadow: 0 0 0 4px rgba(24, 60, 143, 0.14);
  transform-origin: center;
  animation: orbit linear infinite;
  animation-duration: calc(var(--duration) / var(--speed, 1));
}

.electron.valence {
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(196, 79, 52, 0.18);
}

@keyframes orbit {
  from {
    transform: rotate(var(--angle)) translateX(var(--radius)) rotate(calc(-1 * var(--angle)));
  }

  to {
    transform: rotate(calc(var(--angle) + 360deg)) translateX(var(--radius)) rotate(calc(-1 * (var(--angle) + 360deg)));
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.electron-dot,
.paired-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: -1px;
}

.electron-dot {
  background: #183c8f;
}

.valence-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--accent-2);
  vertical-align: -1px;
}

.paired-dot {
  background: linear-gradient(90deg, #183c8f 0 48%, #d64f34 52%);
}

.concept-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.concept {
  min-height: 132px;
  padding: 14px;
}

.concept p,
.bond-text,
.rule-list span {
  color: var(--muted);
  line-height: 1.65;
}

.bond-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.reaction-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reaction-head h2 {
  margin-bottom: 0;
}

.ghost-action {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.reaction-zone {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.reaction-slot {
  min-height: 74px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfffc;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.reaction-slot.empty {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: var(--muted);
  text-align: center;
}

.reaction-slot strong,
.reaction-slot span {
  display: block;
}

.reaction-slot strong {
  font-size: 24px;
}

.reaction-slot span {
  color: var(--muted);
  font-size: 12px;
}

.bond-viz {
  min-height: 252px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfffc;
  padding: 12px;
  overflow: hidden;
}

.reaction-state-canvas {
  min-height: 430px;
  overflow: visible;
}

.bond-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 80px;
}

.mini-atom {
  position: relative;
  display: grid;
  min-width: 74px;
  min-height: 74px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-weight: 800;
}

.mini-atom strong,
.mini-atom em {
  display: block;
  font-style: normal;
}

.mini-atom em {
  color: var(--accent-2);
  font-size: 14px;
}

.mini-atom.metal {
  border-color: var(--metal);
}

.mini-atom.nonmetal {
  border-color: var(--nonmetal);
}

.mini-atom.ion-plus::after,
.mini-atom.ion-minus::after {
  position: absolute;
  right: -6px;
  top: -8px;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
}

.mini-atom.ion-plus::after {
  content: "+";
  background: var(--metal);
}

.mini-atom.ion-minus::after {
  content: "-";
  background: var(--nonmetal);
}

.arrow {
  color: var(--accent-2);
  font-size: 24px;
  font-weight: 900;
}

.shared-pair,
.transfer-electron {
  display: inline-grid;
  min-width: 42px;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #ffe9df;
  color: var(--accent-2);
  font-weight: 900;
}

.molecule {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-top: 18px;
}

.placeholder {
  display: grid;
  min-height: 210px;
  place-items: center;
  color: var(--muted);
}

.reaction-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 132px;
}

.ionic-stage {
  gap: 0;
}

.electron-track {
  position: relative;
  width: 106px;
  height: 44px;
}

.electron-track::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  border-top: 2px dashed rgba(196, 79, 52, 0.48);
}

.flying-electron {
  position: absolute;
  left: 0;
  top: 8px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: #ffe9df;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  animation: transfer 1.7s ease-in-out infinite;
  animation-delay: var(--delay);
}

.flying-electron::after {
  content: "";
  position: absolute;
  right: 23px;
  width: 34px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(196, 79, 52, 0), rgba(196, 79, 52, 0.55));
}

@keyframes transfer {
  0%, 18% {
    transform: translateX(0);
    opacity: 0.4;
  }

  48% {
    opacity: 1;
  }

  82%, 100% {
    transform: translateX(76px);
    opacity: 0.4;
  }
}

.post-reaction {
  position: relative;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(108px, 150px) minmax(190px, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 430px;
}

.post-atom {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 8px;
  min-width: 0;
  text-align: center;
}

.post-atom p {
  min-height: 42px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.post-label {
  display: inline-grid;
  justify-self: center;
  min-width: 58px;
  min-height: 30px;
  place-items: center;
  border-radius: 999px;
  background: #f7fbf8;
  color: var(--ink);
  font-weight: 900;
}

.post-bridge {
  position: relative;
  z-index: 3;
  display: grid;
  min-height: 96px;
  place-items: center;
  text-align: center;
}

.post-bridge strong {
  position: relative;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--line);
}

.post-bridge .flight-count {
  position: relative;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fff7f3;
  color: var(--accent-2);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(196, 79, 52, 0.16);
}

.transfer-stream {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 18px;
  height: 48px;
}

.transfer-stream::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 2px dashed rgba(196, 79, 52, 0.5);
}

.transfer-stream .flying-electron {
  animation-duration: 1.35s;
}

.shell-transfer-bridge {
  min-height: 152px;
}

.full-transfer-layer {
  position: absolute;
  inset: 74px 0 76px;
  z-index: 4;
  pointer-events: none;
}

.full-path-guide {
  position: absolute;
  left: -12px;
  right: -12px;
  top: 50%;
  height: 74px;
  transform: translateY(-50%);
}

.full-path-guide::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 3px dashed rgba(196, 79, 52, 0.28);
}

.outer-shell-port {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-2);
  border-radius: 50%;
  background: #fff;
  transform: translateY(-50%);
  box-shadow: 0 0 0 8px rgba(196, 79, 52, 0.08);
}

.donor-port {
  left: 0;
}

.acceptor-port {
  right: 0;
}

.state-transfer-stream {
  left: 0;
  right: 0;
  top: 40px;
  height: 70px;
}

.state-transfer-stream::before {
  top: 58%;
  border-top-width: 3px;
  border-style: dashed;
}

.state-flying-electron {
  position: absolute;
  left: var(--start-x, 0);
  top: var(--start-y, 50%);
  z-index: 3;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: #ffe9df;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(196, 79, 52, 0.18);
  animation: shell-hop 1.65s cubic-bezier(.42, 0, .18, 1) infinite;
  animation-delay: var(--delay);
}

.state-flying-electron::after {
  content: "";
  position: absolute;
  right: 24px;
  width: 42px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(196, 79, 52, 0), rgba(196, 79, 52, 0.58));
}

@keyframes shell-hop {
  0%, 14% {
    transform: translate(0, 0) scale(0.86);
    opacity: 0;
  }

  24% {
    opacity: 1;
  }

  52% {
    transform: translate(54px, -30px) scale(1.08);
    opacity: 1;
  }

  86%, 100% {
    transform: translate(108px, 0) scale(0.9);
    opacity: 0;
  }
}

.ionic-full-electron {
  --start-x: 31%;
  --end-x: 69%;
  --start-y: 50%;
  animation-name: atom-to-atom-transfer;
  animation-duration: 2.15s;
}

.left-full-electron {
  --start-x: 31%;
  --end-x: calc(50% - 18px);
  --start-y: 50%;
  animation-name: atom-to-octet-left;
  animation-duration: 2s;
}

.right-full-electron {
  --start-x: 69%;
  --end-x: calc(50% + 18px);
  --start-y: 50%;
  animation-name: atom-to-octet-right;
  animation-duration: 2s;
}

@keyframes atom-to-atom-transfer {
  0%, 12% {
    left: var(--start-x);
    top: var(--start-y);
    transform: translate(-50%, -50%) scale(0.78);
    opacity: 0;
  }

  20% {
    opacity: 1;
  }

  50% {
    left: 50%;
    top: 22%;
    transform: translate(-50%, -50%) scale(1.08);
    opacity: 1;
  }

  88%, 100% {
    left: var(--end-x);
    top: var(--start-y);
    transform: translate(-50%, -50%) scale(0.82);
    opacity: 0;
  }
}

@keyframes atom-to-octet-left {
  0%, 14% {
    left: var(--start-x);
    top: var(--start-y);
    transform: translate(-50%, -50%) scale(0.72);
    opacity: 0;
  }

  26% {
    opacity: 1;
  }

  72%, 100% {
    left: var(--end-x);
    top: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0;
  }
}

@keyframes atom-to-octet-right {
  0%, 14% {
    left: var(--start-x);
    top: var(--start-y);
    transform: translate(-50%, -50%) scale(0.72);
    opacity: 0;
  }

  26% {
    opacity: 1;
  }

  72%, 100% {
    left: var(--end-x);
    top: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0;
  }
}

.shared-post-cloud {
  min-height: 148px;
}

.shared-post-cloud::before {
  content: "";
  position: absolute;
  inset: 28px 8px;
  border: 2px solid rgba(196, 79, 52, 0.25);
  border-radius: 50%;
  animation: pulse-cloud 1.6s ease-in-out infinite;
}

.shared-post-cloud > .octet-ring {
  position: relative;
  z-index: 2;
  display: block;
  width: 112px;
  height: 112px;
  border-radius: 999px;
  background: radial-gradient(circle, #fff 0 42%, #ffe9df 43% 70%, rgba(255, 233, 223, 0) 71%);
  color: var(--accent-2);
  animation: rotate-ring 4s linear infinite, pulse-cloud 1.8s ease-in-out infinite;
}

.octet-bridge {
  min-height: 170px;
}

.octet-bridge::before {
  inset: 22px -6px;
}

.ring-electron {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 5px rgba(196, 79, 52, 0.14);
  transform: rotate(var(--ring-angle)) translateX(48px);
}

@keyframes rotate-ring {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.covalent-inbound {
  position: absolute;
  top: 50%;
  z-index: 1;
  width: 74px;
  height: 52px;
  transform: translateY(-50%);
}

.left-inbound {
  left: -8px;
}

.right-inbound {
  right: -8px;
  transform: translateY(-50%) scaleX(-1);
}

.covalent-inbound .state-flying-electron {
  animation-name: covalent-feed;
  animation-duration: 1.55s;
}

@keyframes covalent-feed {
  0%, 16% {
    transform: translate(0, 4px) scale(0.72);
    opacity: 0;
  }

  34% {
    opacity: 1;
  }

  78%, 100% {
    transform: translate(58px, 4px) scale(0.95);
    opacity: 0;
  }
}

.product-row {
  min-height: 66px;
  border-top: 1px solid var(--line);
}

.covalent-stage {
  gap: 6px;
}

.shared-cloud {
  display: grid;
  min-width: 58px;
  min-height: 38px;
  place-items: center;
  border: 1px solid #f0b7a7;
  border-radius: 999px;
  background: #ffe9df;
  color: var(--accent-2);
  font-size: 20px;
  font-weight: 900;
  animation: pulse-cloud 1.8s ease-in-out infinite;
}

@keyframes pulse-cloud {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(196, 79, 52, 0.2);
  }

  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 8px rgba(196, 79, 52, 0.08);
  }
}

.shared-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.shared-note strong,
.stable-gap,
.electron-sea {
  padding: 5px 10px;
  border-radius: 999px;
  background: #e8f3ee;
  color: var(--accent);
}

.rule-list {
  display: grid;
  gap: 10px;
}

.rule-list div {
  padding: 10px;
  border-left: 4px solid var(--accent);
  background: #f7fbf8;
}

.rule-list strong,
.rule-list span {
  display: block;
}

.orbital-boxes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.orbital {
  min-height: 38px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.spin {
  color: var(--accent-2);
  font-size: 18px;
  font-weight: 900;
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .concept-grid {
    grid-template-columns: 1fr;
  }

  .post-reaction {
    grid-template-columns: 1fr;
  }

  .post-bridge {
    min-height: 84px;
  }
}

@media (max-width: 620px) {
  .app {
    padding: 10px;
  }

  .topbar {
    display: grid;
    padding: 14px 0;
  }

  .summary {
    text-align: left;
  }

  .periodic-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .atom-canvas {
    min-height: 330px;
  }
}
