/* The static pages' card widget (public/static/card-preview.js).
   Two shapes, both copied from the app so a card looks the same on an article
   as it does in ArcaneMetriX:

   - A card figure for lists (<figure class="amx-card">): the picture in a
     frame, then a two-line title (the front face's name, and the other face or
     half as a subtitle, never the "A // B" form).
   - The fanned hand (.card-fan-host > .collection-fan), the Home page's
     `CardFan`: rules below are styles/collection.css's, kept in step by hand.

   A card with a second side or a sideways half gets the app's flip control:
   `.card-action-bar` along the picture's bottom edge holding a 26px square
   `.card-badge.card-flip-btn` with the Refresh icon (styles/cards.css). */

/* The app's tokens these rules use, which the static pages do not define.
   Scoped to the widget so nothing else on the page changes. */
.amx-card,
.card-fan-host,
.amx-card-toggles,
.amx-widget-subject {
    --widget-bg: color-mix(in srgb, var(--bg-color) 86%, transparent);
    --text-primary: var(--text-color);
    --space-px: 1px;
    --space-1: 0.25rem;
    --space-1-5: 0.375rem;
    --radius-sm: 4px;
    --radius-lg: 8px;
    --radius-xl: 10px;
    --radius-round: 50%;
}

/* ── The card figure ────────────────────────────────────────────────────── */
.amx-card {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.amx-card-frame {
    position: relative;
    aspect-ratio: 63 / 88;
    border-radius: 4.75% / 3.5%;
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.amx-card-frame:hover,
.amx-card-frame:focus-within {
    transform: translateY(-3px);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.55);
    border-color: var(--accent-hover);
}

/* The picture's surface: the link, and the action bar over it. Used inside the
   figure's frame and inside a fan's thumb. */
.amx-card-surface {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    line-height: 0;
}

.amx-card-link {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
}

.amx-card-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    transition: transform 0.35s ease, opacity 0.2s ease;
}

/* A flip-layout card reads upside down for its second half; a split card
   reads sideways. The picture turns inside its frame; the frame stays put. */
.is-rotated-180 .amx-card-img {
    transform: rotate(180deg);
}

.is-rotated-90 .amx-card-img {
    transform: rotate(90deg) scale(0.716);
}

.amx-card-img.is-turning {
    opacity: 0;
}

/* The app's action bar and flip badge (styles/cards.css). */
.amx-card-surface .card-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-1-5);
    background: transparent;
    border-radius: 0 0 4.75% 4.75%;
    z-index: 10;
    line-height: normal;
}

.amx-card-surface .card-badge {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    flex-shrink: 0;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.amx-card-surface .card-badge:hover,
.amx-card-surface .card-badge:focus-visible {
    border-color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

.amx-card-surface .card-badge svg {
    width: 18px;
    height: 18px;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
}

.amx-card-title {
    min-width: 0;
    font-size: 0.9rem;
    line-height: 1.3;
}

.amx-card-title a {
    display: block;
    min-width: 0;
    color: var(--text-color);
    text-decoration: none;
}

.amx-card-title a:hover .amx-card-name,
.amx-card-title a:focus-visible .amx-card-name {
    color: var(--accent-light);
}

.amx-card-title .amx-card-name {
    display: block;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.amx-card-title .amx-card-sub {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.amx-card-title .amx-card-sub:empty {
    display: none;
}

/* Lists of cards: a responsive grid of figures. */
.amx-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
    gap: 22px 18px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
}

.amx-card-grid > li {
    min-width: 0;
}

.amx-card-missing {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    padding: 8px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.3;
}

/* ── The fanned hand: the app's CardFan (styles/collection.css) ─────────── */
/* The host is the fan's container: every size inside is a share of its
   width (cqw), so the fan is as large as the column allows and grows taller
   with it, exactly as the Home page's does. No cap: on an article the fan is
   the picture, and the bigger the better. */
.card-fan-host {
    container-type: inline-size;
    /* An explicit width: a size-contained box has no content width, so as a
       grid or flex item with auto margins it would shrink to nothing. */
    width: 100%;
    margin: 14px 0 6px;
}

.collection-fan {
  position: relative;
  width: 100%;
  /* Definite height (absolute children can't size it) — just tall enough for the
     fan, scaling with the panel width, with a floor so it never collapses. */
  height: max(248px, 52cqw);
  margin-top: var(--space-1);
}
.collection-fan-card {
  /* Signed offset from the middle card, e.g. -2,-1,0,1,2 for five cards. */
  --o: calc(var(--i) - (var(--fan-n) - 1) / 2);
  --dx: calc(var(--o) * 18cqw);                       /* horizontal spread */
  --dip: calc(var(--o) * var(--o) * 1.8cqw);          /* outer cards dip down (arc) */
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: var(--i);
  width: 23cqw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transform: translateX(calc(-50% + var(--dx))) translateY(var(--dip));
  transition: transform .18s ease;
}
.collection-fan-card:hover,
.collection-fan-card:focus-within {
  z-index: 30;
  transform: translateX(calc(-50% + var(--dx))) translateY(calc(var(--dip) - 20px));
}
.collection-fan-label {
  width: 16.5cqw;                                      /* < 18cqw spread → never overlaps */
  display: flex;
  flex-direction: column;
  gap: var(--space-px);
  padding: 4px 5px 3px;
  text-align: center;
  border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--border-color) 55%, transparent);
  background: color-mix(in srgb, var(--widget-bg) 90%, #000);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
}
.collection-fan-label strong { max-width: 100%; overflow: hidden; color: var(--text-primary); font-size: clamp(9px, 1.95cqw, 12px); text-overflow: ellipsis; white-space: nowrap; }
.collection-fan-label span { max-width: 100%; overflow: hidden; color: var(--text-muted); font-size: clamp(8px, 1.55cqw, 10px); text-overflow: ellipsis; white-space: nowrap; }
.collection-fan-label span:empty { display: none; }
.collection-fan-thumb {
  width: 100%;
  aspect-ratio: 63/88;
  overflow: hidden;
  border-radius: var(--radius-xl);
  border: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
  background: color-mix(in srgb, var(--widget-bg) 90%, #000);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .5);
  /* Only the image fans (angled); the label above stays perfectly straight. */
  transform: rotate(calc(var(--o) * 6deg));
  transform-origin: center top;
  transition: transform .18s ease, box-shadow .18s ease;
}
.collection-fan-card:hover .collection-fan-thumb,
.collection-fan-card:focus-within .collection-fan-thumb { transform: rotate(0deg) scale(1.04); box-shadow: 0 16px 34px rgba(0, 0, 0, .6); }
.collection-fan-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }

/* One or two cards leave most of the panel empty at the shared 23cqw size, and
   with no crowding to design around the art can simply be bigger. The label
   keeps sitting directly above its own card. */
.collection-fan--one { height: max(268px, calc(56cqw + 70px)); }
.collection-fan--one .collection-fan-card { width: 40cqw; gap: 5px; }
.collection-fan--one .collection-fan-label { width: 40cqw; }

.collection-fan--two { height: max(252px, calc(48cqw + 70px)); }
.collection-fan--two .collection-fan-card { width: 34cqw; --dx: calc(var(--o) * 40cqw); }
.collection-fan--two .collection-fan-label { width: 36cqw; }

@container (max-width: 480px) {
  .collection-fan { --label-h: 48px; --label-gap: 6px; height: max(268px, 76cqw); }
  .collection-fan-card {
    width: 24cqw;
    --dx: calc(var(--o) * 19cqw);
    --dip: 0px;
    padding-top: calc(var(--label-h) * 2 + var(--label-gap) + 6px);
    gap: 0;
  }
  .collection-fan-thumb { transform: rotate(calc(var(--o) * 5deg)); }
  .collection-fan-card:hover .collection-fan-thumb { transform: rotate(0deg) scale(1.04); }
  .collection-fan-label {
    position: absolute;
    left: 50%;
    top: calc(var(--label-h) + var(--label-gap));
    transform: translateX(-50%);
    width: 30cqw;
    height: var(--label-h);
    justify-content: center;
    padding: 3px 5px;
    line-height: 1.2;
  }
  .collection-fan-card:nth-child(odd) .collection-fan-label { top: 0; }
  .collection-fan-label strong { font-size: 10px; }
  .collection-fan-label span { font-size: 8px; }

  .collection-fan--one,
  .collection-fan--two { --label-h: 44px; }

  .collection-fan--one { height: max(292px, calc(74cqw + 64px)); }
  .collection-fan--two { height: max(258px, calc(59cqw + 64px)); }

  .collection-fan--one .collection-fan-card,
  .collection-fan--two .collection-fan-card {
    padding-top: calc(var(--label-h) + var(--label-gap));
  }

  .collection-fan--one .collection-fan-label,
  .collection-fan--two .collection-fan-label,
  .collection-fan--one .collection-fan-card:nth-child(odd) .collection-fan-label,
  .collection-fan--two .collection-fan-card:nth-child(odd) .collection-fan-label {
    top: 0;
  }

  .collection-fan--one .collection-fan-card { width: 52cqw; }
  .collection-fan--one .collection-fan-label { width: 52cqw; }

  .collection-fan--two .collection-fan-card { width: 42cqw; --dx: calc(var(--o) * 48cqw); }
  .collection-fan--two .collection-fan-label { width: 46cqw; }
}

/* A combo's cards sit in a narrower fan above what the combo makes. */
.archetype-combo .card-fan-host {
    grid-column: 1 / -1;
    margin: 0 0 6px;
}

/* ── Cards as switches, in the interactive pieces ───────────────────────── */
/* A card on the battlefield is in full color with an accent edge and a tick;
   one that is not is dimmed. The checkbox (or the button's aria-pressed) is
   the state; the picture is how it reads. */
.amx-card-toggles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 14px 12px;
    margin: 4px 0 0;
    padding: 0;
    list-style: none;
}

.amx-card-toggles > li {
    min-width: 0;
}

/* At most four across, each a quarter of the row less the gaps, and fewer
   when a quarter would be under 150px: bigger pictures, room for a title. */
.amx-card-toggles--four {
    grid-template-columns: repeat(auto-fill, minmax(max(150px, calc((100% - 3 * 16px) / 4)), 1fr));
    gap: 18px 16px;
}

.amx-card-toggles--four .amx-card-toggle-name {
    font-size: 0.95rem;
}

.amx-card-toggle {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    background: none;
    color: var(--text-color);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.amx-card-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.amx-card-toggle-art {
    position: relative;
    display: block;
    aspect-ratio: 63 / 88;
    border-radius: 4.75% / 3.5%;
    overflow: hidden;
    border: 2px solid transparent;
    background: var(--bg-tertiary);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.amx-card-toggle-art img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    opacity: 0.42;
    filter: grayscale(0.65);
    transition: opacity 0.15s ease, filter 0.15s ease;
}

.amx-card-toggle-art .amx-card-missing {
    opacity: 0.7;
}

.amx-card-toggle-tick {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent-color);
    color: var(--button-primary-text);
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.amx-card-toggle-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.25;
}

.amx-card-toggle-note {
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.3;
}

.amx-card-toggle:hover .amx-card-toggle-art {
    transform: translateY(-2px);
}

.amx-card-toggle:hover .amx-card-toggle-art img {
    opacity: 0.7;
}

.amx-card-toggle:has(input:checked) .amx-card-toggle-art,
.amx-card-toggle[aria-pressed="true"] .amx-card-toggle-art {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow), 0 8px 18px rgba(0, 0, 0, 0.5);
}

.amx-card-toggle:has(input:checked) .amx-card-toggle-art img,
.amx-card-toggle[aria-pressed="true"] .amx-card-toggle-art img {
    opacity: 1;
    filter: none;
}

.amx-card-toggle:has(input:checked) .amx-card-toggle-tick,
.amx-card-toggle[aria-pressed="true"] .amx-card-toggle-tick {
    opacity: 1;
    transform: scale(1);
}

.amx-card-toggle:has(input:focus-visible) .amx-card-toggle-art,
.amx-card-toggle:focus-visible .amx-card-toggle-art {
    outline: 2px solid var(--accent-light);
    outline-offset: 2px;
}

.amx-card-toggle:focus-visible {
    outline: none;
}

/* The card a piece is about, shown beside its controls. */
.amx-widget-subject {
    display: grid;
    grid-template-columns: minmax(110px, 150px) 1fr;
    gap: 18px;
    align-items: start;
    margin-bottom: 14px;
}

/* Beside the controls there is room for the whole name. */
.amx-widget-subject .amx-card-title .amx-card-name,
.amx-widget-subject .amx-card-title .amx-card-sub {
    white-space: normal;
}

@media (max-width: 560px) {
    .amx-widget-subject { grid-template-columns: 96px 1fr; gap: 12px; }
    .amx-card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
}

/* The step-through demo's zones hold small cards that move between them. */
.amx-zone-card.amx-zone-card--image {
    padding: 0;
    background: transparent;
    border: none;
    width: 42%;
    min-width: 72px;
    display: inline-block;
    vertical-align: top;
    margin: 0 3% 8px 0;
}

.amx-zone-card--image .amx-card-title {
    font-size: 0.72rem;
}

.amx-zone-card.is-moving .amx-card-frame {
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 2px var(--accent-glow), 0 8px 18px rgba(0, 0, 0, 0.45);
}

@media (prefers-reduced-motion: reduce) {
    .amx-card-frame,
    .amx-card-img,
    .collection-fan-card,
    .collection-fan-thumb,
    .amx-card-toggle-art,
    .amx-card-toggle-art img {
        transition: none;
    }
}
