/* ============================================================
   Mathoor Family Tree - styles
   Palette: sandalwood / temple brass / laterite red
   ============================================================ */
:root {
  --brass:      #B8860B;
  --brass-lt:   #D4A537;
  --laterite:   #8C3A2B;
  --deep:       #3B2317;
  --ink:        #2E1D14;
  --muted:      #7A6455;
  --sand:       #FDF6E9;
  --sand-2:     #F5E9D4;
  --surface:    #FFFFFF;
  --line:       #E3D2B6;
  --male:       #2F6F8F;
  --female:     #A0466B;
  --shadow:     0 2px 10px rgba(59,35,23,.10);
  --shadow-lg:  0 12px 40px rgba(59,35,23,.24);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--sand);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--laterite); }

/* ---------------- Welcome / hero ---------------- */
#welcome {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  background:
    radial-gradient(1200px 600px at 50% -10%, #6B4A2F 0%, transparent 60%),
    linear-gradient(170deg, #2A1810 0%, #4A2E1D 45%, #2A1810 100%);
  transition: opacity .5s ease, visibility .5s ease;
}
#welcome.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.hero {
  width: min(880px, 92vw);
  padding: 40px 24px 56px;
  text-align: center;
  color: #F7EAD4;
}
.hero .eyebrow {
  letter-spacing: .32em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass-lt);
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(30px, 7vw, 60px);
  line-height: 1.08;
  letter-spacing: .01em;
  text-shadow: 0 3px 20px rgba(0,0,0,.5);
}
.hero .ml {
  font-size: clamp(19px, 4.2vw, 30px);
  color: var(--brass-lt);
  margin-top: 12px;
  font-weight: 600;
}
.hero .tagline {
  margin: 20px auto 0;
  max-width: 46ch;
  font-size: 15px;
  line-height: 1.65;
  color: #E2CDAE;
}
.divider {
  width: 190px; height: 20px;
  margin: 26px auto 30px;
  opacity: .95;
}
.hero .actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-hero {
  background: linear-gradient(180deg, var(--brass-lt), var(--brass));
  color: #2A1810;
  border: none;
  padding: 14px 30px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0,0,0,.34);
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn-hero:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.4); }
.btn-hero.ghost {
  background: transparent;
  color: #F0DEBF;
  border: 1.5px solid rgba(212,165,55,.6);
  box-shadow: none;
}
.btn-hero.ghost:hover { background: rgba(212,165,55,.14); }

/* The illustrated mana (ancestral home) */
.mana-art { width: min(660px, 88vw); margin: 6px auto 0; display: block; }
.hero-stats {
  display: flex; gap: 26px; justify-content: center; flex-wrap: wrap;
  margin-top: 34px; padding-top: 24px;
  border-top: 1px solid rgba(212,165,55,.25);
}
.hero-stats .s { min-width: 78px; }
.hero-stats .n { font-size: 26px; font-weight: 700; color: var(--brass-lt); }
.hero-stats .l { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: #C6AE8B; margin-top: 3px; }

/* ---------------- App shell ---------------- */
#app { display: none; min-height: 100vh; flex-direction: column; }
#app.show { display: flex; }

header.bar {
  background: linear-gradient(100deg, var(--deep), #5A3A25);
  color: #F7EAD4;
  padding: 11px 18px;
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
header.bar .brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
header.bar h2 { font-size: 16px; letter-spacing: .02em; }
header.bar .sub { font-size: 11px; color: var(--brass-lt); letter-spacing: .12em; text-transform: uppercase; }
header.bar .spacer { flex: 1; }
#status { font-size: 12px; color: #D8BF98; }
/* ghost buttons sit on the dark bar, so recolour them there */
header.bar button.btn.ghost {
  color: #F0DEBF;
  border-color: rgba(212,165,55,.55);
  background: transparent;
}
header.bar button.btn.ghost:hover { background: rgba(212,165,55,.16); }

nav.tabs {
  display: flex; gap: 4px; padding: 0 12px;
  background: var(--sand-2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  position: sticky; top: 0; z-index: 15;
}
nav.tabs button {
  background: none; border: none;
  padding: 12px 16px;
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
nav.tabs button.active { color: var(--laterite); border-bottom-color: var(--laterite); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 18px; }
section.view { display: none; }
section.view.active { display: block; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=text], .toolbar select { min-width: 170px; flex: 1; }
input[type=text], input[type=search], select, textarea, input:not([type]) {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brass-lt); outline-offset: -1px; }
textarea { min-height: 78px; resize: vertical; }
label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: 4px; font-weight: 600; }

button.btn {
  background: var(--laterite); color: #fff;
  border: none; padding: 9px 16px; border-radius: 9px;
  font-weight: 600; cursor: pointer;
}
button.btn:hover { filter: brightness(1.08); }
button.btn.alt { background: var(--deep); }
button.btn.ghost { background: transparent; color: var(--laterite); border: 1.5px solid var(--line); }
button.btn.danger { background: #8B1E1E; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.sm { padding: 6px 11px; font-size: 13px; }

.empty {
  text-align: center; padding: 54px 20px; color: var(--muted);
}
.empty svg { opacity: .5; margin-bottom: 14px; }
.empty h3 { color: var(--ink); margin-bottom: 8px; }

/* ---------------- Avatars ---------------- */
.av {
  border-radius: 50%;
  object-fit: cover;
  background: var(--sand-2);
  border: 2px solid var(--line);
  flex-shrink: 0;
  display: block;
}
.av.ph {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; border-color: transparent;
}
.av.male   { background: var(--male); }
.av.female { background: var(--female); }
.av.unknown{ background: var(--muted); }

/* ---------------- Tree ---------------- */
.tree-scroll {
  overflow: auto;
  background:
    linear-gradient(var(--sand-2) 1px, transparent 1px) 0 0 / 100% 34px,
    var(--sand);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  min-height: 380px;
}
ul.tree, ul.tree ul { list-style: none; margin: 0; padding: 0; }
ul.tree ul {
  margin-left: 26px;
  padding-left: 22px;
  border-left: 2px solid var(--line);
}
ul.tree li { position: relative; padding: 5px 0; }
ul.tree ul > li::before {
  content: '';
  position: absolute;
  left: -22px; top: 27px;
  width: 20px; height: 2px;
  background: var(--line);
}

.node {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 11px;
  padding: 7px 13px 7px 9px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  max-width: 100%;
}
.node:hover { transform: translateX(2px); box-shadow: 0 4px 14px rgba(59,35,23,.18); }
.node.male   { border-left-color: var(--male); }
.node.female { border-left-color: var(--female); }
.node.sel    { outline: 2px solid var(--brass); }
.node .nm { font-weight: 600; font-size: 14px; }
.node .mlname { font-size: 12px; color: var(--muted); }
.node .yr { font-size: 12px; color: var(--muted); }
.node .sp {
  font-size: 12px; color: var(--laterite);
  background: var(--sand-2); padding: 2px 8px; border-radius: 99px;
  white-space: nowrap;
}
.node .cnt {
  font-size: 11px; font-weight: 700; color: #fff;
  background: var(--brass); border-radius: 99px; padding: 2px 7px;
}
.node .repeat { font-size: 11px; color: var(--muted); font-style: italic; }
.twisty {
  border: none; background: var(--sand-2); color: var(--deep);
  width: 22px; height: 22px; border-radius: 6px;
  cursor: pointer; font-size: 12px; font-weight: 700;
  flex-shrink: 0; padding: 0;
}
li.collapsed > ul { display: none; }
.gen-label {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-left: 4px;
}

/* ---------------- People grid ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 12px;
}
.pcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px;
  display: flex; gap: 12px; align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.pcard:hover { transform: translateY(-2px); }
.pcard .info { min-width: 0; flex: 1; }
.pcard .nm { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------------- Detail panel ---------------- */
.detail-head {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--sand-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px;
  margin-bottom: 16px;
}
.detail-head .who { flex: 1; min-width: 190px; }
.detail-head h2 { font-size: 22px; }
.detail-head .mlname { color: var(--laterite); font-size: 15px; margin-top: 3px; }
.detail-head .meta { color: var(--muted); font-size: 13px; margin-top: 7px; line-height: 1.6; }

.rel-group { margin-bottom: 18px; }
.rel-group h4 {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 9px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.rel-group h4 .add {
  margin-left: auto; text-transform: none; letter-spacing: 0;
  font-size: 12px; color: var(--laterite); cursor: pointer;
  background: none; border: none; font-weight: 700;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 5px 13px 5px 5px;
  cursor: pointer; font-size: 13px;
}
.chip:hover { border-color: var(--brass); }
.chip .x {
  border: none; background: none; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1;
}
.chip .x:hover { color: #8B1E1E; }
.none { color: var(--muted); font-size: 13px; font-style: italic; }

/* ---------------- Compare ---------------- */
.cmp-wrap { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: start; }
.cmp-slot {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 15px; text-align: center;
}
.cmp-slot .av { margin: 0 auto 10px; }
.cmp-vs {
  align-self: center; font-weight: 700; color: var(--brass);
  font-size: 13px; letter-spacing: .1em;
}
.result {
  margin-top: 16px; padding: 22px;
  background: linear-gradient(135deg, var(--deep), #5A3A25);
  color: #F7EAD4; border-radius: 15px; text-align: center;
}
.result .lbl { font-size: clamp(21px, 4.5vw, 31px); font-weight: 700; color: var(--brass-lt); }
.result .det { font-size: 13px; margin-top: 9px; color: #E2CDAE; line-height: 1.6; }
.path {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  flex-wrap: wrap; margin-top: 15px; padding-top: 14px;
  border-top: 1px solid rgba(212,165,55,.28);
}
.path .step {
  background: rgba(255,255,255,.1); border-radius: 99px;
  padding: 4px 11px; font-size: 12px; color: #F7EAD4;
}
.path .arrow { color: var(--brass-lt); font-size: 13px; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(43,24,16,.6);
  display: none; overflow-y: auto;
  padding: 16px;
}
.modal.open { display: block; }
.modal .box {
  background: var(--sand);
  border-radius: 16px;
  width: min(660px, 96vw);
  margin: 20px auto 40px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal .box.wide { width: min(860px, 96vw); }
.modal .mhead {
  background: linear-gradient(100deg, var(--deep), #5A3A25);
  color: #F7EAD4; padding: 15px 20px;
  display: flex; align-items: center; gap: 12px;
}
.modal .mhead h3 { font-size: 17px; flex: 1; }
.modal .mhead .x { background: none; border: none; color: #F7EAD4; font-size: 22px; cursor: pointer; line-height: 1; }
.modal .mbody { padding: 20px; }
.modal .mfoot {
  padding: 14px 20px; background: var(--sand-2);
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
}
.modal .mfoot .msg { flex: 1; font-size: 13px; text-align: left; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.fld { margin-bottom: 13px; }
@media (max-width: 560px) {
  .f2 { grid-template-columns: 1fr; }
  .cmp-wrap { grid-template-columns: 1fr; }
  .cmp-vs { justify-self: center; }
}

.ok  { color: #1B5E20; }
.err { color: #B71C1C; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* photo picker */
.photo-pick { display: flex; align-items: center; gap: 14px; margin-bottom: 15px; }
.photo-pick .prev {
  width: 76px; height: 76px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--line); background: var(--sand-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; text-align: center;
}
.photo-pick .ctl { flex: 1; }
#photoFile { display: none; }

/* search dropdown */
.picker { position: relative; }
.picker-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; margin-top: 4px; max-height: 230px; overflow-y: auto;
  box-shadow: var(--shadow-lg); display: none;
}
.picker-list.open { display: block; }
.picker-list .it {
  padding: 9px 12px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; gap: 9px;
  border-bottom: 1px solid var(--sand-2);
}
.picker-list .it:hover { background: var(--sand-2); }
.picker-list .it .yr { color: var(--muted); font-size: 12px; margin-left: auto; }

.banner {
  background: #FFF3CD; border: 1px solid var(--brass);
  color: #6B4A0F; padding: 12px 15px; border-radius: 10px;
  margin-bottom: 15px; font-size: 13.5px; line-height: 1.6; display: none;
}
.banner.show { display: block; }
.banner code {
  background: rgba(0,0,0,.07); padding: 1px 5px; border-radius: 4px;
  font-size: 12.5px;
}
@media print {
  #welcome, nav.tabs, header.bar, .toolbar { display: none !important; }
  .tree-scroll { border: none; overflow: visible; }
}
