/* Tools page. The moiré display sits on the dark instrument panel of the research cards, in one grey with a single
   accent; Formula Studio is a plain two-column bench on the page's own colours. */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mt, .fs { margin-top: 44px; scroll-margin-top: 112px; }
.fs { margin-top: 88px; }
.mt .section-heading, .fs .section-heading { align-items: center; margin-bottom: 22px; }
.mt .section-heading h2, .fs .section-heading h2 { font-size: 34px; }

/* ---- moiré and supermoiré ---- */
.mt-modes { display: inline-flex; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.mt-modes label { position: relative; display: block; cursor: pointer; }
.mt-modes input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.mt-modes span { display: block; min-width: 96px; padding: 9px 18px; border-radius: 999px; font-size: 15px; font-weight: 600; line-height: 1.3; text-align: center; color: var(--muted); transition: background-color .2s, color .2s; }
.mt-modes input:checked + span { background: var(--ink); color: var(--page); }
.mt-modes input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.mt-panel { display: grid; grid-template-columns: minmax(0, 1fr) 312px; border: 1px solid var(--line); border-radius: 22px; overflow: hidden; background: radial-gradient(120% 90% at 35% 0%, #17232e, #0b1016 70%); color: #eef4f8; }
/* the stage is as tall as it is wide, up to the height of the window, and stretches when the dials beside it need more */
.mt-stage { position: relative; min-width: 0; --tall: max(360px, calc(100dvh - 150px)); }
.mt-stage::before { content: ""; display: block; width: 100%; aspect-ratio: 1; max-height: var(--tall); }
.mt-stage canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.mt-stage canvas.is-hot { cursor: grab; } .mt-stage canvas.is-turning { cursor: grabbing; }
.mt-stage noscript p { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-size: 15px; color: rgba(255, 255, 255, .6); }
.mt-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; padding: 26px 28px 22px; border-left: 1px solid rgba(255, 255, 255, .08); }
.mt-side p, .mt-side dl, .mt-side dd { margin: 0; }
.mt-read-name { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; line-height: 1.4; letter-spacing: .07em; text-transform: uppercase; color: rgba(255, 255, 255, .6); }
/* the key to the one coloured mark in the picture */
.mt-read-name::before { content: ""; flex: none; width: 26px; height: 7px; --c: var(--mark, #6fe3ff); background: radial-gradient(circle at 3.5px 50%, var(--c) 3px, transparent 3.6px), radial-gradient(circle at calc(100% - 3.5px) 50%, var(--c) 3px, transparent 3.6px), linear-gradient(var(--c), var(--c)) center / 100% 1.8px no-repeat; }
.mt-read-value { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 8px !important; font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mt-read-value b { font-size: 34px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; color: #fff; }
.mt-read-value span { font-size: 17px; font-weight: 600; color: rgba(255, 255, 255, .8); }
.mt-read-note { margin-top: 6px !important; font-size: 13.5px; line-height: 1.5; color: rgba(255, 255, 255, .5); }
.mt-read-sub { display: grid; gap: 4px; margin-top: 14px !important; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .1); }
.mt-read-sub div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; line-height: 1.5; }
.mt-read-sub dt { color: rgba(255, 255, 255, .6); }
.mt-read-sub dd { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; font-weight: 600; color: rgba(255, 255, 255, .92); }

.mt-dials { display: grid; gap: 11px; }
.mt-dial { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 12px; }
.mt-dial-name { font-size: 14px; line-height: 1.4; color: rgba(255, 255, 255, .62); }
.mt-dial output { font-family: ui-monospace, Consolas, monospace; font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, .95); }
.mt-track { position: relative; grid-column: 1 / -1; display: block; --knob: 18px; }
/* (a dark mark would be lost on this panel, so its key is given a light rim, as the mark has in the picture) */
.mt[data-mark="dark"] .mt-read-name::before { filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff); }
/* the values a dial catches on */
.mt-track i { position: absolute; top: 50%; left: calc(var(--knob) / 2 + var(--u) * (100% - var(--knob))); width: 1px; height: 11px; margin: -5.5px 0 0 -.5px; background: rgba(255, 255, 255, .42); pointer-events: none; }
/* (--a and --b: where the lit part of the track starts and ends, set by moire.js) */
.mt-track input { --a: 0%; --b: 0%; position: relative; display: block; width: 100%; height: 26px; margin: 0; padding: 0; border: 0; appearance: none; -webkit-appearance: none; cursor: pointer; touch-action: pan-y;
  background: linear-gradient(to right, rgba(255, 255, 255, .17) var(--a), rgba(255, 255, 255, .62) var(--a), rgba(255, 255, 255, .62) var(--b), rgba(255, 255, 255, .17) var(--b)) center / 100% 2px no-repeat; }
.mt-track input::-webkit-slider-runnable-track { height: 26px; background: none; }
.mt-track input::-moz-range-track { height: 26px; background: none; }
.mt-track input::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: var(--knob); height: var(--knob); margin-top: 4px; border: 2px solid #0c1218; border-radius: 50%; background: #d6dee6; transition: transform .15s, background-color .15s; }
.mt-track input::-moz-range-thumb { box-sizing: border-box; width: var(--knob); height: var(--knob); border: 2px solid #0c1218; border-radius: 50%; background: #d6dee6; transition: transform .15s, background-color .15s; }
.mt-track input:hover::-webkit-slider-thumb, .mt-track input:active::-webkit-slider-thumb { background: #fff; transform: scale(1.15); }
.mt-track input:hover::-moz-range-thumb, .mt-track input:active::-moz-range-thumb { background: #fff; transform: scale(1.15); }
.mt-track input:focus-visible { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: 2px; border-radius: 6px; }
/* the colours: a swatch each for the lines, the flake, the ground and the mark, and a few sets to start from */
.mt-colours summary { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .1); list-style: none; font-size: 13px; font-weight: 600; line-height: 1.4; letter-spacing: .07em; text-transform: uppercase; color: rgba(255, 255, 255, .6); cursor: pointer; }
.mt-colours summary::-webkit-details-marker { display: none; }
.mt-colours summary::after { content: ""; width: 7px; height: 7px; margin-right: 4px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform .2s; }
.mt-colours[open] summary::after { transform: translateY(2px) rotate(-135deg); }
.mt-colours summary:focus-visible { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: 4px; border-radius: 4px; }
.mt-swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin-top: 14px; }
.mt-swatch, .mt-split { display: flex; align-items: center; gap: 9px; min-width: 0; font-size: 14px; line-height: 1.3; color: rgba(255, 255, 255, .72); cursor: pointer; }
.mt-swatch input { flex: none; width: 26px; height: 26px; padding: 0; overflow: hidden; border: 1px solid rgba(255, 255, 255, .42); border-radius: 50%; background: none; appearance: none; -webkit-appearance: none; cursor: pointer; }
.mt-swatch input::-webkit-color-swatch-wrapper { padding: 0; }
.mt-swatch input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.mt-swatch input::-moz-color-swatch { border: 0; border-radius: 50%; }
.mt-swatch input:focus-visible, .mt-split input:focus-visible, .mt-preset:focus-visible { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: 2px; }
.mt-split { margin-top: 12px; }
.mt-split input { flex: none; width: 16px; height: 16px; margin: 0 5px; accent-color: #d6dee6; cursor: pointer; }
.mt-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.mt-preset { min-height: 30px; padding: 4px 12px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px; background: transparent; color: rgba(255, 255, 255, .8); font: inherit; font-size: 13px; font-weight: 600; line-height: 1; cursor: pointer; transition: border-color .2s, background-color .2s, color .2s; }
.mt-preset:hover { border-color: rgba(255, 255, 255, .7); }
.mt-preset[aria-pressed="true"] { border-color: #d6dee6; background: #d6dee6; color: #0c1218; }
.mt-reset { align-self: flex-start; margin-top: auto; min-height: 36px; padding: 6px 16px; border: 1px solid rgba(255, 255, 255, .24); border-radius: 999px; background: transparent; color: #eef4f8; font: inherit; font-size: 14px; font-weight: 600; line-height: 1; cursor: pointer; transition: border-color .2s, background-color .2s; }
.mt-reset:hover { border-color: rgba(255, 255, 255, .7); background: rgba(255, 255, 255, .08); }
.mt-reset:focus-visible { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: 3px; }
.mt:not(.is-live) .mt-side { visibility: hidden; }

@media (max-width: 900px) {
  .mt-panel { grid-template-columns: minmax(0, 1fr); }
  .mt-stage { --tall: max(280px, calc(100dvh - 110px)); }
  .mt-side { gap: 20px; padding: 22px 20px 20px; border-left: 0; border-top: 1px solid rgba(255, 255, 255, .08); }
  .mt-reset { margin-top: 0; }
}
@media (max-width: 720px) {
  .mt .section-heading, .fs .section-heading { align-items: flex-start; }
  .mt .section-heading h2, .fs .section-heading h2 { font-size: 28px; }
  .mt-panel { border-radius: 16px; }
  .mt-modes span { min-width: 0; padding: 9px 16px; }
  .fs { margin-top: 64px; }
}

/* ---- Formula Studio ---- */
.fs .section-heading .small-note { margin: 0; }
.fs-bench { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 32px; padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: var(--page); }
.fs-col { min-width: 0; }
.fs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; margin-bottom: 10px; }
.fs-head h3 { margin: 0; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; }
.fs-head h3 span { margin-right: 8px; font-size: 13px; font-variant-numeric: tabular-nums; letter-spacing: 0; color: var(--accent); }
.fs-head + .fs-head, .fs-examples + .fs-head { margin-top: 24px; }
.fs button { min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--page); color: var(--ink); font: inherit; font-size: 14.5px; font-weight: 600; line-height: 1.3; cursor: pointer; transition: background-color .15s, color .15s, border-color .15s; }
.fs button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.fs button:disabled { opacity: .45; cursor: not-allowed; }
.fs button:focus-visible, .fs textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.fs button.fs-text { min-height: 34px; padding: 5px 6px; border: 0; background: transparent; color: var(--accent); font-size: 14px; }
.fs-drop { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 240px; padding: 20px 14px; border: 1px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--accent) 4%, var(--page)); transition: background-color .15s; }
.fs-drop.is-dragging { background: color-mix(in srgb, var(--accent) 14%, var(--page)); }
.fs-empty { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 6px 0 20px; text-align: center; }
.fs-symbol { font: italic 46px Georgia, serif; line-height: 1; color: var(--accent); }
.fs-empty strong { font-size: 17px; font-weight: 600; }
.fs-empty > span:last-child { font-size: 14px; color: var(--muted); }
.fs-image { max-width: 100%; max-height: 230px; margin: 0 auto 14px; object-fit: contain; border-radius: 6px; background: #fff; }
.fs-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fs-hint, .fs-note, .fs-foot { margin: 8px 0 0; font-size: 13.5px; line-height: 1.6; color: var(--muted); overflow-wrap: anywhere; }
.fs-recognise { display: flex; gap: 8px; margin-top: 20px; }
.fs button.fs-primary { flex: 1; min-height: 46px; border-color: var(--accent); background: var(--accent); color: #fff; }
.fs button.fs-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent), #000 12%); color: #fff; }
.fs-progress { height: 6px; margin-top: 12px; border-radius: 999px; background: var(--surface); overflow: hidden; }
.fs-progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .15s linear; }
.fs-status { min-height: 23px; margin: 10px 0 0; font-size: 14.5px; line-height: 1.6; color: var(--accent); overflow-wrap: anywhere; }
.fs-error, .fs-status.is-error { margin: 8px 0 0; font-size: 14.5px; line-height: 1.6; color: #b3261e; overflow-wrap: anywhere; }
.fs textarea { display: block; width: 100%; min-height: 190px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: 15px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; resize: vertical; tab-size: 2; }
.fs textarea::placeholder { color: var(--muted); opacity: .85; }
.fs-examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.fs-examples > span { margin-right: 4px; font-size: 13.5px; color: var(--muted); }
.fs-examples button { min-height: 32px; padding: 5px 11px; border-color: transparent; background: var(--surface); font-size: 13.5px; }
.fs-state { font-size: 13px; color: var(--muted); }
.fs-preview { display: flex; align-items: center; min-height: 132px; padding: 12px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: #17232b; }
.fs-preview svg { flex: 0 0 auto; max-width: none; margin: auto; }
.fs-preview p { width: 100%; margin: 0; font-size: 14.5px; text-align: center; color: var(--muted); }
.fs-export { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.fs-export button { flex: 1; }
.fs-foot { margin-top: 16px; max-width: 760px; }
.fs-spinner { display: inline-block; width: 12px; height: 12px; margin-right: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -1px; animation: fs-spin .8s linear infinite; }
@keyframes fs-spin { to { transform: rotate(360deg); } }
@media (max-width: 860px) { .fs-bench { grid-template-columns: minmax(0, 1fr); gap: 26px; padding: 22px 18px; border-radius: 16px; } }
@media (max-width: 720px) { .fs button { min-height: 44px; } .fs textarea { font-size: 16px; } }
@media (prefers-reduced-motion: reduce) { .fs button, .fs-drop, .fs-progress span, .mt-modes span, .mt-track input::-webkit-slider-thumb { transition: none; } .fs-spinner { animation: none; } }
