:root {
  color-scheme: light;
  --ink: #24160f;
  --muted: rgba(36, 22, 15, 0.62);
  --paper: #fff7e6;
  --paper-edge: #eadcc1;
  --pin-red: #cf3f35;
  --pin-blue: #386b8f;
  --pin-green: #607b49;
  --shadow: rgba(42, 24, 12, 0.34);
}

* {
  box-sizing: border-box;
}

.tree-html,
.tree-page {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.tree-page {
  color: var(--ink);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.tree-page button,
.tree-page input,
.tree-page select,
.tree-page textarea {
  font: inherit;
}

.tree-page [hidden] {
  display: none !important;
}

.tree-app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 231, 171, 0.55), transparent 30rem),
    radial-gradient(circle at 82% 76%, rgba(139, 87, 38, 0.26), transparent 34rem),
    #b87943;
}

.tree-board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background:
    linear-gradient(30deg, rgba(255,255,255,0.04) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,0.04) 87.5%),
    linear-gradient(150deg, rgba(255,255,255,0.04) 12%, transparent 12.5%, transparent 87%, rgba(0,0,0,0.05) 87.5%),
    linear-gradient(30deg, rgba(0,0,0,0.035) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,0.03) 87.5%),
    linear-gradient(150deg, rgba(0,0,0,0.04) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,0.03) 87.5%),
    #a76433;
  background-position: 0 0, 0 0, 28px 48px, 28px 48px;
  background-size: 56px 96px;
}

.tree-board.is-panning {
  cursor: grabbing;
}

.tree-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 5600px;
  height: 3600px;
  transform-origin: 0 0;
}

.tree-links,
.tree-labels,
.tree-nodes {
  position: absolute;
  inset: 0;
}

.tree-links {
  inset: auto;
  top: -50000px;
  left: -50000px;
  width: 100000px;
  height: 100000px;
  overflow: visible;
  pointer-events: none;
}

.tree-page.is-dragging-polaroids .tree-polaroid {
  transition: none;
}

.tree-link {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.tree-link--family {
  stroke: rgba(70, 42, 24, 0.82);
  stroke-width: 3.4;
}

.tree-link--partner {
  stroke-width: 4.2;
  stroke-dasharray: 8 10;
}

.tree-link--map {
  stroke-width: 3.1;
  filter: drop-shadow(0 2px 2px rgba(45, 24, 12, 0.18));
}

.tree-link--map-oneway {
  stroke-width: 4.1;
  filter: drop-shadow(0 3px 3px rgba(45, 24, 12, 0.24));
}

.tree-link--map-reciprocal {
  stroke-width: 3.2;
}

.tree-link--inferred {
  stroke: rgba(40, 78, 104, 0.52);
  stroke-width: 2.1;
  stroke-dasharray: 4 10;
  filter: drop-shadow(0 1px 1px rgba(45, 24, 12, 0.12));
}

.tree-link--inferred-sibling,
.tree-link--inferred-cousin {
  stroke: rgba(76, 98, 54, 0.5);
}

.tree-link--inferred-avuncular {
  stroke: rgba(123, 76, 131, 0.5);
}

.tree-link--custom {
  stroke-dasharray: 10 8;
}

.tree-edge-label,
.tree-family-mark {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tree-edge-label {
  display: inline-flex;
  gap: 0.42rem;
  align-items: center;
  max-width: 18rem;
  padding: 0.34rem 0.5rem;
  border: 1px solid rgba(58, 34, 21, 0.15);
  border-radius: 999px;
  background: rgba(255, 247, 230, 0.86);
  box-shadow: 0 6px 14px rgba(42, 24, 12, 0.16);
  color: rgba(42, 24, 12, 0.78);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tree-edge-label--inferred {
  border-style: dashed;
  border-color: rgba(40, 78, 104, 0.26);
  background: rgba(232, 241, 238, 0.78);
  color: rgba(30, 58, 74, 0.78);
  font-size: 0.62rem;
}

.tree-family-mark {
  display: grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: rgba(255, 247, 230, 0.88);
  box-shadow: 0 5px 12px rgba(42, 24, 12, 0.16);
}

.tree-relation-icon {
  width: 1.08rem;
  height: 1.08rem;
  color: var(--relation-color, #7d3d2f);
}

.tree-polaroid {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  --polaroid-width: 10.8rem;
  --polaroid-padding: 0.58rem;
  --photo-size: calc(var(--polaroid-width) - var(--polaroid-padding) * 2);
  width: 10.8rem;
  padding: var(--polaroid-padding) var(--polaroid-padding) 1rem;
  background: linear-gradient(180deg, #fffdf6, #f3ead7);
  border: 1px solid rgba(73, 43, 24, 0.12);
  box-shadow: 0 18px 32px rgba(52, 30, 14, 0.28), 0 2px 3px rgba(52, 30, 14, 0.14);
  cursor: grab;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0) translate(-50%, -50%) rotate(var(--tilt, 0deg));
  transform-origin: 50% 42%;
  transition: none;
  contain: layout paint style;
  will-change: transform;
}

.tree-polaroid::before {
  position: absolute;
  top: -0.78rem;
  left: 50%;
  width: 4.2rem;
  height: 1.18rem;
  background: rgba(239, 218, 170, 0.62);
  box-shadow: 0 2px 8px rgba(52, 30, 14, 0.14);
  content: "";
  transform: translateX(-50%) rotate(calc(var(--tilt, 0deg) * -0.35));
}

.tree-polaroid.is-dragging {
  z-index: 40;
  cursor: grabbing;
}

.tree-polaroid.is-selected {
  box-shadow: 0 24px 44px rgba(52, 30, 14, 0.34), 0 0 0 3px rgba(255, 246, 218, 0.55);
}

.tree-polaroid.is-multi-selected {
  box-shadow: 0 24px 44px rgba(52, 30, 14, 0.34), 0 0 0 4px rgba(56, 107, 143, 0.44), 0 0 0 8px rgba(255, 246, 218, 0.42);
}

.tree-polaroid__photo {
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--photo-size);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 42%),
    #d2c7ad;
}

.tree-polaroid__photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.tree-polaroid__photo span {
  color: rgba(47, 31, 22, 0.68);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.08em;
  pointer-events: none;
}

.tree-polaroid h3 {
  margin: 0.58rem 0 0;
  color: #2a180e;
  font-family: "Caveat", cursive;
  font-size: 1.42rem;
  font-weight: 700;
  line-height: 0.95;
  text-align: center;
  overflow-wrap: anywhere;
}

.tree-polaroid__birth {
  margin: 0.18rem 0 0;
  color: rgba(42, 24, 14, 0.48);
  font-family: "Caveat", cursive;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.tree-empty {
  position: absolute;
  top: 820px;
  left: 980px;
  z-index: 3;
  width: min(36rem, 78vw);
  padding: 1.2rem 1.3rem;
  border-radius: 0.2rem;
  background: #fff2bf;
  box-shadow: 0 16px 26px rgba(52, 30, 14, 0.22);
  transform: rotate(-2deg);
}

.tree-empty p {
  margin: 0 0 0.45rem;
  color: rgba(42, 24, 14, 0.58);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tree-empty h1 {
  margin: 0;
  color: #2a180e;
  font-family: "Caveat", cursive;
  font-size: clamp(2.4rem, 6vw, 4.6rem);
  line-height: 0.92;
}

.tree-empty span {
  display: block;
  max-width: 30rem;
  margin-top: 0.72rem;
  color: rgba(42, 24, 14, 0.68);
  font-weight: 700;
  line-height: 1.45;
}

.tree-topbar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  left: 1rem;
  z-index: 30;
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 0.72rem;
  align-items: start;
  pointer-events: none;
}

.tree-home,
.tree-note,
.tree-actions,
.tree-topbar p {
  border: 1px solid rgba(70, 42, 24, 0.12);
  border-radius: 0.3rem;
  background: rgba(255, 248, 225, 0.88);
  box-shadow: 0 10px 22px rgba(52, 30, 14, 0.18);
  pointer-events: auto;
}

.tree-actions {
  display: flex;
  gap: 0.38rem;
  padding: 0.36rem;
  transform: rotate(0.4deg);
}

.tree-actions button {
  min-height: 2.2rem;
  padding: 0 0.72rem;
  border: 0;
  border-radius: 0.22rem;
  background: rgba(122, 73, 42, 0.14);
  color: #2b1a10;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.tree-actions button:hover,
.tree-actions button:focus-visible {
  background: rgba(122, 73, 42, 0.24);
}

.tree-home {
  padding: 0.68rem 0.78rem;
  color: #2b1a10;
  font-size: 0.78rem;
  font-weight: 800;
  text-decoration: none;
  text-transform: uppercase;
}

.tree-note {
  display: grid;
  gap: 0.08rem;
  padding: 0.55rem 0.8rem;
  transform: rotate(-1deg);
}

.tree-note strong {
  font-family: "Caveat", cursive;
  font-size: 1.55rem;
  line-height: 0.95;
}

.tree-note span,
.tree-topbar p {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.tree-topbar p {
  justify-self: end;
  max-width: min(42rem, 55vw);
  margin: 0;
  padding: 0.7rem 0.85rem;
  line-height: 1.35;
  transform: rotate(0.7deg);
}

.tree-legend {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 32;
  width: min(21rem, calc(100vw - 2rem));
  max-height: min(44vh, 30rem);
  overflow: auto;
  padding: 0.82rem 0.92rem;
  border: 1px solid rgba(70, 42, 24, 0.14);
  border-radius: 0.34rem;
  background: rgba(255, 248, 225, 0.9);
  box-shadow: 0 14px 30px rgba(52, 30, 14, 0.22);
  pointer-events: none;
  transform: rotate(-0.5deg);
}

.tree-legend h2 {
  margin: 0 0 0.54rem;
  color: #2a180e;
  font-family: "Caveat", cursive;
  font-size: 1.7rem;
  line-height: 0.95;
}

.tree-legend__rows {
  display: grid;
  gap: 0.42rem;
}

.tree-legend__row {
  display: grid;
  grid-template-columns: 2.65rem 1fr;
  gap: 0.5rem;
  align-items: center;
  color: rgba(42, 24, 12, 0.76);
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.22;
}

.tree-legend__line {
  position: relative;
  display: block;
  width: 2.45rem;
  height: 0;
  border-top: 3px solid rgba(64, 39, 23, 0.8);
}

.tree-legend__line--partner {
  border-top-width: 4px;
  border-top-style: dashed;
}

.tree-legend__line--map {
  border-color: rgba(80, 70, 130, 0.78);
}

.tree-legend__line--oneway {
  border-color: rgba(80, 70, 130, 0.9);
  border-top-width: 4px;
}

.tree-legend__line--oneway::after {
  position: absolute;
  top: -0.37rem;
  right: -0.08rem;
  width: 0;
  height: 0;
  border-top: 0.36rem solid transparent;
  border-bottom: 0.36rem solid transparent;
  border-left: 0.62rem solid currentColor;
  color: rgba(80, 70, 130, 0.9);
  content: "";
}

.tree-legend__line--inferred {
  border-color: rgba(40, 78, 104, 0.56);
  border-top-width: 2px;
  border-top-style: dashed;
}

.tree-legend__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.45rem;
}

.tree-legend__custom-dot {
  display: block;
  width: 1rem;
  height: 1rem;
  border: 2px dashed rgba(74, 43, 25, 0.72);
  border-radius: 50%;
}

.tree-context-menu {
  position: fixed;
  z-index: 80;
  min-width: 15rem;
  padding: 0.42rem;
  border: 1px solid rgba(65, 38, 22, 0.16);
  border-radius: 0.72rem;
  background: rgba(255, 250, 236, 0.96);
  box-shadow: 0 18px 38px rgba(52, 30, 14, 0.28);
  backdrop-filter: blur(12px);
}

.tree-context-menu button {
  display: block;
  width: 100%;
  padding: 0.58rem 0.68rem;
  border: 0;
  border-radius: 0.48rem;
  background: transparent;
  color: #2a180e;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  text-align: left;
}

.tree-context-menu button:hover,
.tree-context-menu button:focus-visible {
  background: rgba(183, 117, 63, 0.16);
}

.tree-context-menu hr {
  height: 1px;
  margin: 0.3rem 0;
  border: 0;
  background: rgba(65, 38, 22, 0.12);
}

.tree-dialog {
  width: min(31rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 0;
  border-radius: 0.4rem;
  background: #fff8e8;
  box-shadow: 0 26px 70px rgba(35, 20, 10, 0.38);
  color: #25170f;
}

.tree-dialog--small {
  width: min(26rem, calc(100vw - 2rem));
}

.tree-dialog::backdrop {
  background: rgba(52, 30, 14, 0.38);
  backdrop-filter: blur(3px);
}

.tree-dialog form {
  display: grid;
  gap: 0.82rem;
  margin: 0;
  padding: 1.1rem;
}

.tree-dialog header p {
  margin: 0 0 0.2rem;
  color: rgba(42, 24, 14, 0.55);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tree-dialog h2 {
  margin: 0;
  color: #2a180e;
  font-family: "Caveat", cursive;
  font-size: 2.3rem;
  line-height: 0.92;
}

.tree-dialog label {
  display: grid;
  gap: 0.32rem;
  color: rgba(42, 24, 14, 0.66);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tree-dialog label em {
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
}

.tree-dialog input,
.tree-dialog select,
.tree-dialog textarea {
  width: 100%;
  min-height: 2.45rem;
  border: 1px solid rgba(68, 39, 22, 0.2);
  border-radius: 0.28rem;
  background: rgba(255, 255, 255, 0.58);
  color: #24160f;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.tree-dialog input,
.tree-dialog select {
  padding: 0 0.68rem;
}

.tree-dialog textarea {
  padding: 0.64rem 0.68rem;
  resize: vertical;
}

.tree-check {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.tree-check input {
  width: 1rem;
  min-height: 1rem;
  accent-color: #8f4f2e;
}

.tree-direction-box {
  display: grid;
  gap: 0.72rem;
  padding: 0.72rem;
  border: 1px dashed rgba(68, 39, 22, 0.2);
  border-radius: 0.32rem;
}

.tree-dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.62rem;
  margin-top: 0.2rem;
}

.tree-dialog button {
  min-height: 2.4rem;
  padding: 0 0.85rem;
  border: 1px solid rgba(68, 39, 22, 0.16);
  border-radius: 999px;
  background: #f0dfbb;
  color: #2a180e;
  cursor: pointer;
  font-weight: 900;
}

.tree-dialog button[type="submit"] {
  background: #7b4b2c;
  color: #fff8e8;
}

@media (max-width: 760px) {
  .tree-topbar {
    grid-template-columns: auto 1fr;
  }

  .tree-actions {
    justify-self: end;
  }

  .tree-topbar p {
    grid-column: 1 / -1;
    justify-self: stretch;
    max-width: none;
  }

  .tree-polaroid {
    --polaroid-width: 9.2rem;
    width: 9.2rem;
  }
}
