/*
  Component styles, loaded only where a component is used. Tokens come from
  static/styles.css.
*/

/* #region toc */
/*
  Floats into the left margin, anchored to the centered <main>. Hidden when
  there's no room for it.
*/
.toc-col { display: none; }
/*
  The margin has to hold the TOC on both sides of the centered column, so the
  breakpoint is --max + 2*(--toc-w + --gap). Media queries can't read custom
  properties and resolve rem at 16px (not html's 18px), so it's spelled out in
  px: (46 + 2*(11 + 1.25)) * 18px = 1269px, rounded up for slack.
*/
@media (min-width: 1300px) {
  .toc-col {
    display: block;
    position: absolute;
    top: var(--pad-top); /* same origin as the title */
    bottom: 0;
    right: 100%;
    width: var(--toc-w);
    margin-right: var(--gap);
  }
}
.toc {
  --toc-rule: 2px;
  --toc-indent: 0.9rem;
  position: sticky;
  top: var(--below-header);
  font-size: 0.85rem;
  border-left: var(--toc-rule) solid var(--border);
}
.toc-title {
  margin: 0 0 0.5rem var(--toc-indent);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 0.15rem 0 0.15rem var(--toc-indent);
  border-left: var(--toc-rule) solid transparent;
  margin-left: calc(var(--toc-rule) * -1);
  color: var(--muted);
  text-decoration: none;
  line-height: 1.35;
}
.toc a:hover { color: var(--fg); }
.toc a.active { color: var(--accent); border-left-color: var(--brand); }
.toc-l2 a { padding-left: calc(var(--toc-indent) * 2); font-size: 0.95em; }

@supports (text-box-trim: trim-start) {
  .toc-title,
  main > h1:first-of-type {
    text-box-trim: trim-start;
    text-box-edge: cap alphabetic;
  }
}

/* #endregion */

/* #region callouts */
.callout {
  --callout-accent: var(--note);
  margin: 1.5rem 0;
  padding: 0.85rem 1.1rem;
  border-left: 3px solid var(--callout-accent);
  border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--callout-accent) 9%, transparent);
}
.callout-tip  { --callout-accent: var(--tip); }
.callout-warn { --callout-accent: var(--warn); }

.callout-title {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--callout-accent);
}
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child  { margin-bottom: 0; }

/* #endregion */

/* #region details */
.details {
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  background: var(--surface);
}
.details > summary {
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  list-style-position: inside;
}
.details > summary:hover { color: var(--accent); }
.details[open] > summary { margin-bottom: 0.5rem; }
.details-body > :first-child { margin-top: 0; }
.details-body > :last-child  { margin-bottom: 0; }

/* #endregion */

/* #region blockquote */
.quote {
  margin: 1.75rem 0;
  padding-left: 1.25rem;
  border-left: 3px solid var(--brand);
  font-style: italic;
}
.quote-body > :first-child { margin-top: 0; }
.quote-body > :last-child  { margin-bottom: 0; }
.quote-by {
  margin-top: 0.4rem;
  font-style: normal;
  font-size: 0.85rem;
}
.quote-by::before { content: "— "; }

/* #endregion */

/* #region popover */
.popover-trigger {
  font: inherit;
  font-size: 0.9em;
  margin: 0;
  padding: 0 0.4em;
  border: 1px dashed var(--accent);
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}
/*
  Must stay scoped to the open state: author styles beat the UA sheet whatever
  the specificity, so an unscoped display leaves the panel permanently on.
*/
.popover:popover-open { display: block; }
.popover {
  max-width: 22rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 12px 34px rgba(2, 2, 11, 0.28);
}
/*
  Anchor positioning is Chromium-only for now; elsewhere the popover falls
  back to the UA default, centered.
*/
@supports (position-area: bottom) {
  .popover {
    position-area: bottom span-right;
    position-try-fallbacks: flip-block, flip-inline;
    inset: auto;
    margin: 0.4rem 0 0 0;
  }
}
.popover > :first-child { margin-top: 0; }
.popover > :last-child  { margin-bottom: 0; }

/* #endregion */

/* #region annotations */
/* Markers and tabs are the same colored square. */
.ann-c1 { --ann: var(--c-blue); }
.ann-c2 { --ann: var(--c-paprika); }
.ann-c3 { --ann: var(--c-green); }
.ann-c4 { --ann: #8a6d00; }
.ann-c5 { --ann: #6b4fbb; }
.ann-c6 { --ann: #14707c; }

.ann-ref, .ann-tab, .ann-num {
  display: inline-block;
  border: 0;
  margin: 0;
  font-family: inherit;
  cursor: pointer;
  min-width: 1.5em;
  padding: 0 0.3em;
  border-radius: 3px;
  background: var(--ann);
  color: #fff;
  font-size: 0.72em;
  line-height: 1.6;
  text-align: center;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.ann-ref { vertical-align: super; margin-left: 0.15em; }
.ann-ref:hover, .ann-tab:hover, .ann-num:hover { text-decoration: none; filter: brightness(1.15); }
.ann-panel :is(p):first-child { display: inline; }
.ann-panel > :last-child { margin-bottom: 0; }
.ann-ref { scroll-margin-top: var(--below-header); }
.ann-panel { scroll-margin-top: calc(var(--below-header) + var(--ann-tabs-h, 2.5rem)); }

/* Narrow: notes collapse into tabs at the end of the section, one open at a time. */
.ann-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  margin: 2rem 0 0;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.ann-tabs-label {
  margin-right: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ann-tab { font-size: 0.8rem; }
/* Restated because the generic button:hover outranks .ann-tab and would recolor it. */
.ann-tab:hover { background: var(--ann); color: #fff; }
/* Or a closed tab still looks active while the pointer rests on it. */
.ann-tab[aria-expanded="true"] { box-shadow: 0 0 0 1px var(--bg), 0 0 0 2px var(--ann); }
.ann-panel {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}
/* Scoped to the collapsed width so these never outrank the margin layout. */
@media (max-width: 1449.98px) {
  .ann-panel { display: none; }
  .ann-panel:target { display: block; } /* until the script runs */
  .annotations.js .ann-panel { display: none; }
  .annotations.js .ann-panel[data-open] { display: block; }
}

/*
  Wide: the notes move into the right margin, aligned with their markers by
  lib/annotation.ts. This breakpoint is above the TOC's, so the notes are the
  first thing to fold away as the window narrows.
*/
@media (min-width: 1450px) {
  .ann-tabs { display: none; }
  .ann-panel {
    display: block;
    position: absolute;
    left: 100%;
    margin: 0 0 0 var(--gap);
    width: var(--ann-w);
  }
  .ann-panel:target { background: var(--accent-soft); border-radius: 6px; }
}

/* #endregion */

/* #region layout */
.grid-col, .grid-row, .flex {
  gap: var(--gap-own, var(--gap));
  margin: 1.5rem 0;
}

.grid-col { display: grid; grid-template-columns: 1fr; }

.grid-row { display: grid; grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .grid-row { grid-template-columns: var(--cols); }
}

/* Wrapping does grid-row's job without a breakpoint. */
.flex {
  display: flex;
  flex-flow: row var(--wrap, wrap);
  justify-content: var(--justify, center);
  align-items: var(--align, stretch);
}
.flex > .cell { flex: 1 1 var(--basis, 18rem); }

.cell {
  /*
    Grid and flex items won't shrink below their content unless told to, which
    is how a wide code block would push the page sideways.
  */
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.cell > :first-child { margin-top: 0; }
.cell > :last-child { margin-bottom: 0; }
.cell :is(img, svg) { display: block; max-width: 100%; margin-inline: auto; }

/* #endregion */
