:root {
  --bg: #0c0a13;
  --bg-vignette: #14101f;
  --ink: #e7dfc9;
  --ink-dim: #8b8478;
  --gold: #c9a24b;
  --purple: #6b4fa0;
  --teal: #2f9bb5;
  --crimson: #b6483a;
  --rule: rgba(201,162,75,0.2);     /* Defined fallback variable missing from script */
  --text-muted: #8b8478;            /* Defined fallback variable missing from script */
  --text-dim: #6b4fa0;              /* Defined fallback variable missing from script */
}
*{box-sizing:border-box;}
html,body{
  margin:0; padding:0; height:100%;
  background:
    radial-gradient(ellipse at 50% 30%, var(--bg-vignette) 0%, var(--bg) 65%);
  color:var(--ink);
  font-family:'EB Garamond', serif;
}
#app{ position:relative; width:100%; height:100vh; display: flex; flex-direction: column; }

/* Keep old standalone absolute header styles untouched if referenced elsewhere */
header:not(.topbar){
  position:absolute; top:0; left:0; right:0;
  text-align:center; padding:22px 0 8px;
  z-index:5; pointer-events:none;
}
header:not(.topbar) h1{
  font-family:'Cinzel', serif;
  font-weight:700;
  letter-spacing:0.12em;
  font-size:1.7rem;
  margin:0;
  color:var(--gold);
  text-shadow: 0 0 18px rgba(201,162,75,0.35);
}
header:not(.topbar) p{
  margin:6px 0 0;
  font-style:italic;
  color:var(--ink-dim);
  font-size:0.95rem;
  letter-spacing:0.03em;
}

/* Explicitly repair properties on your persistent topbar template */
header.topbar {
  position: relative;          /* Changed from sticky to relative to reserve header element flow space */
  top: 0;
  z-index: 30;                 /* Raised index higher than chart canvas structures to overlay correctly */
  pointer-events: auto;        /* EXPLICIT FIX: Overrides pointer-events inheritance to enable click control */
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  padding: 14px 28px;          /* Adjusted height profile to safely bound the internal content */
  display: flex;
  align-items: center;
  justify-content: space-between; /* Keeps navigation pills and title cleanly separated on endpoints */
  gap: 28px;
  flex-wrap: wrap;
  margin: 0;                   /* Cleared negative bleed outer layout margins breaking focus */
  background: linear-gradient(to bottom, rgba(26, 15, 10, .4), var(--bg)), url(https://cdn.tamilbookshelf.in/assets/images/tpm-tamilbookshelf.jpg);
  background-size: cover;
  background-position: bottom;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
}
.brand-mark {
  color: var(--gold);
  font-size: 20px;
}
.brand-name {
  font-family: 'Fraunces', serif;
  font-size: 23px;
  font-weight: 600;
  text-align: left;
}
.brand-sub {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cat-pill {
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s ease;
}
.cat-pill:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.cat-pill.active {
  background: var(--gold);
  color: #241c05;
  border-color: var(--gold);
  font-weight: 600;
}

/* Adjust layout canvas bounds so charts run below the interactive header space */
#chart{
  position:absolute; 
  top: 75px;                   /* Push map visualization frame below layout header bounds */
  bottom: 0; left: 0; right: 0;
  display:flex; align-items:center; justify-content:center;
  z-index: 1;                  /* Set layer under navigation controls */
}
svg{ overflow:visible; }

.node{
  font-family:'EB Garamond', serif;
  font-size: 14px;
  fill: #cfcecc;
  cursor:pointer;
  transition: fill 0.25s ease, font-size 0.15s ease;
}
.node:hover{ fill:var(--gold); }
.node--source{ fill:var(--crimson); font-weight:600; }
.node--target{ fill:var(--teal); font-weight:600; }
.node--target.node--source{ fill:var(--gold); }
.node.active{ fill:var(--gold); font-weight:700; }

.link{
  stroke:#4a4460;
  stroke-opacity:0.35;
  stroke-width:1px;
  fill:none;
}
.link--source{ stroke:var(--crimson); stroke-opacity:0.9; stroke-width:1.6px; }
.link--target{ stroke:var(--teal); stroke-opacity:0.9; stroke-width:1.6px; }
.link--source.link--target{ stroke:var(--gold); stroke-width:2px; }

#panel{
  position:absolute;
  top:50%; left:24px;
  transform: translateY(-50%);
  width:280px;
  max-height:70vh;
  overflow-y:auto;
  background: rgba(20,16,32,0.88);
  border:1px solid rgba(201,162,75,0.35);
  border-radius:8px;
  padding:18px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  opacity:0;
  pointer-events:none;
  transition: opacity 0.35s ease;
  z-index:10;                 /* Higher layer placement priority */
}
#panel.visible{ opacity:1; pointer-events:auto; }
#panel h2{
  font-family:'Cinzel', serif;
  font-size:1.1rem;
  color:var(--gold);
  margin:0 0 4px;
  letter-spacing:0.03em;
}
#panel .path{
  font-size:0.78rem;
  color:var(--ink-dim);
  font-style:italic;
  margin:0 0 14px;
}
#panel h3{
  font-size:0.82rem;
  text-transform:uppercase;
  letter-spacing:0.08em;
  color:var(--teal);
  margin:14px 0 6px;
  border-bottom:1px solid rgba(255,255,255,0.08);
  padding-bottom:4px;
}
#panel h3.out{ color:var(--crimson); }
#panel ul{ margin:0 0 6px; padding-left:1.1em; }
#panel li{ font-size:0.88rem; margin-bottom:3px; line-height:1.3; }
#panel .empty{ color:var(--ink-dim); font-size:0.82rem; font-style:italic; }
#panel .close{
  position:absolute; top:10px; right:12px;
  cursor:pointer; color:var(--ink-dim); font-size:1.1rem;
  line-height:1;
}
#panel .close:hover{ color:var(--gold); }
#panel li.ref-link{
  cursor:pointer;
  color:var(--ink);
  text-decoration:underline dotted rgba(201,162,75,0.55);
  text-underline-offset:3px;
}
#panel li.ref-link:hover{ color:var(--gold); }

#hint{
  position:absolute; bottom:16px; left:0; right:0;
  text-align:center; color:var(--ink-dim);
  font-size:0.8rem; font-style:italic;
  letter-spacing:0.02em;
  z-index:5;
}

#verse-panel{
  position:absolute;
  top:0; right:-440px;
  width:400px; height:100%;
  background: linear-gradient(180deg, rgba(16,13,25,0.97), rgba(10,8,16,0.98));
  border-left:1px solid rgba(201,162,75,0.35);
  box-shadow: -10px 0 40px rgba(0,0,0,0.6);
  transition: right 0.45s cubic-bezier(.22,.9,.32,1);
  z-index:40;                 /* Keeps side data sheet safely stacked on the absolute plane */
  overflow-y:auto;
  padding: 26px 24px 50px;
}
#verse-panel.visible{ right:0; }
#verse-panel .vp-header{
  display:flex; justify-content:space-between; align-items:flex-start;
  margin-bottom:2px;
}
#verse-panel h2{
  font-family:'Cinzel', serif;
  color:var(--gold);
  font-size:1.2rem;
  margin:0;
  letter-spacing:0.03em;
}
#verse-panel .vp-close{
  cursor:pointer; color:var(--ink-dim); font-size:1.4rem;
  line-height:1; margin-left:12px;
}
#verse-panel .vp-close:hover{ color:var(--gold); }
#verse-panel .vp-sub{
  color:var(--ink-dim); font-style:italic; font-size:0.82rem;
  margin:4px 0 22px;
  border-bottom:1px solid rgba(201,162,75,0.2);
  padding-bottom:16px;
}
#verse-panel .vp-status{
  color:var(--ink-dim); font-style:italic; font-size:0.92rem;
  padding:30px 6px; text-align:center; line-height:1.6;
}
#verse-panel .vp-status code{
  color:var(--teal); font-style:normal; font-size:0.8rem;
}
.verse-card{
  background: linear-gradient(160deg, rgba(107,79,160,0.16), rgba(47,155,181,0.07));
  border:1px solid rgba(201,162,75,0.28);
  border-radius:10px;
  padding:16px 18px 14px;
  margin-bottom:14px;
  position:relative;
  animation: cardIn 0.4s ease both;
}
@keyframes cardIn{
  from{ opacity:0; transform:translateY(6px); }
  to{ opacity:1; transform:translateY(0); }
}
.verse-card::before{
  content:"";
  position:absolute; left:0; top:10px; bottom:10px; width:3px;
  background:linear-gradient(180deg, var(--gold), var(--teal));
  border-radius:2px;
}
.verse-card .vc-ref{
  font-family:'Cinzel', serif;
  font-size:0.72rem;
  letter-spacing:0.08em;
  color:var(--teal);
  text-transform:uppercase;
  margin-bottom:9px;
}
.verse-card .vc-text{
  font-family:'Noto Sans Tamil', 'EB Garamond', serif;
  font-size:1.08rem;
  line-height:1.85;
  color:var(--ink);
}

::-webkit-scrollbar{ width:6px; }
::-webkit-scrollbar-thumb{ background:rgba(201,162,75,0.4); border-radius:3px; }

/* 1. Clear the layout block container and elevate it on the z-axis */
#maintopheader {
  position: relative;
  z-index: 100;          /* High value ensures it sits on top of all canvas/chart vectors */
  width: 100%;
  pointer-events: auto;  /* Explicitly overrides any inherited pointer freezes */
}

/* 2. Configure the site-header wrapper to allow inner touch triggers */
#site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  pointer-events: auto;  
}

/* 3. Target your navigation buttons directly */
#site-header nav button {
  position: relative;
  z-index: 101;          /* Elevates button priority above parent container layers */
  pointer-events: auto;  /* Force enables click/tap handling */
  cursor: pointer;       /* Changes the mouse pointer to a hand icon on hover */
}

/* 4. Safeguard: Prevent your absolute background chart from eating clicks */
#chart {
  position: absolute;
  /* Make sure top pushes the chart down past your total navbar height */
  top: 80px;             
  bottom: 0; left: 0; right: 0;
  z-index: 1;            /* Keeps map visualization underneath your active links */
}