:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #202124;
  --muted: #697077;
  --line: #d7d1c7;
  --accent: #2f6f73;
  --accent-strong: #23585c;
  --danger: #a43d3d;
  --shadow: 0 16px 40px rgba(42, 38, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.button {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button:active,
.button:active {
  transform: translateY(1px);
}

button.ghost,
.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

button.ghost:hover,
.button.ghost:hover {
  background: #ece6dc;
}

button.danger {
  color: var(--danger);
}

.app-header {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 22px clamp(16px, 3vw, 36px);
}

.app-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  line-height: 1;
  margin: 0;
}

.app-header p {
  color: var(--muted);
  margin: 8px 0 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

#importFile {
  inline-size: 1px;
  opacity: 0;
  position: absolute;
}

.app-shell {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  padding: 0 clamp(16px, 3vw, 36px) 36px;
}

.tree-panel,
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tree-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 130px);
  overflow: hidden;
  padding: 0;
}

.tree-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  padding: 10px;
}

.tree-toolbar output {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  min-width: 54px;
  text-align: center;
}

.zoom-button {
  font-size: 1.25rem;
  min-width: 40px;
  padding: 0;
}

.tree-viewport {
  cursor: grab;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.tree-viewport.dragging {
  cursor: grabbing;
}

.tree-canvas {
  left: 0;
  min-height: 100%;
  min-width: 100%;
  padding: 34px;
  position: absolute;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.tree {
  min-width: max-content;
  padding: 4px 14px 20px;
}

.tree ul {
  display: flex;
  gap: 18px;
  justify-content: center;
  list-style: none;
  margin: 0;
  padding: 26px 0 0;
  position: relative;
}

.tree li {
  align-items: center;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  position: relative;
}

.tree li::before,
.tree li::after {
  border-top: 2px solid var(--line);
  content: "";
  height: 18px;
  position: absolute;
  top: 0;
  width: 50%;
}

.tree li::before {
  border-right: 2px solid var(--line);
  right: 50%;
}

.tree li::after {
  border-left: 2px solid var(--line);
  left: 50%;
}

.tree li:only-child::before,
.tree li:only-child::after,
.tree > ul > li::before,
.tree > ul > li::after {
  display: none;
}

.tree li:first-child::before,
.tree li:last-child::after {
  border-top: 0;
}

.tree li:only-child {
  padding-top: 0;
}

.tree ul ul::before {
  border-left: 2px solid var(--line);
  content: "";
  height: 26px;
  left: 50%;
  position: absolute;
  top: 0;
}

.member-card {
  background: #ffffff;
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(39, 37, 31, 0.11);
  display: grid;
  gap: 8px;
  inline-size: 180px;
  padding: 10px;
}

.member-card.selected {
  border-color: var(--accent);
}

.member-main {
  align-items: flex-start;
  background: transparent;
  border: 0;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 64px;
  padding: 0;
  text-align: left;
}

.member-main:hover {
  background: transparent;
  color: var(--accent-strong);
}

.member-name {
  font-size: 1rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.member-meta {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.member-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 40px;
}

.icon-button {
  min-height: 34px;
  padding: 0 10px;
}

.add-child {
  font-size: 1.3rem;
  padding: 0;
}

.editor-panel {
  align-self: start;
  padding: 20px;
  position: sticky;
  top: 16px;
}

.panel-header,
.form-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panel-header h2 {
  font-size: 1.2rem;
  margin: 0;
}

form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.9rem;
  font-weight: 700;
  gap: 7px;
}

input,
textarea {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  inline-size: 100%;
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible,
.button:focus-visible {
  outline: 3px solid rgba(47, 111, 115, 0.24);
  outline-offset: 2px;
}

.help-text {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-top: 18px;
  padding-top: 16px;
}

@media (max-width: 860px) {
  .app-header,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .tree-panel {
    min-height: 52vh;
  }

  .editor-panel {
    position: static;
  }
}

@media (max-width: 520px) {
  .app-header,
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tree-panel {
    min-height: 56vh;
  }

  .tree-canvas {
    padding: 22px 12px;
  }

  button,
  .button {
    min-height: 38px;
    padding: 0 10px;
  }
}
