:root {
  font-family: Georgia,'Times New Roman',serif;
  color: var(--ct-text);
  background: var(--ct-page);
  font-size: 15px;
  --details-width: clamp(360px,30vw,560px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1100px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 22px;
  background: var(--ct-surface);
  border-bottom: 1px solid var(--ct-border);
  gap: 24px;
}

h1 {
  font-size: 36px;
  margin: 5px 0;
}

h2 {
  font-size: 22px;
  margin: 0 0 10px;
}

h3 {
  font-size: 17px;
  margin: 24px 0 8px;
}

p {
  line-height: 1.6;
  margin: 5px 0 12px;
  color: var(--ct-text-secondary);
}

.eyebrow {
  font: 11px system-ui;
  letter-spacing: 2px;
  color: var(--ct-text-muted);
}

button,input,select {
  font: 14px system-ui;
  border: 1px solid var(--ct-border-control);
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--ct-surface);
  color: var(--ct-text);
}

button {
  cursor: pointer;
}

button:hover {
  background: var(--ct-hover);
}

button:disabled {
  opacity: .4;
  cursor: default;
}

button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible {
  outline: 3px solid var(--ct-focus);
  outline-offset: 3px;
}

form {
  width: 360px;
  position: relative;
}

label {
  font: 13px system-ui;
}

form label {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  margin: 0 0 4px;
}

.search-row {
  display: flex;
  gap: 6px;
}

input {
  width: 100%;
}

#results:not(:empty) {
  position: absolute;
  top: 55px;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 8px;
  background: var(--ct-surface);
  box-shadow: 0 8px 30px var(--ct-shadow);
  max-height: 350px;
  overflow: auto;
}

#results button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 3px 0;
}

nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 22px;
  border-bottom: 1px solid var(--ct-border);
  flex-wrap: wrap;
}

select {
  margin-left: 8px;
  min-width: 190px;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 7px;
}

#level {
  min-width: 135px;
  text-align: center;
  font: 13px system-ui;
}

main {
  display: grid;
  grid-template-columns: minmax(0,1fr) 7px var(--details-width);
  height: auto;
  min-height: 0;
  flex: 1;
}

#canvas {
  min-width: 0;
  padding: 15px 16px 10px;
  display: flex;
  flex-direction: column;
}

.scope {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.scope p,#count {
  font: 13px/1.5 system-ui;
  color: var(--ct-text-muted);
}

#graph {
  flex: 1;
  min-height: 200px;
  overflow: auto;
  border: 1px solid var(--ct-border);
  border-radius: 12px;
  background: var(--ct-surface);
  position: relative;
  height: 0;
}

aside {
  overflow: auto;
  background: var(--ct-surface);
  border-left: 1px solid var(--ct-border);
  padding: 20px 24px;
}

aside ul {
  padding-left: 20px;
  line-height: 1.6;
}

aside a {
  color: var(--ct-link);
  overflow-wrap: anywhere;
}

.legend {
  display: flex;
  gap: 12px;
  font: 11px system-ui;
  color: var(--ct-text-muted);
  padding-top: 8px;
  flex-wrap: wrap;
}

.node {
  cursor: pointer;
}

.node rect {
  fill: var(--ct-surface);
  stroke: var(--ct-node-border);
  stroke-width: 1.3;
}

.node.selected rect {
  fill: var(--ct-node-selected);
  stroke: var(--ct-accent);
  stroke-width: 2.5;
}

.node text {
  fill: var(--ct-text);
  font: 12px system-ui;
}

.node .date {
  font: 11px system-ui;
  fill: var(--ct-text-muted);
  font-size: 11px;
}

.link {
  fill: none;
  stroke: var(--ct-relationship);
  stroke-width: 1.5;
  cursor: pointer;
  opacity: .7;
}

.link.split {
  stroke: var(--ct-relationship-split);
}

.link:hover {
  stroke: var(--ct-focus);
  stroke-width: 5;
}

.tick text {
  fill: var(--ct-text-muted);
  font: 11px system-ui;
}

.tick line {
  stroke: var(--ct-grid);
}

.empty {
  padding: 30px;
}

.source {
  font: 13px/1.5 system-ui;
  border-top: 1px solid var(--ct-border);
  padding: 12px 0;
}

.relationship {
  display: block;
  text-align: left;
  width: 100%;
  margin: 6px 0;
  font-size: 12px;
}

.badge {
  font: 11px system-ui;
  color: var(--ct-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

header,nav {
  flex-shrink: 0;
}

#canvas,aside {
  min-height: 0;
}

header>div {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  column-gap: 16px;
}

header .eyebrow {
  display: none;
}

header h1 {
  font-size: 29px;
  margin: 0;
}

header p {
  font-size: 14px;
  margin: 0;
}

.search-row input,.search-row button {
  padding: 7px 10px;
}

nav button,nav select {
  padding: 7px 9px;
}

nav select {
  min-width: 0;
}

#branch {
  width: 145px;
}

#layout {
  width: 170px;
}

.scope h2 {
  font-size: 21px;
  margin: 0 0 5px;
}

.scope p {
  margin: 0 0 12px;
  max-width: 720px;
}

aside h2 {
  font-size: 26px;
  line-height: 1.2;
}

aside p,aside li {
  font-size: 16px;
}

#splitter {
  cursor: col-resize;
  background: var(--ct-splitter);
  touch-action: none;
}

#splitter:hover,#splitter:focus {
  background: var(--ct-splitter-hover);
}

#period {
  font: 12px system-ui;
}

#period input {
  width: 75px;
  padding: 6px;
}

.link:hover,.link:focus {
  opacity: 1;
  stroke-width: 4;
}

.context rect {
  fill: var(--ct-lane);
  stroke-dasharray: 4 3;
}

.aggregate rect {
  fill: var(--ct-group);
  stroke: var(--ct-group-border);
}

.mode-note {
  font: 12px system-ui;
  fill: var(--ct-text-muted);
}

.edge-count {
  font: 11px system-ui;
  fill: var(--ct-text-secondary);
  paint-order: stroke;
  stroke: var(--ct-surface);
  stroke-width: 4px;
}

.horizontal-scene {
  position: relative;
  min-height: 100%;
}

.horizontal-scene>svg {
  display: block;
}

.horizontal-lanes {
  position: sticky;
  left: 0;
  width: 155px;
  background: var(--ct-surface);
  border-right: 1px solid var(--ct-border);
  pointer-events: none;
  z-index: 2;
}

.horizontal-origin {
  position: absolute;
  top: 15px;
  left: 10px;
  width: 135px;
  font: 12px/1.4 system-ui;
  pointer-events: auto;
}

.horizontal-origin button {
  width: 100%;
  font-size: 12px;
  padding: 8px;
  text-align: left;
}

.horizontal-origin small {
  display: block;
  color: var(--ct-text-muted);
  font-size: 10px;
  margin-top: 5px;
}

.horizontal-lane-label {
  position: absolute;
  left: 10px;
  width: 135px;
  font: 13px/1.4 system-ui;
  color: var(--ct-text-secondary);
}

.horizontal-axis text {
  font: 11px system-ui;
}

.link.mixed { stroke: var(--ct-relationship-mixed); stroke-dasharray: 4 3; }
#period-error { color: var(--ct-error); font: 12px system-ui; }
.node:focus-visible rect { stroke: var(--ct-focus); stroke-width: 3; }
.orientation { display: flex; border: 1px solid var(--ct-border-control); border-radius: 7px; overflow: hidden; }
.orientation[hidden] { display: none; }
.orientation button { border: 0; border-radius: 0; background: transparent; padding: 7px 11px; }
.orientation button + button { border-left: 1px solid var(--ct-border-control); }
.orientation button[aria-pressed="true"] { background: var(--ct-accent); color: var(--ct-on-accent); }
.orientation button:focus-visible { outline-offset: -3px; }
#layout { width: 145px; }
/* Mobile controls and reading sheet are isolated from the desktop workspace. */
.mobile-only { display: none; }
.scope-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
#mobile-details { border: 1px solid var(--ct-border-control); border-radius: 14px; padding: 0; color: var(--ct-text); background: var(--ct-surface); }
#mobile-details::backdrop { background: var(--ct-backdrop); }
#mobile-details[open] { display: flex; flex-direction: column; width: min(560px,calc(100vw - 16px)); height: min(88dvh,900px); max-height: calc(100dvh - 16px); }
.mobile-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--ct-border); font: 14px system-ui; }
#mobile-details-body { min-height: 0; flex: 1; display: flex; }
#mobile-details-body aside { min-width: 0; width: 100%; border: 0; }
@media (max-width: 1099px) {
  body { min-width: 0; width: 100%; height: 100dvh; }
  header { padding: 10px 12px; flex-direction: column; align-items: stretch; gap: 7px; }
  header>div { display: flex; align-items: baseline; gap: 10px; }
  header h1 { font-size: 24px; }
  header p { font-size: 12px; }
  header form { width: 100%; }
  header form label { display: none; }
  #search { min-width: 0; }
  input,select,button { font-size: 16px; }
  button,select,.search-row input,.search-row button { min-height: 44px; }
  #results:not(:empty) { top: 46px; max-height: min(45dvh,350px); }
  nav { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 6px 8px; padding: 8px 12px; }
  nav>label { display: flex; flex-direction: column; gap: 3px; }
  nav>label:first-child { grid-column: 1; grid-row: 1; }
  nav>label:nth-of-type(2) { grid-column: 2; grid-row: 1; }
  nav select,#branch,#layout { width: 100%; margin: 0; }
  .zoom { grid-column: 1; grid-row: 2; gap: 4px; }
  .zoom button { min-width: 44px; }
  #level { min-width: 0; flex: 1; font-size: 11px; }
  .orientation { grid-column: 2; grid-row: 2; }
  .orientation button { min-width: 0; flex: 1; padding: 7px 5px; font-size: 13px; }
  #reset { grid-column: 1; }
  #mobile-range-toggle { grid-column: 2; }
  #clear-focus { grid-column: 1 / -1; }
  #period { grid-column: 1 / -1; align-items: center; gap: 5px; flex-wrap: wrap; }
  #period input { width: 80px; min-height: 44px; font-size: 16px; }
  body:not(.mobile-dates-open) #period { display: none; }
  body.mobile-dates-open #period:not([hidden]) { display: flex; }
  #period-error { width: 100%; }
  main { grid-template-columns: minmax(0,1fr); }
  #splitter { display: none; }
  #canvas { padding: 10px 10px 8px; }
  .scope { gap: 8px; }
  .scope h2 { font-size: 18px; }
  .scope p { font-size: 11px; margin-bottom: 8px; }
  #count { font-size: 10px; text-align: right; }
  .scope-actions { flex: 0 0 94px; }
  #mobile-open-details { padding: 7px; font-size: 12px; width: 94px; }
  #graph { min-height: 160px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .legend { gap: 4px 9px; font-size: 9px; }
  .legend span:last-child { display: none; }
  .mobile-only:not([hidden]) { display: block; }
  #mobile-pan:not([hidden]) { display: flex; gap: 8px; padding-top: 6px; }
  #mobile-pan button { flex: 1; }
  #mobile-details-body aside { padding: 16px; }
  #mobile-details-body h2 { font-size: 25px; }
  #mobile-close-details { font-size: 14px; min-height: 44px; }
}
@media (max-width: 1099px) and (max-height: 650px) {
  body { height: auto; min-height: 100dvh; overflow-y: auto; }
  main { flex: none; height: 520px; }
}
@media (max-width: 1099px) {
  .horizontal-lanes { width: 96px; }
  .horizontal-origin { left: 7px; width: 80px; }
  .horizontal-lane-label { left: 7px; width: 80px; font-size: 11px; overflow-wrap: anywhere; }
}


.site-home { color: inherit; text-decoration: none; }
.site-home:hover { text-decoration: underline; }
/* A single compact row leaves the timeline in charge on touch screens. */
#view-settings { display: contents; }
@media (max-width: 1099px) {
  header { padding: 5px 10px; gap: 4px; }
  header h1 { margin: 0; }
  nav { display: flex; flex-wrap: wrap; align-items: center; padding: 5px 10px; gap: 5px 8px; }
  nav .zoom { flex: 1; margin: 0; }
  #mobile-settings-toggle { padding: 6px 10px; font-size: 13px; }
  #view-settings { display: none; width: 100%; }
  .mobile-settings-open #view-settings { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 6px 8px; padding: 6px 0; }
  #view-settings>label { display: flex; flex-direction: column; gap: 3px; }
  #view-settings .orientation { grid-column: 1 / -1; grid-row: auto; }
  #view-settings #reset,#view-settings #mobile-range-toggle { grid-column: auto; }
  #canvas { padding: 6px 10px; }
  .scope { align-items: center; }
  .scope h2 { font-size: 15px; line-height: 1.25; margin: 0; }
  .scope p,#count { display: none; }
  .scope-actions { flex-basis: auto; }
  #mobile-open-details { width: auto; padding: 6px 8px; }
  .scope { margin-bottom: 5px; }
  #mobile-pan { padding-top: 3px; }
  #mobile-pan button { padding: 5px 10px; font-size: 13px; }
}
