/*
 * NosyDoodle component set (Phase 0.5 draft)
 *
 * Reads only design/tokens.css. This is the reference that `packages/ui`
 * implements in React; the class names map one to one onto components.
 *
 * Two line rules keep the product "one hand":
 *   1. Anything you can press, type into, or that Maizy says wears the 2px
 *      ink line (the same weight as her outline at UI size).
 *   2. Containers (cards, panels, tables) wear a 1px hairline and a soft lift.
 */

/* ---------------------------------------------------------------------- */
/* Base                                                                   */
/* ---------------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
}

h2 {
  font-size: var(--text-xl);
}

h3 {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: inherit;
  font-weight: var(--weight-bold);
  text-decoration-line: underline;
  text-decoration-color: var(--color-primary);
  text-decoration-thickness: 3px;
  text-underline-offset: 0.2em;
  border-radius: 2px;
  transition: background-color var(--dur-fast) var(--ease-out);
}

a:hover {
  background: var(--color-primary-tint);
  text-decoration-color: var(--color-primary-pressed);
}

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

::selection {
  background: var(--yellow-300);
  color: var(--ink-900);
}

.num {
  font-variant-numeric: tabular-nums lining-nums;
}

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

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-2);
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--sm {
  width: 1rem;
  height: 1rem;
}

.icon--lg {
  width: 1.5rem;
  height: 1.5rem;
}

.muted {
  color: var(--color-text-muted);
}

.eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.lead {
  font-size: var(--text-md);
  color: var(--color-text-soft);
  max-width: var(--reading-max);
}

/* A hand-drawn marker swash under a key word in a heading. */
.swash {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 16' preserveAspectRatio='none'%3E%3Cpath d='M3 11c32-5 66-7 98-6 31 1 62 2 96-3' fill='none' stroke='%23F9C519' stroke-width='7' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 0.42em;
  padding-bottom: 0.08em;
}

/* ---------------------------------------------------------------------- */
/* Layout                                                                 */
/* ---------------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: rgb(253 251 247 / 0.94);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: var(--line-hair) solid var(--color-hairline);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-right: auto;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: 1.375rem;
  letter-spacing: var(--tracking-display);
  border-radius: var(--radius-sm);
}

.brand:hover {
  background: none;
}

.brand img {
  width: 2.5rem;
  height: 2.5rem;
}

.site-nav {
  display: none;
}

.site-nav a {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: var(--weight-bold);
  color: var(--color-text-soft);
}

.site-nav a:hover {
  background: var(--color-surface-quiet);
  color: var(--color-text);
}

.site-nav a[aria-current="page"] {
  color: var(--color-text);
  text-decoration-line: underline;
  text-decoration-color: var(--color-primary);
  text-decoration-thickness: 3px;
  text-underline-offset: 0.45em;
}

.site-nav.is-open {
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 100% 0 auto 0;
  padding: var(--space-2) var(--gutter) var(--space-4);
  background: var(--color-bg);
  border-bottom: var(--line) solid var(--color-line);
  box-shadow: var(--shadow-float);
}

.site-nav.is-open a {
  min-height: var(--control-h);
  font-size: var(--text-md);
}

@media (min-width: 48rem) {
  .site-header .nav-toggle {
    display: none;
  }

  .site-nav,
  .site-nav.is-open {
    display: flex;
    flex-direction: row;
    position: static;
    padding: 0;
    gap: var(--space-1);
    background: none;
    border: 0;
    box-shadow: none;
    margin-right: var(--space-2);
  }

  .site-nav.is-open a {
    min-height: 2.75rem;
    font-size: var(--text-base);
  }
}

.page {
  padding-block: var(--space-8) var(--space-16);
}

@media (min-width: 64rem) {
  .page {
    padding-block: var(--space-12) var(--space-20);
  }
}

.page-head {
  display: grid;
  gap: var(--space-5);
  margin-bottom: var(--space-8);
}

.page-head__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
}

.stack > * + * {
  margin-top: var(--stack, var(--space-4));
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster, var(--space-3));
}

.site-footer {
  border-top: var(--line-hair) solid var(--color-hairline);
  padding-block: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
  align-items: center;
  justify-content: space-between;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
}

.site-footer a {
  font-weight: var(--weight-semibold);
  color: var(--color-text-soft);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--color-surface);
  --btn-bg-hover: var(--color-surface-quiet);
  --btn-bg-pressed: var(--sand-200);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding: 0 var(--space-5);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--color-text);
  box-shadow: var(--shadow-key);
  font: var(--weight-heavy) var(--text-base) / 1 var(--font-body);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
  margin-bottom: 3px; /* room for the key ledge so layouts do not jump */
}

.btn:hover,
.btn.is-hover {
  background: var(--btn-bg-hover);
}

.btn:active,
.btn.is-pressed {
  background: var(--btn-bg-pressed);
  transform: translateY(2px);
  box-shadow: var(--shadow-key-pressed);
}

.btn:focus-visible,
.btn.is-focus {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: 3px;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  background: var(--color-disabled-bg);
  border-color: var(--color-disabled-line);
  color: var(--color-disabled-text);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.btn--primary {
  --btn-bg: var(--color-primary);
  --btn-bg-hover: var(--color-primary-hover);
  --btn-bg-pressed: var(--color-primary-pressed);
}

.btn--secondary {
  --btn-bg: var(--color-secondary);
  --btn-bg-hover: var(--coral-300);
  --btn-bg-pressed: var(--color-secondary-pressed);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-bg-hover: var(--color-surface-quiet);
  --btn-bg-pressed: var(--sand-200);
  border-color: transparent;
  box-shadow: none;
  margin-bottom: 0;
}

.btn--ghost:active,
.btn--ghost.is-pressed {
  transform: none;
  box-shadow: none;
}

.btn--ghost[disabled] {
  background: transparent;
  border-color: transparent;
}

.btn--danger {
  color: var(--color-error);
}

.btn--sm {
  min-height: var(--control-h-sm);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

.btn--icon {
  padding: 0;
  width: var(--control-h);
}

.btn--icon.btn--sm {
  width: var(--control-h-sm);
}

.btn--block {
  width: 100%;
}

@media (max-width: 29.99rem) {
  .btn__label--wide {
    display: none;
  }
}

/* ---------------------------------------------------------------------- */
/* Form fields                                                            */
/* ---------------------------------------------------------------------- */

.field {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  min-width: 0;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-heavy);
}

.field__hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.input,
.input-group {
  width: 100%;
  min-height: var(--control-h);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.input {
  padding: 0 var(--space-4);
  font:
    var(--weight-semibold) 1rem / 1.2 var(--font-body); /* 16px stops iOS zoom */
  appearance: none;
}

.input::placeholder,
.input-group input::placeholder {
  color: var(--color-text-muted);
  font-weight: var(--weight-regular);
  opacity: 1;
}

.input:disabled {
  background: var(--color-disabled-bg);
  border-color: var(--color-disabled-line);
  color: var(--color-disabled-text);
  cursor: not-allowed;
}

.input:focus,
.input-group:focus-within {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

.input-group {
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

.input-group input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0 var(--space-4);
  font: var(--weight-semibold) 1rem / 1.2 var(--font-body);
  color: inherit;
  font-variant-numeric: tabular-nums;
}

.input-group input:focus {
  outline: none;
}

.input-group__affix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--color-surface-quiet);
  border-right: var(--line) solid var(--color-line);
  font-weight: var(--weight-heavy);
  color: var(--color-text-soft);
}

.input-group__affix--end {
  border-right: 0;
  border-left: var(--line) solid var(--color-line);
}

.input-group__status {
  display: none;
  align-items: center;
  padding-right: var(--space-3);
}

/* Validation states: color AND a message AND an icon, never color alone. */
.field.is-invalid .input,
.field.is-invalid .input-group {
  border-color: var(--color-error);
  background: var(--color-error-tint);
}

.field.is-invalid .input-group__affix {
  border-color: var(--color-error);
  background: var(--error-200);
}

.field.is-valid .input,
.field.is-valid .input-group {
  border-color: var(--color-success);
}

.field.is-valid .input-group__affix {
  border-color: var(--color-success);
}

.field.is-valid .input-group__status {
  display: flex;
  color: var(--color-success);
}

.field__msg {
  display: none;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
}

.field__msg.is-shown,
.field.is-valid .field__msg--ok {
  display: flex;
}

.field__msg--error {
  color: var(--color-error);
}

.field__msg--ok {
  color: var(--color-success);
}

.field__msg .face {
  --size: 1.75rem;
  margin-top: -0.2rem;
}

/* ---------------------------------------------------------------------- */
/* Custom select (listbox)                                                */
/* ---------------------------------------------------------------------- */

.select {
  position: relative;
  min-width: 0;
}

.select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--space-3) 0 var(--space-4);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: var(--weight-bold) 1rem / 1.2 var(--font-body);
  text-align: left;
  cursor: pointer;
}

.select__trigger:hover {
  background: var(--color-surface-quiet);
}

.select__trigger .icon {
  transition: transform var(--dur-base) var(--ease-out);
}

.select__trigger[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}

.select__list {
  position: absolute;
  z-index: var(--z-menu);
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  max-height: 18rem;
  overflow: auto;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--color-surface);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
}

.select__list[hidden] {
  display: none;
}

.select__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  cursor: pointer;
}

.select__option .icon {
  visibility: hidden;
}

.select__option[aria-selected="true"] {
  font-weight: var(--weight-heavy);
}

.select__option[aria-selected="true"] .icon {
  visibility: visible;
}

.select__option:hover,
.select__option.is-active {
  background: var(--color-primary-tint);
}

.select__option.is-active {
  outline: var(--line) solid var(--color-line);
  outline-offset: -2px;
}

.select__option[aria-disabled="true"] {
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.select__option small {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-text-muted);
}

/* Compact variant used inside sentences (the rule builder) */
.select--inline {
  display: inline-block;
}

.select--inline .select__trigger {
  min-height: var(--control-h-sm);
  border-radius: var(--radius-sm);
  background: var(--yellow-50);
}

/* ---------------------------------------------------------------------- */
/* Switch, checkbox, radio                                                */
/* ---------------------------------------------------------------------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: var(--weight-bold) var(--text-base) / 1.3 var(--font-body);
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.switch__track {
  position: relative;
  flex: none;
  width: 3.25rem;
  height: 1.875rem;
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--sand-200);
  transition: background-color var(--dur-base) var(--ease-out);
}

.switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.375rem;
  height: 1.375rem;
  border: var(--line) solid var(--color-line);
  border-radius: 50%;
  background: var(--color-surface);
  transition: transform var(--dur-base) var(--ease-bounce);
}

.switch[aria-checked="true"] .switch__track {
  background: var(--color-primary);
}

.switch[aria-checked="true"] .switch__thumb {
  transform: translateX(1.375rem);
}

.switch__state {
  font-size: var(--text-xs);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-muted);
  min-width: 2rem;
}

.switch[disabled] {
  cursor: not-allowed;
  color: var(--color-disabled-text);
}

.switch[disabled] .switch__track,
.switch[disabled] .switch__thumb {
  border-color: var(--color-disabled-line);
  background: var(--color-disabled-bg);
}

.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 2.75rem;
  padding-top: 0.6rem;
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.check input {
  appearance: none;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  margin: -0.05rem 0 0;
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-xs);
  background: var(--color-surface) center / 1rem no-repeat;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.check input[type="radio"] {
  border-radius: 50%;
}

.check input:hover {
  background-color: var(--color-primary-tint);
}

.check input:checked {
  background-color: var(--color-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232B2421' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

.check input[type="radio"]:checked {
  background-image: radial-gradient(
    circle,
    var(--ink-900) 0 32%,
    transparent 36%
  );
  background-size: 100%;
}

.check input:disabled {
  border-color: var(--color-disabled-line);
  background-color: var(--color-disabled-bg);
  cursor: not-allowed;
}

.check input:disabled + span {
  color: var(--color-disabled-text);
}

.check small {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
}

/* Choice cards: radio or checkbox options that need a sentence each
   (what to watch, cadence, channel). */
.choices {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(
      auto-fit,
      minmax(min(100%, var(--choice-min, 11rem)), 1fr)
    );
  margin: 0;
  padding: 0;
  border: 0;
}

.choice {
  position: relative;
  display: grid;
  gap: var(--space-1);
  align-content: start;
  padding: var(--space-4);
  padding-right: var(--space-10);
  border: var(--line) solid var(--ink-300);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

.choice:hover {
  border-color: var(--color-line);
}

.choice input {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  appearance: none;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  border: var(--line) solid var(--color-line);
  border-radius: 50%;
  background: var(--color-surface) center / 1rem no-repeat;
  cursor: pointer;
}

.choice input[type="checkbox"] {
  border-radius: var(--radius-xs);
}

.choice input:focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

.choice:has(input:checked) {
  border-color: var(--color-line);
  background: var(--color-primary-tint);
  box-shadow: var(--shadow-key);
}

.choice input:checked {
  background-color: var(--color-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232B2421' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}

.choice__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-heavy);
}

.choice__body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.choice__big {
  font-family: var(--font-body);
  font-weight: var(--weight-heavy);
  font-size: var(--text-lg);
  line-height: 1.1;
}

.choice:has(input:disabled) {
  border-style: dashed;
  border-color: var(--ink-300);
  background: var(--color-surface-quiet);
  cursor: not-allowed;
}

.choice:has(input:disabled) .choice__title,
.choice:has(input:disabled) .choice__big {
  color: var(--color-text-muted);
}

.choice input:disabled {
  display: none;
}

.choice__lock {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------- */
/* Chips, pills, tags                                                     */
/* ---------------------------------------------------------------------- */

.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: 4px 4px 6px;
  margin: -4px -4px 0;
  scrollbar-width: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  border: var(--line) solid var(--ink-300);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-soft);
  font: var(--weight-bold) var(--text-sm) / 1 var(--font-body);
  white-space: nowrap;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--color-line);
  color: var(--color-text);
}

.chip[aria-pressed="true"] {
  border-color: var(--color-line);
  background: var(--color-text);
  color: var(--paper);
}

.chip__count {
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-heavy);
  opacity: 0.8;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 1.75rem;
  padding: 0 0.625rem;
  border-radius: var(--radius-pill);
  font: var(--weight-heavy) var(--text-xs) / 1 var(--font-body);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pill .icon {
  width: 0.9rem;
  height: 0.9rem;
  stroke-width: 2.5;
}

.pill--quiet {
  background: var(--sand-200);
  color: var(--ink-700);
}

.pill--triggered {
  background: var(--color-alert);
  color: var(--color-on-alert);
  box-shadow: inset 0 0 0 var(--line) var(--color-line);
}

.pill--paused {
  background: var(--color-surface);
  color: var(--ink-700);
  box-shadow: inset 0 0 0 1.5px var(--ink-300);
}

.pill--failing {
  background: var(--color-error-tint);
  color: var(--color-error);
}

.pill--success {
  background: var(--color-success-tint);
  color: var(--color-success);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------- */
/* Cards and panels                                                       */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: var(--line-hair) solid var(--color-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.card__body {
  padding: var(--space-5);
}

@media (min-width: 48rem) {
  .card__body {
    padding: var(--space-6);
  }
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.panel-title h2 {
  font-size: var(--text-lg);
}

.stage {
  position: relative;
  background: var(--color-stage);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.divider {
  border: 0;
  border-top: var(--line-hair) solid var(--color-hairline);
  margin: var(--space-6) 0;
}

.kv {
  display: grid;
  grid-template-columns: minmax(7rem, auto) 1fr;
  gap: var(--space-3) var(--space-4);
  margin: 0;
}

.kv dt {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  padding-top: 0.1rem;
}

.kv dd {
  margin: 0;
  font-weight: var(--weight-semibold);
}

/* ---------------------------------------------------------------------- */
/* Maizy: faces, speech, the "Maizy says" row                             */
/* ---------------------------------------------------------------------- */

/* A round crop of Maizy's face from any full-body pose.
   Set --fx / --fy to the face center (0..1) and --zoom to the scale. */
.face {
  --size: 2.5rem;
  --zoom: 3;
  --fx: 0.45;
  --fy: 0.3;
  position: relative;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-stage);
  box-shadow: inset 0 0 0 var(--line) var(--color-line);
}

.face img {
  position: absolute;
  max-width: none;
  width: calc(var(--size) * var(--zoom));
  height: calc(var(--size) * var(--zoom));
  left: calc(var(--size) / 2 - var(--size) * var(--zoom) * var(--fx));
  top: calc(var(--size) / 2 - var(--size) * var(--zoom) * var(--fy));
}

.face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 var(--line) var(--color-line);
}

.face--confused {
  --fx: 0.46;
  --fy: 0.3;
  --zoom: 2.4;
}

.face--proud {
  --fx: 0.4;
  --fy: 0.24;
  --zoom: 2.4;
}

.face--alert {
  --fx: 0.36;
  --fy: 0.3;
  --zoom: 2.3;
}

.face--sleeping {
  --fx: 0.36;
  --fy: 0.45;
  --zoom: 2;
}

.face--sniffing {
  --fx: 0.24;
  --fy: 0.63;
  --zoom: 2.4;
}

.face--waving {
  --fx: 0.5;
  --fy: 0.33;
  --zoom: 2.4;
}

.face--tail-chase {
  --fx: 0.52;
  --fy: 0.28;
  --zoom: 2.4;
}

.speech {
  position: relative;
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-xl);
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
  text-wrap: pretty;
}

.speech strong {
  font-weight: var(--weight-semibold);
}

/* The tail: a rotated square sharing the bubble's border */
.speech::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: inherit;
  border: inherit;
  border-width: 0 0 var(--line) var(--line);
  border-radius: 0 0 0 4px;
}

.speech--left::before {
  left: -9px;
  top: calc(50% - 8px);
  transform: rotate(45deg);
}

.speech--top::before {
  left: var(--tail-x, 2rem);
  top: -9px;
  transform: rotate(135deg);
}

.speech--bottom::before {
  left: var(--tail-x, 2rem);
  bottom: -9px;
  transform: rotate(-45deg);
}

.speech--alert {
  background: var(--color-alert);
}

.maizy-says {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.maizy-says__art {
  flex: none;
  width: var(--art, 5.5rem);
}

.maizy-says .speech {
  flex: 1;
  min-width: 0;
}

/* ---------------------------------------------------------------------- */
/* Notices (inline banners), toasts, modals                               */
/* ---------------------------------------------------------------------- */

.notice {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: var(--line) solid var(--color-line);
  background: var(--color-surface);
}

.notice--fired {
  background: var(--color-alert);
  box-shadow: var(--shadow-key);
}

.notice--error {
  border-color: var(--color-error);
  background: var(--color-error-tint);
}

.notice__title {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  line-height: 1.15;
}

.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  left: var(--space-4);
  right: var(--space-4);
  bottom: var(--space-4);
  display: grid;
  gap: var(--space-3);
  justify-items: center;
  pointer-events: none;
}

@media (min-width: 48rem) {
  .toast-region {
    left: auto;
    right: var(--space-6);
    bottom: var(--space-6);
    justify-items: end;
    width: 24rem;
  }
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 26rem;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3);
  background: var(--color-surface);
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  animation: toast-in var(--dur-slow) var(--ease-bounce);
}

.toast__text {
  flex: 1;
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.toast__text b {
  display: block;
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
}

.toast--fired {
  background: var(--color-alert);
}

.toast--success .toast__text b {
  color: var(--color-success);
}

.toast--error {
  border-color: var(--color-error);
}

.toast--error .toast__text b {
  color: var(--color-error);
}

.toast.is-static {
  animation: none;
  box-shadow: var(--shadow-card);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.modal {
  width: min(34rem, calc(100% - 2 * var(--space-4)));
  max-height: calc(100dvh - 2 * var(--space-4));
  padding: 0;
  border: var(--line) solid var(--color-line);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-float);
}

.modal::backdrop {
  background: rgb(43 36 33 / 0.5);
}

.modal[open] {
  animation: toast-in var(--dur-slow) var(--ease-out);
}

.modal__body {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
}

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.modal__head img {
  width: 5.5rem;
  flex: none;
}

.modal__actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6) var(--space-6);
}

@media (min-width: 30rem) {
  .modal__actions {
    flex-direction: row;
    justify-content: flex-end;
  }
}

.modal-static {
  position: relative;
  display: block;
  margin: 0;
  width: 100%;
}

/* ---------------------------------------------------------------------- */
/* Stepper (first-watch flow)                                             */
/* ---------------------------------------------------------------------- */

.steps {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--color-text-muted);
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border: var(--line) solid var(--ink-300);
  border-radius: 50%;
  background: var(--color-surface);
  font-weight: var(--weight-heavy);
}

.steps li::after {
  content: "";
  flex: 1;
  height: var(--line);
  min-width: var(--space-3);
  background: var(--color-hairline);
  border-radius: 2px;
}

.steps li:last-child {
  flex: none;
}

.steps li:last-child::after {
  display: none;
}

.steps li[aria-current="step"] {
  color: var(--color-text);
}

.steps li[aria-current="step"]::before {
  border-color: var(--color-line);
  background: var(--color-primary);
}

.steps li.is-done {
  color: var(--color-text-soft);
}

.steps li.is-done::before {
  content: "\2713";
  border-color: var(--color-line);
  background: var(--color-text);
  color: var(--paper);
}

.steps li.is-done::after {
  background: var(--color-text);
}

@media (max-width: 34rem) {
  .steps li:not([aria-current="step"]) .steps__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
}

/* ---------------------------------------------------------------------- */
/* Watch rows (dashboard)                                                 */
/* ---------------------------------------------------------------------- */

.watch-list {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 48rem) {
  .watch-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 90rem) {
  .watch-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.watch {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-surface);
  border: var(--line-hair) solid var(--color-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition:
    transform var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

.watch:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}

.watch:focus-within {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

.watch__fired {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-2);
  background: var(--color-alert);
  border-bottom: var(--line) solid var(--color-line);
  border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0;
  font-family: var(--font-body);
  font-weight: var(--weight-heavy);
  line-height: 1.2;
}

.watch--triggered {
  border: var(--line) solid var(--color-line);
}

.watch__main {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5) var(--space-3);
  flex: 1;
}

.watch__thumb {
  width: 4rem;
  height: 4rem;
  border-radius: var(--radius-md);
  background: var(--sand-100);
  border: var(--line-hair) solid var(--color-hairline);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.watch__title {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-heavy);
  letter-spacing: 0;
  line-height: var(--leading-snug);
}

.watch__title a {
  text-decoration: none;
}

.watch__title a:hover {
  background: none;
  text-decoration: underline;
  text-decoration-color: var(--color-primary);
  text-decoration-thickness: 3px;
}

/* The whole card is the link's hit area */
.watch__title a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
}

.watch__title a:focus-visible {
  outline: none;
}

.watch__site {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch__value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  margin-top: var(--space-3);
}

.watch__big {
  font-family: var(--font-body);
  font-weight: var(--weight-heavy);
  font-size: 1.625rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.watch__was {
  color: var(--color-text-muted);
  font-weight: var(--weight-bold);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.watch__rule {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-soft);
}

.watch__rule--error {
  color: var(--color-error);
  font-weight: var(--weight-bold);
}

.watch__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: var(--line-hair) solid var(--color-hairline);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-text-muted);
}

.watch__foot .cluster {
  --cluster: var(--space-1) var(--space-3);
}

/* ---------------------------------------------------------------------- */
/* Tables and timelines                                                   */
/* ---------------------------------------------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-heavy);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--line) solid var(--color-line);
}

.table td {
  padding: var(--space-3);
  border-bottom: var(--line-hair) solid var(--color-hairline);
  font-variant-numeric: tabular-nums;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 2.25rem 1fr;
  gap: var(--space-3);
  padding-bottom: var(--space-5);
}

.timeline li::before {
  content: "";
  position: absolute;
  left: calc(1.125rem - 1px);
  top: 2.25rem;
  bottom: 0.25rem;
  width: 2px;
  background: var(--color-hairline);
}

.timeline li:last-child::before {
  display: none;
}

.timeline__dot {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--sand-100);
  border: var(--line) solid var(--ink-300);
  color: var(--ink-700);
}

.timeline__dot .icon {
  width: 1rem;
  height: 1rem;
}

.timeline__dot--fired {
  background: var(--color-alert);
  border-color: var(--color-line);
  color: var(--ink-900);
}

.timeline__dot--error {
  background: var(--color-error-tint);
  border-color: var(--color-error);
  color: var(--color-error);
}

.timeline__what {
  font-weight: var(--weight-bold);
  padding-top: 0.35rem;
}

.timeline__when {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------- */
/* Loading: Maizy chasing her tail                                        */
/* ---------------------------------------------------------------------- */

.spin-maizy {
  animation: chase 1.4s linear infinite;
}

@keyframes chase {
  to {
    transform: rotate(-360deg);
  }
}

/* Reading a new URL: Maizy's nose bobs along the page */
.sniff-maizy {
  transform-origin: 30% 80%;
  animation: sniff 0.9s var(--ease-out) infinite alternate;
}

@keyframes sniff {
  0% {
    transform: translateX(-3px) rotate(-2deg);
  }
  100% {
    transform: translateX(4px) rotate(2.5deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spin-maizy,
  .sniff-maizy {
    animation: none;
  }

  .watch:hover {
    transform: none;
  }
}
