/* =============================================================================
 *  global.css - the reset, and nothing else.
 *
 *  Loaded immediately after tokens.css and before any component, so every rule
 *  here is either a browser default being corrected or a house default being
 *  set once. Nothing in this file knows what a button, a card or a table is:
 *  that is what the CSS modules beside each component are for.
 *
 *  Six rules earn their place:
 *
 *    * one border-box declaration, because every layout in the product assumes
 *      it;
 *    * the root font size, which is the text-size setting: every size in
 *      tokens.css is in rem, so this one number scales the whole product;
 *    * one focus ring, drawn with --accent-ring, on :focus-visible only - so a
 *      mouse click does not leave a halo but a Tab key always does;
 *    * a scrollbar that is quiet in both themes, because a dense tool has a lot
 *      of them;
 *    * a prefers-reduced-motion block that kills transitions and animations
 *      globally, so no component can forget;
 *    * a print block, because the frame is a fixed-height box and without it a
 *      printed report is one clipped screen.
 * ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* -- Text size --------------------------------------------------------------
 * lib/theme.tsx stamps data-text-size on <html> ("large" | "xlarge") and
 * removes it for "standard" - absent means default, the same discipline as
 * data-theme. Percentages, not px, so a browser's own default font size (an
 * accessibility setting in its own right) still multiplies through: 100% of a
 * 16px browser default is the 16px body the type scale is drawn around, and
 * 106.25% / 112.5% make that 17px / 18px. */

html {
  height: 100%;
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html[data-text-size="large"] {
  font-size: 106.25%;
}

html[data-text-size="xlarge"] {
  font-size: 112.5%;
}

body {
  height: 100%;
  margin: 0;
  /* The chrome ground: every full-page screen and the frame sit on it, so
     painting it here removes the light flash before React mounts. */
  background-color: var(--chrome-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

#root {
  min-height: 100%;
  isolation: isolate;
}

/* -- Rhythm ---------------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

ul,
ol {
  margin: 0;
  padding: 0;
}

/* -- Controls inherit the house face --------------------------------------- */

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  background: none;
  border: none;
  padding: 0;
}

a {
  /* --accent-text, not --accent: the fill colour is under 4.5:1 as small text
     on a light card. No :hover rule here on purpose - an element selector with
     :hover would outrank a component's own colour (a Button rendered as a
     link) - so a component that wants a hover colour sets
     --accent-text-hover itself. */
  color: var(--accent-text);
  /* At a 16px+ body the default underline sits on the descenders; a little
     air keeps "g", "p" and "y" legible in a link. */
  text-underline-offset: 0.18em;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

hr {
  height: 1px;
  margin: 0;
  border: 0;
  background-color: var(--border-subtle);
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.95em;
}

/* Numerals that line up in a column: any element can opt in, and every table of
   amounts, durations and counts should. */
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
}

/* Proportional text with lining figures, for a sentence that contains a number
   without switching to the mono face. */
.tnum {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1;
}

/* -- Focus ----------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--accent-ring);
}

/* A mouse press never leaves a ring; :focus-visible above still does. */
:focus:not(:focus-visible) {
  outline: none;
}

/* -- Selection ------------------------------------------------------------- */

::selection {
  background-color: var(--accent-tint-strong);
  color: var(--text-primary);
}

/* -- Scrollbars ------------------------------------------------------------ */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* 12px with a 3px transparent border: a 6px thumb, big enough to grab with a
   mouse on a large monitor, still quiet next to the content. */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--radius-pill);
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-faint);
  background-clip: padding-box;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* -- Screen-reader only ---------------------------------------------------- */

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* -- Motion ---------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -- Print ----------------------------------------------------------------- */

/* The frame is a fixed-height, hidden-overflow box with every scroller nested
   inside it, so without this a print is one clipped screen. Reports are the
   one thing anyone prints. Hiding the chrome and unclamping a table's scroller
   are separate decisions and are deliberately not made here. */
@media print {
  html,
  body,
  #root {
    height: auto;
    overflow: visible;
  }
}
