/* How a rendered body looks on the 'ton' site.
 *
 * This file is committed and it is yours. ,web-tcm-add writes it once and never
 * again — a re-run to take a newer TCM leaves whatever you have made of it.
 *
 * TCM serves it at /tcm/style.css and reads none of it. Link it from the page
 * that shows TCM content:
 *
 *     <link rel="stylesheet" href="/tcm/style.css">
 *
 * The editor's View column links the same URL, which is what makes one edit
 * here change the preview and the page together.
 *
 * Everything is scoped under `.tcm`, because that is the wrapper the site puts
 * a rendered body in:
 *
 *     <div class="tcm">…the fragment TCM rendered…</div>
 *
 * The editor's preview wraps the fragment in the same div, so a selector means
 * the same thing in both places. Two rules follow from that, and breaking
 * either is how the preview starts lying:
 *
 *   - Nothing may depend on an ancestor above `.tcm`. On the site there is a
 *     whole page up there; in the preview there is nothing.
 *   - `.tcm` sets the inherited basics — font, line height, colour — itself.
 *     On the site they would otherwise come from the site's own body, which the
 *     preview does not have.
 */

.tcm {
  font: 16px/1.6 system-ui, sans-serif;
  color: #111;
  /* Measured in characters rather than pixels: the limit that matters is how
     far the eye travels back to the next line, and that is a count of letters
     however large they are. */
  max-width: 34em;
}

/* The h1 is the item's title, put there by the renderer whichever way the
   author wrote it. A site with its own page heading above the fragment should
   say so here rather than teach authors not to have titles. */
.tcm h1 {
  font-size: 1.9em;
  line-height: 1.2;
  margin: 0 0 0.6em;
}

.tcm h2 { font-size: 1.35em; line-height: 1.3; margin: 1.8em 0 0.5em; }
.tcm h3 { font-size: 1.1em;  line-height: 1.3; margin: 1.6em 0 0.4em; }

.tcm p,
.tcm ul,
.tcm ol,
.tcm blockquote { margin: 0 0 1em; }

.tcm li { margin: 0.2em 0; }

/* A heading is a link target: every one carries an id, and a reader arriving at
   one should not find it under the site's fixed header. */
.tcm :is(h1, h2, h3) { scroll-margin-top: 1rem; }

.tcm a { color: #02529c; }

.tcm blockquote {
  border-left: 3px solid #8884;
  padding-left: 1em;
  margin-left: 0;
  color: #555;
}

.tcm code {
  font-family: ui-monospace, monospace;
  font-size: 0.9em;
  background: #8881;
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.tcm pre {
  background: #8881;
  padding: 0.8em 1em;
  border-radius: 4px;
  /* A long line scrolls its own block. The page must not scroll sideways. */
  overflow-x: auto;
}

.tcm pre code { background: none; padding: 0; }

.tcm table { border-collapse: collapse; margin: 0 0 1em; }
.tcm :is(th, td) { border: 1px solid #8884; padding: 0.3em 0.6em; text-align: left; }

/* Figures.
 *
 * A captioned image is a <figure>; an uncaptioned one is a bare <img>. The
 * classes below land on whichever is outermost, so each is written to work on
 * both. The default <figure> margin is 40px on each side, which is wrong at
 * every width this content is read at. */
.tcm figure { margin: 1.5em 0; }

.tcm img { max-width: 100%; height: auto; display: block; }

.tcm figcaption {
  font-size: 0.9em;
  color: #555;
  margin-top: 0.4em;
}

/* The five names in `image_classes:`. That list is the menu the editor offers;
   these rules are what the names mean, and there is nowhere else they mean
   anything. A name added there without a rule here does nothing. */

/* Wider than the measure, still inside the page. */
.tcm :is(figure, img).wide {
  max-width: 130%;
  width: 130%;
  margin-left: -15%;
}

/* Edge to edge, out of the column entirely. */
.tcm :is(figure, img).full {
  width: 100vw;
  max-width: 100vw;
  margin-left: 50%;
  transform: translateX(-50%);
}

.tcm :is(figure, img).left,
.tcm :is(figure, img).right {
  max-width: 45%;
  margin-top: 0.3em;
}

.tcm :is(figure, img).left  { float: left;  margin-right: 1.5em; }
.tcm :is(figure, img).right { float: right; margin-left: 1.5em; }

/* In the line of text rather than on a line of its own — a glyph, a logo, a
   small mark. The only class that undoes `display: block`. */
.tcm img.inline {
  display: inline;
  max-height: 1.2em;
  width: auto;
  vertical-align: baseline;
}

/* A float taken out of the flow still has to stop before the next heading. */
.tcm :is(h1, h2, h3) { clear: both; }

/* Narrow screens have no room to float and no room for a negative margin. */
@media (max-width: 34em) {
  .tcm :is(figure, img):is(.wide, .full, .left, .right) {
    width: auto;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
    float: none;
    transform: none;
  }
}

/* Tagged lines — `DO: buy milk` on a line of its own, in a block of its own,
   when the type's `tmltags:` declares DO. The renderer puts each block in one
   paragraph of class tmlblock, one element per line in the element and class
   the type file named, with the tag as the element's title. These rules are
   what those classes mean, and there is nowhere else they mean anything: a
   class named in a type file without a rule here looks like plain text. */

.tcm .tmlblock {
  margin: 0 0 1em;
  padding: 0.5em 0.8em;
  background: #f3f3f3;
  border-radius: 3px;
  box-shadow: 0 1px 2px #0002;
}

/* One tagged line per line. The renderer writes the elements inline with a
   newline between them, so a site that wants them stacked says so here. */
.tcm .tmlblock > * { display: block; }

/* The tag is the element's title, so it is not drawn. This puts it back in
   front of the text; drop the rule to show the text alone. */
.tcm .tmlblock > *::before { content: attr(title) ": "; font-weight: bold; }

/* One rule per class the type files name. */
/* .tcm .tmlblock > .tml-do   { }                                          */
/* .tcm .tmlblock > .tml-done { text-decoration: line-through; color: #555; } */
