/* ==========================================================================
   Pixel kit: stepped frames and buttons

   The app keeps its fonts and layout; pixel lives in the edges. A frame is
   two clipped boxes: the outer one is the 3px border in the tone colour with
   3px stair steps at each corner, the inner one is the surface. Buttons are
   filled with the tone and stepped at 4px.

     <div class="px-frame px-tone--late">
       <div class="px-frame__body">…</div>
     </div>
     <button class="px-btn px-tone--late">…</button>

   Tones map to the status tokens, so both themes work without overrides.
   Requires tokens.css.
   ========================================================================== */

.px-tone--brand {
  --px-tone: var(--brand);
  --px-tone-ink: var(--brand-ink);
}

.px-tone--late {
  --px-tone: var(--late);
  --px-tone-ink: var(--danger-ink);
}

.px-tone--izin {
  --px-tone: var(--izin);
  --px-tone-ink: var(--ink-inverse);
}

.px-tone--early {
  --px-tone: var(--early);
  --px-tone-ink: var(--early-ink);
}

.px-tone--ok {
  --px-tone: var(--ok);
  --px-tone-ink: var(--ok-ink);
}

/* --- Frame --------------------------------------------------------------- */

.px-frame {
  padding: 3px;
  background: var(--px-tone, var(--brand));
  clip-path: polygon(
    0 9px, 3px 9px, 3px 6px, 6px 6px, 6px 3px, 9px 3px, 9px 0,
    calc(100% - 9px) 0, calc(100% - 9px) 3px, calc(100% - 6px) 3px, calc(100% - 6px) 6px,
    calc(100% - 3px) 6px, calc(100% - 3px) 9px, 100% 9px,
    100% calc(100% - 9px), calc(100% - 3px) calc(100% - 9px), calc(100% - 3px) calc(100% - 6px),
    calc(100% - 6px) calc(100% - 6px), calc(100% - 6px) calc(100% - 3px), calc(100% - 9px) calc(100% - 3px),
    calc(100% - 9px) 100%, 9px 100%, 9px calc(100% - 3px), 6px calc(100% - 3px),
    6px calc(100% - 6px), 3px calc(100% - 6px), 3px calc(100% - 9px), 0 calc(100% - 9px)
  );
}

.px-frame__body {
  background: var(--surface);
  color: var(--ink);
  clip-path: polygon(
    0 6px, 3px 6px, 3px 3px, 6px 3px, 6px 0,
    calc(100% - 6px) 0, calc(100% - 6px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 6px, 100% 6px,
    100% calc(100% - 6px), calc(100% - 3px) calc(100% - 6px), calc(100% - 3px) calc(100% - 3px),
    calc(100% - 6px) calc(100% - 3px), calc(100% - 6px) 100%,
    6px 100%, 6px calc(100% - 3px), 3px calc(100% - 3px), 3px calc(100% - 6px), 0 calc(100% - 6px)
  );
}

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

/* Without a tone class a button is brand. */
.px-btn:not([class*="px-tone--"]) {
  --px-tone: var(--brand);
  --px-tone-ink: var(--brand-ink);
}

.px-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-5);
  border: 0;
  /* Page styles that round every button would show through the steps. */
  border-radius: 0;
  background: var(--px-tone);
  color: var(--px-tone-ink);
  font: 700 var(--text-base) / 1.2 var(--font-display);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  clip-path: polygon(
    0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px,
    100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%,
    4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px)
  );
  /* The hover and press shades are an inset rim, so they stay inside the clip. */
  box-shadow: inset 0 -4px 0 color-mix(in srgb, var(--px-tone) 70%, #000);
  transition:
    transform var(--dur-instant) steps(2),
    box-shadow var(--dur-instant) steps(2);
}

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

.px-btn:hover {
  box-shadow:
    inset 0 -4px 0 color-mix(in srgb, var(--px-tone) 70%, #000),
    inset 0 4px 0 color-mix(in srgb, var(--px-tone) 70%, #fff);
}

.px-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 4px 0 color-mix(in srgb, var(--px-tone) 70%, #000);
}

/* An outline would be cut off by the clip, so focus is an inset ring in the
   button's ink colour. */
.px-btn:focus-visible {
  outline: none;
  box-shadow:
    inset 0 0 0 3px var(--px-tone-ink),
    inset 0 0 0 5px var(--px-tone);
}

.px-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .px-btn {
    transition: none;
  }

  .px-btn:active {
    transform: none;
  }
}
