:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --ink: #1e2825;
  --muted: #68736f;
  --line: #d8dfda;
  --brand: #2e7d70;
  --brand-2: #dcefe9;
  --accent: #b85f32;
  --danger: #b94a48;
  --warn: #b8802d;
  --shadow: 0 18px 42px rgba(29, 48, 42, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  margin-top: 2px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.top-actions,
.row,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page {
  flex: 1;
}

.home {
  max-width: 1040px;
  margin: 0 auto;
  padding: 52px 24px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 42px;
  align-items: center;
}

.intro h1 {
  font-size: clamp(36px, 5vw, 58px);
  line-height: 1.06;
  margin: 0 0 18px;
  letter-spacing: 0;
}

.intro p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.72;
  margin: 0 0 28px;
}

.intro .release-note {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.65;
  margin: -8px 0 24px;
  padding: 12px 14px;
}

.save-guide {
  display: grid;
  gap: 8px;
  margin: -8px 0 22px;
}

.save-guide div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: center;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
}

.save-guide strong {
  color: var(--ink);
  font-size: 13px;
}

.save-guide span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.workflow-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 24px;
}

.workflow-guide div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 108px;
  padding: 13px;
}

.workflow-guide span,
.quick-steps span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-2);
  color: var(--brand);
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}

.workflow-guide strong {
  display: block;
  font-size: 15px;
  margin: 10px 0 5px;
}

.workflow-guide em {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-style: normal;
  line-height: 1.55;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 24px;
}

.entry-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.entry-panel h2,
.section-title {
  margin: 0 0 8px;
  font-size: 20px;
}

.entry-panel p,
.hint {
  color: var(--muted);
  margin: 0 0 18px;
  line-height: 1.55;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.template-button,
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
}

.template-button:hover,
.card:hover {
  border-color: #9bc7bd;
}

.template-button strong {
  display: block;
  margin-bottom: 4px;
}

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

.primary,
.secondary,
.ghost,
.icon-button {
  border-radius: 8px;
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.secondary {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid #c8dcd5;
}

.ghost {
  background: transparent;
  color: var(--muted);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
}

.wizard {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.steps {
  border-right: 1px solid var(--line);
  padding: 24px;
  background: #fbfcfa;
}

.step-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.step-button.active {
  background: var(--brand-2);
  color: var(--ink);
  font-weight: 700;
}

.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e7ece8;
  font-size: 13px;
}

.step-button.active .step-number {
  background: var(--brand);
  color: #fff;
}

.form-pane {
  padding: 34px 42px 90px;
  max-width: 960px;
}

.form-pane h1 {
  margin: 0 0 8px;
  font-size: 30px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field.full {
  grid-column: 1 / -1;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field label {
  font-weight: 700;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 82px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(46, 125, 112, 0.14);
}

.repeat-list {
  display: grid;
  gap: 12px;
  margin: 22px 0;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.mini-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.mini-card-title {
  font-weight: 760;
}

.checkbox-grid,
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
}

.chip input {
  width: auto;
  min-height: auto;
}

.wizard-footer {
  position: fixed;
  left: 280px;
  right: 0;
  bottom: 0;
  min-height: 70px;
  padding: 14px 42px;
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
  display: flex;
  justify-content: space-between;
}

.workspace {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 330px;
  height: calc(100vh - 64px);
}

.toolbox,
.inspector {
  background: #fbfcfa;
  border-color: var(--line);
  overflow: auto;
}

.toolbox {
  border-right: 1px solid var(--line);
  padding: 18px;
}

.inspector {
  border-left: 1px solid var(--line);
  padding: 18px;
}

.toolbox .primary,
.toolbox .secondary {
  width: 100%;
  margin-bottom: 10px;
}

.quick-steps {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.quick-steps div {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 8px;
  grid-template-columns: 24px minmax(0, 1fr);
  line-height: 1.4;
  padding: 9px;
}

.canvas-wrap {
  min-width: 0;
  position: relative;
  overflow: auto;
  cursor: grab;
  background:
    linear-gradient(rgba(40, 62, 56, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40, 62, 56, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
}

.canvas-wrap.is-panning {
  cursor: grabbing;
}

.chart-svg {
  width: 1800px;
  height: 1100px;
  display: block;
}

.legend {
  margin-top: 22px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-subtitle {
  font-weight: 760;
  color: var(--ink);
  margin-top: 8px;
}

.legend-line {
  width: 34px;
  height: 18px;
  display: inline-block;
  position: relative;
  flex: 0 0 34px;
}

.legend-line::before,
.legend-line::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 8px;
  border-top: 2px solid #38443f;
}

.legend-line.structural::before {
  border-color: #38443f;
}

.legend-line.separated::before,
.legend-line.divorced::before {
  border-color: #38443f;
}

.legend-line.separated::after,
.legend-line.divorced::after {
  width: 14px;
  left: 11px;
  right: auto;
  top: 8px;
  border-color: #38443f;
  transform: rotate(-58deg);
}

.legend-line.divorced {
  background:
    linear-gradient(122deg, transparent 40%, #38443f 42%, #38443f 48%, transparent 50%) 15px 2px / 14px 14px no-repeat;
}

.legend-line.cohabiting::before {
  border-color: #38443f;
  border-top-style: dashed;
}

.legend-line.close::before,
.legend-line.close::after {
  border-color: #2f5df5;
  border-width: 3px;
}

.legend-line.close::before {
  top: 5px;
}

.legend-line.close::after {
  top: 12px;
}

.legend-line.fused::before,
.legend-line.fused::after {
  border-color: #df2b2b;
  border-width: 3px;
}

.legend-line.fused {
  background: linear-gradient(#df2b2b, #df2b2b) 0 8px / 34px 3px no-repeat;
}

.legend-line.fused::before {
  top: 3px;
}

.legend-line.fused::after {
  top: 13px;
}

.legend-line.distant::before {
  border-color: #df2b2b;
  border-top-style: dashed;
  border-width: 3px;
}

.legend-line.cutoff::before {
  border-color: #df2b2b;
  border-width: 3px;
}

.legend-line.cutoff::after {
  border-color: #df2b2b;
  border-width: 0 3px 0 3px;
  height: 18px;
  width: 10px;
  top: 0;
  left: 12px;
}

.legend-line.hostile::before {
  border: 0;
  height: 14px;
  top: 2px;
  background: linear-gradient(135deg, transparent 0 35%, #df2b2b 36% 44%, transparent 45% 55%, #df2b2b 56% 64%, transparent 65%);
  background-size: 12px 14px;
}

.legend-line.focused::before {
  border-color: #df2b2b;
  border-width: 3px;
}

.legend-line.focused::after {
  width: 0;
  height: 0;
  left: auto;
  right: 0;
  top: 3px;
  border: 6px solid transparent;
  border-left-color: #df2b2b;
}

.person-node {
  cursor: grab;
}

.node-shape {
  fill: #fff;
  stroke: #33413c;
  stroke-width: 2;
}

.pregnancy-shape {
  stroke-width: 2.2;
}

.person-node.focus .node-shape {
  fill: #fff;
  stroke: #33413c;
  stroke-width: 3;
}

.node-inner-shape {
  fill: none;
  stroke: #33413c;
  stroke-width: 2;
  pointer-events: none;
}

.death-mark,
.miscarriage-mark {
  stroke: #33413c;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
}

.node-death-year {
  font-size: 13px;
  fill: var(--ink);
  font-weight: 700;
  text-anchor: middle;
}

.node-age {
  font-size: 14px;
  fill: var(--ink);
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.node-label {
  font-size: 13px;
  fill: var(--ink);
  font-weight: 700;
  text-anchor: middle;
}

.node-sub {
  font-size: 12px;
  fill: var(--muted);
  text-anchor: middle;
}

.tag-pill {
  fill: #fff4e8;
  stroke: #f1d1b6;
}

.tag-text {
  font-size: 10px;
  fill: #80502f;
  text-anchor: middle;
  font-weight: 700;
}

.event-dot {
  fill: #f8e7df;
  stroke: var(--accent);
  stroke-width: 1.5;
}

.event-dot-text {
  fill: #7d3d23;
  font-size: 10px;
  font-weight: 800;
  text-anchor: middle;
}

.edge {
  stroke: #3e4a45;
  stroke-width: 2;
  fill: none;
}

.edge.parent_child {
  stroke-width: 2;
}

.edge.separated,
.edge.divorced {
  stroke: #3e4a45;
}

.edge.remarried {
  stroke: #3e4a45;
}

.edge.cohabiting {
  stroke: #3e4a45;
  stroke-dasharray: 12 7;
}

.edge.dating {
  stroke: #3e4a45;
  stroke-dasharray: 2 7;
  stroke-linecap: round;
}

.edge.former_partner,
.edge.never_together {
  stroke: #3e4a45;
  stroke-dasharray: 4 6;
}

.edge.unknown {
  stroke: #3e4a45;
  stroke-dasharray: 8 7;
}

.separation-mark,
.divorce-mark {
  stroke: #3e4a45;
  stroke-width: 3;
}

.widowed-mark line {
  stroke: #3e4a45;
  stroke-width: 3;
}

.edge.emotional.close,
.edge.emotional.supportive {
  stroke: #2e7d70;
  stroke-width: 3;
}

.edge.emotional.conflict,
.edge.emotional.stressful {
  stroke: var(--danger);
  stroke-width: 3;
}

.edge.emotional.distant,
.edge.emotional.cutoff {
  stroke: #7b8581;
  stroke-dasharray: 7 6;
}

.edge.interpersonal.close {
  stroke: #2f5df5;
  stroke-width: 3;
}

.edge.interpersonal.fused {
  stroke: #df2b2b;
  stroke-width: 3;
}

.edge.interpersonal.hostile,
.edge.interpersonal.close_hostile,
.edge.interpersonal.emotional_abuse,
.edge.interpersonal.physical_abuse,
.edge.interpersonal.sexual_abuse {
  stroke: #df2b2b;
  stroke-width: 3;
  fill: none;
}

.edge.interpersonal.distant {
  stroke: #df2b2b;
  stroke-dasharray: 10 9;
  stroke-width: 3;
}

.edge.interpersonal.cutoff,
.edge.interpersonal.cutoff-bar {
  stroke: #df2b2b;
  stroke-width: 3;
}

.edge.interpersonal.focused_on {
  stroke: #df2b2b;
  stroke-width: 3;
}

.edge.interpersonal.functional {
  stroke: var(--accent);
  stroke-dasharray: 6 7;
  stroke-width: 2;
  opacity: 0.68;
}

.interpersonal-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  cursor: pointer;
}

.interpersonal-group.selected .edge.interpersonal {
  filter: drop-shadow(0 0 4px rgba(46, 125, 112, 0.55));
  stroke-width: 4;
}

.relation-arrow {
  stroke: #df2b2b;
  stroke-width: 3;
}

.relation-arrow.open {
  fill: #fff;
}

.relation-arrow.filled {
  fill: #df2b2b;
}

.relation-arrow.focused_on {
  fill: #df2b2b;
}

.edge.functional {
  stroke: var(--accent);
  stroke-dasharray: 5 5;
}

.edge-label {
  font-size: 11px;
  fill: #3e4a45;
  text-anchor: middle;
  font-weight: 700;
}

.chart-credit {
  fill: #7b8581;
  font-size: 12px;
  text-anchor: end;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.panel-group {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.panel-group:last-child {
  border-bottom: 0;
}

.event-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.event-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.event-card-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.event-card-head strong {
  font-size: 14px;
}

.summary-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.inspector-guide {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.inspector-guide div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.inspector-guide span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 3px;
}

.inspector-guide strong {
  color: var(--ink);
  display: block;
  font-size: 13px;
  line-height: 1.45;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.summary-item strong {
  color: var(--ink);
}

.structure-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.family-unit-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.family-unit-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.family-unit-row .field {
  gap: 5px;
}

.family-unit-row select {
  min-height: 38px;
}

.union-year-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.family-unit-row strong,
.family-unit-row span {
  display: block;
}

.family-unit-row span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.danger-zone {
  background: #fffafa;
  border: 1px solid #f0d6d4;
  border-radius: 8px;
  padding: 14px;
}

.danger-button {
  color: var(--danger);
  border-color: #efc7c4;
  background: #fff;
  width: 100%;
}

.danger-button:disabled {
  color: #a8adab;
  cursor: not-allowed;
  background: #f3f5f3;
  border-color: var(--line);
}

.mode-toggle {
  display: inline-flex;
  background: #edf2ef;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
}

.mode-toggle button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.mode-toggle button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(31, 48, 43, 0.08);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #25332e;
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  z-index: 30;
}

.export-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: min(520px, calc(100vw - 44px));
  max-height: min(560px, calc(100vh - 100px));
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 35;
}

.export-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.export-link {
  width: 100%;
  text-decoration: none;
  margin: 8px 0 12px;
}

.export-save {
  background: #f4f7f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.55;
  margin: 0 0 12px;
  padding: 10px 12px;
}

.export-save code {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.export-save.pending {
  color: var(--muted);
}

.export-save.error {
  background: #fff3f0;
  border-color: #f1c1b8;
  color: #9f3432;
}

.export-copy textarea {
  min-height: 180px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

@media (max-width: 980px) {
  .intro,
  .wizard,
  .workspace {
    grid-template-columns: 1fr;
  }

  .steps,
  .toolbox,
  .inspector {
    border: 0;
  }

  .steps {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 14px;
  }

  .step-button {
    min-width: 190px;
  }

  .form-pane {
    padding: 24px 18px 90px;
  }

  .form-grid,
  .template-grid {
    grid-template-columns: 1fr;
  }

  .wizard-footer {
    left: 0;
    padding: 12px 18px;
  }

  .workspace {
    height: auto;
  }

  .canvas-wrap {
    height: 620px;
  }
}
