:root {
  color-scheme: dark;
  --background: #151512;
  --surface: #22221e;
  --surface-raised: #2c2c27;
  --surface-soft: #373730;
  --text: #f6f3e9;
  --muted: #bdb8aa;
  --accent: #d3a34a;
  --accent-strong: #efbd5d;
  --accent-ink: #21190c;
  --border: rgba(255, 255, 255, 0.12);
  --danger: #ff9d8e;
  --success: #92d3a3;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.28);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(211, 163, 74, 0.16), transparent 30rem),
    var(--background);
  color: var(--text);
}

.tree-page {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

.site-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  min-height: 116px;
  padding: 1.5rem clamp(1rem, 4vw, 3.5rem);
  border-bottom: 1px solid var(--border);
  background: rgba(21, 21, 18, 0.9);
}

.site-header h1,
.person-panel h2,
.proposal-card h1,
.help-dialog h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.site-header h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.header-actions {
  display: flex;
  align-items: end;
  gap: 0.75rem;
}

.help-button-icon {
  display: none;
}

.person-search {
  display: flex;
  align-items: end;
  gap: 0.55rem;
}

.search-field {
  display: grid;
  gap: 0.3rem;
}

.search-field label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.search-field label span {
  font-weight: 500;
}

.search-field input {
  width: clamp(130px, 13vw, 190px);
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface);
  color: var(--text);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.header-copy {
  max-width: 46rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    transform 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
.dialog-close:focus-visible,
.panel-close:focus-visible,
input:focus-visible,
textarea:focus-visible,
.drop-zone:focus-visible {
  outline: 3px solid rgba(239, 189, 93, 0.45);
  outline-offset: 2px;
}

.button-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-secondary {
  border-color: var(--border);
  background: var(--surface-raised);
  color: var(--text);
}

.button-full {
  width: 100%;
}

.button[disabled] {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.tree-layout {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  min-height: 0;
  overflow: hidden;
}

.tree-layout.panel-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.chart-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.family-chart {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    #20201d;
  background-size: 28px 28px;
  color: #fff;
}

.chart-message {
  position: absolute;
  z-index: 5;
  inset: 1rem auto auto 50%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  transform: translateX(-50%);
}

.chart-message[hidden] {
  display: none;
}

.mobile-card-data-button {
  display: none;
}

.person-panel {
  position: relative;
  z-index: 4;
  min-height: 0;
  padding: clamp(2.75rem, 4vw, 3.25rem) clamp(1.25rem, 3vw, 2rem)
    clamp(1.25rem, 3vw, 2rem);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: rgba(34, 34, 30, 0.98);
  box-shadow: var(--shadow);
}

.panel-close {
  position: absolute;
  z-index: 2;
  top: 0.75rem;
  right: 0.75rem;
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 1.55rem;
  line-height: 1;
}

.panel-close:hover {
  border-color: var(--accent);
}

.person-panel h2 {
  margin-bottom: 1.25rem;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.person-avatar {
  margin: 0 0 1.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface-soft);
}

.person-avatar img {
  display: block;
  width: 100%;
  max-height: min(48vh, 520px);
  object-fit: contain;
}

.search-results-summary {
  margin: -0.65rem 0 1.25rem;
  color: var(--muted);
  line-height: 1.5;
}

.search-results {
  display: grid;
  gap: 0.7rem;
}

.search-result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: left;
}

.search-result:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.search-result-person {
  color: var(--accent-strong);
  font-weight: 800;
}

.search-result-separator {
  color: var(--muted);
}

.search-empty {
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  color: var(--muted);
  line-height: 1.6;
}

.privacy-note {
  color: var(--muted);
  line-height: 1.6;
}

.person-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem 1rem;
  margin: 0 0 1.5rem;
  padding: 1rem 0;
  border-block: 1px solid var(--border);
}

.person-details dt {
  color: var(--muted);
}

.person-details dd {
  margin: 0;
  font-weight: 700;
}

.person-biography {
  margin: 0 0 1.5rem;
  padding: 1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 0.65rem 0.65rem 0;
  background: rgba(255, 255, 255, 0.035);
}

.person-biography h3 {
  margin: 0 0 0.65rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.person-biography p {
  margin: 0;
  color: var(--text);
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.relation-group {
  margin: 0 0 1.25rem;
}

.relation-group h3 {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.relation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.relation-button {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
}

.relation-button:hover {
  border-color: var(--accent);
}

.privacy-note {
  margin: 0.9rem 0 0;
  font-size: 0.82rem;
  text-align: center;
}

.help-dialog {
  width: min(92vw, 520px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
}

.help-dialog form {
  position: relative;
  padding: 2rem;
}

.help-dialog ul {
  margin: 1.25rem 0 1.75rem;
  padding-left: 1.25rem;
  color: var(--muted);
  line-height: 1.7;
}

.dialog-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 1.5rem;
}

.proposal-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.proposal-shell {
  width: min(100%, 760px);
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.proposal-card {
  padding: clamp(1.25rem, 5vw, 3rem);
  border: 1px solid var(--border);
  border-radius: 1.2rem;
  background: rgba(34, 34, 30, 0.97);
  box-shadow: var(--shadow);
}

.proposal-card h1 {
  margin-bottom: 0.6rem;
  font-size: clamp(2rem, 6vw, 3.7rem);
}

.proposal-intro {
  margin: 0 0 1.5rem;
  color: var(--muted);
  line-height: 1.6;
}

.published-person {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.75rem;
  padding: 1rem;
  border-left: 3px solid var(--accent);
  background: var(--surface-raised);
}

.published-person strong {
  font-size: 1.15rem;
}

.published-person span {
  color: var(--muted);
}

.proposal-form {
  display: grid;
  gap: 1.35rem;
}

.form-field {
  display: grid;
  gap: 0.5rem;
}

.form-field label,
.field-label {
  font-weight: 750;
}

.field-hint {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

textarea,
input[type="text"],
input[type="email"] {
  width: 100%;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: #171714;
  color: var(--text);
}

textarea {
  min-height: 190px;
  resize: vertical;
  line-height: 1.55;
}

.drop-zone {
  display: grid;
  min-height: 150px;
  place-items: center;
  padding: 1.25rem;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  text-align: center;
}

.drop-zone.is-dragging {
  border-color: var(--accent);
  background: rgba(211, 163, 74, 0.08);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone span {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.selected-file {
  margin: 0.45rem 0 0;
  color: var(--success);
  font-size: 0.88rem;
}

.form-status {
  min-height: 1.5rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.form-status.is-error {
  color: var(--danger);
}

.form-status.is-success {
  color: var(--success);
}

.success-panel {
  padding: 1.25rem;
  border: 1px solid rgba(146, 211, 163, 0.32);
  border-radius: 0.8rem;
  background: rgba(146, 211, 163, 0.08);
}

.success-panel h2 {
  margin: 0 0 0.5rem;
}

.success-panel p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 850px) {
  .mobile-data-buttons-visible .mobile-card-data-button {
    position: absolute;
    right: 0.4rem;
    bottom: 0.4rem;
    z-index: 3;
    display: grid;
    width: 27px;
    height: 27px;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 3px 9px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1;
  }

  .mobile-card-data-button:active {
    background: var(--accent-strong);
  }

  .mobile-card-data-button:focus-visible {
    outline: 3px solid rgba(239, 189, 93, 0.55);
    outline-offset: 2px;
  }

  .site-header {
    position: relative;
    display: grid;
    align-items: flex-start;
    gap: 0.75rem;
    min-height: auto;
    padding:
      max(0.85rem, env(safe-area-inset-top))
      max(1rem, env(safe-area-inset-right))
      0.85rem
      max(1rem, env(safe-area-inset-left));
  }

  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .person-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    width: 100%;
  }

  .search-field {
    min-width: 0;
  }

  .search-field input {
    width: 100%;
  }

  .site-header h1 {
    display: none;
  }

  .header-copy {
    display: none;
  }

  .site-header > div:first-child {
    padding-right: 3rem;
  }

  .site-header .eyebrow {
    margin: 0;
  }

  .help-button {
    position: absolute;
    top: max(0.65rem, env(safe-area-inset-top));
    right: max(0.75rem, env(safe-area-inset-right));
    width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 50%;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.15rem;
  }

  .help-button-label {
    display: none;
  }

  .help-button-icon {
    display: inline;
  }

  .tree-layout {
    display: block;
    position: relative;
  }

  .chart-panel,
  .family-chart {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .person-panel {
    position: fixed;
    z-index: 100;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding:
      max(4.25rem, calc(env(safe-area-inset-top) + 3.25rem))
      max(1.25rem, env(safe-area-inset-right))
      max(1.5rem, env(safe-area-inset-bottom))
      max(1.25rem, env(safe-area-inset-left));
    overscroll-behavior: contain;
    border-top: 0;
    border-left: 0;
    background: var(--surface);
  }

  .panel-close {
    position: fixed;
    top: max(0.75rem, env(safe-area-inset-top));
    right: max(0.75rem, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 560px) {
  .site-header {
    gap: 0.6rem;
  }

  .site-header .eyebrow {
    margin-bottom: 0.15rem;
  }

  .header-actions {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .person-search {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.45rem;
  }

  .person-search .button {
    grid-column: 1 / -1;
    min-height: 40px;
  }

  .search-field input {
    min-height: 40px;
    padding: 0.55rem 0.65rem;
  }

  .proposal-page {
    padding: 0;
  }

  .proposal-shell {
    width: 100%;
  }

  .back-link {
    margin: 1rem;
  }

  .proposal-card {
    border-inline: 0;
    border-radius: 0;
  }
}
