/* The Tholin window, in HTML: laid out in the app's points (one CSS pixel a point) from its own
   measures (TholinKit/Sources/Workspace/WorkspaceMetrics.swift) and colours (Style/Palette.swift,
   Workspace/GraphDocument.swift's GraphColor). The page scales the whole window as it needs. */

@property --tw-paper { syntax: "<color>"; inherits: true; initial-value: #f4f3f0; }
@property --tw-ink { syntax: "<color>"; inherits: true; initial-value: #1d1e21; }
@property --tw-menu { syntax: "<color>"; inherits: true; initial-value: #fdfdfb; }

.tw {
  /* Light: marble paper, deep-grey ink, the menus' off-white. */
  --tw-paper: #f4f3f0;
  --tw-ink: #1d1e21;
  --tw-menu: #fdfdfb;
  --tw-accent: #0088ff;
  --tw-wash: 30%;            /* the slab's wash of the menus' colour (frostWashOpacity) */
  --tw-dim: 15%;             /* how far the frosted graph fades towards the paper (frostDim) */
  --tw-blue: #2a7df0; --tw-orange: #b84800; --tw-pink: #e0388f; --tw-green: #00936a; --tw-purple: #6e2ba8; --tw-yellow: #a48600;
  --tw-panel: 440px;
  --tw-radius: 26px;
  --tw-hair: 0.5px;          /* a device pixel at 2× */

  position: absolute; left: 0; top: 0; width: 1440px; height: 900px;
  transform-origin: 0 0; overflow: hidden; isolation: isolate;
  border-radius: var(--tw-radius); background: var(--tw-paper); color: var(--tw-ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0; -webkit-font-smoothing: antialiased;
  transition: --tw-paper 0.7s ease, --tw-ink 0.7s ease, --tw-menu 0.7s ease;
  user-select: none; -webkit-user-select: none;
}
.tw[data-theme="dark"] {
  --tw-paper: #191a1c;
  --tw-ink: #ececee;
  --tw-menu: #27282b;
  --tw-accent: #0091ff;
  --tw-wash: 45%;
  --tw-dim: 22%;
  --tw-blue: #6ccbff; --tw-orange: #ee9a2e; --tw-pink: #f15ca8; --tw-green: #1fb27a; --tw-purple: #9478f5; --tw-yellow: #eee35b;
}
/* The window's edge and shadow, as macOS draws an active window's. */
.tw::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 20;
  box-shadow: inset 0 0 0 var(--tw-hair) color-mix(in srgb, var(--tw-ink) 22%, transparent);
}

/* ---- The graph: the whole window, under the panel and the bar. ---- */
.tw-graph { position: absolute; inset: 0; z-index: 0; }
.tw-graph canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tw-graph .tw-film { position: absolute; left: 0; top: 0; transform-origin: 0 0; visibility: hidden; pointer-events: none; }
.tw-graph .tw-film.on { visibility: visible; }
/* The video a film's canvas is drawn from: decoding, never shown itself. */
.tw-graph .tw-film-source { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.tw-graph .tw-still {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0;
  transition: opacity 0.5s ease;
}
.tw-graph .tw-still.on { opacity: 1; }

/* ---- Slabs: the graph beneath blurred, dimmed towards the paper, under a wash of the menus' colour;
   a hairline rim of the ink at 0.12. ---- */
.tw-slab {
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  background:
    linear-gradient(color-mix(in srgb, var(--tw-menu) var(--tw-wash), transparent), color-mix(in srgb, var(--tw-menu) var(--tw-wash), transparent)),
    color-mix(in srgb, var(--tw-paper) var(--tw-dim), transparent);
  box-shadow: inset 0 0 0 var(--tw-hair) color-mix(in srgb, var(--tw-ink) 12%, transparent);
}

/* ---- The sidebar: flush with the window's leading, top and bottom edges, under the title bar. ---- */
.tw-panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: var(--tw-panel); z-index: 2;
  box-shadow: inset calc(-1 * var(--tw-hair)) 0 0 color-mix(in srgb, var(--tw-ink) 12%, transparent);
}
.tw-rows {
  position: absolute; left: 0; right: 0; top: 52px; bottom: 0; overflow: hidden;
  /* The rows fade at an edge with more beyond it (scrollEdgeFade). */
  -webkit-mask-image: linear-gradient(transparent 0, #000 6px, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(transparent 0, #000 6px, #000 calc(100% - 28px), transparent);
}
.tw-rows-track { position: relative; transition: transform 0.45s cubic-bezier(0.25, 0.1, 0.25, 1); }

/* A row: on the panel's one grid — margin, number, gap, tile, gap, mathematics — between hairlines. */
.tw-row { position: relative; padding: 5px 6px; }
.tw-row:first-child { padding-top: 0; }
.tw-row::after {
  content: ""; position: absolute; left: 82px; right: 12px; bottom: 0; height: var(--tw-hair);
  background: color-mix(in srgb, var(--tw-ink) 14%, transparent);
}
.tw-row:last-child::after { display: none; }
.tw-row-body {
  position: relative; display: flex; align-items: center; min-height: 48px; border-radius: 12px;
  padding-left: 4px; transition: background-color 0.2s;
}
.tw-row.active .tw-row-body { background: color-mix(in srgb, var(--tw-ink) 5%, transparent); }
.tw-num {
  flex: none; width: 26px; text-align: center; align-self: center;
  font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--tw-ink) 36%, transparent);
}
.tw-row.active .tw-num { color: color-mix(in srgb, var(--tw-ink) 65%, transparent); }

/* The tile: the row's colour round a miniature of what it draws; a value's is quiet. */
.tw-tile {
  --c: var(--tw-blue);
  flex: none; position: relative; width: 26px; height: 26px; margin-left: 10px; border-radius: 7px;
  box-shadow: inset 0 0 0 1.5px var(--c); color: var(--c);
}
.tw-tile[data-colour="orange"] { --c: var(--tw-orange); }
.tw-tile[data-colour="pink"] { --c: var(--tw-pink); }
.tw-tile[data-colour="green"] { --c: var(--tw-green); }
.tw-tile[data-colour="purple"] { --c: var(--tw-purple); }
.tw-tile[data-colour="yellow"] { --c: var(--tw-yellow); }
.tw-tile[data-colour="quiet"] {
  background: color-mix(in srgb, var(--tw-ink) 5%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--tw-ink) 16%, transparent);
  color: color-mix(in srgb, var(--tw-ink) 85%, transparent);
}
.tw-tile[data-colour="next"] { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--tw-ink) 16%, transparent); }
.tw-tile svg { position: absolute; inset: 3.5px; width: 19px; height: 19px; overflow: hidden; border-radius: 3.5px; }
.tw-tile svg * { vector-effect: non-scaling-stroke; }
.tw-tile .tw-glyph-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 500; }

/* A row whose graph is switched off: its tile dims. */
.tw-row.tw-off .tw-tile { opacity: 0.4; }
.tw-tile { transition: opacity 0.3s; }

/* The mathematics, at the rows' size (22 pt), with its own margin of the grid's gap. */
.tw-math {
  position: relative; flex: 1; min-width: 0; padding: 12px 37px 12px 10px; align-self: stretch;
  display: flex; flex-direction: column; justify-content: center;
}
.tw-line { position: relative; display: flex; align-items: center; min-width: 0; }
.tw-tex {
  flex: none; white-space: nowrap; font-size: 18.18px; /* KaTeX draws at 1.21em: 22 pt */
}
.tw-tex .katex { font-size: 1.21em; line-height: 1; }
.tw-math, .tw-line, .tw-tex { line-height: 1; }
/* KaTeX's boxes run a point taller than the app's typesetter's: the room about them is the app's. */
.tw-tex { margin: -0.5px 0; }
/* What is too wide for its row fades out short of the edge, as the app's does (the caret still shows). */
.tw-line.clips {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  overflow: hidden;
}
/* The caret, where typing goes: the accent. */
.tw-caret {
  position: absolute; top: 50%; width: 2px; height: 26px; margin-top: -13px; border-radius: 1px;
  background: var(--tw-accent); left: 10px; opacity: 0; pointer-events: none;
}
.tw-row.typing .tw-caret, .tw-row.waiting .tw-caret { opacity: 1; }
.tw-row.waiting .tw-caret { animation: tw-blink 1.06s steps(1) infinite; }
@keyframes tw-blink { 50% { opacity: 0; } }

/* A result, at the row's trailing edge on the mathematics' axis: typeset smaller and quieter. */
.tw-result {
  margin-left: auto; padding-left: 16px; flex: none; display: flex; align-items: center; gap: 8px; white-space: nowrap;
  height: 0; /* centred on the line, over the row's padding: a tall result never makes the row taller */
  color: color-mix(in srgb, var(--tw-ink) 70%, transparent); font-size: 13.22px; /* 16 pt */
  opacity: var(--shown, 1);
}
.tw-result .katex { font-size: 1.21em; }
.tw-approx { font-family: "KaTeX_Main", "Latin Modern Roman", serif; font-size: 15px; color: color-mix(in srgb, var(--tw-ink) 55%, transparent); }
/* What a result is said to equal by — "=", "x =" — at the results' text size, before the typeset value. */
.tw-result .tw-prefix { font-size: 10.74px; margin-right: -4px; }
.tw-below {
  /* Too wide for beside the mathematics, a result goes under it, at the results' size (13 pt),
     fading out short of the edge if it is wider still. */
  align-self: stretch; margin-top: 3px; white-space: nowrap; overflow: hidden; font-size: 10.74px;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent);
  color: color-mix(in srgb, var(--tw-ink) 65%, transparent); opacity: var(--shown, 1);
}
.tw-below .katex { font-size: 1.21em; }
.tw-under { margin-top: 2px; white-space: nowrap; font-size: 14.05px; /* 17 pt, the rows' bounds */ opacity: var(--shown, 1); }
.tw-under .katex { font-size: 1.21em; }

/* A slider under its definition: its ends typed either side, the track between. */
.tw-slider-line { display: flex; align-items: center; gap: 4px; margin: 3.6px 0 -4px; font-size: 14.05px; opacity: var(--shown, 1); }
.tw-slider-line .katex { font-size: 1.21em; }
.tw-slider-line .tw-bound { color: color-mix(in srgb, var(--tw-ink) 65%, transparent); flex: none; }
.tw-track { position: relative; flex: 1; height: 20px; cursor: grab; touch-action: none; }
.tw-track:active { cursor: grabbing; }
.tw-track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 4px; border-radius: 2px;
  background: color-mix(in srgb, var(--tw-ink) 18%, transparent);
}
.tw-fill { position: absolute; left: 0; top: 8px; height: 4px; border-radius: 2px; background: var(--tw-ink); }
.tw-knob {
  position: absolute; top: 2px; width: 22px; height: 16px; margin-left: -11px; border-radius: 6px;
  background: var(--tw-ink); box-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.25);
}

/* A table: its names on the quiet wash, the cells between faint rules. */
.tw-table {
  margin: 0 0 0 0; border-collapse: separate; border-spacing: 0; width: calc(100% - 2px);
  border-radius: 6px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tw-ink) 12%, transparent);
  font-size: 13.22px; /* 16 pt */ overflow: hidden; opacity: var(--shown, 1);
}
.tw-table .katex { font-size: 1.21em; }
.tw-table th, .tw-table td { height: 28px; padding: 0; text-align: center; font-weight: 400; }
.tw-table th { background: color-mix(in srgb, var(--tw-ink) 5%, transparent); position: relative; }
.tw-table td + td, .tw-table th + th { box-shadow: inset var(--tw-hair) 0 0 color-mix(in srgb, var(--tw-ink) 8%, transparent); }
.tw-table tr + tr td { border-top: var(--tw-hair) solid color-mix(in srgb, var(--tw-ink) 8%, transparent); }
.tw-table .tw-dot-col { position: absolute; left: 6px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 4px; background: var(--tw-blue); }

.tw-table th.tw-add, .tw-table td.tw-add { width: 26px; color: color-mix(in srgb, var(--tw-ink) 45%, transparent); font: 400 14px -apple-system, sans-serif; }
.tw-table tr.tw-blank td { height: 28px; }
/* A table's row: its number and tile beside the column names, the grid 10 points in. */
.tw-row.has-table .tw-math { padding-top: 10px; padding-bottom: 6px; }
.tw-row.has-table .tw-num, .tw-row.has-table .tw-tile { align-self: flex-start; margin-top: 11px; }


/* ---- The title bar: no fill — the graph and the panel run under it; the controls on slabs. ---- */
.tw-bar { position: absolute; left: 0; right: 0; top: 0; height: 52px; z-index: 5; }
.tw-lights { position: absolute; left: 19px; top: 19px; display: flex; gap: 9px; }
.tw-lights i { display: block; width: 14px; height: 14px; border-radius: 7px; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12); }
.tw-lights i:nth-child(1) { background: #ff5f57; }
.tw-lights i:nth-child(2) { background: #febc2e; }
.tw-lights i:nth-child(3) { background: #28c840; }
.tw-lead { position: absolute; left: 96.5px; top: 8px; height: 36px; display: flex; align-items: center; padding: 0 2px; }
.tw-title {
  position: absolute; left: 184.5px; top: 8px; height: 36px; display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600; white-space: nowrap; color: var(--tw-ink);
}
.tw-save { width: 7px; height: 7px; border-radius: 4px; background: #28c840; }
.tw-trail { position: absolute; right: 8px; top: 8px; display: flex; gap: 10px; }
.tw-group { display: flex; height: 36px; padding: 0 2px; border-radius: 18px; align-items: center; }
.tw-btn {
  position: relative; width: 36px; height: 32px; border-radius: 16px; flex: none;
  color: color-mix(in srgb, var(--tw-ink) 85%, transparent); transition: background-color 0.15s, color 0.3s;
}
.tw-btn:hover { background: color-mix(in srgb, var(--tw-ink) 7%, transparent); }
.tw-btn.on { color: var(--tw-accent); background: color-mix(in srgb, var(--tw-accent) 18%, transparent); }
.tw-btn.off { color: color-mix(in srgb, var(--tw-ink) 30%, transparent); }
.tw-btn.off:hover { background: none; }
.tw-ic {
  position: absolute; inset: 0; background: currentColor;
  -webkit-mask: var(--ic) center / 100% 100% no-repeat; mask: var(--ic) center / 100% 100% no-repeat;
}
.tw-unit { display: grid; place-items: center; font: italic 21px/1 "KaTeX_Math", "Latin Modern Math", serif; padding-top: 4px; box-sizing: border-box; }
.tw-btn .tw-ic-on { display: none; }
.tw-btn.on .tw-ic-on { display: block; }
.tw-btn.on .tw-ic-off { display: none; }

/* ---- The graph's controls, at its bottom-trailing corner, 8 points in. ---- */
.tw-controls { position: absolute; right: 8px; bottom: 8px; z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tw-zoom { flex-direction: column; height: auto; width: 36px; padding: 2px 0; }
.tw-zoom .tw-btn { width: 36px; height: 36px; border-radius: 18px; }
.tw-circle { width: 36px; height: 36px; border-radius: 18px; padding: 0; }
.tw-circle .tw-btn { width: 36px; height: 36px; border-radius: 18px; }

/* ---- Narrow: the graph above, the rows as a sheet beneath it, as a phone would show them. ---- */
.tw.compact { border-radius: 0; }
.tw.compact .tw-panel { top: auto; height: 46%; width: auto; right: 0; border-radius: 18px 18px 0 0; box-shadow: inset 0 var(--tw-hair) 0 color-mix(in srgb, var(--tw-ink) 12%, transparent); }
.tw.compact .tw-rows { top: 10px; }
.tw.compact .tw-lead, .tw.compact .tw-title { display: none; }
.tw.compact .tw-trail { left: 8px; right: 8px; justify-content: center; }
.tw.compact .tw-trail .tw-group:nth-child(3) { display: none; }
.tw.compact .tw-lights { display: none; }
.tw.compact .tw-controls { bottom: calc(46% + 8px); }
