:root {
  color-scheme: dark;
  --bg: #0c1210;
  --panel: #151c19;
  --line: #2c3b34;
  --text: #e7f0ea;
  --muted: #9aada4;
  --low: #3d8b7a;
  --mid: #d4a017;
  --high: #c4302a;
  --banner: #3a2a12;
  --banner-text: #ffe7c2;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.banner {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--banner);
  color: var(--banner-text);
  border-bottom: 1px solid #8a6428;
  padding: 10px 18px 12px;
}

.banner p { margin: 0; line-height: 1.4; }
.banner-en { font-size: 15px; font-weight: 650; }
.banner-zh { margin-top: 4px; font-size: 14px; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.78fr);
  gap: 18px;
  padding: 16px 18px 28px;
  align-items: start;
}

.stage-head h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.03em;
  font-weight: 650;
}

.stage-head p {
  margin: 0 0 12px;
  color: var(--muted);
  max-width: 62ch;
  line-height: 1.45;
}

#canvas-wrap {
  position: relative;
  height: min(72vh, 740px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #24312c 0%, #101614 70%);
}

#heart { width: 100%; height: 100%; display: block; touch-action: none; }

.view-tag, .diagram-note {
  position: absolute;
  left: 14px;
  color: #d5e4dc;
  font-size: 13px;
  background: rgba(12, 18, 16, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 4px 10px;
}

.view-tag { top: 12px; }
.diagram-note { bottom: 12px; max-width: calc(100% - 28px); border-radius: 12px; }

.legend {
  position: absolute;
  right: 14px;
  bottom: 12px;
  width: 180px;
  background: rgba(12, 18, 16, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend-bar {
  height: 8px;
  border-radius: 99px;
  margin: 6px 0;
  background: linear-gradient(90deg, var(--low), var(--mid), var(--high));
}

.legend span { display: flex; justify-content: space-between; }

aside {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}

.record-row, .editor-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.record-row { margin-bottom: 8px; }

button, select, input[type="number"] {
  font: inherit;
  color: var(--text);
  background: #101614;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
}

button { cursor: pointer; }
button:hover { border-color: #6d857a; }

#record-id { width: 5.2rem; }

.fold-note, .hint, .method-note, footer, .empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.target {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 2px 10px;
  width: 100%;
  text-align: left;
  margin: 8px 0;
  padding: 10px;
  border-radius: 14px;
}

.target strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.target .full { grid-column: 1 / 3; color: var(--muted); font-size: 12px; }
.target .bar {
  grid-column: 2 / 3;
  align-self: center;
  height: 8px;
  border-radius: 99px;
  background: #24302b;
  overflow: hidden;
}
.target .bar i { display: block; height: 100%; }
.target .table-label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.target.selected { box-shadow: inset 0 0 0 1px #d5e4dc; }

h2 {
  margin: 16px 0 8px;
  font-size: 15px;
  font-weight: 650;
}

.contrib { margin: 8px 0 12px; }
.contrib-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(80px, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: 5px 0;
  font-size: 13px;
}
.track {
  position: relative;
  height: 8px;
  background: #24302b;
  border-radius: 99px;
}
.track .zero {
  position: absolute;
  left: 50%;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: #c9d6cf;
}
.track .pos, .track .neg {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 99px;
}
.track .pos { left: 50%; background: var(--high); }
.track .neg { right: 50%; background: var(--low); }
.contrib-row b { font-weight: 600; font-variant-numeric: tabular-nums; }

.editor {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  margin: 8px 0;
  font-size: 14px;
}
.editor input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: #d4a017; }
.choice { display: flex; gap: 6px; }
.choice button[aria-pressed="true"] { background: #24382f; border-color: #d4a017; }

.metrics { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.metrics th, .metrics td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.metrics th:first-child, .metrics td:first-child { text-align: left; }

details { margin-top: 8px; }
summary { cursor: pointer; color: var(--muted); }

.measure-group { margin: 8px 0; }
.measure-group h3 { margin: 0 0 4px; font-size: 13px; color: #c5d5cc; }
.measure-group li { font-size: 13px; }

#integrity {
  display: none;
  margin-top: 8px;
  color: #ffd0c8;
  background: #4a1d1a;
  border-radius: 10px;
  padding: 8px 10px;
}

footer {
  padding: 0 18px 28px;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #canvas-wrap { height: 58vh; min-height: 340px; }
  .legend { display: none; }
  .stage-head h1 { font-size: 24px; }
  aside { position: static; max-height: none; }
}

@media (min-width: 901px) {
  aside { position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; }
}
