* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #f7efe5, #eadbc6);
  color: #2f2216;
}

.page { padding: 14px; }

.hero,
.panel,
.stat,
.modal-card {
  background: rgba(255, 250, 244, 0.94);
  border: 1px solid rgba(108, 68, 29, 0.14);
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(78, 48, 17, 0.1);
}

.hero {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  align-items: start;
}

.hero.compact h1 {
  font-size: 22px;
}

.hero.collapsed .hero-detail {
  display: none;
}

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

.hero-copy {
  min-width: 0;
  flex: 1 1 auto;
}

h1,
h2,
h3 {
  margin: 0;
}

.muted {
  color: #6d5846;
  line-height: 1.45;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 10px;
}

.stat {
  padding: 12px;
  text-align: center;
}

.stat span {
  display: block;
  font-size: 24px;
  font-weight: 700;
}

.toolbar,
.panel {
  margin-top: 12px;
  padding: 16px;
}

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

.root-filter-group {
  min-width: min(820px, 100%);
}

.root-filter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.tree-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
}

.zoom-actions {
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  margin-top: 12px;
}

.side-column {
  display: grid;
  gap: 12px;
  align-self: start;
}

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

.list-panel,
.anniversary-panel {
  margin-top: 0;
}

.list-panel .panel-header h2 {
  white-space: nowrap;
}

.tree-wrap {
  margin-top: 14px;
  overflow: auto;
  border-radius: 22px;
  background: linear-gradient(180deg, #fff9f2, #f3e5d1);
  padding: 8px;
  cursor: grab;
  user-select: none;
}

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

#treeSvg {
  width: 100%;
  min-width: 1400px;
  min-height: 1200px;
  display: block;
  transform-origin: top center;
  transition: transform 0.18s ease;
}

.selected-card,
.flat-item {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(108, 68, 29, 0.12);
  background: rgba(255, 248, 240, 0.9);
}

.selected-card {
  display: grid;
  gap: 6px;
}

.button-stack,
.flat-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.flat-list {
  max-height: 30vh;
  overflow: auto;
}

.anniversary-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
  align-items: start;
  padding: 2px;
}

.anniversary-item {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(108, 68, 29, 0.12);
  background: #ffffff;
  min-height: 92px;
}

.flat-item {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.flat-item.active {
  border-color: #a85618;
  background: #f6dcc0;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #70350c;
}

.inline-field {
  min-width: 160px;
}

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

.mini-grid,
.more-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(117, 78, 36, 0.18);
  background: #fffaf5;
}

textarea {
  resize: vertical;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  background: #a85618;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn.secondary {
  background: #ead8c1;
  color: #70350c;
}

.btn.danger {
  background: #b42318;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #ead8c1;
  color: #70350c;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

#toggleHeroBtn {
  position: absolute;
  top: -10px;
  right: -10px;
  box-shadow: 0 8px 20px rgba(78, 48, 17, 0.14);
}

.list-header {
  margin-top: 14px;
}

.anniversary-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.anniversary-item div {
  font-size: 13px;
  line-height: 1.35;
}

.tree-node { cursor: pointer; }

.node-card {
  fill: #fff8f1;
  stroke: rgba(112, 53, 12, 0.2);
  stroke-width: 2;
}

.node-name {
  font-size: 21px;
  font-weight: 700;
}

.node-meta {
  font-size: 16px;
  fill: #6d5846;
}

.node-sub {
  font-size: 15px;
  fill: #8c6949;
}

.tree-node.active .node-card {
  fill: #f2c98d;
  stroke: #a85618;
  stroke-width: 3;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none; }

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(47, 34, 22, 0.38);
}

.modal-card {
  position: relative;
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 20px;
}

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

.more-fields {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px dashed rgba(117, 78, 36, 0.25);
  background: rgba(255, 249, 242, 0.9);
}

.more-fields summary {
  cursor: pointer;
  font-weight: 700;
  color: #6b3d14;
}

.more-grid {
  margin-top: 12px;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .tree-panel { min-height: 72vh; }
}

@media (max-width: 720px) {
  .page { padding: 12px; }

  .hero,
  .toolbar,
  .panel-header,
  .actions,
  .compact-header,
  .tree-tools,
  .hero-head {
    flex-direction: column;
    align-items: stretch;
  }

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

  .modal-card {
    width: calc(100vw - 12px);
  }
}
