/* ================= Graph view ================= */
body[data-view="graph"] { background: var(--bg); overflow: hidden; }
.graph-view {
  position: fixed; inset: 56px 0 0 0; z-index: 1; font-family: var(--font-ui); overflow: hidden;
  background: var(--bg);
  animation: graph-in .7s ease-out both;
}
@keyframes graph-in { from { opacity: 0; } }
.graph-stage { position: absolute; inset: 0; touch-action: none; }
.graph-stage canvas { display: block; }
/* Title on the left, search and filters on the right; on phones the controls drop to a row under the title */
.graph-top {
  position: absolute; left: clamp(16px, 3vw, 32px); right: clamp(12px, 3vw, 28px); top: clamp(14px, 2.4vw, 26px);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; pointer-events: none; z-index: 2;
}
.graph-head { pointer-events: none; }
.graph-head h1 { margin: 0; font: 400 clamp(30px, 3.6vw, 40px)/1.05 var(--font-display); letter-spacing: -.01em; }
.graph-head p { margin: 6px 0 0; font-size: 13.5px; color: var(--ink-2); }
.graph-draft { margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; background: color-mix(in srgb, #d4a72c 22%, var(--surface)); color: var(--ink); }

.graph-key {
  position: absolute; left: clamp(12px, 3vw, 32px); bottom: clamp(12px, 2.4vw, 24px); z-index: 2; width: max-content; max-width: min(300px, calc(100% - 24px));
  padding: 8px 14px 8px 12px; border-radius: 12px; font-size: 12.5px; color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 86%, transparent); border: 1px solid color-mix(in srgb, var(--rule) 70%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.graph-key[open] { width: min(300px, calc(100% - 24px)); }
/* Web | Timeline: a two-way switch in the bottom right corner, under an open key on phones */
.graph-layout {
  position: absolute; right: clamp(12px, 3vw, 32px); bottom: clamp(12px, 2.4vw, 24px); z-index: 1; display: inline-flex; padding: 3px;
  border-radius: 999px; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.graph-layout button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px 0 9px; border: 0; border-radius: 999px; background: none; cursor: pointer;
  font: 500 13px var(--font-ui); color: var(--ink-3);
}
.graph-layout svg { width: 18px; height: 18px; fill: currentColor; }
.graph-layout button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.graph-layout button:not([aria-pressed="true"]):hover { color: var(--ink); }
.graph-key summary { cursor: pointer; font-weight: 500; color: var(--ink); list-style: none; }
.graph-key summary::-webkit-details-marker { display: none; }
.graph-key summary::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 8px 2px 2px; border: solid var(--ink-3); border-width: 0 1.5px 1.5px 0; transform: rotate(-135deg); transition: transform .2s; }
.graph-key[open] summary::before { transform: rotate(45deg); }
.key-body { max-height: calc(100vh - 260px); overflow-y: auto; overscroll-behavior: contain; margin-right: -8px; padding-right: 8px; }
.graph-key h3 { margin: 10px 0 2px; font: 600 10.5px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.graph-key ul { list-style: none; margin: 0; padding: 0; }
.graph-key li { display: flex; align-items: baseline; gap: 10px; margin: 5px 0; line-height: 1.4; }
.graph-key li b { font-weight: 600; color: var(--ink); }
.graph-key li i:not([class]) { font-family: var(--font-read); font-size: 13.5px; }
.key-line { flex: none; width: 28px; border-top: 2.4px solid var(--c, var(--ink-2)); transform: translateY(-3px); }
.key-documented { border-top-style: solid; }
.key-probable { border-top-style: dashed; }
.key-none { border-top-style: dotted; }
.key-documented, .key-probable, .key-none { border-top-width: 2px; border-top-color: var(--ink-2); }
.key-case { border-top-color: var(--ink-2); }
/* the direction: a line ending in an arrowhead, with a dot on its way */
.key-arrow {
  flex: none; position: relative; width: 28px; height: 0; border-top: 2px solid var(--ink-2); transform: translateY(-3px);
  background: radial-gradient(circle, var(--ink-2) 2.6px, transparent 3px) 6px -4px / 7px 7px no-repeat;
}
.key-arrow::after { content: ""; position: absolute; right: -2px; top: -6px; border: 5px solid transparent; border-left: 8px solid var(--ink-2); border-right: 0; }
.key-medal {
  flex: none; width: 13px; height: 13px; margin: 0 8px 0 7px; border-radius: 50%; align-self: center;
  background: var(--bg); box-shadow: inset 0 0 0 1.2px var(--ink-3);
}
.graph-key .key-last { margin-top: 10px; }

.graph-tip {
  position: absolute; left: 0; top: 0; z-index: 3; max-width: 280px; padding: 9px 12px 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--rule); box-shadow: var(--shadow);
  pointer-events: none; font-size: 13px; color: var(--ink-2); line-height: 1.4;
}
.graph-tip b { display: block; margin-bottom: 2px; font: 500 18px/1.2 var(--font-display); color: var(--ink); }
.graph-tip b.tip-pair { font-style: normal; font-size: 15.5px; }
.graph-tip b.tip-pair em { font-style: normal; font-weight: 500; }
.graph-tip b.tip-pair i { font-style: italic; }
.graph-tip span { display: block; }
.graph-tip .tip-rel { margin-top: 4px; color: var(--ink-3); font-size: 12px; }
@media (prefers-reduced-motion: reduce) { .graph-view { animation: none; } }
.graph-standin { position: absolute; visibility: hidden; pointer-events: none; }
.graph-tip .tip-def, .gp-def { margin-top: 2px; color: var(--ink-3); font-size: 12.5px; line-height: 1.4; }
.graph-tip .tip-def .def-k, .gp-def .def-k { display: inline; margin: 0; font: 600 12.5px var(--font-ui); color: var(--ink-2); }
.graph-tip .tip-def .def-k span, .gp-def .def-k span { display: inline; font-weight: 500; font-style: italic; }
.graph-tip:has(.tip-def) { max-width: 384px; }
.graph-tip .tip-claim { max-width: 360px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.graph-tip:has(.tip-claim) { max-width: 384px; }

/* Relation popover: at the middle of the line; a sheet along the bottom on phones */
.graph-pop {
  position: absolute; left: 0; top: 0; z-index: 4; width: min(430px, calc(100% - 20px)); max-height: min(72%, 600px);
  display: flex; flex-direction: column; border-radius: 14px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--rule); border-top: 3px solid var(--c, var(--ink-3)); box-shadow: var(--shadow);
  font-family: var(--font-ui); color: var(--ink); animation: gp-in .18s ease-out;
}
.graph-pop[hidden] { display: none; }
.graph-pop.is-sheet {
  left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 64%; transform: none !important;
  border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
}
.gp-head { position: relative; padding: 12px 44px 8px 16px; border-bottom: 1px solid var(--rule); flex: none; }
.gp-pair { margin: 0; font: 500 19px/1.3 var(--font-display); }
.gp-pair em { font-style: normal; font-weight: 500; }
.gp-pair i { font-style: italic; }
.gp-def { margin: 3px 0 0; }
.gp-contact { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.gp-close {
  position: absolute; right: 6px; top: 6px; width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: none; color: var(--ink-3); font: 22px/1 var(--font-ui); cursor: pointer;
}
.gp-close:hover { background: var(--surface-2); color: var(--ink); }
.gp-tabs { display: flex; gap: 4px; padding: 8px 16px 0; flex: none; }
.gp-tabs button {
  padding: 4px 12px; min-height: 30px; border: 1px solid var(--rule); border-radius: 999px; background: none;
  font: 500 12.5px var(--font-ui); color: var(--ink-2); cursor: pointer;
}
.gp-tabs button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.gp-body { overflow-y: auto; overscroll-behavior: contain; padding: 10px 16px 14px; }
.gp-tags { margin: 0 0 6px; }
.gp-tags .tag { display: inline-block; margin-right: 4px; padding: 1px 8px; border-radius: 999px; font: 500 11px/1.6 var(--font-ui); background: var(--surface-2); color: var(--ink-2); }
.gp-tags .tag.draft { background: color-mix(in srgb, #d4a72c 22%, var(--surface)); color: var(--ink); }
.gp-claim { margin: 0 0 12px; font: 16.5px/1.5 var(--font-read); }
.gp-pairs { list-style: none; margin: 0; padding: 0; }
.gp-pairs li { padding: 12px 0 8px; border-top: 1px solid var(--rule); }
.gp-psg { margin: 0 0 8px; padding: 9px 12px; border-radius: 10px; background: var(--bg); border-left: 3px solid var(--c, var(--rule)); }
.gp-psg p { margin: 0 0 4px; font: italic 15px/1.45 var(--font-read); }
.gp-psg footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; font-size: 12.5px; }
.gp-psg cite { font-style: normal; color: var(--ink-3); }
.gp-psg a { color: var(--accent); text-decoration: none; font-weight: 500; }
.gp-psg a:hover { text-decoration: underline; }
.gp-line { margin: 0 0 4px; font: 14.5px/1.45 var(--font-read); color: var(--ink-2); }
.gp-line b { margin-right: 6px; font: 600 10.5px var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.gp-q { padding-top: 10px; border-top: 1px solid var(--rule); }
.gp-q h3 { margin: 0 0 4px; font: 600 10.5px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.gp-q p { margin: 0; font: italic 16px/1.45 var(--font-read); }
@keyframes gp-in { from { opacity: 0; } }

/* Author panel: on the right under the controls; a sheet along the bottom on phones */
.graph-author {
  position: absolute; right: clamp(12px, 3vw, 28px); top: 84px; z-index: 4; width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 110px); display: flex; flex-direction: column; border-radius: 14px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--rule); border-top: 2px solid var(--ink); box-shadow: var(--shadow);
  font-family: var(--font-ui); color: var(--ink); animation: gp-in .18s ease-out;
}
.graph-author[hidden] { display: none; }
.graph-author.is-sheet {
  left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 50%;
  border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
}
.ga-head { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px 44px 10px 16px; border-bottom: 1px solid var(--rule); flex: none; }
.ga-medal {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg); box-shadow: inset 0 0 0 1.2px var(--ink-3);
  font: 600 12px/1 var(--font-ui); letter-spacing: .08em; color: var(--ink-2);
}
.ga-head h2 { margin: 0; font: 500 24px/1.15 var(--font-display); text-wrap: balance; }
.ga-life { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ga-body { overflow-y: auto; overscroll-behavior: contain; padding: 10px 16px 14px; }
.ga-about { margin: 0 0 12px; font: 15.5px/1.5 var(--font-read); color: var(--ink-2); }
.ga-body h3 { margin: 2px 0 4px; font: 600 10.5px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.ga-books { list-style: none; margin: 0; padding: 0; }
.ga-books button {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%; min-height: 36px; padding: 6px 0;
  border: 0; border-bottom: 1px solid var(--rule); background: none; color: var(--ink); text-align: left; cursor: pointer;
}
.ga-books li:last-child button { border-bottom: 0; }
.ga-books .t { font: 500 17px/1.3 var(--font-display); }
.ga-books .k { flex: none; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ga-books button:hover .t, .ga-books button:focus-visible .t { text-decoration: underline; text-underline-offset: 3px; }
.ga-books button.is-out .t { color: var(--ink-3); }
.ga-more { display: inline-block; margin-top: 10px; font: 500 13.5px var(--font-ui); color: var(--accent); text-decoration: none; }
.ga-more:hover { text-decoration: underline; }
.gc-hits li.is-author b { font-style: normal; }

/* Search and filters */
.graph-ctrl {
  position: relative; pointer-events: auto; width: min(420px, 100%);
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: start;
}
/* 2D | 3D: a small two-way switch beside Filter */
.gc-mode {
  display: inline-flex; height: 40px; padding: 3px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.gc-mode button {
  min-width: 34px; padding: 0 8px; border: 0; border-radius: 999px; background: none; cursor: pointer;
  font: 500 12.5px var(--font-ui); letter-spacing: .02em; color: var(--ink-3);
}
.gc-mode button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.gc-mode button:not([aria-pressed="true"]):hover { color: var(--ink); }
.gc-mode button:disabled { opacity: .4; cursor: default; }
.gc-search { position: relative; }
.gc-search input {
  width: 100%; height: 40px; padding: 0 14px 0 36px; border-radius: 999px; font: 15px var(--font-ui); color: var(--ink);
  background: color-mix(in srgb, var(--surface) 88%, transparent) no-repeat 13px 50% / 15px 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23888' stroke-width='1.6'%3E%3Ccircle cx='6.8' cy='6.8' r='5'/%3E%3Cpath d='M10.6 10.6 15 15' stroke-linecap='round'/%3E%3C/svg%3E");
  border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent); box-shadow: 0 1px 2px rgba(0,0,0,.04);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.gc-search input::placeholder { color: var(--ink-3); }
.gc-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.gc-search input::-webkit-search-cancel-button { cursor: pointer; }
.gc-hits {
  position: absolute; left: 0; right: 0; top: 46px; z-index: 5; margin: 0; padding: 4px; list-style: none;
  max-height: min(340px, 60vh); overflow-y: auto; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--rule); box-shadow: var(--shadow);
}
.gc-hits li { padding: 7px 10px; border-radius: 8px; cursor: pointer; line-height: 1.3; }
.gc-hits li b { display: block; font: 500 17px/1.25 var(--font-display); color: var(--ink); }
.gc-hits li span { font-size: 12.5px; color: var(--ink-3); }
.gc-hits li[aria-selected="true"], .gc-hits li:hover { background: var(--surface-2); }
.gc-hits li.is-out b { color: var(--ink-3); }
.gc-hits .gc-none { cursor: default; color: var(--ink-3); font-size: 13px; }
.gc-toggle {
  height: 40px; padding: 0 14px; border-radius: 999px; font: 500 14px var(--font-ui); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.gc-toggle::after { content: ""; width: 5px; height: 5px; margin: 0 0 3px 2px; border: solid var(--ink-3); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); transition: transform .2s; }
.gc-toggle[aria-expanded="true"]::after { transform: rotate(-135deg); margin: 3px 0 0 2px; }
.gc-toggle.is-on { border-color: var(--ink-2); }
.gc-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; font: 600 11px/18px var(--font-ui); text-align: center; background: var(--ink); color: var(--bg); }
.gc-panel {
  grid-column: 1 / -1; z-index: 4; padding: 6px 14px 12px; border-radius: 14px; font-size: 13px;
  max-height: calc(100vh - 200px); overflow-y: auto; overscroll-behavior: contain;
  background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--rule); box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: gp-in .15s ease-out;
}
.gc-panel[hidden] { display: none; }
.gc-panel fieldset { margin: 0; padding: 8px 0 6px; border: 0; }
.gc-panel fieldset + fieldset { border-top: 1px solid var(--rule); }
.gc-panel legend { float: left; width: 100%; margin-bottom: 7px; padding: 0; font: 600 10.5px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.gc-panel legend output { margin-left: 4px; font: italic 400 15px var(--font-read); letter-spacing: 0; text-transform: none; color: var(--ink); }
.gc-chips { clear: both; display: flex; flex-wrap: wrap; gap: 6px; }
.gc-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 3px 11px; border-radius: 999px;
  border: 1px solid var(--rule); background: none; font: 13px var(--font-ui); color: var(--ink-2); cursor: pointer;
}
.gc-chip:hover { border-color: var(--ink-3); color: var(--ink); }
.gc-chip .n { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.gc-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.gc-chip[aria-pressed="true"] .n { color: color-mix(in srgb, var(--bg) 70%, transparent); }
.gc-dot { width: 14px; height: 0; border-top: 2.6px solid var(--c, var(--ink-2)); border-radius: 2px; }
.gc-year input { clear: both; display: block; width: 100%; margin: 4px 0 0; accent-color: var(--ink); }
.gc-year p { display: flex; justify-content: space-between; margin: 2px 0 0; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.gc-clear {
  margin-top: 8px; padding: 4px 0; border: 0; background: none; font: 500 13px var(--font-ui); color: var(--accent); cursor: pointer;
}
.gc-clear:disabled { color: var(--ink-3); opacity: .6; cursor: default; }
@media (max-width: 639px) {
  .graph-top { flex-direction: column; align-items: stretch; gap: 10px; left: 12px; right: 12px; }
  .graph-head { padding-left: 4px; }
  .graph-ctrl { width: 100%; }
  .gc-panel { max-height: calc(100vh - 56px - 150px); }
  .gc-search input, .gc-toggle { font-size: 16px; } /* no zoom on focus in iOS */
}

/* Connected books in a book's panel: what this book does to the other, then the other's title */
.fi-links .s { min-width: 0; }
.fi-links .v { margin-right: 4px; font: 500 12.5px var(--font-ui); color: var(--ink-3); }
.gp-side {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 12px; padding: 6px 14px 6px 10px; border-radius: 999px;
  border: 1px solid var(--c, var(--rule)); color: var(--ink); text-decoration: none; font: 500 13px var(--font-ui);
}
.gp-side:hover { background: color-mix(in srgb, var(--c, var(--ink)) 12%, transparent); }
.gp-side svg { width: 18px; height: 18px; color: var(--c, var(--ink-2)); }

/* A book's cascade: a bar along the bottom with the way back, the book's title and Read */
.graph-cascade {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: clamp(12px, 2.4vw, 24px); z-index: 3;
  display: flex; align-items: center; gap: 4px; max-width: calc(100% - 32px); padding: 4px;
  border-radius: 999px; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent);
  box-shadow: var(--shadow); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.graph-cascade[hidden] { display: none; }
.graph-cascade button {
  flex: none; display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 14px; border: 0; border-radius: 999px;
  background: none; cursor: pointer; font: 500 13px var(--font-ui); color: var(--ink-2);
}
.graph-cascade button:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.graph-cascade button[hidden] { display: none; }
.graph-cascade svg { width: 16px; height: 16px; margin-left: -4px; }
.graph-cascade .gk-title { min-width: 0; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 17px var(--font-display); color: var(--ink); }
.graph-cascade .gk-read { background: var(--ink); color: var(--bg); }
.graph-cascade .gk-read:hover { background: var(--ink); color: var(--bg); opacity: .88; }
/* the Web | Timeline switch and the key make room for it */
.graph-view:has(.graph-cascade:not([hidden])) .graph-layout { display: none; }
@media (max-width: 639px) {
  .graph-view:has(.graph-cascade:not([hidden])) .graph-key { display: none; }
  .graph-cascade .gk-title { font-size: 14px; }
}
