:root{
  --page-gutter:clamp(18px,4.5vw,28px);
  --bg:#FFFFFF;
  --fg:#000000;
  --dim:#767676;
  --line:#D2D2D2;
  --hair:#E8E8E8;
  --serif:"Literata",Charter,Georgia,serif;
  --mono:"IBM Plex Mono",ui-monospace,Menlo,monospace;
  --top:env(safe-area-inset-top,0px);
  --bot:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#000000; --fg:#FFFFFF; --dim:#7C7C7C; --line:#343434; --hair:#1C1C1C;
  }
}
:root[data-theme="dark"]{
  --bg:#000000; --fg:#FFFFFF; --dim:#7C7C7C; --line:#343434; --hair:#1C1C1C;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html{-webkit-text-size-adjust:100%}
html,body{
  width:100%;height:100%;margin:0;background:var(--bg);color:var(--fg);
  overflow:hidden;overscroll-behavior:none;
}
body{
  font-family:var(--serif);font-size:.90625rem;line-height:1.47;
  font-weight:400;font-optical-sizing:auto;
  -webkit-font-smoothing:antialiased;
  -webkit-user-select:text;user-select:text;
}

.app{
  width:100%;height:100vh;height:100svh;height:100dvh;
  max-width:520px;margin:0 auto;overflow:hidden;
  display:grid;grid-template-rows:auto minmax(0,1fr);
  border-left:1px solid var(--hair);border-right:1px solid var(--hair);
  padding-left:env(safe-area-inset-left,0px);
  padding-right:env(safe-area-inset-right,0px);
}
@media (max-width:522px){.app{border:0}}

/* ---- top ---- */
.bar{
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  padding:calc(var(--top) + 6px) var(--page-gutter) 4px;
  font-family:var(--mono);font-size:10px;letter-spacing:.02em;color:var(--dim);
}
.document-links{display:inline-flex;align-items:center;gap:18px;min-width:0}
.bar a{display:inline-flex;align-items:center;min-height:28px;color:inherit;text-decoration:none}
.bar a:hover{color:var(--fg)}
.bar a:focus-visible{outline:1px solid var(--dim);outline-offset:3px}

/* ---- tree strip ---- */
/* Scrolls in after Lesekode, then stays at the reading edge only while
   propositions are visible; the containing section supplies the end stop. */
.proposition-section{position:relative;min-width:0}
.strip{position:sticky;top:0;z-index:10;background:var(--bg);padding:1px 0 4px;border-bottom:1px solid var(--hair);margin-inline:calc(0px - var(--page-gutter))}
.strip[hidden]{display:none}
.strip svg{display:block;width:100%;height:auto;overflow:visible;touch-action:none}
.strip{-webkit-user-select:none;user-select:none}
.rbar{stroke:var(--line);stroke-width:1.1;fill:none;stroke-linecap:round}
.rbar.on{stroke:var(--dim)}
.stem{stroke:var(--line);stroke-width:.9;fill:none}
.stem.sec{stroke:var(--dim)}
.stem.on{stroke:var(--fg);stroke-width:1.2}
.dot{fill:var(--fg)}
.rlab{font-family:var(--mono);font-size:9px;fill:var(--dim);text-anchor:middle}
.rlab.on{fill:var(--fg)}
.tap{fill:transparent}


/* ---- reading / continuous stream ---- */
.read{min-width:0;min-height:0;overflow-x:hidden;overflow-y:auto;overscroll-behavior-y:contain;-webkit-overflow-scrolling:touch;padding:0 var(--page-gutter) calc(1.5rem + var(--bot));touch-action:pan-y pinch-zoom;scrollbar-width:none}
.read::-webkit-scrollbar{display:none}
.read:focus-visible{outline:1px solid var(--dim);outline-offset:-1px}
.stream{padding:.375rem 0 1.25rem}
.section-title{font-family:var(--serif);font-size:1.15rem;font-weight:400;line-height:1.3;margin:2.4rem 0 .8rem;padding-top:.65rem;border-top:1px solid var(--hair);scroll-margin-top:12px}
.section-title:first-child{margin-top:.65rem;padding-top:0;border-top:0}
#introduksjon,#del-lesekode{border-top:0;border-bottom:1px solid var(--hair);padding-top:0;padding-bottom:.55rem}
.plain-paragraph{font-size:.90rem;line-height:1.5;font-weight:400;white-space:pre-line;margin:.9rem 0;overflow-wrap:anywhere;text-align:justify;hyphens:auto;-webkit-hyphens:auto;-webkit-user-select:text;user-select:text}
.plain-paragraph em,.prop em{font-style:italic}.plain-paragraph strong,.prop strong{font-weight:600}
.prop{position:relative;display:grid;grid-template-columns:4rem minmax(0,1fr);gap:0 .75rem;align-items:start;width:100%;min-width:0;font-size:.93rem;line-height:1.5;font-weight:400;padding:.18rem 0;scroll-margin-top:calc(var(--tree-height,0px) + 12px)}
.prop .n{font:inherit;color:var(--fg);font-weight:400;white-space:nowrap;text-align:left}
.prop .status{font-size:.6em;font-style:italic;margin-left:.2em;font-weight:400;color:var(--dim)}
.prop .t{font:inherit;min-width:0;width:100%;letter-spacing:0;text-align:justify;hyphens:auto;-webkit-hyphens:auto;overflow-wrap:break-word;-webkit-user-select:text;user-select:text}
.prop-paragraph{white-space:pre-line;margin:0;max-width:none}.prop-paragraph+.prop-paragraph{margin-top:.8em}
/* One fixed left edge for every proposition. Depth is communicated by
   the interactive proposition tree above the text, never by indentation. */
.prop.depth0{margin-left:0;font-weight:400;margin-top:1.3rem;padding-top:.18rem}
.prop.depth1,.prop.depth2,.prop.depth3,.prop.depth4{margin-left:0;margin-top:.8rem}
.prop.active .n{color:var(--fg)}

/* Book drawings live in the normal text stream, never in a floating overlay. */
.figure-set{display:flex;flex-direction:column;align-items:flex-start;gap:.7rem;width:100%;max-width:100%;min-width:0;margin:.5rem 0 1.65rem 0;padding:0}
.tractate-figure{margin:0;padding:0;max-width:100%;width:100%;text-align:left}
.figure-open{display:block;color:inherit}
.figure-open:focus-visible{outline:1px solid var(--dim);outline-offset:3px}
.figure-caption{font-size:.85em;line-height:1.5;margin-top:.6rem;color:var(--dim)}
.tractate-figure img{display:block;width:100%;max-width:100%;height:auto;object-fit:contain;object-position:left center}
@media(prefers-color-scheme:dark){
 :root:not([data-theme="light"]) .tractate-figure img{filter:invert(1)}
}
:root[data-theme="dark"] .tractate-figure img{filter:invert(1)}

/* References are in-text, and the preview is anchored to the number. */
.xref{
  display:inline;color:inherit;background:transparent;border:0;border-radius:0;
  margin:0;padding:0;font:inherit;line-height:inherit;cursor:pointer;vertical-align:baseline;
  text-decoration:underline;text-decoration-style:dotted;text-decoration-color:var(--dim);
  text-decoration-thickness:1px;text-underline-offset:.16em;touch-action:manipulation;
  -webkit-appearance:none;-webkit-tap-highlight-color:transparent;
}
.xref:hover,.xref:focus-visible,.xref.previewing{
  text-decoration-style:solid;text-decoration-color:var(--fg);
}
.xref:focus-visible{outline:1px solid var(--fg);outline-offset:2px}
.prop-preview{
  position:fixed;z-index:9999;box-sizing:border-box;
  width:min(302px,calc(100vw - 24px));padding:9px 11px;
  color:var(--fg);background:var(--bg);border:1px solid var(--line);
  border-radius:8px;box-shadow:0 8px 30px rgba(0,0,0,.17);
  pointer-events:none;font-family:var(--serif);font-size:.81rem;line-height:1.39;
  text-align:left;overflow-wrap:break-word;
}
.prop-preview[hidden]{display:none!important}
.prop-preview-num{font-family:var(--mono);font-size:.75rem;font-weight:500;margin-bottom:3px}
.prop-preview-body{white-space:pre-line;max-height:min(26vh,180px);overflow:hidden}
.math-inline{white-space:nowrap}
.math-scripts{display:inline-grid;grid-template-rows:.85em .85em;vertical-align:middle;font-size:.72em;line-height:.85em;margin-left:.025em}
.math-scripts>.math-script{position:static;vertical-align:baseline;font:inherit;line-height:inherit;text-align:left}
.math-scripts>sup{grid-row:1;grid-column:1}
.math-scripts>sub{grid-row:2;grid-column:1}

@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]) .prop-preview{box-shadow:0 8px 30px rgba(0,0,0,.6)}
}
:root[data-theme="dark"] .prop-preview{box-shadow:0 8px 30px rgba(0,0,0,.6)}

/* Endnotes belong to the document, with the same left edge as the text. */
.endmatter{margin-top:3rem;scroll-margin-top:1rem}
.endmatter .section-title{margin-bottom:.8rem}
.endmatter-list{list-style:none;margin:0;padding:0}
.glossary-list{margin:0;padding:0}
.glossary-entry{margin:0 0 .8rem 4.5rem;font-size:.81rem;line-height:1.45;scroll-margin-top:1rem}
.glossary-term{font-weight:600;margin:0 0 .15rem}
.glossary-symbol{font-weight:400;font-style:italic;margin-left:.45em}
.glossary-definition{margin:0;min-width:0;overflow-wrap:anywhere}
.glossary-definition p{margin:0}
.glossary-definition .glossary-links{margin-top:.2rem;font:400 .65rem var(--mono);color:var(--dim)}
.endnote{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:.55rem;padding:.45rem 0;font-size:.81rem;line-height:1.5;scroll-margin-top:1rem}
.endnote-number{font:400 .65rem var(--mono);color:var(--dim);padding-top:.12rem}
.endnote-body{min-width:0;overflow-wrap:anywhere;text-align:left;hyphens:auto;-webkit-hyphens:auto}
.endnote-body p{margin:0}.endnote-body p+p{margin-top:.3rem}
.endnote-meta{font:400 .62rem var(--mono);color:var(--dim);margin-bottom:.25rem}
.endnote a{color:inherit;text-underline-offset:.16em}
.source-links{font:400 .65rem var(--mono)}
.source-ref{font-family:var(--mono);font-size:.63em;line-height:0;vertical-align:super;text-decoration:none;padding:0 .1em}
.source-ref .xref{display:inline-block;line-height:1;padding:.2em .1em;margin:-.2em 0}
.note-ref{display:inline-block;margin-left:.3em;color:var(--dim);font-family:var(--mono);font-size:.62em;line-height:1;vertical-align:super}
@media print{
  @page{margin:16mm 14mm}
  :root{--bg:#fff;--fg:#000;--dim:#555;--line:#bbb;--hair:#ddd}
  html,body{width:auto;height:auto;overflow:visible}
  .app{display:block;max-width:none;height:auto;min-height:0;margin:0;border:0;padding:0;overflow:visible}
  .bar,.strip,.prop-preview{display:none!important}
  .read{padding:0;overflow:visible}.stream{padding:0}
  .prop,.plain-paragraph{font-size:10.5pt;line-height:1.42}
  .prop .n{font-size:8pt}
  .endmatter{break-before:page}
  .endnote{break-inside:avoid;font-size:9pt}
  .glossary-entry{break-inside:avoid;font-size:9pt}
  p{orphans:3;widows:3}
  .xref{text-decoration:none}
  .tractate-figure{break-inside:avoid}
  .tractate-figure img{filter:none!important}
}
@media (prefers-reduced-motion:reduce){
  *{transition:none!important}
  .read{scroll-behavior:auto}
}

/* Native mathematics comes from the shared LaTeX manuscript. */
.native-math{font-size:1em}
.native-math math{font-size:1em}
.math-display{display:block;max-width:100%;overflow-x:auto;padding:.65em 0}
