:root {
  --bg: #08080b;
  --fg: #f5f2ea;
  --muted: rgba(245, 242, 234, 0.55);
  --line: rgba(255, 255, 255, 0.09);
  --accent: #e7d7b8;
  --male: #7fa6c2;
  --female: #d49aa5;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(1100px 720px at 8% -10%, rgba(91, 129, 166, 0.22), transparent 62%),
    radial-gradient(900px 650px at 102% 8%, rgba(175, 105, 126, 0.16), transparent 58%),
    linear-gradient(180deg, #0a0b10 0%, #08080b 55%, #050507 100%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.035), transparent 42%),
    linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, 0.35));
}

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

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- access gate ---------- */

.access-gate[hidden] {
  display: none;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow-y: auto;
  background:
    radial-gradient(900px 620px at 8% -10%, rgba(91, 129, 166, 0.2), transparent 62%),
    radial-gradient(800px 560px at 104% 8%, rgba(175, 105, 126, 0.14), transparent 58%),
    linear-gradient(180deg, #0a0b10 0%, #08080b 55%, #050507 100%);
}

body.needs-access .app,
body.needs-access .loader {
  visibility: hidden;
}

.access-panel {
  width: min(390px, 100%);
  padding: 1.8rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(22, 24, 31, 0.97), rgba(10, 11, 15, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  text-align: center;
}

.access-panel h2 {
  margin: 0.6rem 0 0.5rem;
  font-size: 1.4rem;
  letter-spacing: -0.04em;
}

.access-desc {
  margin: 0 0 1.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.65;
}

.access-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

.access-field span {
  color: rgba(245, 242, 234, 0.5);
  font-size: 0.68rem;
  font-weight: 600;
}

.access-field input {
  width: 100%;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.access-field input:focus {
  border-color: rgba(231, 215, 184, 0.55);
}

.access-field input::placeholder {
  color: rgba(245, 242, 234, 0.25);
}

.access-error {
  margin: 0.7rem 0 0;
  color: #f0bcc4;
  font-size: 0.7rem;
  line-height: 1.5;
}

.access-submit {
  width: 100%;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(231, 215, 184, 0.5);
  border-radius: 10px;
  background: rgba(231, 215, 184, 0.16);
  color: var(--fg);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.access-submit:hover:not(:disabled) {
  border-color: rgba(231, 215, 184, 0.8);
  background: rgba(231, 215, 184, 0.24);
}

.access-submit:disabled {
  cursor: default;
  opacity: 0.4;
}

.access-note {
  margin: 1rem 0 0;
  color: rgba(245, 242, 234, 0.3);
  font-size: 0.62rem;
  line-height: 1.5;
}

.access-home {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.85rem;
  color: rgba(245, 242, 234, 0.42);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color 0.2s ease;
}

.access-home:hover {
  color: var(--accent);
}

/* ---------- header ---------- */

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 1.4rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 8, 12, 0.7);
  backdrop-filter: blur(16px);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color 0.2s ease;
}

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

.back-arrow {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 0.9rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.back:hover .back-arrow {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
}

.titles {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.28rem;
}

.eyebrow {
  margin: 0;
  color: rgba(231, 215, 184, 0.72);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.member-count {
  margin-right: 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.member-count strong {
  color: var(--fg);
  font-weight: 700;
}

/* ---------- admin link ---------- */

.admin-link {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: rgba(245, 242, 234, 0.42);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.admin-link:hover {
  border-color: rgba(231, 215, 184, 0.4);
  color: var(--accent);
}

.zoom-group {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.icon-btn {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1;
  transition: background 0.2s ease;
}

.icon-btn + .icon-btn {
  border-left: 1px solid var(--line);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.13);
}

.fit-btn {
  padding: 0.55rem 0.9rem;
  border: 1px solid rgba(231, 215, 184, 0.38);
  border-radius: 10px;
  background: rgba(231, 215, 184, 0.08);
  color: var(--fg);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.fit-btn:hover {
  border-color: rgba(231, 215, 184, 0.7);
  background: rgba(231, 215, 184, 0.15);
}

.home-btn {
  flex: 0 0 auto;
  padding-right: 0.75rem;
  padding-left: 0.75rem;
}

/* ---------- chart ---------- */

.chart-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#FamilyChart {
  width: 100%;
  height: 100%;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  --background-color: transparent;
  --text-color: var(--fg);
  --male-color: var(--male);
  --female-color: var(--female);
  --genderless-color: #8d8d93;
}

#FamilyChart .f3-nav-cont {
  display: none;
}

#FamilyChart .link {
  stroke: rgba(255, 255, 255, 0.15);
}

#FamilyChart .link.f3-path-to-main {
  stroke: rgba(231, 215, 184, 0.65);
}

#FamilyChart .card_cont {
  will-change: transform, opacity;
}

#FamilyChart .card {
  cursor: pointer;
  outline: none;
}

#FamilyChart .family-card {
  position: relative;
  display: flex;
  width: 196px;
  min-height: 76px;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: linear-gradient(150deg, rgba(28, 30, 38, 0.96), rgba(13, 14, 19, 0.97));
  box-shadow:
    0 12px 34px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: var(--fg);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

#FamilyChart .card:hover .family-card {
  border-color: rgba(255, 255, 255, 0.3);
  background: linear-gradient(150deg, rgba(35, 38, 47, 0.98), rgba(17, 18, 24, 0.98));
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.52),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#FamilyChart .card:focus-visible .family-card {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#FamilyChart .card-main .family-card {
  border-color: rgba(231, 215, 184, 0.6);
  box-shadow:
    0 0 0 1px rgba(231, 215, 184, 0.14),
    0 18px 54px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

#FamilyChart .card-main .card-inner {
  outline: 2px solid rgba(231, 215, 184, 0.72);
  outline-offset: 2px;
}

#FamilyChart .card-main .family-card::after {
  content: "";
  position: absolute;
  top: 11px;
  right: 11px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(231, 215, 184, 0.9);
}

#FamilyChart .avatar {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 50%;
  color: #0b0b0f;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

#FamilyChart .avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

#FamilyChart .avatar.has-photo {
  background: #14151a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}

#FamilyChart .avatar.is-editable {
  cursor: pointer;
}

#FamilyChart .avatar.is-editable:hover {
  box-shadow: 0 0 0 2px rgba(231, 215, 184, 0.6);
}

#FamilyChart .avatar-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  display: grid;
  width: 17px;
  height: 17px;
  place-items: center;
  border: 2px solid #15161c;
  border-radius: 50%;
  background: var(--accent);
  color: #0b0b0f;
  pointer-events: none;
}

body.photo-busy #FamilyChart .avatar.is-editable {
  opacity: 0.45;
  pointer-events: none;
}

#FamilyChart .card-male .avatar {
  background: linear-gradient(145deg, #c6dcea, #7fa6c2);
}

#FamilyChart .card-female .avatar {
  background: linear-gradient(145deg, #f2d0d5, #d49aa5);
}

#FamilyChart .card-main .avatar {
  background: linear-gradient(145deg, #f4e6c8, #d8bf8f);
}

#FamilyChart .meta {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.2rem;
}

#FamilyChart .name {
  overflow: hidden;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#FamilyChart .sub {
  overflow: hidden;
  color: rgba(245, 242, 234, 0.52);
  font-size: 0.68rem;
  letter-spacing: 0.01em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#FamilyChart .role {
  color: rgba(231, 215, 184, 0.8);
}

#FamilyChart .card-inner.f3-path-to-main {
  outline: 1px solid rgba(231, 215, 184, 0.55);
  outline-offset: 2px;
}

/* ---------- chart overlays ---------- */

.chart-ui {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.chart-hint {
  position: absolute;
  bottom: 1.15rem;
  left: clamp(1rem, 3vw, 2rem);
  margin: 0;
  color: rgba(245, 242, 234, 0.4);
  font-size: 0.68rem;
  letter-spacing: 0.01em;
  line-height: 1.7;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.8);
}

.legend {
  position: absolute;
  right: clamp(1rem, 3vw, 2rem);
  bottom: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  color: rgba(245, 242, 234, 0.42);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.legend .male {
  background: var(--male);
}

.legend .female {
  background: var(--female);
}

.license-link {
  position: absolute;
  top: 0.8rem;
  right: clamp(1rem, 3vw, 2rem);
  z-index: 4;
  color: rgba(245, 242, 234, 0.3);
  font-size: 0.6rem;
  letter-spacing: 0.03em;
  text-decoration: none;
  transition: color 0.2s ease;
}

.license-link:hover {
  color: var(--accent);
}

/* ---------- loader ---------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: #08080b;
  transition: opacity 0.55s ease, visibility 0.55s ease;
}

body.is-ready .loader {
  visibility: hidden;
  opacity: 0;
}

.loader-ring {
  width: 34px;
  height: 34px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loader p {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 1.6rem;
  left: 50%;
  z-index: 60;
  padding: 0.7rem 1.1rem;
  border: 1px solid rgba(231, 215, 184, 0.34);
  border-radius: 999px;
  background: rgba(20, 22, 28, 0.96);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  color: var(--fg);
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
  visibility: hidden;
  white-space: nowrap;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
}

.toast.is-error {
  border-color: rgba(212, 154, 165, 0.6);
  color: #f2d0d5;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.65rem 0.9rem;
    padding: 0.8rem 1rem;
  }

  .back-label {
    display: none;
  }

  .back-arrow {
    width: 32px;
    height: 32px;
  }

  .titles {
    flex: 1;
  }

  .actions {
    width: 100%;
    margin-left: 0;
  }

  .member-count {
    display: none;
  }

  .fit-btn {
    flex: 1;
    text-align: center;
  }

  .home-btn {
    flex: 0 0 auto;
  }

  #FamilyChart .family-card {
    width: 176px;
    min-height: 72px;
    padding: 0.72rem 0.8rem;
  }

  .chart-hint {
    right: 1rem;
    left: 1rem;
    bottom: 0.9rem;
    text-align: center;
    font-size: 0.63rem;
  }

  .legend {
    display: none;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 1rem;
  }

  .eyebrow {
    font-size: 0.54rem;
  }

  #FamilyChart .family-card {
    width: 164px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
