/* Design system parts used across features: chips, stats, thermometer, bento grid and tiles, disclosure, selectable choice, bottom sheet (popover). Shown together at /styleguide/. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 0.2rem 0.75rem;
  background: color-mix(in oklab, var(--tone, var(--c-teal)) 16%, var(--surface));
  color: var(--text);
  border: 1px solid color-mix(in oklab, var(--tone, var(--c-teal)) 40%, transparent);
  border-radius: 999px;
  font-size: var(--fs-0);
  font-weight: var(--fw-strong);
  line-height: 1.4;
}

.chip .icon {
  inline-size: 16px;
  block-size: 16px;
}

.stat {
  display: grid;
  gap: var(--s-1);
}

.stat-figure {
  color: var(--accent-text);
  font-size: var(--fs-figure);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat-label {
  color: var(--text-muted);
  font-size: var(--fs-0);
}

/* Thermometer: a native progress bar (its value is the page's data, no inline style); the fill wipes in
   with a registered custom property, in the reading direction */
@property --wipe {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 100%;
}

@keyframes wipe {
  from {
    --wipe: 0%;
  }

  to {
    --wipe: 100%;
  }
}

.thermo,
.progress {
  --wipe-dir: to right;
  appearance: none;
  inline-size: 100%;
  block-size: 16px;
  overflow: hidden;
  background: var(--surface-2);
  border: 0;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--level, var(--accent));
  mask-image: linear-gradient(var(--wipe-dir), #000 var(--wipe), transparent var(--wipe));
  animation: wipe 1100ms var(--ease) both;
}

[dir="rtl"] .thermo,
.progress {
  --wipe-dir: to left;
}

.thermo::-webkit-progress-bar,
.progress::-webkit-progress-bar {
  background: transparent;
}

.thermo::-webkit-progress-value,
.progress::-webkit-progress-value {
  background: linear-gradient(90deg, color-mix(in oklab, currentColor 70%, var(--c-white)), currentColor);
  border-radius: 999px;
}

.thermo::-moz-progress-bar,
.progress::-moz-progress-bar {
  background: linear-gradient(90deg, color-mix(in oklab, currentColor 70%, var(--c-white)), currentColor);
  border-radius: 999px;
}

/* Bento grid: tiles reflow by the width of their own container, not the window */
.bento {
  container: bento / inline-size;
}

.bento-grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: minmax(0, 1fr);
}

.tile {
  display: grid;
  align-content: start;
  gap: var(--s-2);
  padding: var(--s-5);
  background: linear-gradient(180deg, color-mix(in oklab, var(--tone, var(--c-teal)) 9%, var(--surface)), var(--surface) 5rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.tile h2,
.tile h3 {
  margin: 0;
  font-size: var(--fs-2);
}

.tile p {
  margin: 0;
  color: var(--text-muted);
}

@container bento (min-width: 38rem) {
  .bento-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile-wide {
    grid-column: span 2;
  }
}

@container bento (min-width: 62rem) {
  .bento-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tile-tall {
    grid-row: span 2;
  }
}

/* Disclosure: a details element, with an arrow that turns */
.disclosure {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-block-size: 48px;
  padding: var(--s-3) var(--s-4);
  font-weight: var(--fw-strong);
  list-style: none;
  cursor: pointer;
}

.disclosure > summary::-webkit-details-marker {
  display: none;
}

.disclosure > summary::after {
  content: "";
  flex: none;
  inline-size: 0.55rem;
  block-size: 0.55rem;
  border-block-end: 2px solid currentColor;
  border-inline-end: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}

.disclosure[open] > summary::after {
  transform: rotate(-135deg);
}

.disclosure > :not(summary) {
  padding: 0 var(--s-4) var(--s-4);
}

/* Selectable choice: the card reacts to its own radio or checkbox with :has() */
.choice {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color var(--dur) var(--ease),
    background-color var(--dur) var(--ease);
}

.choice input {
  accent-color: var(--accent-text);
}

.choice:has(:checked) {
  background: color-mix(in oklab, var(--accent) 16%, var(--surface));
  border-color: var(--accent-text);
}

.choice:has(:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Bottom sheet: a popover that rises from the bottom edge on phones and sits centred on wide screens */
.sheet[popover] {
  position: fixed;
  inset: auto;
  inset-block-end: 0;
  inset-inline: 0;
  inline-size: 100%;
  max-inline-size: 34rem;
  margin-inline: auto;
  padding: var(--s-5) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-start-start-radius: var(--radius-lg);
  border-start-end-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  transform: translateY(100%);
  transition:
    transform var(--dur) var(--ease),
    overlay var(--dur) allow-discrete,
    display var(--dur) allow-discrete;
}

.sheet[popover]:popover-open {
  transform: none;
}

@starting-style {
  .sheet[popover]:popover-open {
    transform: translateY(100%);
  }
}

.sheet::backdrop {
  background: oklch(0 0 0 / 0.5);
}

.sheet h2 {
  font-size: var(--fs-2);
}

@media (min-width: 768px) {
  .sheet[popover] {
    inset-block: 0;
    block-size: fit-content;
    border-radius: var(--radius-lg);
    transform: translateY(1rem);
    opacity: 0;
  }

  .sheet[popover]:popover-open {
    opacity: 1;
    transform: none;
  }
}
