:root {
  --stb-bg: #0a0908;
  --stb-bg-2: #14110d;
  --stb-card: #16130e;
  --stb-ink: #e8e0cc;
  --stb-ink-2: #a8a08a;
  --stb-ink-3: #6e6856;
  --stb-line: #2a251c;
  --stb-accent: #d99863;
  --stb-parchment: #f4ecd8;
  --stb-parchment-2: #e3d4ad;
  color: var(--stb-ink);
  background: var(--stb-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(217, 152, 99, 0.13), transparent 46%),
    linear-gradient(180deg, #0a0908, #14110d 54%, #0a0908);
}

button,
a,
input {
  font: inherit;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(176, 74, 28, 0.08), transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(120, 80, 30, 0.1), transparent 55%),
    linear-gradient(180deg, #f0e5cc, #e3d4ad);
}

.login-screen::before,
.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  mix-blend-mode: overlay;
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 240, 200, 0.35) 1px, transparent 1px);
  background-size: 3px 3px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(100%, 468px);
  padding: 44px 48px 40px;
  border: 1px solid #bba98a;
  color: #1d160c;
  background: linear-gradient(180deg, #fbf5e3, #f0e5cc);
  box-shadow:
    0 30px 80px -30px rgba(60, 40, 15, 0.45),
    inset 0 0 80px rgba(120, 80, 30, 0.08);
}

.login-card h1 {
  margin: 6px 0 0;
  color: #1d160c;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(2.45rem, 6vw, 3.9rem);
  font-weight: 500;
  line-height: 0.98;
}

.login-card p {
  margin-bottom: 0;
  color: #5a4a32;
  line-height: 1.5;
}

.hand-note {
  color: var(--stb-accent) !important;
  font-family: Caveat, cursive;
  font-size: 1.55rem;
}

.login-card label {
  display: grid;
  gap: 8px;
  color: #5a4a32;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.login-card input {
  min-height: 42px;
  padding: 10px 0;
  border: none;
  border-bottom: 1px solid #bba98a;
  color: #1d160c;
  background: transparent;
  outline: none;
}

.login-card input:focus {
  border-color: var(--stb-accent);
}

.login-card button,
.toolbar button,
.toolbar a,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border: 1px solid var(--stb-accent);
  border-radius: 1px;
  color: #0a0908;
  background: var(--stb-accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: filter 160ms ease, background 160ms ease, color 160ms ease;
}

.login-card button:hover,
.toolbar button:hover,
.toolbar a:hover,
.file-button:hover {
  filter: brightness(1.08);
}

.login-card small {
  color: #8a7a5a;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  line-height: 1.5;
  text-transform: uppercase;
}

.ornament-line {
  height: 14px;
  color: #bba98a;
  background-image:
    radial-gradient(circle at 50% 50%, currentColor 25%, transparent 28%),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
  background-position: center, left center, right center;
  background-repeat: no-repeat;
  background-size: 14px 14px, 38% 1px, 38% 1px;
}

.wax-seal {
  position: absolute;
  right: -30px;
  bottom: -30px;
  display: grid;
  width: 96px;
  height: 96px;
  place-items: center;
  border-radius: 50%;
  color: #f4d1ae;
  background: radial-gradient(circle at 35% 35%, #c14a2a, #6e1d10 70%, #4a0d05);
  box-shadow:
    0 8px 24px -6px rgba(80, 15, 5, 0.6),
    inset 0 -6px 12px rgba(0, 0, 0, 0.4),
    inset 0 6px 12px rgba(255, 200, 160, 0.3);
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: rotate(-14deg);
}

.wax-seal::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1.5px dashed rgba(255, 220, 180, 0.5);
  border-radius: 50%;
}

.wax-seal span {
  font-size: 0.44rem;
}

.wax-seal strong {
  margin: -8px 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.25rem;
}

.shake .login-card {
  animation: shake 280ms ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  35% {
    transform: translateX(-8px);
  }

  70% {
    transform: translateX(8px);
  }
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 20px;
}

.app-shell.is-locked {
  max-height: 100vh;
  overflow: hidden;
  filter: blur(2px);
}

.topbar,
.intro,
.data-panel,
.stats-strip div {
  border: 1px solid rgba(168, 160, 138, 0.24);
  background: rgba(20, 17, 13, 0.78);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

.topbar,
.intro,
.data-panel,
.backup-panel {
  width: min(100%, 1540px);
  margin: 0 auto 16px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(320px, auto);
  align-items: center;
  gap: 20px;
  min-height: 64px;
  padding: 14px 18px;
}

.eyebrow,
.screen-nav a,
.toolbar span,
.stats-strip span {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--stb-accent);
  font-weight: 600;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 500;
  letter-spacing: 0.005em;
}

h1 {
  margin-bottom: 0;
  color: var(--stb-ink);
  font-size: clamp(2rem, 4vw, 3.25rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  color: var(--stb-ink);
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.04;
}

.screen-nav,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.screen-nav a {
  border-bottom: 1px solid transparent;
  color: var(--stb-ink-2);
  text-decoration: none;
}

.screen-nav a:first-child {
  border-color: var(--stb-accent);
  color: var(--stb-accent);
}

.toolbar {
  justify-content: flex-end;
  gap: 8px;
}

.toolbar button,
.toolbar a,
.file-button {
  min-height: 36px;
  padding: 8px 12px;
}

.toolbar button:not(:first-child),
.toolbar a,
.file-button {
  border-color: var(--stb-line);
  color: var(--stb-ink-2);
  background: transparent;
}

.toolbar .danger-action {
  border-color: rgba(193, 74, 42, 0.72);
  color: #e9a28d;
}

.toolbar .danger-action.is-armed {
  border-color: #c14a2a;
  color: #fff1e9;
  background: #7a1d12;
  animation: pulse-danger 900ms ease-in-out infinite alternate;
}

.toolbar button:not(:first-child):hover,
.toolbar a:hover,
.file-button:hover {
  border-color: var(--stb-ink);
  color: var(--stb-ink);
  filter: none;
}

@keyframes pulse-danger {
  from {
    box-shadow: 0 0 0 rgba(193, 74, 42, 0);
  }

  to {
    box-shadow: 0 0 22px rgba(193, 74, 42, 0.45);
  }
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.toolbar span {
  padding: 8px 10px;
  border: 1px solid rgba(168, 160, 138, 0.25);
  border-radius: 999px;
  color: var(--stb-accent);
  background: rgba(0, 0, 0, 0.18);
}

.toolbar .backend-status {
  border-color: rgba(217, 152, 99, 0.42);
  color: #ffd8a8;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  gap: 18px;
  padding: 24px 28px;
}

.intro p:last-child {
  margin-bottom: 0;
  color: var(--stb-ink-2);
  line-height: 1.55;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: min(100%, 1540px);
  margin: 0 auto 16px;
}

.stats-strip div {
  padding: 14px;
}

.stats-strip strong,
.stats-strip span {
  display: block;
}

.stats-strip strong {
  color: var(--stb-ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.65rem;
  font-weight: 500;
}

.stats-strip span {
  margin-top: 2px;
  color: var(--stb-ink-3);
}

.chart-wrap {
  position: relative;
  width: min(100%, 1540px);
  margin: 0 auto 16px;
  overflow: hidden;
  border: 1px solid rgba(168, 160, 138, 0.24);
  background: #0a0908;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.36);
}

.chart-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.62;
  background:
    radial-gradient(circle at 12% 18%, rgba(232, 224, 204, 0.7) 0 1px, transparent 1.5px),
    radial-gradient(circle at 31% 62%, rgba(232, 224, 204, 0.55) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 24%, rgba(232, 224, 204, 0.7) 0 1px, transparent 1.5px),
    radial-gradient(circle at 90% 74%, rgba(232, 224, 204, 0.45) 0 1px, transparent 1.5px),
    radial-gradient(ellipse at 50% 60%, rgba(176, 74, 28, 0.1), transparent 60%),
    linear-gradient(180deg, #0a0908, #14110d);
}

.chart-meta {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-meta span {
  padding: 6px 9px;
  border: 1px solid rgba(168, 160, 138, 0.22);
  border-radius: 999px;
  color: var(--stb-ink-2);
  background: rgba(20, 17, 13, 0.78);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.chart-meta span:first-child {
  color: var(--stb-accent);
}

#FamilyChart {
  position: relative;
  z-index: 1;
  width: 100%;
  height: min(76vh, 850px);
  min-height: 620px;
  color: #fff;
  background: transparent;
}

.f3 {
  --female-color: #c98d9c;
  --male-color: #75a5b7;
  --genderless-color: #d8d0c4;
  --background-color: #0a0908;
  --text-color: #ffffff;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.f3 .card_family_tree rect.card-body-rect,
.f3 rect.card-male,
.f3 rect.card-female {
  filter: drop-shadow(0 16px 22px rgba(0, 0, 0, 0.3));
}

.f3 .card-main-outline {
  stroke: var(--stb-accent);
}

#FamilyChart input,
#FamilyChart textarea,
#FamilyChart select {
  color: #fff;
  background: #232323;
}

.data-panel {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 22px 24px;
}

.data-panel p {
  margin-bottom: 0;
  color: var(--stb-ink-2);
  line-height: 1.5;
}

#jsonPreview {
  width: 100%;
  min-height: 210px;
  padding: 12px;
  border: 1px solid rgba(168, 160, 138, 0.24);
  color: var(--stb-ink);
  background: rgba(10, 9, 8, 0.42);
  font: 0.82rem/1.45 "JetBrains Mono", Consolas, monospace;
}

.backup-panel {
  padding: 22px 24px;
  border: 1px solid rgba(168, 160, 138, 0.24);
  background: rgba(20, 17, 13, 0.84);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

.backup-panel[hidden] {
  display: none;
}

.backup-panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--stb-line);
}

.backup-actions,
.backup-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.backup-actions button,
.backup-actions a,
.backup-item-actions button,
.backup-item-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid var(--stb-line);
  color: var(--stb-ink-2);
  background: transparent;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.backup-actions button:first-child,
.backup-item-actions button {
  border-color: var(--stb-accent);
  color: #0a0908;
  background: var(--stb-accent);
}

.backup-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.backup-item,
.backup-empty {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid rgba(168, 160, 138, 0.2);
  background: rgba(10, 9, 8, 0.42);
}

.backup-item strong,
.backup-item span,
.backup-item small {
  display: block;
}

.backup-item strong {
  color: var(--stb-ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 500;
}

.backup-item span {
  margin-top: 3px;
  color: var(--stb-ink-2);
}

.backup-item small,
.backup-empty {
  color: var(--stb-ink-3);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@media (max-width: 1040px) {
  .topbar,
  .intro,
  .data-panel,
  .backup-panel-header,
  .backup-item,
  .stats-strip {
    grid-template-columns: 1fr;
  }

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

  .screen-nav,
  .toolbar,
  .backup-actions,
  .backup-item-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .login-card {
    padding: 34px 28px;
  }

  .wax-seal {
    right: -18px;
    bottom: -18px;
    width: 76px;
    height: 76px;
  }

  #FamilyChart {
    min-height: 540px;
  }
}
