/*
 * Base styles and hierarchy primitives (WP02; FR-014, NFR-003). Values come
 * from tokens.css only. Every screen composes these few classes instead of
 * bespoke sizes; selectors are single classes (or :where()) so a screen can
 * refine them with one more class.
 *
 * Text styles
 *   .page-title     the one heading of a screen (24 px, bold)
 *   .section-title  a region of a screen (20 px, semibold)
 *   .caption        help text, units, secondary facts (14 px, muted)
 *
 * Panels: one group of related content and its actions
 *   .panel          panel surface, subtle edge, radius, padding; a grid with a
 *                   regular gap. .panel--raised adds the raised surface and
 *                   shadow (a card that floats over the page).
 *   .panel__title   the panel's heading (16 px, semibold); use a real h2/h3
 *   .panel__actions a wrapping row of the panel's buttons
 *
 * Buttons: every `button` (and `.button`) is a secondary action by default:
 * control background, 3:1 outline, 44 px target.
 *   .button--primary  THE emphasised action, filled with the accent.
 *                     Rule: one primary per panel (at most one per dialog);
 *                     if two actions compete, the rarer one is secondary.
 *   .button--quiet    low emphasis (toolbars, "show more", dismiss): no
 *                     outline until hovered or focused.
 *   .button--icon     a square, icon-only or one-glyph button (44 x 44 px);
 *                     it must carry an aria-label.
 * States are the same for all of them:
 *   hover            a tinted background (primary: a darker accent)
 *   :active          the pressed background
 *   :focus-visible   a 3 px accent ring, 2 px off the edge (3:1 on every surface)
 *   disabled         `disabled` or aria-disabled="true" (which keeps focus):
 *                    dimmed AND a dashed outline AND the not-allowed cursor,
 *                    so the state is never shown by colour alone
 *
 * Layout helpers (spacing tokens only)
 *   .stack          vertical flow; gap var(--stack-gap) (default 12 px);
 *                   .stack--tight 8 px, .stack--loose 24 px
 *   .cluster        a wrapping row, centred vertically; gap var(--cluster-gap)
 *                   (default 8 px); .cluster--end aligns it to the end
 *
 * Reference use: the analysis bar, move details and graph (analysis.css).
 */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface-page);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--line-height);
}

h1,
h2,
h3,
p,
ul,
ol,
figure {
  margin: 0;
}

h1 {
  font-size: var(--text-xl);
  line-height: var(--line-height-tight);
}

h2 {
  font-size: var(--text-lg);
  line-height: var(--line-height-tight);
}

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

code,
kbd,
pre,
.mono {
  font-family: var(--font-mono);
}

a {
  color: var(--accent);
}

/* ---- text styles ------------------------------------------------------ */

.page-title {
  font-size: var(--text-page-title);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

.section-title {
  font-size: var(--text-section-title);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

.caption {
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  line-height: var(--line-height-snug);
}

/* ---- focus ------------------------------------------------------------ */

/* Visible for keyboard users only, at least 3:1 against every surface. */
:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}

/* Hidden visually but read by screen readers. */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- panels ----------------------------------------------------------- */

.panel {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-panel);
}

.panel--raised {
  background: var(--surface-raised);
  box-shadow: var(--shadow-raised);
}

.panel__title {
  font-size: var(--text-panel-title);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

.panel__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

@media (max-width: 719.98px) {
  .panel {
    padding: var(--space-3);
  }
}

/* ---- layout helpers --------------------------------------------------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, var(--space-3));
  min-width: 0;
}

.stack--tight {
  --stack-gap: var(--space-2);
}

.stack--loose {
  --stack-gap: var(--space-5);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster-gap, var(--space-2));
  min-width: 0;
}

.cluster--end {
  justify-content: flex-end;
}

/* ---- form controls ---------------------------------------------------- */

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

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-snug);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

:where(button, .button):hover {
  background: var(--control-bg-hover);
  border-color: var(--color-text-muted);
}

:where(button, .button):active {
  background: var(--control-bg-pressed);
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: var(--font-weight-semibold);
}

.button--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button--primary:active {
  background: var(--accent-pressed);
  border-color: var(--accent-pressed);
}

.button--quiet {
  background: transparent;
  border-color: transparent;
}

.button--quiet:hover {
  background: var(--control-bg-hover);
  border-color: var(--color-border-subtle);
}

.button--icon {
  width: var(--touch-target);
  padding: 0;
  font-size: var(--text-lg);
  line-height: 1;
}

/* Disabled: dimmed, dashed and the not-allowed cursor (never colour alone).
   Hover and press do not change it. */
:where(button, .button):is(:disabled, [aria-disabled="true"]),
:where(button, .button):is(:disabled, [aria-disabled="true"]):is(:hover, :active) {
  cursor: not-allowed;
  opacity: var(--disabled-opacity);
  border-style: dashed;
}

:where(button, .button):not(.button--primary):is(:disabled, [aria-disabled="true"]):is(:hover, :active) {
  background: var(--control-bg);
  border-color: var(--color-border);
}

.button--quiet:is(:disabled, [aria-disabled="true"]):is(:hover, :active) {
  background: transparent;
}

.button--primary:is(:disabled, [aria-disabled="true"]):is(:hover, :active) {
  background: var(--accent);
  border-color: var(--accent);
}

input,
select,
textarea {
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

:where(input, select, textarea):disabled {
  cursor: not-allowed;
  opacity: var(--disabled-opacity);
}

/* ---- notices ---------------------------------------------------------- */

/* Plain messages: loading, not built yet, unsupported browser. */
.notice {
  max-width: 40rem;
  margin: var(--space-6) auto;
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--surface-panel);
  display: grid;
  gap: var(--space-3);
}

.notice--unsupported {
  border-color: var(--color-danger);
}

.notice__list {
  padding-left: var(--space-5);
  display: grid;
  gap: var(--space-2);
}

@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;
  }
}
