/* motekaitis.net — parchment, ink and watercolor */

:root {
  --paper: #e8d8b4;
  --paper-light: #f4ead3;
  --paper-dark: #d6c095;
  --ink: #3b2e1f;
  --ink-soft: #6b5638;
  --moss: #5f7444;
  --ochre: #b08a4a;
  --rust: #8c4f2b;
  --serif: "IM Fell English", Georgia, "Times New Roman", serif;
  --serif-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --panel-w: 26rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
}

a { color: var(--rust); text-decoration-color: rgba(140, 79, 43, 0.4); text-underline-offset: 0.15em; }
a:hover { text-decoration-color: currentColor; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Header & footer ---------- */

.site-header { text-align: center; padding: 2.5rem 1.25rem 1rem; }
.site-header h1 {
  font-family: var(--serif-sc);
  font-weight: normal;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.05;
  margin: 0;
  letter-spacing: 0.01em;
}
.site-header p { margin: 0.25rem 0 0; font-style: italic; color: var(--ink-soft); }

.site-footer { text-align: center; padding: 2rem 1rem 3rem; font-style: italic; color: var(--ink-soft); font-size: 0.95rem; }

/* ---------- Family units (readable without JavaScript) ---------- */

.map { display: none; }

#families {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
}

.family-unit {
  background: var(--paper-light);
  border: 1px solid rgba(80, 55, 25, 0.3);
  border-radius: 3px;
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: 0 2px 10px rgba(60, 40, 15, 0.12);
}

.family-unit h2 {
  font-family: var(--serif-sc);
  font-weight: normal;
  font-size: clamp(1.45rem, 3vw, 1.9rem);
  line-height: 1.1;
  margin: 0;
}
.family-unit > h2::after,
.family-unit > .person > h2::after {
  content: "❦";
  display: block;
  font-family: Georgia, serif;
  font-size: 1rem;
  color: var(--moss);
  margin: 0.45rem 0 0.9rem;
}

.person { overflow: hidden; }
.family-unit > .person + .person {
  border-top: 1px dashed rgba(80, 55, 25, 0.35);
  margin-top: 1.25rem;
  padding-top: 1.25rem;
}
.person h3 {
  font-family: var(--serif-sc);
  font-weight: normal;
  font-size: 1.3rem;
  line-height: 1.15;
  margin: 0;
}

.lineage { font-style: italic; color: var(--ink-soft); margin: 0.2rem 0 0.75rem; }
.bio p { margin: 0 0 0.75em; }

.portrait {
  float: right;
  width: 7rem;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 50% / 42%;
  border: 3px double var(--ink-soft);
  filter: sepia(0.45) contrast(0.95);
  margin: 0.25rem 0 0.75rem 1rem;
}

.links h3, .children h3 {
  font-family: var(--serif-sc);
  font-weight: normal;
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 1.1rem 0 0.35rem;
  letter-spacing: 0.03em;
}
.links ul, .children ul { list-style: none; margin: 0; padding: 0; }
.links li, .children li { padding-left: 1.3em; position: relative; margin: 0.2em 0; }
.links li::before, .children li::before {
  content: "✦";
  position: absolute; left: 0; top: 0.05em;
  color: var(--moss);
  font-size: 0.8em;
}

/* ---------- Map mode (JavaScript has drawn the map) ---------- */

.map-ready, .map-ready body { height: 100%; overflow: hidden; }

.map-ready main {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: minmax(0, 1fr);
}

.map-ready .site-header {
  position: fixed;
  top: 0; left: 0;
  z-index: 4;
  padding: 1rem 1.4rem;
  text-align: left;
  pointer-events: none;
  max-width: calc(100% - var(--panel-w));
}
.map-ready .site-header h1 {
  font-size: clamp(1.5rem, 3.2vw, 2.5rem);
  text-shadow: 0 0 10px var(--paper), 0 0 4px var(--paper);
}
.map-ready .site-header p { text-shadow: 0 0 6px var(--paper); }
.map-ready .site-footer { display: none; }

.map-ready .map {
  display: block;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .26 0 0 0 0 .12 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.32'/%3E%3C/svg%3E");
  background-size: 260px 260px;
}
.map-ready .map.is-dragging { cursor: grabbing; }
.map-ready .map::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 140px rgba(95, 62, 22, 0.35), inset 0 0 30px rgba(95, 62, 22, 0.2);
  z-index: 1;
}

.map-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: hidden; }

/* Ink */
.mg-ink { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.mg-w0 { stroke-width: 1.3; }
.mg-w1 { stroke-width: 0.85; }
.mg-w2 { stroke-width: 0.5; }
.mg-ambient { opacity: 0.2; }
.mg-cord-halo { stroke-width: 6; opacity: 0.1; }
.mg-cord-main { stroke-width: 2; }
.mg-cord-strand { stroke-width: 0.8; opacity: 0.8; }
.mg-frame-outer { stroke-width: 1.6; }
.mg-frame-inner { stroke-width: 0.7; }
.mg-leaf { fill: rgba(95, 116, 68, 0.5); stroke: var(--ink); stroke-width: 0.7; }
.mg-stain { opacity: 0.55; }
.mg-lichen { fill: rgba(176, 138, 74, 0.28); }

.mg-bulb { stroke: var(--ink); stroke-width: 1.6; }
.mg-bulb-shine { fill: none; stroke: rgba(255, 252, 240, 0.7); stroke-width: 1.6; stroke-linecap: round; }
.mg-speck { fill: var(--ink); opacity: 0.35; }
.mg-bridge-out { fill: none; stroke: var(--ink); stroke-width: 12; stroke-linecap: round; }
.mg-bridge-in { fill: none; stroke: #d3b67f; stroke-width: 9; stroke-linecap: round; }

.mg-label {
  font-family: var(--serif-sc);
  fill: var(--ink);
  paint-order: stroke;
  stroke: rgba(240, 228, 200, 0.85);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.mg-label-given { font-size: 17px; }
.mg-label-family { font-family: var(--serif); font-style: italic; font-size: 13px; }

/* Fading by distance from the focus */
.mg-node, .mg-edge { transition: opacity 0.6s ease; }
.mg-node[data-d="0"], .mg-edge[data-d="0"] { opacity: 1; }
.mg-node[data-d="1"], .mg-edge[data-d="1"] { opacity: 0.85; }
.mg-node[data-d="2"], .mg-edge[data-d="2"] { opacity: 0.4; }
.mg-node[data-d="3"], .mg-edge[data-d="3"] { opacity: 0.2; }
.mg-node[data-d="4"], .mg-edge[data-d="4"] { opacity: 0.1; }

/* The looking glass */
.map-svg .lens, .map-svg .lens-rim, .map-svg .lens-shadow { pointer-events: none; }
.map-svg .lens-paper { fill: #f1e6cb; }
.map-svg .lens-shine { fill: rgba(255, 255, 255, 0.22); }

/* Arrows around the glass */
.lens-arrows { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.lens-arrow {
  position: absolute;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 234, 211, 0.95) 52%, rgba(244, 234, 211, 0) 71%);
  color: var(--ink);
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.25s ease, transform 0.2s ease, color 0.2s ease;
  animation: arrow-in 0.5s ease both;
  -webkit-tap-highlight-color: transparent;
}
.lens-arrow svg { display: block; width: 100%; height: 100%; transform: rotate(var(--a)); }
.lens-arrow:hover, .lens-arrow:focus-visible { color: var(--rust); transform: scale(1.12); outline: none; }
.lens-arrow:focus-visible { box-shadow: 0 0 0 2px var(--rust); }
.lens-arrow-label {
  position: absolute;
  left: 50%; top: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink);
  background: rgba(244, 234, 211, 0.95);
  border-radius: 3px;
  padding: 0.05rem 0.45rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.lens-arrow:hover .lens-arrow-label, .lens-arrow:focus-visible .lens-arrow-label { opacity: 1; }
.is-dragging .lens-arrow { opacity: 0; pointer-events: none; }

@keyframes arrow-in { from { opacity: 0; } to { opacity: 1; } }

.map-hint {
  position: absolute;
  left: 1.1rem; bottom: 0.8rem;
  margin: 0;
  z-index: 2;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-soft);
  pointer-events: none;
  text-shadow: 0 0 6px var(--paper);
}

/* The detail panel */
.map-ready #families {
  display: block;
  max-width: none;
  margin: 0;
  padding: 1.75rem 1.75rem 3rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  position: relative;
  z-index: 3;
  background:
    linear-gradient(90deg, rgba(120, 85, 35, 0.12), transparent 1.5rem),
    radial-gradient(ellipse at 30% 10%, rgba(255, 252, 240, 0.6), transparent 60%),
    var(--paper-light);
  border-left: 1px solid rgba(80, 55, 25, 0.35);
  box-shadow: -10px 0 28px rgba(60, 40, 15, 0.22);
}
.map-ready .family-unit {
  display: none;
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
}
.map-ready .family-unit.is-focus { display: block; animation: unit-in 0.45s ease both; }

@keyframes unit-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Phones and narrow screens: map on top, details below */
@media (max-width: 760px) {
  .map-ready main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .map-ready .site-header { max-width: none; padding: 0.7rem 1rem; }
  .map-ready .site-header h1 { font-size: 1.45rem; }
  .map-ready .site-header p { font-size: 0.9rem; }
  .map-ready #families {
    max-height: 42vh;
    max-height: 42dvh;
    padding: 1.25rem 1.25rem calc(2rem + env(safe-area-inset-bottom));
    border-left: 0;
    border-top: 1px solid rgba(80, 55, 25, 0.35);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 26px rgba(60, 40, 15, 0.25);
    background:
      radial-gradient(ellipse at 30% 0%, rgba(255, 252, 240, 0.6), transparent 60%),
      var(--paper-light);
  }
  .map-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mg-node, .mg-edge, .lens-arrow { transition: none; animation: none; }
  .map-ready .family-unit.is-focus { animation: none; }
}
