/* =====================================================================
   components.css: buttons, chips, pickers, fields, segmented, toggle,
   meta, spinner, skeleton, empty states, toast.
   ===================================================================== */

/* ---------------------------------------------------------------- .btn */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control); padding: 0 22px; border-radius: var(--radius-pill);
  font: 600 15px/1 var(--font); letter-spacing: -.005em; white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease-std), color var(--dur-2) var(--ease-std), transform var(--dur-1) var(--ease-std);
}
.btn .icon { width: 20px; height: 20px; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: default; }
.btn[aria-busy="true"] > .icon { display: none; }
/* playTitle() puts a spinner before the label; the inline min-width holds the width. */
.btn[aria-busy="true"]:disabled { opacity: 1; cursor: progress; }
.btn > .spinner { flex: none; width: 20px; height: 20px; border-width: 2px; }
.btn--primary > .spinner { border-color: rgba(11, 11, 13, .2); border-top-color: var(--on-inverse); }
.btn--lg { height: var(--control-lg); padding: 0 28px; font-size: 17px; }
.btn--lg .icon { width: 22px; height: 22px; }
.btn--sm { height: var(--control-sm); padding: 0 16px; font-size: 14px; }
.btn--icon { width: var(--control); padding: 0; }
.btn--sm.btn--icon { width: var(--control-sm); }
.btn--lg.btn--icon { width: var(--control-lg); }
.btn--block { width: 100%; }
.btn--primary { background: var(--inverse); color: var(--on-inverse); }
.btn--secondary { background: var(--fill-2); color: var(--text); }
.btn--overlay { background: var(--btn-overlay); color: var(--text); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22); }
.btn--ghost { color: var(--text-2); }
@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover { background: var(--inverse-hover); }
  .btn--secondary:hover { background: var(--fill-3); }
  .btn--overlay:hover { background: var(--btn-overlay-hover); }
  .btn--ghost:hover { background: var(--fill-1); color: var(--text); }
}
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--focus-halo); }
.btn--overlay:focus-visible { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 0 0 2px var(--focus-halo); }
html.is-tv .btn:focus-visible { background: var(--inverse); color: var(--on-inverse); transform: scale(1.04); }

/* --------------------------------------------------------------- .chip */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); color: var(--text-2);
  font: 500 15px/1 var(--font); white-space: nowrap; flex: none;
  transition: background-color var(--dur-2), color var(--dur-2);
}
@media (pointer: coarse) { .chip { height: 44px; } }
@media (hover: hover) and (pointer: fine) { .chip:hover { background: var(--fill-3); color: var(--text); } }
.chip[aria-pressed="true"], .chip[aria-current="page"], .chip[aria-current="true"], .chip[aria-selected="true"], .chip.is-active {
  background: var(--inverse); color: var(--on-inverse); font-weight: 600;
}
.chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 3px var(--focus-halo); }
html.is-tv .chip { height: var(--control); font-size: var(--fs-callout); transition: background-color var(--dur-2), color var(--dur-2), transform var(--dur-3) var(--ease-calm); }
html.is-tv .chip:focus-visible { transform: scale(1.06); }

/* ------------------------------------------------------------- .picker */
/* pickerControl(): a native <select> stretched invisibly over a chip. */
.picker-wrap { position: relative; display: inline-flex; align-items: center; flex: none; }
.picker {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); color: var(--text);
  font: 500 15px/1 var(--font); white-space: nowrap;
  transition: background-color var(--dur-2), color var(--dur-2);
}
@media (pointer: coarse) { .picker { height: 44px; } }
.picker select {
  position: absolute; inset: 0; width: 100%; opacity: 0; font-size: 16px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
.picker select option { background: var(--surface-2); color: var(--text); }
.picker__text { max-width: 18ch; overflow: hidden; text-overflow: ellipsis; }
.picker .icon { width: 16px; height: 16px; color: var(--text-2); }
@media (hover: hover) and (pointer: fine) { .picker:hover { background: var(--fill-3); } }
.picker[data-set] { background: var(--inverse); color: var(--on-inverse); font-weight: 600; }
.picker[data-set] .icon { color: var(--on-inverse); }
/* With a clear button the chevron gives way to the X. */
.picker-wrap--clearable .picker[data-set] { padding-right: 40px; }
.picker-wrap--clearable .picker[data-set] > .icon { display: none; }
/* Chip ring. :focus-within is the base for engines without :has(); where :has()
   exists, the second rule removes the ring for mouse focus. */
.picker:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 3px var(--focus-halo); }
.picker:focus-within:not(:has(select:focus-visible)) { outline: none; box-shadow: none; }
.picker__clear {
  position: absolute; top: 50%; right: 0; width: 44px; height: 44px; margin-top: -22px;
  display: grid; place-items: center; border-radius: 50%; color: var(--on-inverse);
}
.picker__clear .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.picker__clear:focus-visible { outline: 2px solid var(--on-inverse); outline-offset: -8px; box-shadow: none; }
html.is-tv .picker { height: var(--control); font-size: var(--fs-callout); transition: background-color var(--dur-2), color var(--dur-2), transform var(--dur-3) var(--ease-calm); }
html.is-tv .picker:focus-within { transform: scale(1.06); }

/* -------------------------------------------------------------- .field */
.field {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 16px;
  border-radius: var(--radius-pill); background: var(--fill-1); border: 1px solid transparent; color: var(--text-2);
  transition: background-color var(--dur-2);
}
.field input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: none; color: var(--text); font-size: var(--fs-input); }
.field input::placeholder { color: var(--text-3); }
.field input::-webkit-search-cancel-button { display: none; }
.field .icon { width: 18px; height: 18px; }
@media (hover: hover) and (pointer: fine) { .field:hover { background: rgba(255, 255, 255, .11); } }
.field:focus-within { background: var(--fill-2); outline: 2px solid var(--focus); outline-offset: 2px; color: var(--text); }
.field--lg { height: 56px; }
.field--lg input { font-size: max(17px, var(--fs-input)); }
html.is-tv .field--lg { height: calc(72px * var(--tvu)); }
/* Clear button inside a search field (search.js, live.js). */
.field__clear {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin-right: -12px;
  border-radius: 50%; color: var(--text-2);
}
.field__clear .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.field__clear:focus-visible { outline-offset: -4px; box-shadow: none; }
@media (hover: hover) and (pointer: fine) { .field__clear:hover { color: var(--text); } }

/* ---------------------------------------------------------- .segmented */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; height: 40px; max-width: 100%;
  border-radius: var(--radius-pill); background: var(--fill-1);
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
@media (pointer: coarse) { .segmented { height: 44px; } }
.segmented button {
  flex: none; padding: 0 14px; border-radius: var(--radius-pill);
  font: 600 14px/1 var(--font); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.segmented button[aria-pressed="true"] { background: var(--inverse); color: var(--on-inverse); }
.segmented button:focus-visible { outline-offset: -3px; box-shadow: none; }

/* ------------------------------------------------------------- .toggle */
.toggle { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; color: var(--text-2); font-size: 15px; cursor: pointer; user-select: none; }
.toggle input {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: 44px; height: 26px; border-radius: var(--radius-pill); background: var(--toggle-off);
  transition: background-color var(--dur-2);
}
.toggle input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform var(--dur-2) var(--ease-calm), background-color var(--dur-2);
}
.toggle input:checked { background: var(--inverse); }
.toggle input:checked::after { background: #0b0b0d; transform: translateX(18px); }

/* --------------------------------------------------------------- .meta */
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; color: var(--text-2); font-size: var(--fs-callout); }
.meta > * + *::before {
  content: ""; display: inline-block; width: 3px; height: 3px; border-radius: 50%;
  background: currentColor; opacity: .55; margin: 0 8px; vertical-align: middle;
}
.meta .score { display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
.meta .score .icon { width: 12px; height: 12px; color: var(--star); }

/* ------------------------------------------------------------ spinners */
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .18); border-top-color: #fff; animation: spin .9s linear infinite; }
.spinner--sm { width: 20px; height: 20px; border-width: 2px; }
.spinner--lg { width: 40px; height: 40px; }

/* ------------------------------------------------------------ skeleton */
/* An opacity pulse, no shimmer: background-position is never animated. */
.skeleton { background: var(--skeleton); border-radius: var(--radius-sm); animation: skeleton-pulse 1.4s ease-in-out infinite alternate; }
@keyframes skeleton-pulse { from { opacity: .55; } to { opacity: 1; } }
html.is-tv .skeleton { animation: none; }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.skeleton-card { min-width: 0; }
.skeleton--poster { aspect-ratio: 2 / 3; border-radius: var(--radius-card); }
.skeleton--line { width: 80%; height: 12px; margin-top: 10px; border-radius: var(--radius-xs); }
.skeleton--title { width: 180px; height: 22px; }
.skeleton--pill { width: 160px; height: 48px; border-radius: var(--radius-pill); }

/* skeletonHero(): the billboard, or the stacked shape (media, three lines, two pills). */
.skeleton-hero { position: relative; height: min(82vh, 920px); height: min(82svh, 920px); min-height: 520px; overflow: hidden; }
.skeleton-hero__media { position: absolute; inset: 0; border-radius: 0; }
.skeleton-hero__body { position: absolute; left: var(--gutter); bottom: 136px; width: min(640px, 46vw); }
.skeleton-hero__body .skeleton { background: var(--surface-3); }
.skeleton-hero__body .skeleton--line { height: 20px; margin-top: 14px; }
.skeleton-hero__body .skeleton--line:nth-child(1) { width: 60%; height: 44px; margin-top: 0; }
.skeleton-hero__body .skeleton--line:nth-child(2) { width: 40%; }
.skeleton-hero__body .skeleton--line:nth-child(3) { width: 30%; }
.skeleton-hero__actions { display: flex; gap: 12px; margin-top: 28px; }
@media (min-width: 861px) and (max-width: 1279px) {
  .skeleton-hero { height: min(78vh, 760px); height: min(78svh, 760px); }
  .skeleton-hero__body { bottom: 120px; width: min(560px, 52vw); }
}
@media (max-width: 860px), (orientation: portrait) and (max-width: 1119px) {
  .skeleton-hero { height: auto; min-height: 0; }
  .skeleton-hero__media { position: relative; inset: auto; aspect-ratio: 16 / 9; }
  .skeleton-hero__body { position: relative; left: auto; bottom: auto; width: auto; max-width: 600px; margin-top: -48px; padding: 0 var(--gutter); }
}
@media (max-width: 599px) {
  .skeleton-hero__media { aspect-ratio: 4 / 3; }
  .skeleton-hero__body .skeleton--line { margin-left: auto; margin-right: auto; }
  .skeleton-hero__actions { display: grid; grid-template-columns: 1fr 1fr; }
  .skeleton-hero__actions .skeleton--pill { width: auto; }
}
html.is-tv .skeleton-hero { height: 74vh; height: 74svh; }
html.is-tv .skeleton-hero__body { bottom: calc(160px * var(--tvu)); width: calc(820px * var(--tvu)); }

/* ------------------------------------------------------- empty / error */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 72px 16px; color: var(--text-2); }
.empty__icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); }
.empty__icon .icon { width: 26px; height: 26px; }
.empty h2 { margin-top: 6px; color: var(--text); font-size: var(--fs-title-3); font-weight: 600; }
.empty p { max-width: 44ch; font-size: 15px; line-height: 1.55; }
.empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 16px; }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--tabbar-total)); z-index: var(--z-toast);
  transform: translate(-50%, 12px); opacity: 0; display: flex; align-items: center; gap: 12px;
  /* max-content: with left:50% a shrink-to-fit box only gets half the screen and wraps word by word. */
  width: max-content; min-height: 44px; padding: 10px 20px; max-width: min(480px, calc(100% - 32px));
  border-radius: var(--radius-pill); background: var(--inverse); color: var(--on-inverse);
  font: 500 15px/1.3 var(--font); box-shadow: var(--shadow-1); pointer-events: none;
  transition: opacity var(--dur-3), transform var(--dur-3) var(--ease-calm);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.has-action.is-visible { pointer-events: auto; }
.toast__text { min-width: 0; }
/* 44px hit area inside a 44px pill: the negative margins cancel the vertical padding. */
.toast__action {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; margin: -10px -8px -10px 0; padding: 0 8px 0 12px;
  border-left: 1px solid rgba(0, 0, 0, .15); color: var(--on-inverse); font: 700 15px/1 var(--font);
}
.toast__action:focus-visible { outline: 2px solid var(--focus-on-inverse); outline-offset: -4px; box-shadow: none; }
