/* ============================================================
   Our Family Tree — stylesheet
   Theme: a banyan tree — the traditional gathering tree of
   Bengali family life. Deep foliage greens, brass/registry gold.
   ============================================================ */

:root[data-theme="dark"] {
  --bg: #10261B;
  --bg-vignette: radial-gradient(ellipse at 50% -10%, #1B3A28 0%, #10261B 55%);
  --surface-0: #17301F;   /* Elahi   */
  --surface-1: #1E3C27;   /* Azim    */
  --surface-2: #2A4E30;   /* branch heads */
  --surface-3: #3B6339;   /* grandchildren */
  --surface-4: #4E7A44;   /* great-grandchildren+ */
  --card-border: rgba(226, 210, 160, 0.14);
  --ink: #F3ECD9;
  --ink-dim: #C8D3C3;
  --muted: #93AC96;
  --gold: #C9A24B;
  --gold-bright: #E6C878;
  --branch: #8A9E7F;
  --danger: #D97757;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --overlay: rgba(10, 20, 14, 0.72);
}

:root[data-theme="light"] {
  --bg: #F4EFE1;
  --bg-vignette: radial-gradient(ellipse at 50% -10%, #FFFDF6 0%, #F4EFE1 60%);
  --surface-0: #E4DCC2;
  --surface-1: #D8CFAE;
  --surface-2: #CBDFC5;
  --surface-3: #B4D2AC;
  --surface-4: #9BC393;
  --card-border: rgba(30, 50, 30, 0.14);
  --ink: #1B2E1C;
  --ink-dim: #33452F;
  --muted: #5B6E52;
  --gold: #9C7A2B;
  --gold-bright: #7C611F;
  --branch: #7C8F6D;
  --danger: #B75236;
  --shadow: 0 10px 24px rgba(60,50,20,0.12);
  --overlay: rgba(244, 239, 225, 0.85);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Work Sans', sans-serif;
  scroll-behavior: smooth;
}

body {
  background-image: var(--bg-vignette);
  min-height: 100vh;
}

h1, h2 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  margin: 0;
}

::selection { background: var(--gold); color: #17301F; }

/* ---------------- Header ---------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--overlay);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-border);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 4px 0;
}

.title-block h1 {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  letter-spacing: 0.01em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

#search-input {
  font-family: 'Work Sans', sans-serif;
  font-size: 0.9rem;
  padding: 9px 12px 9px 32px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--surface-0);
  color: var(--ink);
  width: 190px;
  outline: none;
  transition: width 0.25s ease, border-color 0.2s ease;
}
#search-input:focus {
  width: 230px;
  border-color: var(--gold);
}
#search-input::placeholder { color: var(--muted); }

.icon-btn, .text-btn {
  font-family: 'Work Sans', sans-serif;
  border: 1px solid var(--card-border);
  background: var(--surface-0);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.icon-btn:hover, .text-btn:hover { border-color: var(--gold); }
.icon-btn:active, .text-btn:active, .fab:active, .view-toggle button:active { transform: scale(0.97); }
.icon-btn:focus-visible, .text-btn:focus-visible, #search-input:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn svg { width: 18px; height: 18px; color: var(--ink); }

.text-btn {
  font-size: 0.8rem;
  padding: 9px 14px;
  white-space: nowrap;
}

:root[data-theme="dark"] .moon { display: block; }
:root[data-theme="dark"] .sun { display: none; }
:root[data-theme="light"] .moon { display: none; }
:root[data-theme="light"] .sun { display: block; }

/* ---------------- Main / layout ---------------- */

main {
  width: 100%;
  margin: 0;
  padding: 28px 16px 90px;
  min-height: 60vh;
}

.no-results {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  margin-top: 40px;
}
.hidden { display: none !important; }

.view-toggle {
  display: none;
  width: min(100%, 360px);
  margin: 0 auto 14px;
  padding: 4px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--surface-0);
}

.view-toggle button {
  flex: 1;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: 'Work Sans', sans-serif;
  font-weight: 600;
  padding: 9px 12px;
  cursor: pointer;
  transition: color 0.18s ease, background-color 0.18s ease, transform 0.15s ease;
}

.view-toggle button.active {
  background: var(--gold);
  color: #17301F;
}

/* ---------------- Node card (shared look) ---------------- */

.node-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  cursor: default;
  position: relative;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: rise 0.5s ease both;
}
.node-card.has-children { cursor: pointer; }
.node-card:hover { transform: translateY(-2px); }

.node-card .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.14);
  color: var(--ink);
  border: 1px solid var(--card-border);
}

.node-card .name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  color: var(--ink);
}

.node-card .count-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  color: var(--gold-bright);
  letter-spacing: 0.03em;
}

.node-card.match {
  box-shadow: 0 0 0 3px var(--gold-bright), var(--shadow);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.gen-0 .node-card { background: var(--surface-0); }
.gen-1 .node-card { background: var(--surface-1); }
.gen-2 .node-card { background: var(--surface-2); }
.gen-3 .node-card { background: var(--surface-3); }
.gen-4 .node-card, .gen-5 .node-card { background: var(--surface-4); }

/* ================================================================
   DESKTOP — pure-CSS org-chart tree with branch-style connectors
   ================================================================ */

.tree-canvas {
  display: block;
  width: 100%;
  min-height: calc(100vh - 250px);
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 18px 20px 34px;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  cursor: zoom-in;
}

.tree-canvas::-webkit-scrollbar {
  display: none;
}

.export-canvas {
  position: fixed;
  left: -100000px;
  top: 0;
  width: max-content;
  min-height: 0;
  overflow: visible;
  pointer-events: none;
}

.export-canvas .collapse-toggle {
  display: none;
}

.mobile-tree {
  display: none;
}

.tree-stage {
  min-width: 100%;
  display: inline-block;
}

.tree-stage > ul {
  transform-origin: top left;
  width: max-content;
}

.tree-canvas, .tree-canvas ul {
  text-align: center;
}

.tree-canvas ul {
  list-style: none;
  margin: 0;
  padding-top: 30px;
  display: flex;
  justify-content: center;
  position: relative;
}

.tree-canvas > .tree-stage > ul { padding-top: 0; }

.tree-canvas li {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 30px 36px 0 36px;
}

/* connector lines, drawn as branches */
.tree-canvas li::before,
.tree-canvas li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  width: 50%;
  height: 30px;
  border-top: 2.5px solid var(--branch);
}
.tree-canvas li::after {
  right: auto;
  left: 50%;
  border-left: 2.5px solid var(--branch);
}
.tree-canvas li:only-child::before,
.tree-canvas li:only-child::after { display: none; }
.tree-canvas li:only-child { padding-top: 0; }

.tree-canvas li:first-child::before,
.tree-canvas li:last-child::after { border: 0 none; }

.tree-canvas li:last-child::before {
  border-right: 2.5px solid var(--branch);
  border-radius: 0 8px 0 0;
}
.tree-canvas li:first-child::after {
  border-radius: 8px 0 0 0;
}

.tree-canvas > .tree-stage > ul > li::before,
.tree-canvas > .tree-stage > ul > li::after,
.tree-canvas > .tree-stage > ul::before {
  display: none;
}

.tree-canvas ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2.5px solid var(--branch);
  width: 0;
  height: 30px;
}

.collapse-toggle {
  margin-top: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--gold);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.collapse-toggle:hover { border-color: var(--gold); }

/* ================================================================
   MOBILE — accordion list
   ================================================================ */

.tree-accordion { display: none; padding: 4px 4px 20px; }

.acc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  border: 1px solid var(--card-border);
  min-height: 44px;
  animation: rise 0.4s ease both;
}

.acc-row .avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.14);
  border: 1px solid var(--card-border);
}

.acc-row .name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
}

.acc-row.match { box-shadow: 0 0 0 3px var(--gold-bright); }

.acc-toggle {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--gold);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}
.acc-toggle.open { transform: rotate(90deg); }
.acc-toggle svg { width: 14px; height: 14px; }

.acc-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--gold-bright);
}

.acc-children { padding-left: 20px; border-left: 2px solid var(--card-border); margin-left: 17px; }

.gen-0.acc-row { background: var(--surface-0); }
.gen-1.acc-row { background: var(--surface-1); }
.gen-2.acc-row { background: var(--surface-2); }
.gen-3.acc-row { background: var(--surface-3); }
.gen-4.acc-row, .gen-5.acc-row { background: var(--surface-4); }

/* ---------------- Breakpoint ---------------- */

@media (max-width: 860px) {
  .tree-canvas { display: none; }
  .view-toggle { display: flex; }
  #tree-mobile.mobile-tree:not(.hidden) {
    display: block;
    min-height: calc(100vh - 275px);
    padding: 14px 8px 28px;
  }
  #tree-mobile-list:not(.hidden) { display: block; }
  .tree-canvas li { padding-left: 24px; padding-right: 24px; }
  .node-card { padding: 10px 14px; }
  .node-card .avatar { width: 36px; height: 36px; font-size: 0.85rem; }
  .node-card .name { font-size: 0.9rem; }
  #search-input { width: 140px; }
  #search-input:focus { width: 170px; }
  .text-btn { padding: 9px 10px; font-size: 0.72rem; }
}

/* ---------------- Footer ---------------- */

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 20px;
  border-top: 1px solid var(--card-border);
}
.site-footer p {
  margin: 6px 0;
}
.site-footer a {
  color: var(--gold-bright);
  text-decoration: none;
}
.site-footer a:hover {
  text-decoration: underline;
}
.site-footer code {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--surface-0);
  padding: 2px 6px;
  border-radius: 6px;
}

/* ---------------- Feedback FAB + panel ---------------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 56px;
  min-height: 56px;
  max-width: calc(100vw - 40px);
  padding: 0 18px;
  gap: 8px;
  border-radius: 999px;
  background: var(--gold);
  color: #17301F;
  border: none;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: transform 0.2s ease;
  font-family: 'Work Sans', sans-serif;
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
}
.fab:hover { transform: scale(1.06); }
.fab svg { width: 20px; height: 20px; flex: 0 0 auto; }

.feedback-panel {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 12, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.feedback-card {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
  margin-bottom: 6vh;
}

@media (min-width: 640px) {
  .feedback-panel { align-items: center; }
}

.feedback-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.feedback-card h2 { font-size: 1.3rem; margin-bottom: 8px; }
.feedback-sub { color: var(--muted); font-size: 0.88rem; margin: 0 0 18px; line-height: 1.4; }

#feedback-form label {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-dim);
  margin: 12px 0 6px;
}
.optional { color: var(--muted); font-weight: 400; }

#feedback-form input,
#feedback-form textarea {
  width: 100%;
  font-family: 'Work Sans', sans-serif;
  font-size: 0.92rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--surface-0);
  color: var(--ink);
  resize: vertical;
  outline: none;
}
#feedback-form input:focus,
#feedback-form textarea:focus { border-color: var(--gold); }

.submit-btn {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--gold);
  color: #17301F;
  font-family: 'Work Sans', sans-serif;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.submit-btn:hover { filter: brightness(1.08); }
.submit-btn:disabled { opacity: 0.6; cursor: default; }

.feedback-status {
  min-height: 20px;
  font-size: 0.82rem;
  margin: 10px 0 0;
  color: var(--gold-bright);
}
.feedback-status.error { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
