/* ==========================================================================
   Embeds for other sites, in the notebook look of jasperhaynes.com.
   They run in an iframe on someone else's page: 360x270 (count) and 640x400 (chart), the sizes
   given out on /embed.html, and narrower on a phone (the snippet has max-width:100%).

   Self-contained on purpose: an embed loads only /notebook/tokens.css (the vendored main tokens)
   and this file, never /style.css, so a change to the tracker's own pages cannot move or break an
   embed that is already on another site. The chart rules below therefore repeat the series rules
   of the tracker's charts: keep the two in step.
   No Google Fonts here (the embed CSP blocks them): Geist falls back to the system font through the
   token stacks. Colours only through var() tokens. The theme follows the visitor's operating
   system (/embed/theme-os.js), because an embed has no switch of its own.

   Colour meaning, as on the tracker: in a figure the pen means only "airline flights" and ink
   means "all planes". Status colours never appear in an embed.
   ========================================================================== */

/* Old flights colour names, aliased onto the notebook tokens as on the tracker's pages, so anything
   that still asks for them resolves (also on an element with its own data-theme). */
:root, [data-theme] {
  --sign-red: var(--error);
  --sign-red-ink: var(--card);
  --sign-black: var(--ink);
  --sign-yellow: var(--pen);
  --link: var(--ink);
  --ok: var(--done);
  --warn-bg: var(--doing-bg);
  --warn-ink: var(--doing);
  --focus: var(--accent);
  --map-sea: var(--card);
  --map-land: var(--tint);
  --map-edge: var(--muted);
  --map-other: var(--muted);
}

*, *::before, *::after { box-sizing: border-box; }

/* The page itself is transparent and the card (.embed) fills the frame, so the host page shows in
   the four rounded corners. Where the host's colour scheme differs from the visitor's, browsers
   paint an opaque backdrop behind the frame instead, which only changes those corners. */
html {
  height: 100%;
  background: transparent;
  color: var(--ink);
  font: 400 15px/1.45 var(--body);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
body { height: 100%; margin: 0; }
p { margin: 0; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* The sheet: a card with a 1.5px ink edge and 8px corners, like a figure sheet on jasperhaynes.com.
   It fills the frame, and the credit sits at the bottom. */
.embed {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 12px 14px 10px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
}

/* A mono label, as on the main site. */
.embed-label {
  font: 400 12px/1.4 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.embed-title {
  font: 600 18px/1.25 var(--display);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.embed-meta { margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--muted); }

/* Credit: the main site's footer line (mono, pen-underlined links). */
.embed-credit {
  margin-top: auto;
  padding-top: 8px;
  font: 400 12px/1.6 var(--mono);
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ---------- Count embed ---------- */
/* Ink number (it counts all planes), a mono label above it and the ink trend line below. */
.embed-number {
  margin-top: 4px;
  font: 600 56px/0.92 var(--display);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.embed-trend { margin-top: 12px; }
.embed-trend svg { display: block; width: 100%; height: 40px; overflow: visible; }
.trend-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* ---------- Chart embed ---------- */
/* The series rules of the tracker's charts (classes from /chart.js), the same values as the chart
   part of /notebook/figures.css: all planes a thin ink line (always the upper one, drawn on top),
   airline flights a thick pen line (always the lower one), the archive part dashed, a week earlier
   muted dots, the
   stop and the lift thin dotted ink lines with mono labels. Grid lines a fine rule, axis labels mono. */
.chart { min-height: 240px; margin-top: 6px; }
.chart svg { display: block; }
/* Before the first drawing, or with too few minutes: an empty dashed sheet keeps the place.
   (Two rules, so a browser without :has() still keeps the first.) */
.chart:empty { border: 1.5px dashed var(--rule); border-radius: 8px; }
.chart:has(> .chart-empty) { border: 1.5px dashed var(--rule); border-radius: 8px; }
.chart-empty { display: none; }
.chart-grid { stroke: var(--rule); stroke-width: 1; }
.chart-axis { fill: var(--muted); font: 400 11px var(--mono); }
.chart-total, .chart-airline { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart-total { stroke: var(--ink); stroke-width: 1.5; }
.chart-airline { stroke: var(--pen); stroke-width: 3.5; }
.chart-archive { stroke-dasharray: 5 4; stroke-linecap: butt; }
.chart-normal { fill: var(--muted); stroke: none; }
.chart-stop { stroke: var(--ink); stroke-width: 1.25; stroke-dasharray: 1.5 3.5; stroke-linecap: round; }
/* A halo of the sheet colour keeps the label readable where it crosses a line. */
.chart-stop-label {
  fill: var(--ink);
  font: 500 11px var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Key: drawn swatches with the series classes, and words that name the shape, never a colour
   (the look of .fig-key on the tracker's pages, a little closer to the chart to save room). */
.embed-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 20px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font: 400 12.5px/1.5 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}
.embed-legend[hidden] { display: none; }
.embed-legend li { display: flex; align-items: center; gap: 8px; }
.embed-legend svg { display: block; flex: none; width: 26px; height: 10px; overflow: visible; }
.embed-chart .embed-meta { margin-top: 4px; }
.embed-chart .embed-credit { padding-top: 6px; }

/* ---------- Tight frames ---------- */
/* Set by /embed/fit.js only when the content would make the frame scroll. The side padding stays,
   so the chart keeps the width it was drawn for. The chart's summary sentence is then only read
   out; the key, the warnings and the credit always stay. */
.embed.is-tight { padding-top: 9px; padding-bottom: 7px; }
.embed.is-tight .embed-number { font-size: 46px; }
.embed.is-tight .embed-trend { margin-top: 8px; }
.embed.is-tight .embed-trend svg { height: 30px; }
.embed.is-tight .embed-title { font-size: 16px; }
.embed.is-tight .embed-credit { padding-top: 5px; }
.embed-chart.is-tight .embed-legend:not([hidden]) + .embed-meta {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Opened on its own ---------- */
/* html[data-alone] (set by /embed/theme-os.js) when the page is not in a frame, for example from
   "See the count on its own" on /embed.html: the sheet at the size of its snippet, centred on the
   paper ground, so it shows what another site will show. */
[data-alone] { background: var(--ground); }
[data-alone] body { display: flex; align-items: flex-start; justify-content: center; height: auto; min-height: 100%; padding: 24px 16px; }
[data-alone] .embed { width: 100%; min-height: 0; }
[data-alone] .embed-count { max-width: 360px; height: 270px; }
[data-alone] .embed-chart { max-width: 640px; height: 400px; }
