/* InstantPalette - base (layer 2 of 4: tokens -> base -> site -> tool)
   Reset, type, icons, focus, kbd, generic buttons, dialog / popover / sheet / drawer / modal shells, toasts,
   reduced motion. No page layout here (site.css) and nothing tool-specific (tool.css).

   FONTS - copy these three tags verbatim into every page <head>, before the stylesheets. No CSS @import anywhere.
   Exactly two families: Instrument Sans (variable wght 400-700) and Martian Mono (wdth 75-100, wght 500 only).

   <link rel="preconnect" href="https://fonts.googleapis.com">
   <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400..700&family=Martian+Mono:wdth,wght@75..100,500&display=swap">

   Martian Mono is only ever used at weight 500: never set another weight on mono text (no synthetic bold). */

/* ---------- Metric-matched fallback (measured 2026-09-11 against Arial: width 102%, ascent .97, descent .25) ---------- */
@font-face {
  font-family: "Instrument Sans Fallback";
  src: local("Arial"), local("ArialMT"), local("Helvetica"), local("Liberation Sans");
  size-adjust: 102%;
  ascent-override: 95%;
  descent-override: 24.5%;
  line-gap-override: 0%;
}

/* ---------- Reset + base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink-1);
  font: 400 15px/1.5 var(--f-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;   /* fallback */
  overflow-x: clip;     /* clip, not hidden: keeps position: sticky working */
}
[hidden] { display: none !important; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; margin: 0; text-align: inherit; }
button:disabled { cursor: default; }
a { color: inherit; }
kbd {
  font: 500 12px/1 var(--f-mono);
  padding: 4px 6px 3px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--raised);
  color: var(--ink-1);
  white-space: nowrap;
}
.mono { font-family: var(--f-mono); font-weight: 500; }

/* Icons: <svg class="i"><use href="#i-name"/></svg> from the inline sprite. 24x24 grid, 1.75 stroke. */
.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.i-chev { width: 16px; height: 16px; color: var(--ink-2); }
.i-flip { transform: scaleX(-1); }   /* i-arrow as a back arrow */

/* Visually hidden (screen-reader only) */
.vh {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: 8px; top: -120px; z-index: var(--z-skip);
  padding: 10px 14px; border-radius: var(--r);
  background: var(--raised); color: var(--ink-1); text-decoration: none;
  font: 500 14px/1.2 var(--f-sans);
}
.skip:focus { top: 8px; box-shadow: var(--shadow-pop); }

/* Focus: one ring everywhere (swatches use their own dual ring in tool.css). Never outline:none without a replacement. */
:focus-visible { outline: 2px solid var(--ink-1); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- Brand mark (step wedge) + wordmark, shared by the tool top bar and the site header ---------- */
.wedge { width: 24px; height: 24px; color: var(--ink-1); flex: none; }
.wm { font: 700 18px/20px var(--f-sans); letter-spacing: -.02em; }

/* ---------- Generic buttons ---------- */
/* Icon button (40px; 44px on touch) */
.ib { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r); color: var(--ink-1); flex: none; }
/* Hover styles apply to real hover-capable pointers only: touch browsers keep :hover on the last tapped control */
@media (hover: hover) and (pointer: fine) { .ib:hover { background: var(--hover); } }
.ib:active { background: var(--press); }
.ib-sm { width: 32px; height: 32px; }
/* Text nav link with a 44px hit area */
.nav-a {
  display: inline-flex; align-items: center; min-height: 44px;
  padding: 0 10px; border-radius: var(--r);
  font: 500 14px/1 var(--f-sans); color: var(--ink-1); text-decoration: none; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) { .nav-a:hover { background: var(--hover); } }
.nav-a[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }
/* Outlined button on raised surfaces (dialogs, sheets) */
.btn-o {
  height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--raised); color: var(--ink-1);
  font: 500 14px/1 var(--f-sans); white-space: nowrap; text-decoration: none;
}
@media (hover: hover) and (pointer: fine) { .btn-o:hover { border-color: var(--ink-3); } }
.btn-o.ic { width: 40px; padding: 0; }
.btn-o .i { width: 18px; height: 18px; }
.btn-strong { border-color: var(--ink-1); }
@media (hover: hover) and (pointer: fine) { .btn-strong:hover { border-color: var(--ink-1); box-shadow: inset 0 0 0 1px var(--ink-1); } }
/* Ghost button on the ground (content CTAs, "Use <Mode>", back link, 404). Never filled. */
.ghost {
  align-self: flex-start;
  height: 36px; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: transparent; color: var(--ink-1);
  font: 500 14px/1 var(--f-sans); text-decoration: none; white-space: nowrap;
  transition: border-color var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .ghost:hover { border-color: var(--ink-1); } }
.ghost .i { width: 18px; height: 18px; }
.ghost-lg { height: 44px; padding: 0 16px; }
.ghost-strong { border-color: var(--ink-1); }
@media (hover: hover) and (pointer: fine) { .ghost-strong:hover { box-shadow: inset 0 0 0 1px var(--ink-1); } }
/* A <button> that reads as a link (footer "Privacy & cookie settings") */
.linklike { color: var(--ink-1); text-decoration: none; font: 500 14px/1.6 var(--f-sans); }
@media (hover: hover) and (pointer: fine) { .linklike:hover { text-decoration: underline; text-underline-offset: 3px; } }

@media (hover: none), (pointer: coarse) {
  .ib { width: 44px; height: 44px; }
  .btn-o { min-height: 44px; }
  .btn-o.ic { width: 44px; }
}

/* ---------- Dialog shells ---------- */
dialog { color: var(--ink-1); }
dialog::backdrop { background: transparent; }
/* ::backdrop only inherits custom properties in 2024+ engines, hence the literal fallback */
.sheet::backdrop, .drawer::backdrop, .modal::backdrop, .as-sheet::backdrop { background: var(--scrim, rgb(0 0 0 / .45)); }

/* Popovers: anchored, non-modal, opened with .show() and placed by UI.openPopover() */
.pop {
  position: fixed; inset: auto; margin: 0; padding: 0;
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
  background: var(--raised);
  box-shadow: var(--shadow-pop);
  max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  overflow: auto;
  z-index: var(--z-pop);
}
.pop[open] { animation: pop-in 140ms var(--ease); }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px); } }
.pop-hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 8px 6px 16px; }
.pop-title { margin: 0; font: 600 15px/1.3 var(--f-sans); }
.pop-narrow { width: 330px; }
.pop-note { margin: 0; padding: 10px 16px 14px; font-size: 13px; line-height: 1.5; color: var(--ink-2); border-top: 1px solid var(--line); }
.pop-ft { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.grab { display: none; }

/* Sheets (phones, landscape): modal, bottom-anchored */
.sheet, .drawer { padding: 0; border: 0; background: var(--raised); color: var(--ink-1); }
.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0;
  width: 100%; max-width: 100%;
  max-height: 88vh; max-height: 88svh;
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  overflow: auto; overscroll-behavior: contain;
  box-shadow: var(--shadow-sheet);
}
.sheet[open] { animation: sheet-in 220ms var(--ease); }
@keyframes sheet-in { from { transform: translateY(28px); opacity: .5; } }
.sheet .grab, .as-sheet .grab {
  display: block; width: 36px; height: 4px; margin: 8px auto 0;
  border-radius: 2px; background: var(--line-2);
}
.sheet .pop-hd { padding: 6px 8px 4px 16px; }
.sheet .pop-hd .ib { width: 44px; height: 44px; }
.sheet-bd { padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 16px; }

/* Drawer (desktop library): modal, full height from the right */
.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0;
  width: 420px; max-width: 100vw;
  height: 100vh; height: 100dvh; max-height: none;
  border-left: 1px solid var(--line-2);
  display: none; flex-direction: column;
  box-shadow: -18px 0 48px -18px rgb(0 0 0 / .35);
}
.drawer[open] { display: flex; animation: drawer-in 220ms var(--ease); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: .6; } }

/* Centred modal (shortcuts) */
.modal {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 0 0 16px;
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
  background: var(--raised); box-shadow: var(--shadow-pop);
}
.modal[open] { animation: pop-in 140ms var(--ease); }

/* ---------- Toasts (UI.toast) ---------- */
/* Default placement: centred, above the bottom edge (and above a phone anchor ad). Tool pages override the
   position at runtime through UI.setToastPlacement(). */
.toasts {
  position: fixed; left: 50%; bottom: max(12px, calc(env(safe-area-inset-bottom) + 12px));
  transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: var(--z-toast); pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 14px;
  max-width: 100%;
  min-height: 40px; padding: 8px 8px 8px 14px;
  border-radius: var(--r);
  background: var(--ink-1); color: var(--ground);
  font: 500 14px/1.3 var(--f-sans);
  box-shadow: var(--shadow-pop);
  animation: pop-in 160ms var(--ease);
}
.toast-msg { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.toast .mono { font-size: 13px; overflow-wrap: anywhere; }
.toast .dot {
  width: 14px; height: 14px; border-radius: 4px; flex: none;
  background: var(--c);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ground) 45%, transparent);
}
.toast button {
  flex: none; min-height: 28px; padding: 6px 8px; border-radius: 6px;
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.toast button:focus-visible { outline-color: var(--ground); }
.toast:not(:has(button)) { padding-right: 14px; }
.toast.no-act { padding-right: 14px; }
@media (hover: none), (pointer: coarse) { .toast button { min-height: 44px; min-width: 44px; } }
/* While a bottom sheet is open, toasts move into it (UI.toast) and sit in the scrim above it, never over its controls */
.sheet > .toasts, .as-sheet > .toasts { top: max(12px, calc(env(safe-area-inset-top) + 12px)); bottom: auto; }

/* Hidden native colour input (tool editor "System picker") */
/* Hidden native colour input (tool editor "System picker"). Parked off screen; app.js moves it under the button
   just before opening, because Chromium anchors its colour chooser to the input's box. */
.sys-picker { position: fixed; left: -200px; top: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
