:root {
  --bg: #f3f6f8;
  --ink: #17212b;
  --muted: #657383;
  --line: #d7e0e7;
  --panel: #ffffff;
  --soft: #f8fbfc;
  --accent: #16786c;
  --accent2: #315f93;
  --amber: #b36f1d;
  --shadow: 0 16px 36px rgba(23, 33, 43, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
button {
  border: 0;
  min-height: 38px;
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
button.secondary { background: #e8eef2; color: #24333f; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: flex-end;
  padding: 30px clamp(18px, 4vw, 52px) 22px;
  background: #17202a;
  color: #fff;
}
.topbar h1 { margin: 0 0 10px; font-size: clamp(32px, 5vw, 54px); }
.topbar p { margin: 0; color: #d4dde5; line-height: 1.65; }
.eyebrow { color: #8bd6cc !important; text-transform: uppercase; font-size: 13px; }
.status {
  min-width: 180px;
  padding: 13px 16px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
}
.status span { display: block; color: #bed0dd; font-size: 13px; margin-bottom: 6px; }

.app {
  display: grid;
  grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  grid-template-areas:
    "controls stage"
    "notes stage"
    "exports stage";
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 52px) 36px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.controls { grid-area: controls; }
.stage { grid-area: stage; }
.notes { grid-area: notes; }
.exports { grid-area: exports; }
h2, h3 { margin: 0 0 8px; }
p { line-height: 1.65; }
label { display: grid; gap: 7px; margin-bottom: 14px; font-weight: 800; color: #2f3e4d; }
input[type="text"], input:not([type]), select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.checks { display: grid; gap: 8px; margin: 14px 0; }
.checks label { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; }
.info, .validation {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  line-height: 1.65;
  margin-top: 12px;
}
.validation { border-left: 4px solid var(--accent2); }
.validation strong { color: var(--accent2); }
.validation ul { margin: 8px 0 0; padding-left: 18px; }
.validation a { color: var(--accent); font-weight: 800; }

.stageHead {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.stageHead p { margin: 0; color: var(--muted); }
#formulaBadge {
  align-self: flex-start;
  min-width: 88px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 6px;
  background: #e5f3f0;
  color: #145d53;
}
.canvasBox {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  overflow: hidden;
}
#cellCanvas {
  display: block;
  width: 100%;
  height: min(66vh, 640px);
  min-height: 500px;
  touch-action: none;
}
#cellCanvas.rotatable { cursor: grab; }
#cellCanvas.dragging { cursor: grabbing; }
.cell-edge {
  fill: none;
  stroke: #5f7181;
  stroke-width: 2;
  stroke-linecap: round;
}
.bond-line {
  stroke: #8798a6;
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
}
.atom-node { cursor: move; }
.atom-node:hover .atom-main { stroke: var(--amber); stroke-width: 3; }
.atom-label {
  font-size: 13px;
  font-weight: 900;
  fill: #17212b;
  paint-order: stroke;
  stroke: white;
  stroke-width: 4px;
  stroke-linejoin: round;
}
.coordPanel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}
.coordHead {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.coordHead p { margin: 0; color: var(--muted); }
.coordEditor { max-height: 300px; overflow: auto; }
.coordEditor table { width: 100%; border-collapse: collapse; font-size: 14px; }
.coordEditor th, .coordEditor td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.coordEditor th { position: sticky; top: 0; background: #eef4f6; z-index: 1; }
.coordEditor input {
  width: 72px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
}
.geometryControls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 110px;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.geometryControls label {
  margin: 0;
}
.geometryPanel {
  padding: 13px 15px 15px;
  overflow: auto;
}
.geometryPanel h4 {
  margin: 10px 0 6px;
  font-size: 15px;
}
.geometryPanel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.geometryPanel th,
.geometryPanel td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.geometryPanel th {
  color: #2d3b47;
  background: #eef4f6;
}
.geometryNote {
  margin: 0 0 8px;
  color: var(--muted);
}
#lesson ul { margin: 0; padding-left: 20px; line-height: 1.75; }
#hint { color: var(--muted); margin-bottom: 0; }

.shortcuts {
  margin: 14px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}
.shortcuts summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
}
.shortcuts ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.shortcuts li {
  padding: 4px 0;
  font-size: 14px;
}
.shortcuts kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-family: monospace;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

@media (max-width: 980px) {
  .topbar { display: block; }
  .status { margin-top: 16px; }
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "controls" "stage" "notes" "exports";
  }
  .coordEditor { max-height: 200px; }
  #cellCanvas { min-height: 400px; height: 50vh; }
}

@media (max-width: 640px) {
  .topbar { padding: 20px 16px 16px; }
  .topbar h1 { font-size: 28px; }
  .app { padding: 16px 12px 24px; gap: 12px; }
  .geometryControls { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
  .row button { width: 100%; }
}
