/**
 * Hand-written component styles. Token refs only — no raw hex or px.
 * Built against dist/css/<theme>/tokens.css (U7).
 */

/* -------------------------------------------------------------------------- */
/* Button                                                                     */
/* -------------------------------------------------------------------------- */

.cp-button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--cp-space-8);
  min-height: var(--cp-button-min-height-regular);
  padding-block: var(--cp-space-12);
  padding-inline: var(--cp-button-padding-inline-regular);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: transparent;
  border-radius: var(--cp-button-radius);
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-label-size);
  font-weight: var(--cp-font-weight-medium);
  line-height: var(--cp-font-role-label-line-height);
  letter-spacing: var(--cp-font-role-label-letter-spacing);
  text-decoration: none;
  cursor: pointer;
  transition-property: background-color, border-color, color, box-shadow;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-button:focus {
  outline: none;
}

.cp-button:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-button--compact {
  min-height: var(--cp-button-min-height-compact);
  padding-inline: var(--cp-button-padding-inline-compact);
}

/*
 * Primary and secondary are material buttons (D-041, D-043): the primary is
 * lapis, the secondary limestone, in every register. A raking light follows
 * the pointer (dist/js/cp-button.js sets --cp-button-x and --cp-button-y), and
 * the Winchester frame is drawn on ::before (bars) and ::after (corner rings
 * and the budded cross). At rest the bars stand short at the corners; hover,
 * focus, press and a tap run them to the middle, where the cross closes the
 * frame. On touch there is no hover, so a tap shows the same (D-042).
 */

@property --cp-button-run { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --cp-button-side { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --cp-button-sign { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --cp-button-glow { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --cp-button-press { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --cp-button-lamp { syntax: "<length>"; inherits: true; initial-value: 0; }
@property --cp-button-x { syntax: "<length-percentage>"; inherits: true; initial-value: 50%; }
@property --cp-button-y { syntax: "<length-percentage>"; inherits: true; initial-value: 50%; }

.cp-button--primary, .cp-button--secondary {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: var(--cp-button-frame-min-height);
  padding-inline: var(--cp-space-32);
  border-color: transparent;
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-body-size);
  letter-spacing: normal;
  line-height: 1;
  white-space: nowrap;
  background-repeat: no-repeat, no-repeat, no-repeat;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition-property: transform, box-shadow, color, background-color, --cp-button-run, --cp-button-side, --cp-button-sign, --cp-button-glow, --cp-button-lamp;
  transition-duration: var(--cp-motion-duration), var(--cp-motion-duration), var(--cp-motion-duration), var(--cp-motion-duration), var(--cp-button-motion-run), var(--cp-button-motion-side), var(--cp-button-motion-sign), var(--cp-button-motion-lamp), var(--cp-button-motion-lamp);
  transition-timing-function: var(--cp-motion-ease), var(--cp-motion-ease), var(--cp-motion-ease), var(--cp-motion-ease), var(--cp-motion-ease), var(--cp-motion-ease), var(--cp-button-motion-spring), var(--cp-motion-ease), var(--cp-motion-ease);
  transition-delay: 0s;
  /* Open states read these, so reduced motion can zero them without matching each state's selector. */
  --cp-button-delay-side: var(--cp-button-motion-side-delay);
  --cp-button-delay-sign: var(--cp-button-motion-sign-delay);
}

/* Lapis: the primary */
.cp-button--primary {
  --cp-button-gold: var(--cp-button-lapis-gold);
  --cp-button-light: calc(0.6 + var(--cp-button-glow) * 0.4);
  color: var(--cp-button-lapis-label);
  background-color: var(--cp-button-lapis-ground);
  background-image:
    radial-gradient(circle calc(var(--cp-button-lamp) * 1.7) at var(--cp-button-x) var(--cp-button-y), color-mix(in srgb, var(--cp-button-lapis-lamp) calc(var(--cp-button-light) * 20%), transparent), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--cp-button-lapis-label) calc(var(--cp-button-light) * 7%), transparent), transparent 50%, color-mix(in srgb, var(--cp-button-lapis-shade) calc(var(--cp-button-light) * 18%), transparent)),
    url("../../assets/textures/lapis-button.jpg");
  background-size: auto, auto, cover;
  background-position: 0 0, 0 0, center;
  background-blend-mode: screen, screen, normal;
  box-shadow:
    inset 0 var(--cp-stroke-1) 0 color-mix(in srgb, var(--cp-button-lapis-label) 16%, transparent),
    inset 0 calc(-1 * var(--cp-stroke-1)) 0 color-mix(in srgb, var(--cp-button-lapis-shade) 50%, transparent),
    inset 0 0 0 var(--cp-stroke-1) color-mix(in srgb, var(--cp-button-lapis-gold) calc((0.4 + var(--cp-button-glow) * 0.35) * 100%), transparent),
    0 var(--cp-stroke-1) calc(var(--cp-stroke-1) * 2) color-mix(in srgb, var(--cp-button-lapis-ground) 25%, transparent),
    0 var(--cp-space-8) var(--cp-space-20) calc(-1 * var(--cp-space-8)) color-mix(in srgb, var(--cp-button-lapis-ground) 50%, transparent);
}

/* Limestone: the secondary */
.cp-button--secondary {
  --cp-button-gold: var(--cp-button-limestone-gold);
  --cp-button-light: calc(0.35 + var(--cp-button-glow) * 0.65);
  color: var(--cp-button-limestone-label);
  background-color: var(--cp-button-limestone-ground);
  background-image:
    radial-gradient(circle calc(var(--cp-button-lamp) * 1.6) at var(--cp-button-x) var(--cp-button-y), color-mix(in srgb, var(--cp-button-limestone-lamp) calc(var(--cp-button-light) * 90%), transparent), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--cp-button-limestone-highlight) calc(var(--cp-button-light) * 35%), transparent), transparent 55%, color-mix(in srgb, var(--cp-button-limestone-shade) calc(var(--cp-button-light) * 6%), transparent)),
    url("../../assets/textures/limestone-button.jpg");
  background-size: auto, auto, var(--cp-button-limestone-tile);
  background-position: 0 0, 0 0, center;
  background-repeat: no-repeat, no-repeat, repeat;
  background-blend-mode: soft-light, soft-light, normal;
  box-shadow:
    inset 0 var(--cp-stroke-1) 0 color-mix(in srgb, var(--cp-button-limestone-highlight) 95%, transparent),
    inset 0 calc(-1 * var(--cp-stroke-1)) 0 color-mix(in srgb, var(--cp-button-limestone-shade) 14%, transparent),
    inset 0 0 0 var(--cp-stroke-1) color-mix(in srgb, var(--cp-button-limestone-rim) calc((0.16 + var(--cp-button-glow) * 0.4) * 100%), transparent),
    0 var(--cp-stroke-1) calc(var(--cp-stroke-1) * 2) color-mix(in srgb, var(--cp-button-limestone-shade) 14%, transparent),
    0 var(--cp-space-8) var(--cp-space-20) calc(-1 * var(--cp-space-8)) color-mix(in srgb, var(--cp-button-limestone-shade) 28%, transparent);
}

/* The frame: both layers sit under the label and fade from 25% to 60% as it closes. */
.cp-button--primary::before,
.cp-button--secondary::before,
.cp-button--primary::after,
.cp-button--secondary::after {
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
  color: var(--cp-button-gold);
  opacity: calc(var(--cp-button-frame-opacity-rest) + (var(--cp-button-frame-opacity-closed) - var(--cp-button-frame-opacity-rest)) * var(--cp-button-run));
}

/* Bars: two 1 px lines per arm, eight arms, each reaching from its corner ring.
   The short-edge bars overlap by half a stroke at the middle so no seam shows. */
.cp-button--primary::before,
.cp-button--secondary::before {
  --cp-button-reach-long: calc(var(--cp-button-frame-rest-long) - var(--cp-button-frame-start) + (50% - var(--cp-button-frame-rest-long) - var(--cp-button-frame-sign-gap)) * var(--cp-button-run));
  --cp-button-reach-short: calc(var(--cp-button-frame-rest-short) - var(--cp-button-frame-start) + (50% - var(--cp-button-frame-rest-short) + var(--cp-stroke-1) / 2) * var(--cp-button-side));
  inset: var(--cp-button-frame-inset);
  background-image:
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
  background-size:
    var(--cp-button-reach-long) var(--cp-stroke-1), var(--cp-button-reach-long) var(--cp-stroke-1),
    var(--cp-button-reach-long) var(--cp-stroke-1), var(--cp-button-reach-long) var(--cp-stroke-1),
    var(--cp-button-reach-long) var(--cp-stroke-1), var(--cp-button-reach-long) var(--cp-stroke-1),
    var(--cp-button-reach-long) var(--cp-stroke-1), var(--cp-button-reach-long) var(--cp-stroke-1),
    var(--cp-stroke-1) var(--cp-button-reach-short), var(--cp-stroke-1) var(--cp-button-reach-short),
    var(--cp-stroke-1) var(--cp-button-reach-short), var(--cp-stroke-1) var(--cp-button-reach-short),
    var(--cp-stroke-1) var(--cp-button-reach-short), var(--cp-stroke-1) var(--cp-button-reach-short),
    var(--cp-stroke-1) var(--cp-button-reach-short), var(--cp-stroke-1) var(--cp-button-reach-short);
  background-position:
    left var(--cp-button-frame-start) top 0, left var(--cp-button-frame-start) top var(--cp-button-frame-pitch),
    right var(--cp-button-frame-start) top 0, right var(--cp-button-frame-start) top var(--cp-button-frame-pitch),
    left var(--cp-button-frame-start) bottom 0, left var(--cp-button-frame-start) bottom var(--cp-button-frame-pitch),
    right var(--cp-button-frame-start) bottom 0, right var(--cp-button-frame-start) bottom var(--cp-button-frame-pitch),
    left 0 top var(--cp-button-frame-start), left var(--cp-button-frame-pitch) top var(--cp-button-frame-start),
    right 0 top var(--cp-button-frame-start), right var(--cp-button-frame-pitch) top var(--cp-button-frame-start),
    left 0 bottom var(--cp-button-frame-start), left var(--cp-button-frame-pitch) bottom var(--cp-button-frame-start),
    right 0 bottom var(--cp-button-frame-start), right var(--cp-button-frame-pitch) bottom var(--cp-button-frame-start);
  background-repeat: no-repeat;
}

/* Corner rings and the budded cross, drawn as masks over the gold. The cross
   is only as large as --cp-button-sign, so it is absent at rest. */
.cp-button--primary::after,
.cp-button--secondary::after {
  --cp-button-sign-size: calc(var(--cp-button-frame-unit) * var(--cp-button-sign) * (1 - 0.1 * var(--cp-button-press)));
  --cp-button-sign-offset: calc((var(--cp-button-frame-unit) - var(--cp-button-sign-size)) / 2);
  inset: calc(var(--cp-button-frame-inset) + (var(--cp-button-frame-pitch) + var(--cp-stroke-1)) / 2 - var(--cp-button-frame-unit) / 2);
  background-color: currentColor;
  -webkit-mask-image:
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M5.55 3.6H6.45V8.4H5.55ZM3.6 5.55H8.4V6.45H3.6Z'/><circle cx='6' cy='3.2' r='0.6'/><circle cx='5.26' cy='3.55' r='0.6'/><circle cx='6.74' cy='3.55' r='0.6'/><circle cx='6' cy='8.8' r='0.6'/><circle cx='5.26' cy='8.45' r='0.6'/><circle cx='6.74' cy='8.45' r='0.6'/><circle cx='3.2' cy='6' r='0.6'/><circle cx='3.55' cy='5.26' r='0.6'/><circle cx='3.55' cy='6.74' r='0.6'/><circle cx='8.8' cy='6' r='0.6'/><circle cx='8.45' cy='5.26' r='0.6'/><circle cx='8.45' cy='6.74' r='0.6'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M5.55 3.6H6.45V8.4H5.55ZM3.6 5.55H8.4V6.45H3.6Z'/><circle cx='6' cy='3.2' r='0.6'/><circle cx='5.26' cy='3.55' r='0.6'/><circle cx='6.74' cy='3.55' r='0.6'/><circle cx='6' cy='8.8' r='0.6'/><circle cx='5.26' cy='8.45' r='0.6'/><circle cx='6.74' cy='8.45' r='0.6'/><circle cx='3.2' cy='6' r='0.6'/><circle cx='3.55' cy='5.26' r='0.6'/><circle cx='3.55' cy='6.74' r='0.6'/><circle cx='8.8' cy='6' r='0.6'/><circle cx='8.45' cy='5.26' r='0.6'/><circle cx='8.45' cy='6.74' r='0.6'/></svg>");
  mask-image:
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><circle cx='6' cy='6' r='2.2' fill='none' stroke='black' stroke-width='0.9'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M5.55 3.6H6.45V8.4H5.55ZM3.6 5.55H8.4V6.45H3.6Z'/><circle cx='6' cy='3.2' r='0.6'/><circle cx='5.26' cy='3.55' r='0.6'/><circle cx='6.74' cy='3.55' r='0.6'/><circle cx='6' cy='8.8' r='0.6'/><circle cx='5.26' cy='8.45' r='0.6'/><circle cx='6.74' cy='8.45' r='0.6'/><circle cx='3.2' cy='6' r='0.6'/><circle cx='3.55' cy='5.26' r='0.6'/><circle cx='3.55' cy='6.74' r='0.6'/><circle cx='8.8' cy='6' r='0.6'/><circle cx='8.45' cy='5.26' r='0.6'/><circle cx='8.45' cy='6.74' r='0.6'/></svg>"),
    url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M5.55 3.6H6.45V8.4H5.55ZM3.6 5.55H8.4V6.45H3.6Z'/><circle cx='6' cy='3.2' r='0.6'/><circle cx='5.26' cy='3.55' r='0.6'/><circle cx='6.74' cy='3.55' r='0.6'/><circle cx='6' cy='8.8' r='0.6'/><circle cx='5.26' cy='8.45' r='0.6'/><circle cx='6.74' cy='8.45' r='0.6'/><circle cx='3.2' cy='6' r='0.6'/><circle cx='3.55' cy='5.26' r='0.6'/><circle cx='3.55' cy='6.74' r='0.6'/><circle cx='8.8' cy='6' r='0.6'/><circle cx='8.45' cy='5.26' r='0.6'/><circle cx='8.45' cy='6.74' r='0.6'/></svg>");
  -webkit-mask-size: var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-sign-size) var(--cp-button-sign-size), var(--cp-button-sign-size) var(--cp-button-sign-size);
  mask-size: var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-frame-unit) var(--cp-button-frame-unit), var(--cp-button-sign-size) var(--cp-button-sign-size), var(--cp-button-sign-size) var(--cp-button-sign-size);
  -webkit-mask-position: left top, right top, left bottom, right bottom, left 50% top var(--cp-button-sign-offset), left 50% bottom var(--cp-button-sign-offset);
  mask-position: left top, right top, left bottom, right bottom, left 50% top var(--cp-button-sign-offset), left 50% bottom var(--cp-button-sign-offset);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* Compact and icon-only buttons keep the material and the light; the frame needs the full height. */
.cp-button--compact:is(.cp-button--primary, .cp-button--secondary),
.cp-button--icon:is(.cp-button--primary, .cp-button--secondary) {
  min-height: var(--cp-button-min-height-compact);
  font-size: var(--cp-font-label-size);
}

.cp-button--compact:is(.cp-button--primary, .cp-button--secondary) {
  padding-inline: var(--cp-button-padding-inline-compact);
}

.cp-button--compact::before,
.cp-button--compact::after,
.cp-button--icon::before,
.cp-button--icon::after {
  display: none;
}

/* Open: the frame closes. Hover only where a pointer can hover, so a tap never sticks. */
@media (hover: hover) {
  .cp-button--primary:not(:disabled):not([aria-disabled='true']):hover,
  .cp-button--secondary:not(:disabled):not([aria-disabled='true']):hover {
    --cp-button-run: 1;
    --cp-button-side: 1;
    --cp-button-sign: 1;
    --cp-button-glow: 1;
    --cp-button-lamp: var(--cp-button-lamp-hover);
    transition-delay: 0s, 0s, 0s, 0s, 0s, var(--cp-button-delay-side), var(--cp-button-delay-sign), 0s, 0s;
    transform: translateY(calc(-1 * var(--cp-stroke-1)));
  }
}

/* Focus and a touch tap (D-042) show what hover shows. cp-button.js sets data-cp-tapped. */
.cp-button--primary:focus-visible,
.cp-button--secondary:focus-visible,
.cp-button--primary:not(:disabled):not([aria-disabled='true'])[data-cp-tapped],
.cp-button--secondary:not(:disabled):not([aria-disabled='true'])[data-cp-tapped] {
  --cp-button-run: 1;
  --cp-button-side: 1;
  --cp-button-sign: 1;
  --cp-button-glow: 1;
  --cp-button-lamp: var(--cp-button-lamp-hover);
  transition-delay: 0s, 0s, 0s, 0s, 0s, var(--cp-button-delay-side), var(--cp-button-delay-sign), 0s, 0s;
}

/* Pressed: the frame closes, the cross draws in a little, the light narrows. */
.cp-button--primary:not(:disabled):not([aria-disabled='true']):active,
.cp-button--secondary:not(:disabled):not([aria-disabled='true']):active {
  --cp-button-run: 1;
  --cp-button-side: 1;
  --cp-button-sign: 1;
  --cp-button-press: 1;
  --cp-button-glow: 0.5;
  --cp-button-lamp: var(--cp-button-lamp-pressed);
  transition-delay: 0s, 0s, 0s, 0s, 0s, var(--cp-button-delay-side), var(--cp-button-delay-sign), 0s, 0s;
  transform: translateY(var(--cp-stroke-1));
}

.cp-button--primary:not(:disabled):not([aria-disabled='true']):active {
  box-shadow:
    inset 0 calc(var(--cp-stroke-1) * 2) var(--cp-space-8) color-mix(in srgb, var(--cp-button-lapis-shade) 55%, transparent),
    inset 0 0 0 var(--cp-stroke-1) color-mix(in srgb, var(--cp-button-lapis-gold) 70%, transparent),
    0 var(--cp-stroke-1) 0 color-mix(in srgb, var(--cp-button-lapis-label) 25%, transparent);
}

.cp-button--secondary:not(:disabled):not([aria-disabled='true']):active {
  box-shadow:
    inset 0 calc(var(--cp-stroke-1) * 2) var(--cp-space-8) color-mix(in srgb, var(--cp-button-limestone-shade) 22%, transparent),
    inset 0 calc(-1 * var(--cp-stroke-1)) 0 color-mix(in srgb, var(--cp-button-limestone-highlight) 70%, transparent),
    inset 0 0 0 var(--cp-stroke-1) color-mix(in srgb, var(--cp-button-limestone-rim) 50%, transparent),
    0 var(--cp-stroke-1) 0 color-mix(in srgb, var(--cp-button-limestone-highlight) 80%, transparent);
}

/* Busy: the frame stays closed and the light walks across and back. */
.cp-button--primary[aria-busy='true'],
.cp-button--secondary[aria-busy='true'] {
  --cp-button-run: 1;
  --cp-button-side: 1;
  --cp-button-sign: 1;
  --cp-button-glow: 1;
  --cp-button-lamp: var(--cp-button-lamp-hover);
  transition-delay: 0s, 0s, 0s, 0s, 0s, var(--cp-button-delay-side), var(--cp-button-delay-sign), 0s, 0s;
  --cp-button-y: 50%;
}

@media (prefers-reduced-motion: no-preference) {
  .cp-button--primary[aria-busy='true'],
  .cp-button--secondary[aria-busy='true'] {
    animation: cp-button-walk var(--cp-button-motion-walk) var(--cp-motion-ease) infinite alternate;
  }
}

@keyframes cp-button-walk {
  from {
    --cp-button-x: 8%;
  }

  to {
    --cp-button-x: 92%;
  }
}

/* Disabled: muted ink on the inset fill, no material, no light, no frame — never opacity. */
.cp-button--primary:disabled,
.cp-button--primary[aria-disabled='true'] {
  background: var(--cp-button-primary-background-disabled);
  color: var(--cp-button-primary-label-disabled);
  box-shadow: inset 0 0 0 var(--cp-stroke-1) var(--cp-color-line);
  transform: none;
  cursor: not-allowed;
}

.cp-button--secondary:disabled,
.cp-button--secondary[aria-disabled='true'] {
  background: var(--cp-button-secondary-background-disabled);
  color: var(--cp-button-secondary-label-disabled);
  box-shadow: inset 0 0 0 var(--cp-stroke-1) var(--cp-color-line);
  transform: none;
  cursor: not-allowed;
}

:is(.cp-button--primary, .cp-button--secondary):is(:disabled, [aria-disabled='true'])::before,
:is(.cp-button--primary, .cp-button--secondary):is(:disabled, [aria-disabled='true'])::after {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .cp-button--primary, .cp-button--secondary {
    --cp-button-delay-side: 0s;
    --cp-button-delay-sign: 0s;
    transition-duration: var(--cp-motion-duration-reduced);
    transition-delay: 0s;
  }
}

.cp-button--icon {
  width: var(--cp-button-min-height-regular);
  min-width: var(--cp-button-min-height-regular);
  height: var(--cp-button-min-height-regular);
  padding: 0;
}

.cp-button--icon .cp-button__icon,
.cp-button__icon {
  width: var(--cp-button-icon-size);
  height: var(--cp-button-icon-size);
  flex-shrink: 0;
}

.cp-button[aria-busy='true'] {
  cursor: progress;
}

.cp-button__spinner {
  /* Slot filled by U8 spinner; reserved so layout does not jump. */
  display: inline-flex;
  width: var(--cp-button-icon-size);
  height: var(--cp-button-icon-size);
}

/* -------------------------------------------------------------------------- */
/* Action row (D-051)                                                         */
/* -------------------------------------------------------------------------- */
/* The small actions under a result: Print, Share, Copy, Copy link, Save image, */
/* Email me. A gold icon above a short word, in even columns on one line,       */
/* centred under the result. A tool's main next step stays a .cp-button.        */

.cp-actions {
  box-sizing: border-box;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  width: 100%;
  max-width: calc(var(--cp-space-64) * 6.5);
  margin-inline: auto;
  padding: 0;
}

.cp-actions[hidden],
.cp-actions .cp-action[hidden] {
  display: none;
}

.cp-actions .cp-action {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: calc(var(--cp-space-4) * 1.5) /* cp-space: icon to word as picked in D-051, the bound role (4 px) would lift every tool's words 2 px */;
  min-width: 0;
  min-height: var(--cp-space-64);
  margin: 0;
  padding: var(--cp-space-8) var(--cp-space-4) var(--cp-space-4) /* cp-space: places the icon and word inside the action's 64 px tap column (D-051) */;
  border: 0;
  border-radius: var(--cp-radius-control);
  background: none;
  box-shadow: none;
  color: var(--cp-color-ink);
  font-family: var(--cp-font-role-body-font-family);
  font-size: var(--cp-font-body-small-size);
  font-weight: var(--cp-font-role-body-font-weight);
  line-height: var(--cp-font-role-label-line-height);
  letter-spacing: normal;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.cp-actions .cp-action__icon,
.cp-actions .cp-action > svg {
  display: block;
  flex: none;
  width: var(--cp-space-24);
  height: var(--cp-space-24);
  color: var(--cp-color-accent-gold);
}

.cp-actions .cp-action__label {
  overflow-wrap: anywhere;
  text-decoration-color: var(--cp-color-accent-gold);
  text-decoration-thickness: var(--cp-stroke-1);
  text-underline-offset: var(--cp-space-4);
}

/* Hover underlines the word in gold; a tap does the action at once (D-042). */
@media (hover: hover) {
  .cp-actions .cp-action:hover .cp-action__label {
    text-decoration-line: underline;
  }
}

.cp-actions .cp-action:focus {
  outline: none;
}

.cp-actions .cp-action:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: calc(var(--cp-stroke-3) * -1);
}

.cp-actions .cp-action:disabled,
.cp-actions .cp-action[aria-disabled='true'] {
  color: var(--cp-color-ink-muted);
  cursor: default;
}

@media print {
  .cp-actions {
    display: none;
  }
}

/* -------------------------------------------------------------------------- */
/* Text link                                                                  */
/* -------------------------------------------------------------------------- */

.cp-text-link {
  display: inline-flex;
  align-items: center;
  gap: var(--cp-gap-label);
  color: var(--cp-link-label);
  font-family: var(--cp-font-family-body);
  font-size: var(--cp-font-body-size);
  font-weight: var(--cp-font-weight-regular);
  line-height: var(--cp-font-role-body-line-height);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  transition-property: color;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-text-link:focus {
  outline: none;
}

.cp-text-link:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-text-link__marker {
  color: var(--cp-link-marker);
  transition-property: color;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-text-link--underline {
  text-decoration: underline;
  text-decoration-color: var(--cp-link-marker);
  text-underline-offset: var(--cp-space-4);
}

.cp-text-link:disabled,
.cp-text-link[aria-disabled='true'] {
  color: var(--cp-color-ink-muted);
  cursor: not-allowed;
}

.cp-text-link:disabled .cp-text-link__marker,
.cp-text-link[aria-disabled='true'] .cp-text-link__marker {
  color: var(--cp-color-ink-muted);
}

/* Text-link style on .cp-button for API parity with live .cp-button text links */
.cp-button--text-link {
  background: transparent;
  border-color: transparent;
  color: var(--cp-link-label);
  min-height: var(--cp-button-min-height-regular);
  padding-inline: var(--cp-space-8);
}

.cp-button--text-link .cp-button__marker {
  color: var(--cp-link-marker);
}

.cp-button--text-link:disabled,
.cp-button--text-link[aria-disabled='true'] {
  color: var(--cp-color-ink-muted);
  background: transparent;
  cursor: not-allowed;
}

/* -------------------------------------------------------------------------- */
/* Input                                                                      */
/* -------------------------------------------------------------------------- */

.cp-input {
  display: flex;
  flex-direction: column;
  gap: var(--cp-gap-label);
}

.cp-input__label {
  color: var(--cp-input-label);
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-label-size);
  font-weight: var(--cp-font-weight-medium);
  line-height: var(--cp-font-role-label-line-height);
}

.cp-input__required {
  color: var(--cp-color-status-danger);
}

.cp-input__control {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--cp-input-min-height);
  padding-block: var(--cp-space-12) /* cp-space: with the line height, sets the text field's height (its 44 px min-height is only a floor) */;
  padding-inline: var(--cp-inset-field);
  color: var(--cp-color-ink);
  background-color: var(--cp-input-background);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-input-border);
  border-radius: var(--cp-input-radius);
  font-family: var(--cp-font-family-body);
  font-size: var(--cp-font-body-size);
  line-height: var(--cp-font-role-body-line-height);
  transition-property: border-color, box-shadow;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-input__control:focus {
  outline: none;
}

.cp-input__control:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-input__control:disabled {
  background-color: var(--cp-color-surface-inset);
  color: var(--cp-color-ink-muted);
  cursor: not-allowed;
}

.cp-input__control--textarea {
  min-height: var(--cp-space-96);
  resize: vertical;
}

.cp-input--error .cp-input__control {
  border-color: var(--cp-input-border-error);
}

.cp-input__helper {
  color: var(--cp-input-helper);
  font-family: var(--cp-font-family-body);
  font-size: var(--cp-font-body-small-size);
  line-height: var(--cp-font-role-body-small-line-height);
}

.cp-input__error {
  color: var(--cp-input-error);
  font-family: var(--cp-font-family-body);
  font-size: var(--cp-font-body-small-size);
  line-height: var(--cp-font-role-body-small-line-height);
}

/* -------------------------------------------------------------------------- */
/* Card                                                                       */
/* -------------------------------------------------------------------------- */

.cp-card {
  box-sizing: border-box;
  display: block;
  background-color: var(--cp-card-background);
  border-radius: var(--cp-card-radius);
  padding: var(--cp-card-padding);
  box-shadow: var(--cp-card-shadow);
  color: var(--cp-color-ink);
  transition-property: background-color, box-shadow;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-card--link {
  text-decoration: none;
  cursor: pointer;
}

@media (hover: hover) {
  .cp-card--link:hover {
    background-color: var(--cp-color-surface-band);
    box-shadow: var(--cp-shadow-panel);
  }
}

.cp-card--link:active {
  background-color: var(--cp-color-surface-inset);
}

.cp-card--link:focus {
  outline: none;
}

.cp-card--link:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

/* -------------------------------------------------------------------------- */
/* Dropdown — native select + APG menu-button (Option A)                      */
/* -------------------------------------------------------------------------- */

.cp-select {
  box-sizing: border-box;
  min-height: var(--cp-dropdown-trigger-min-height);
  width: 100%;
  padding-block: 0;
  padding-inline: var(--cp-inset-field);
  color: var(--cp-dropdown-trigger-label);
  background-color: var(--cp-dropdown-trigger-background);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-dropdown-trigger-border);
  border-radius: var(--cp-dropdown-trigger-radius);
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-label-size);
}

.cp-select:focus {
  outline: none;
}

.cp-select:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-select:disabled {
  color: var(--cp-color-ink-muted);
  background-color: var(--cp-color-surface-inset);
  cursor: not-allowed;
}

.cp-select[aria-invalid='true'],
.cp-select.is-invalid {
  border-color: var(--cp-dropdown-invalid-border);
}

.cp-menu {
  position: relative;
  display: inline-block;
}

.cp-menu__trigger {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: var(--cp-gap-label);
  min-height: var(--cp-dropdown-trigger-min-height);
  padding-inline: var(--cp-button-padding-inline-regular);
  color: var(--cp-dropdown-trigger-label);
  background-color: var(--cp-dropdown-trigger-background);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-dropdown-trigger-border);
  border-radius: var(--cp-dropdown-trigger-radius);
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-label-size);
  cursor: pointer;
}

.cp-menu__trigger:focus {
  outline: none;
}

.cp-menu__trigger:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-menu__trigger:disabled,
.cp-menu__trigger[aria-disabled='true'] {
  color: var(--cp-color-ink-muted);
  background-color: var(--cp-color-surface-inset);
  cursor: not-allowed;
}

.cp-menu__list {
  margin: var(--cp-gap-label) 0 0;
  padding: var(--cp-inset-chip) 0;
  list-style: none;
  background-color: var(--cp-dropdown-menu-background);
  border-radius: var(--cp-dropdown-menu-radius);
  box-shadow: var(--cp-dropdown-menu-shadow);
}

.cp-menu__item {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin: 0;
  padding: var(--cp-space-12) var(--cp-space-24) /* cp-space: sets the menu row's height, and the 24 lines its words up with the trigger's */;
  text-align: left;
  color: var(--cp-color-ink);
  background: transparent;
  border: 0;
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-body-size);
  cursor: pointer;
  transition-property: background-color;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

@media (hover: hover) {
  .cp-menu__item:hover {
    background-color: var(--cp-dropdown-menu-item-hover);
  }
}

.cp-menu__item:focus {
  outline: none;
}

.cp-menu__item:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: calc(var(--cp-stroke-3) * -1);
}

.cp-menu__item[aria-selected='true'] {
  font-weight: var(--cp-font-weight-medium);
}

.cp-menu__item[aria-selected='true']::before {
  content: '◆';
  color: var(--cp-dropdown-menu-marker);
  margin-right: var(--cp-gap-label);
  font-size: var(--cp-font-caption-size);
}

.cp-menu__item:disabled {
  color: var(--cp-color-ink-muted);
  cursor: not-allowed;
}

/* -------------------------------------------------------------------------- */
/* Selection — radio & checkbox (Option A)                                    */
/* -------------------------------------------------------------------------- */

.cp-radio-group,
.cp-checkbox-group {
  display: grid;
  gap: var(--cp-gap-check);
  margin: 0;
  padding: 0;
  min-width: 0;
  border: 0;
}

.cp-radio-group > legend,
.cp-checkbox-group > legend {
  padding: 0;
  color: var(--cp-input-label);
  font-family: var(--cp-font-family-ui);
  font-size: var(--cp-font-label-size);
  font-weight: var(--cp-font-weight-medium);
  line-height: var(--cp-font-role-label-line-height);
}

.cp-radio,
.cp-checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--cp-gap-check);
  min-height: var(--cp-button-min-height-regular);
  color: var(--cp-selection-label);
  cursor: pointer;
}

.cp-radio__control,
.cp-checkbox__control {
  appearance: none;
  box-sizing: border-box;
  width: var(--cp-selection-control-size);
  height: var(--cp-selection-control-size);
  margin: 0;
  display: grid;
  place-content: center;
  background-color: var(--cp-selection-control-background);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-selection-control-border);
  transition-property: background-color, border-color;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-radio__control {
  border-radius: var(--cp-radius-pill);
}

.cp-checkbox__control {
  border-radius: var(--cp-radius-control);
}

.cp-radio__control:checked,
.cp-checkbox__control:checked,
.cp-checkbox__control:indeterminate {
  background-color: var(--cp-selection-control-checked-background);
  border-color: var(--cp-selection-control-checked-background);
}

.cp-radio__control:checked::before {
  content: '';
  width: var(--cp-space-8);
  height: var(--cp-space-8);
  border-radius: var(--cp-radius-pill);
  background-color: var(--cp-selection-control-mark);
}

.cp-checkbox__control:checked::before {
  content: '';
  width: var(--cp-space-8);
  height: var(--cp-space-4);
  border-left: var(--cp-stroke-3) solid var(--cp-selection-control-mark);
  border-bottom: var(--cp-stroke-3) solid var(--cp-selection-control-mark);
  transform: rotate(-45deg);
  margin-bottom: var(--cp-gap-bound);
}

.cp-checkbox__control:indeterminate::before {
  content: '';
  width: var(--cp-space-8);
  height: var(--cp-stroke-3);
  background-color: var(--cp-selection-control-mark);
}

.cp-radio__control:focus,
.cp-checkbox__control:focus {
  outline: none;
}

.cp-radio__control:focus-visible,
.cp-checkbox__control:focus-visible {
  outline: var(--cp-stroke-3) solid var(--cp-color-focus-ring);
  outline-offset: var(--cp-stroke-3);
}

.cp-radio__control:disabled,
.cp-checkbox__control:disabled {
  border-color: var(--cp-selection-control-disabled-border);
  background-color: var(--cp-selection-control-disabled-background);
  cursor: not-allowed;
}

.cp-radio__control:disabled:checked,
.cp-checkbox__control:disabled:checked {
  background-color: var(--cp-selection-control-disabled-checked);
  border-color: var(--cp-selection-control-disabled-checked);
}

.cp-radio-group--error .cp-radio__control,
.cp-checkbox-group--error .cp-checkbox__control {
  border-color: var(--cp-selection-control-error-border);
}

.cp-radio-group__error,
.cp-checkbox-group__error {
  color: var(--cp-selection-error);
  font-size: var(--cp-font-body-small-size);
  margin: 0;
}

/* -------------------------------------------------------------------------- */
/* Progress — linear, steps, spinner (Option A)                               */
/* -------------------------------------------------------------------------- */

.cp-progress {
  display: block;
  width: 100%;
  height: var(--cp-progress-track-height);
  background-color: var(--cp-progress-track-background);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-progress-track-border);
  border-radius: var(--cp-radius-pill);
  overflow: hidden;
}

.cp-progress__fill {
  height: 100%;
  background-color: var(--cp-progress-fill);
  border-radius: var(--cp-radius-pill);
  transition-property: width;
  transition-duration: var(--cp-motion-duration);
  transition-timing-function: var(--cp-motion-ease);
}

.cp-progress--indeterminate .cp-progress__fill {
  width: 40%;
  animation: cp-progress-indeterminate 1.2s var(--cp-motion-ease) infinite;
}

@keyframes cp-progress-indeterminate {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(250%);
  }
}

.cp-steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cp-gap-item);
  list-style: none;
  margin: 0;
  padding: 0;
}

.cp-step {
  display: grid;
  justify-items: center;
  gap: var(--cp-gap-label);
  color: var(--cp-color-ink-muted);
  font-size: var(--cp-font-caption-size);
}

.cp-step__medallion {
  box-sizing: border-box;
  width: var(--cp-progress-step-size);
  height: var(--cp-progress-step-size);
  display: grid;
  place-content: center;
  border-radius: var(--cp-radius-pill);
  border-width: var(--cp-stroke-1);
  border-style: solid;
  border-color: var(--cp-progress-step-upcoming-border);
  background-color: var(--cp-progress-step-upcoming-background);
  color: var(--cp-progress-step-upcoming-label);
  font-family: var(--cp-font-family-heading);
}

.cp-step--completed .cp-step__medallion {
  background-color: var(--cp-progress-step-completed);
  border-color: var(--cp-progress-step-completed);
  color: var(--cp-progress-step-completed-label);
}

.cp-step--current {
  color: var(--cp-color-ink);
  font-weight: var(--cp-font-weight-medium);
}

.cp-step--current .cp-step__medallion {
  border-color: var(--cp-progress-step-current-ring);
  box-shadow: 0 0 0 var(--cp-stroke-3) var(--cp-progress-step-current-ring);
}

.cp-step--locked .cp-step__medallion {
  background-color: var(--cp-progress-step-locked-background);
  color: var(--cp-progress-step-locked-label);
}

.cp-step--locked {
  /* Caption sits on the register ground; the medallion keeps locked-label on its light fill. */
  color: var(--cp-color-ink-muted);
}

.cp-spinner {
  box-sizing: border-box;
  display: inline-block;
  width: var(--cp-progress-spinner-size);
  height: var(--cp-progress-spinner-size);
  border-width: var(--cp-stroke-3);
  border-style: solid;
  border-color: var(--cp-progress-spinner-track);
  border-top-color: var(--cp-progress-spinner-head);
  border-radius: var(--cp-radius-pill);
  animation: cp-spin 0.7s linear infinite;
}

.cp-spinner--compact {
  width: var(--cp-progress-spinner-size-compact);
  height: var(--cp-progress-spinner-size-compact);
  border-width: var(--cp-stroke-1);
}

.cp-button__spinner .cp-spinner {
  width: var(--cp-progress-spinner-size-compact);
  height: var(--cp-progress-spinner-size-compact);
  border-width: var(--cp-stroke-1);
  /* Inside a button the spinner follows the label colour, so it shows on every fill and register. */
  border-color: transparent;
  border-top-color: currentColor;
}

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

@media (prefers-reduced-motion: reduce) {
  .cp-progress--indeterminate .cp-progress__fill {
    animation: none;
  }

  .cp-spinner {
    animation: none;
  }
}

/* -------------------------------------------------------------------------- */
/* Registers — variables are generated into tokens.css from                   */
/* tokens/modes/inverse.tokens.json (D-017). Last in the file so a component  */
/* that is also a register (.cp-card.cp-surface-inverse) takes the register.  */
/* -------------------------------------------------------------------------- */

/* Colour bands and panels (D-050). The register variables are generated into  */
/* tokens.css from tokens/semantic/band.tokens.json. The ground is the band     */
/* colour under the house stone, laid on with multiply as the header lays it,   */
/* with a faint ivory light in the middle.                                      */
:is(.cp-surface-wine, .cp-surface-green, .cp-surface-peacock, .cp-surface-violet, .cp-surface-sage, .cp-surface-wheat, .cp-surface-rose) {
  color: var(--cp-color-ink);
  background-image:
    radial-gradient(ellipse 78% 56% at 50% 42%, var(--cp-color-band-lift), transparent 72%),
    url("../../assets/textures/stone-texture.webp");
  background-size: auto, var(--cp-band-texture-width) var(--cp-band-texture-height);
  background-repeat: no-repeat, repeat;
  background-blend-mode: normal, multiply;
}

.cp-surface-wine { background-color: var(--cp-color-band-wine-fill); }
.cp-surface-green { background-color: var(--cp-color-band-green-fill); }
.cp-surface-peacock { background-color: var(--cp-color-band-peacock-fill); }
.cp-surface-violet { background-color: var(--cp-color-band-violet-fill); }
.cp-surface-sage { background-color: var(--cp-color-band-sage-fill); }
.cp-surface-wheat { background-color: var(--cp-color-band-wheat-fill); }
.cp-surface-rose { background-color: var(--cp-color-band-rose-fill); }

.cp-surface-standard {
  color: var(--cp-color-ink);
}

.cp-surface-inverse {
  color: var(--cp-color-ink);
  background-color: var(--cp-color-surface-inverse);
}
