/* ========================================
   STRANGE FRONTIERS CARDS
   ========================================
   One stylesheet for every Trait, Item and Background card, wherever it's
   drawn. The Character Creator and Player Tools are the reference:

     strange-frontiers-character-creator  src/app/cards.css (this file)
                                          src/app/components/cards.tsx
     portfolio_site                       css/sf-cards.css (a copy)
                                          php/rpg/components/cards.php

   Both copies must stay identical: change it in the creator, then copy it
   to the site. The components in both repos draw the same markup and take
   the same options for how a card behaves where it's used (see cards.tsx).

   Cards carry their own colors (the creator's on-screen dark), so a card
   looks the same in a light section, a dark one or a popup. Each interface
   only adds its own layout (grids, popups) and its picker states. */

.sf-card,
.sf-item-card {
    --card-bg: var(--sf-gray-800);
    --card-text: var(--sf-gray-100);
    --card-soft: var(--sf-gray-200);
    color: var(--card-text);
}

/* ---- Chips: the side nav's badges, gray on the black card ---- */

.sf-chip {
    display: inline-block;
    margin: .15rem .25rem .15rem 0;
    padding: .2rem .5rem;
    border-radius: 4px;
    background: var(--sf-gray-500);
    color: var(--sf-gray-0);
    font-size: .875rem;
    font-weight: 600;
    white-space: nowrap;

    &.sf-chip--muted {
        background: var(--sf-gray-100);
        color: var(--sf-gray-800);
    }

    &.sf-chip--accent {
        background: var(--sf-gray-400);
    }

    &.sf-chip--bad {
        background: var(--sf-crimson-500);
    }
}

/* ---- Trait and Background cards: a 1px edge the color of the bar ---- */

/* The grain behind Trait and Kind cards' content: pixel-fine SVG noise,
   only its peaks showing, in faint white, drawn at half size and doubled
   (a 200px tile) so each grain is an even 2px; and the light from the top
   it lies over */
:root {
    --sf-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.91' numOctaves='1' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .7 -.448'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    /* The same grain stronger, for the sheet's boxes */
    --sf-grain-strong: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.91' numOctaves='1' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.1 -.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    --sf-grain-light: linear-gradient(color-mix(in srgb, var(--sf-gray-0) 9%, transparent), transparent 85%);
}

.sf-card {
    --card-edge: var(--sf-gray-900);
    position: relative;
    width: 100%;
    background-color: var(--card-bg);
    border: 1px solid var(--card-edge);
    border-radius: 12px;
    box-shadow: 0 4px 10px #00000030;
    transition: border-color 200ms;

    /* Isekai's cards: Dreft's green bar and edge */
    &.sf-card--dreft {
        --card-edge: var(--sf-green-900);
    }

    > .sf-card-bar {
        border-radius: 10px 10px 0 0;
        background-color: var(--card-edge);
        color: var(--sf-gray-0);
    }

    /* A picked card (a picker's): a green ring and a check on its corner */
    &.selected {
        border-color: var(--sf-green-500);
        box-shadow: 0 0 0 1px var(--sf-green-500), 0 4px 10px #00000030;
    }

    &.selected::after {
        content: "✓";
        position: absolute;
        top: -12px;
        right: -12px;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: var(--sf-green-500);
        color: var(--sf-gray-0);
        font-size: .9rem;
        font-weight: 600;
    }
}

/* The setting's mark before a card's name, in the bar's text color */
.setting-icon {
    display: inline-block;
    flex-shrink: 0;
    width: 1.15em;
    height: 1.15em;
    margin-right: .45em;
    vertical-align: -.2em;
    background-color: currentColor;
    mask: center / contain no-repeat;

    &.setting-isekai {
        mask-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 512 512%22%3E%3Cg%3E%3Cpath d=%22m194.547 20.182-12.815 195.064L73.522 94.22l45.562 160.89-92.547-8.542 54.106 103.94-61.225 8.54 79.943 65.73a159.426 159.426 0 0 1-4.204-36.206l-20.963-1.7 1.508-18.626 20.536 1.664a156.566 156.566 0 0 1 15.233-51.414l-40.48-29.09 10.908-15.176 38.9 27.96a158.684 158.684 0 0 1 35.288-38.31l-27.73-50.21 16.36-9.033 26.845 48.607a156.696 156.696 0 0 1 48.88-19.217l-12.952-90.87 18.502-2.637 12.94 90.785c4.583-.4 9.22-.62 13.906-.62h.004c4.13 0 8.223.163 12.275.475l6.574-62.775 18.587 1.945-6.634 63.37a157.415 157.415 0 0 1 37.95 12.68l18.37-36.737L356.678 218l-18.746 37.492a159.36 159.36 0 0 1 24.59 19.342l46.53-52.115 13.942 12.446-47.707 53.438a157.87 157.87 0 0 1 20.957 33.115l32.97-22.372 10.493 15.464-36.393 24.696a155.963 155.963 0 0 1 7.327 36.707l19.594-3.19 3.002 18.448-22.29 3.627a156.823 156.823 0 0 1-4.706 32.09l80.9-63.87-56.24-5.695 54.034-85.428-59.73 9.252 39.868-103.57-88.28 35.94 32.75-116.752-96.82 111.057-17.085-168.008-42.715 108.207-58.375-128.142zm58.29 229.193c-76.976.002-138.993 62.02-138.993 138.996 0 33.147 11.532 63.544 30.783 87.485l-130.545-46.02h-.713v62.487h146.823l.004.004h29.6c-.002 0-.004-.002-.006-.004h1.548l-3.07-1.082c-28.443-20.302-46.98-53.577-46.98-91.19 0-61.712 49.773-112.13 111.55-112.13 61.776 0 112.13 50.354 112.13 112.13 0 37.508-18.62 70.66-47.05 90.97l-3.69 1.302h1.848l-.006.004h29.424c.002 0 .003-.003.004-.004h146.7v-62.488h-.716l-130.195 45.898c19.395-23.942 31.13-54.303 31.13-87.36 0-76.932-62.6-138.995-139.577-138.997h-.004z%22 fill=%22%23000000%22 fill-opacity=%221%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
    }

    &.setting-systems {
        mask-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 512 512%22%3E%3Cg%3E%3Cpath d=%22M133.813 38.28c-62.975 0-113.407 51.22-113.407 114.19 0 62.972 50.432 113.405 113.406 113.405 12.027 0 23.638-1.835 34.532-5.25a95.864 95.864 0 0 1-1.25-2.906l-69.78-120.876-8.19-13.625 16-.345h138.97c-13.07-48.662-57.543-84.596-110.28-84.594zm247.843 0c-52.74 0-96.672 35.93-109.562 84.595H426.47l-8.19 14.28-71.124 123.314c-.004.007.004.02 0 .03-.013.03-.017.064-.03.094 10.874 3.434 22.47 5.28 34.53 5.28 62.975 0 114.156-50.432 114.156-113.405 0-62.972-51.18-114.19-114.156-114.19zm-260.53 103.314 39.093 67.562c3.127-27.534 17.792-51.71 39-67.562h-78.095zm125.405 0c-38.53 5.45-68.186 38.596-68.186 78.625 0 11.152 2.282 21.772 6.437 31.405l1.064 1.844c36.87-18.726 62.156-56.763 62.156-101 0-3.67-.19-7.295-.53-10.876h-.94zm22.25 0c-.334 3.58-.53 7.206-.53 10.875 0 44.112 24.748 82.062 61.22 100.843l1.75-3.032a79.097 79.097 0 0 0 5.905-30.06c0-40.03-29.657-73.175-68.188-78.626h-.156zm47.47 0c21.134 15.798 35.742 39.864 38.938 67.28l38.937-67.28H316.25zm-58.5 109.28c-23.044 0-44.42 6.85-62.25 18.626.005.006-.005.025 0 .03 14.546 18.33 37.014 30.095 62.22 30.095 25.257 0 47.766-11.823 62.31-30.22-17.92-11.708-39.308-18.53-62.28-18.53zm-77.094 30.345c-22.37 20.864-36.312 50.707-36.312 83.81 0 62.974 50.43 113.408 113.406 113.408 62.975 0 114.156-50.434 114.156-113.407 0-33.095-14.16-62.915-36.72-83.78l-69.06 119.72-8.5 13.967-7.813-13.968-69.157-119.75zm38 28.936 38.97 67.344 38.905-67.22a97.13 97.13 0 0 1-38.81 8.064c-13.87 0-27.07-2.93-39.064-8.188z%22 fill=%22%23000000%22 fill-opacity=%221%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
    }
}

/* A Trait card's kind as an icon before its name, in the bar's text
   color, in place of a category chip: so far a Knowledge's mortarboard, a
   Language's speech bubbles, a Skill's pencil and wrench, an Ability's
   weightlifter or a Condition's figure in its viewfinder */
.sf-trait-card .sf-card-name > .sf-card-kind-icon {
    flex-shrink: 0;
    width: 1.3em;
    height: 1.15em;
    fill: currentColor;
}

/* A Trait card's Rank, after its kind's icon and before its name: the
   number in a rounded square, in the bar's text color with its border at
   30%, so it reads as a figure on the card rather than part of the name */
.sf-card-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    height: 1.5em;
    padding: 0 .3em;
    border: 1.5px solid color-mix(in srgb, currentColor 30%, transparent);
    border-radius: 5px;
    font-size: .8125em;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.sf-card-chips {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}

/* A card's paragraphs, .4rem above and below, as the creator sets them */
.sf-card-body p {
    margin: .4rem 0;
}

/* A card's note: where a Trait came from, how long a Condition lasts, what
   a Trait needs, small and muted */
.sf-card-note {
    margin: 0;
    color: var(--card-soft);
    font-size: .75rem;
}

/* ---- Trait cards ---- */

.sf-trait-card {
    display: flex;
    flex-direction: column;
    /* As much room under the bar as at the card's bottom */
    gap: 1rem;
    padding: 0 1rem 1rem;
    font-size: 14px;
    /* Tighter corners than other cards; the bar fits inside the 1px border */
    border-radius: 8px;
    /* The body in the default bar's dark gray, lit from the top and
       grained (the bar covers both) */
    background-color: var(--sf-gray-900);
    background-image:
        var(--sf-grain),
        var(--sf-grain-light);
    background-size: 200px 200px, auto;

    > .sf-card-bar {
        border-radius: 7px 7px 0 0;
    }

    > .sf-card-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        margin: 0 -1rem;
        padding: 10px 16px;
        font-size: 1rem;
        font-weight: 600;

        /* The kind's icon, the Rank, the setting's mark and the name in a
           row, spaced by the gap rather than each one's margin */
        > .sf-card-name {
            display: flex;
            align-items: center;
            gap: .45em;
            min-width: 0;

            > .setting-icon {
                margin-right: 0;
            }
        }
    }

    > .sf-card-body {
        display: flex;
        flex-direction: column;
        gap: .5rem;
        min-width: 0;
    }

    /* Conditions in grays: a mid gray edge, a light gray bar, dark text,
       and a lighter bracket at each corner, laid over the border */
    &.sf-trait-card--condition {
        --card-edge: var(--sf-gray-400);
        /* The bracket, a step darker than the light bar it sits on */
        --bracket: var(--sf-gray-300);
        --bracket-size: 22px;
        --bracket-width: 4px;

        /* The bar reaches out over the border at the top and sides, so its
           light gray is the card's edge around the header */
        > .sf-card-bar {
            position: relative;
            margin: -1px calc(-1rem - 1px) 0;
            border-radius: 8px 8px 0 0;
            background-color: var(--sf-gray-200);
            color: var(--sf-gray-800);
        }

        /* The bracket, at the top right corner only: a stroke that follows
           the card's rounded corner for --bracket-size each way, set 4px in
           from the card's edge, with the corner's own 8px curve */
        > .sf-card-bar::before {
            content: "";
            position: absolute;
            top: 4px;
            right: 4px;
            width: var(--bracket-size);
            height: var(--bracket-size);
            border: var(--bracket-width) solid var(--bracket);
            border-left: 0;
            border-bottom: 0;
            border-radius: 0 8px 0 0;
            pointer-events: none;
        }
    }
}

/* A Trait card's category and flags, a row of chips at the top of its
   body, and where it came from after them */
.sf-card-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;

    > .sf-card-note {
        margin: 0 0 0 4px;
    }
}

/* Its effect: a line for each part that does something different */
.sf-card-effect {
    margin: 0;
    font-size: .9rem;

    > p,
    > ul {
        margin: 0;
    }

    > * + * {
        margin-top: 4px;
    }

    > ul {
        padding-left: 1.25em;
    }

    li + li {
        margin-top: 2px;
    }
}

/* The Action a Trait grants, set off by a rule at its left */
.sf-card-action {
    margin: 0;
    padding-left: 10px;
    border-left: 2px solid var(--sf-gray-300);
    font-size: .9rem;

    > p {
        margin: 0;
    }

    /* A temporary weapon's badges, between the Action's lines */
    > .sf-card-action-badges {
        margin: 8px 0;
    }
}

/* A card that folds (fold): the chevron at the end of its bar opens and
   closes it, and is the only place that does. Closed, the card keeps what
   stays in view (.has-keep, like an Ability's effect), or is its bar
   alone, rounded all round. */
.sf-card-fold {
    flex: none;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    margin-left: 4px;
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;

    &:is(:hover, :focus-visible) {
        background: none;
        color: inherit;
    }
}

.sf-card-chevron {
    width: 12px;
    height: 8px;
    opacity: .4;
    transition: opacity 200ms, transform 200ms;

    .sf-card-fold:is(:hover, :focus-visible, [aria-expanded="true"]) > & {
        opacity: 1;
    }

    .sf-card-fold[aria-expanded="true"] > & {
        transform: rotate(180deg);
    }
}

.sf-card-more {
    display: contents;
}

.sf-card.is-closed .sf-card-more {
    display: none;
}

.sf-trait-card.is-closed:not(.has-keep) {
    gap: 0;
    padding-bottom: 0;

    /* The bar fills the card, as tall as the others in its row */
    > .sf-card-bar {
        flex: 1;
        border-radius: 7px;
    }

    /* A condition's bar covers the border, so it takes the card's own radius */
    &.sf-trait-card--condition > .sf-card-bar {
        border-radius: 8px;
    }

    > .sf-card-body {
        display: none;
    }
}

/* ---- Background cards: Kinds, Origins, Professions and Pasts ---- */

/* ---- Background cards (an Origin, Profession or Past): the Kind card's
   frame (below), with what the background gives as labeled rows of chips
   under its summary, each label in the Kind card's small capitals over
   its chips, then its features */
.sf-background-rows {
    display: grid;
    gap: 16px;
    margin: 20px 0 6px;

    > div {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px 6px;
    }

    > p,
    .sf-chip {
        margin: 0;
    }

    /* Its features, a little apart from the chips */
    > p:first-of-type {
        margin-top: 8px;
    }
}

.sf-background-label {
    /* On its own line, over its chips */
    flex-basis: 100%;
    margin-bottom: -2px;
    font-family: 'bebas_neueregular', sans-serif;
    font-size: .9375rem;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--key-label, var(--card-soft));
}

/* A Kind's or package's lore line, under its summary */
.sf-card-lore {
    color: var(--card-soft);
}

/* ---- Kind cards (KindCard; the site's sf_card_kind): a thin gunmetal
   border running in to a 2px line in the card's key color (silver, or
   Dreft's green for Isekai), with a large cut-out at the top left holding
   a star, around a
   dark field with a faded sun and planets. The frame is four corner pieces
   (one SVG, turned; only the top left has a star) joined by straight edges,
   so the card grows with its text. ---- */

.sf-kind-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.sf-kind-card {
    position: relative;
    /* The key color: silver for The Settled Systems (and anything else),
       Dreft's green for Isekai (sf-kind-card--dreft, below) */
    /* Every color here is from the palette (css/tokens.css and the
       component library's Colors): White, Text, Soft Text, Medium Gray,
       Condition Edge, Gray, Panel Box, Panel, Card, Card Edge, Dreft and
       Green */
    --key-label: var(--sf-gray-200);
    --key-soft: var(--sf-gray-100);
    --key-line: var(--sf-gray-600);
    --key-name: var(--sf-gray-100);
    /* The frame line's gradient, quieter than the text's key colors (the
       corner star's SVG gradient matches it: KIND_KEY_STOPS) */
    /* The frame line: solid Medium Gray (#949798) */
    --kind-line: var(--sf-gray-300);
    /* The field behind the content (Card Edge). Everything drawn on it is
       mixed into this color */
    --kind-field: var(--sf-gray-900);
    --kind-text: var(--sf-gray-100);
    --kind-muted: var(--sf-gray-300);
    /* The other cards' diffuse floating shadow (box-shadow: 0 4px 10px
       #00000030), as a drop-shadow so it follows the cut-out corner */
    --kind-shadow: drop-shadow(0 4px 10px #00000030);
    display: flex;
    flex-direction: column;
    /* Drop shadows on the whole card, so they follow the cut-out corner and
       fall only outside it; nothing inside casts its own */
    filter: var(--kind-shadow);
    color: var(--kind-text);
}

/* The plate: a thin band around the field that stops 40px short
   of the top left corner on both edges, leaving the field's cut-out and
   the star in it clear */
.sf-kind-plate {
    position: absolute;
    inset: 0;
    /* Curved about the same center as the frame line and the field inside
       it (17px, 6px in), so the band runs an even width around the corners */
    border-radius: 0 23px 23px;
    /* Solid Gray, so a page of cards stays calm */
    background: var(--sf-gray-500);
    -webkit-mask: linear-gradient(to right, transparent 40px, #000 40px), linear-gradient(to bottom, transparent 40px, #000 40px);
    mask: linear-gradient(to right, transparent 40px, #000 40px), linear-gradient(to bottom, transparent 40px, #000 40px);
}

.sf-kind-panel {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
}

/* The dark field inside the key-colored line, 6px in from the card's edge.
   A 24px quarter-circle is cut out of its top left corner (about the
   corner itself), and its other corners round off with the line's */
.sf-kind-field {
    position: absolute;
    inset: 6px;
    border-radius: 0 17px 17px;
    /* Lit from the top and grained like a Trait card's body, behind the art */
    background-color: var(--kind-field);
    background-image: var(--sf-grain), var(--sf-grain-light);
    background-size: 200px 200px, auto;
    -webkit-mask: radial-gradient(circle at 0 0, transparent 24px, #000 24.5px);
    mask: radial-gradient(circle at 0 0, transparent 24px, #000 24.5px);
    overflow: hidden;
    /* So the sky can size itself by the field's width (cqw) */
    container-type: inline-size;
    /* The browser skips drawing and animating the art while the card is
       off screen, so a long list of cards (the creator's Origins) only
       runs the ones in view */
    content-visibility: auto;
}

/* The sky: a faded sun half below the bottom of the field, rays fanning
   out from its middle to the top of the card, and a column of
   planets above it. The planets are the field's own color, so they show only
   by blocking the rays and by the crescent the sun lights along their bottom
   edge, thin at the sides and --lit thick at the bottom. All of it is
   sized in the field's width (cqw) and stacked up from the sun, so the gaps
   between them stay the same on cards of any height */
.sf-kind-sky { position: absolute; inset: 0; pointer-events: none; }
.sf-kind-rays {
    position: absolute;
    inset: 0;
    background: repeating-conic-gradient(from 0deg at 50% 100%, rgb(255 255 255 / 4.5%) 0 .6deg, transparent .6deg 4deg);
}
.sf-kind-sun {
    position: absolute;
    top: 100%;
    left: 50%;
    width: 44cqw;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: color-mix(in srgb, var(--sf-gray-200) 10%, var(--kind-field));
    box-shadow: 0 0 40px 6px rgb(255 255 255 / 4%);
}
.sf-kind-planet {
    position: absolute;
    left: 50%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: var(--kind-field);
    box-shadow: inset 0 calc(-1 * var(--lit, 2px)) 0 0 color-mix(in srgb, var(--sf-gray-200) 22%, transparent);
}

/* ---- The other Kind card backgrounds, kept as options (KindCard's
   `background`; sf_card_kind()'s): "compass", an eight-point compass over a
   faint starfield, "planet", a dark planet's disc under a dense starfield,
   and "orbits", a solar system's rings over the faint starfield, the
   default. The sun and planets ("sun") are above ---- */

/* The compass: two palette steps up from the field (Card Edge), Panel and
   Card, so no part of it is darker than its background */
.sf-kind-emblem {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 94%;
    height: 94%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
.sf-kind-rose-light { fill: color-mix(in srgb, var(--sf-gray-700) 75%, var(--kind-field)); }
.sf-kind-rose-dark { fill: color-mix(in srgb, var(--sf-gray-800) 75%, var(--kind-field)); }
.sf-kind-rose-ring { fill: none; stroke: color-mix(in srgb, var(--sf-gray-800) 75%, var(--kind-field)); }

/* The planet: a dark disc a little narrower than the card, centered in the
   lower part of the field behind the content, so its curve and both sides
   show before it runs off the bottom. Its edge is a faded silver line with a
   faint glow inside along the rim, so it reads as a sphere. It covers the
   stars behind it */
.sf-kind-globe {
    position: absolute;
    top: 58%;
    left: 50%;
    width: 86%;
    aspect-ratio: 1;
    transform: translateX(-50%);
    border-radius: 50%;
    background: var(--kind-field);
    border: 1.5px solid color-mix(in srgb, var(--sf-gray-200) 30%, transparent);
    box-shadow:
        inset 0 0 18px -6px color-mix(in srgb, var(--sf-gray-200) 22%, transparent),
        0 0 10px color-mix(in srgb, var(--sf-gray-200) 9%, transparent);
    pointer-events: none;
}

/* The orbits: the solar system's rings, sun and planets in one solid faded
   silver (mixed into the field's color, so the rings don't show through the
   planets), in an SVG twice the field's width centered on it, its lines 1px
   whatever its size */
.sf-kind-orbits {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200cqw;
    height: 200cqw;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
.sf-kind-orbits { --orbit: color-mix(in srgb, var(--sf-gray-200) 14%, var(--kind-field)); }
/* On Isekai cards the solar system is Dreft Shade, mixed into the field
   as far as the gray is */
.sf-kind-card--dreft .sf-kind-orbits { --orbit: color-mix(in srgb, var(--sf-green-850) 78%, var(--kind-field)); }
.sf-kind-orbit { fill: none; stroke: var(--orbit); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.sf-kind-orbit-sun, .sf-kind-orbit-planet { fill: var(--orbit); }
/* Each planet circles the sun, counterclockwise, in its own year (set on it
   as animation-duration) */
.sf-kind-orbit-turn {
    transform-box: view-box;
    transform-origin: 100px 100px;
    animation: sf-kind-orbit-turn 60s linear infinite;
}
@keyframes sf-kind-orbit-turn { to { transform: rotate(-360deg); } }
@media (prefers-reduced-motion: reduce) {
    .sf-kind-orbit-turn { animation: none; }
}

/* The starfields, after the site's night sky (css/rpg-night.css): dots that
   pulse slowly and a few four-pointed twinkles that flare now and then.
   The planet's dense one has larger dots */
.sf-kind-stars { position: absolute; inset: 0; pointer-events: none; opacity: .55; }
/* The dots in three layers, each pulsing as one a third of a beat apart
   (one animation per layer, not per dot) */
.sf-kind-dots {
    position: absolute;
    inset: 0;
    animation: sf-kind-pulse 6s ease-in-out infinite;
}
.sf-kind-dots:nth-child(2) { animation-delay: -2s; }
.sf-kind-dots:nth-child(3) { animation-delay: -4s; }
.sf-kind-dot {
    position: absolute;
    width: 1px;
    height: 1px;
    border-radius: 50%;
    background: var(--sf-gray-0);
}
.sf-kind-dot.is-big { width: 2px; height: 2px; }
.sf-kind-card--bg-planet .sf-kind-dot { width: 1.5px; height: 1.5px; }
.sf-kind-card--bg-planet .sf-kind-dot.is-big { width: 2.5px; height: 2.5px; }
.sf-kind-twinkle {
    position: absolute;
    width: 7px;
    height: 7px;
    margin: -3.5px 0 0 -3.5px;
    transform: scale(.35);
    animation: sf-kind-flare 12s ease-out infinite;
}
.sf-kind-twinkle::before, .sf-kind-twinkle::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(#fff4, #fffc, #fff4);
}
.sf-kind-twinkle::before { top: -100%; left: 45%; width: 10%; height: 300%; }
.sf-kind-twinkle::after { top: 45%; left: -100%; width: 300%; height: 10%; }
@keyframes sf-kind-pulse { 50% { opacity: .15; } }
@keyframes sf-kind-flare {
    0%, 100% { transform: scale(.35) rotate(0deg); opacity: .5; }
    6% { transform: scale(1) rotate(45deg); opacity: 1; }
    12% { transform: scale(.35) rotate(90deg); opacity: .5; }
}
@media (prefers-reduced-motion: reduce) {
    .sf-kind-dots, .sf-kind-twinkle { animation: none; }
}

.sf-kind-corner {
    position: absolute;
    width: 100px;
    height: 100px;
    pointer-events: none;
    color: var(--kind-line);
}
.sf-kind-corner--tl { top: 0; left: 0; }
.sf-kind-corner--tr { top: 0; right: 0; transform: scaleX(-1); }
.sf-kind-corner--bl { bottom: 0; left: 0; transform: scaleY(-1); }
.sf-kind-corner--br { bottom: 0; right: 0; transform: scale(-1); }

/* The straight edges between the corners: the 2px key-colored line 6px in from
   the card's edge, matching the corner pieces */
.sf-kind-edge { position: absolute; pointer-events: none; }
.sf-kind-edge--top, .sf-kind-edge--bottom {
    left: 100px;
    right: 100px;
    height: 2px;
    background: var(--kind-line);
}
.sf-kind-edge--top { top: 5px; }
.sf-kind-edge--bottom { bottom: 5px; }
.sf-kind-edge--left, .sf-kind-edge--right {
    top: 100px;
    bottom: 100px;
    width: 2px;
    background: var(--kind-line);
}
.sf-kind-edge--left { left: 5px; }
.sf-kind-edge--right { right: 5px; }

.sf-kind-content {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 28px 22px 20px;
    container-type: inline-size;
    font-size: .875rem;
    line-height: 1.5;
}

.sf-kind-name {
    margin: 0 0 8px;
    font-family: 'bebas_neueregular', sans-serif;
    font-size: 2.5rem;
    font-weight: 400;
    letter-spacing: .04em;
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
    color: var(--key-name);
}

.sf-kind-summary {
    margin: 0;
    font-style: italic;
    text-align: center;
    color: var(--kind-text);
}

.sf-kind-label {
    display: block;
    margin-bottom: 4px;
    font-family: 'bebas_neueregular', sans-serif;
    font-size: .9375rem;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--key-label);
}

/* The three groups as wide as their stats, the row's spare room shared
   evenly before, between and after them (at least 16px between), so they
   stay centered and inside the padding at any card width */
.sf-kind-stats {
    display: grid;
    grid-template-columns: repeat(3, auto);
    justify-content: space-evenly;
    gap: 12px 16px;
    margin: 24px -15px;
    padding: 8px 16px;
    font-size: 1rem;
}
/* On a narrow card, the groups stack */
@container (max-width: 280px) {
    .sf-kind-stats { gap: 8px 16px; font-size: .875rem; }
}
@container (max-width: 230px) {
    .sf-kind-stats { grid-template-columns: 1fr; max-width: 180px; margin-inline: auto; }
}
.sf-kind-stats .sf-kind-label--physical { color: var(--sf-red-500); }
.sf-kind-stats .sf-kind-label--social { color: var(--sf-purple-500); }
.sf-kind-stats .sf-kind-label--mental { color: var(--sf-yellow-400); }
/* Each stat's label and number 24px apart, the labels as wide as the
   widest (MEM), so the numbers line up */
.sf-kind-stat { display: flex; gap: 24px; }
.sf-kind-stat abbr { min-width: 1.75em; }
.sf-kind-stat abbr { font-family: 'bebas_neueregular', sans-serif; letter-spacing: .06em; text-decoration: none; cursor: help; }
.sf-kind-num { font-variant-numeric: tabular-nums; color: var(--key-soft); }
.sf-kind-num span { color: var(--kind-muted); }

.sf-kind-grants { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; margin-bottom: 14px; }
/* Its Grants are the cards' usual accent chips */
.sf-kind-grants .sf-chip { margin: 0; }
/* Its label on its own line, over the chips, as on Background cards */
.sf-kind-grants .sf-kind-label { flex-basis: 100%; margin: 0 0 -2px; }
.sf-kind-features { margin: 0 0 18px; padding: 0; list-style: none; }
.sf-kind-features li { margin-bottom: 8px; }
.sf-kind-features strong { color: var(--key-soft); }

/* "Kind ✦ The Settled Systems" (or Isekai) over the name */
.sf-kind-setting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 10px;
    font-family: 'bebas_neueregular', sans-serif;
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: .1em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--key-label);
}
.sf-kind-setting span { font-size: .625rem; }

/* Isekai's cards key on the palette's greens: Dreft (#1c372b) and Green
   (#47b767) */
.sf-kind-card--dreft {
    --kind-line: var(--sf-green-700);
    --key-label: var(--sf-green-500);
    --key-line: var(--sf-green-900);
}
/* Isekai's band is Dreft, under the lighter Dreft Mid line, as Settled
   Systems' Gray sits under Medium Gray */
.sf-kind-card--dreft .sf-kind-plate {
    background: var(--sf-green-900);
}
@media (max-width: 480px) {
    .sf-kind-content { padding: 26px 18px 18px; }
    .sf-kind-setting { gap: 6px; font-size: .875rem; letter-spacing: .06em; }
}

/* A Kind to pick (the creator's Character step): a green ring and a check
   on its corner while picked, as the other cards' */
.sf-kind-card.is-selectable { cursor: pointer; }
.sf-kind-card.is-selectable:hover:not(.selected),
.sf-kind-card.is-selectable:focus-visible { filter: drop-shadow(0 0 1px var(--sf-gray-300)) drop-shadow(0 0 1px var(--sf-gray-300)) drop-shadow(0 0 1px var(--sf-gray-300)) var(--kind-shadow); outline: none; }
.sf-kind-card.selected { filter: drop-shadow(0 0 1px var(--sf-green-500)) drop-shadow(0 0 1px var(--sf-green-500)) drop-shadow(0 0 1.5px var(--sf-green-500)) var(--kind-shadow); }
.sf-kind-card.selected::after {
    content: "✓";
    position: absolute;
    top: -12px;
    right: -12px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sf-green-500);
    color: var(--sf-gray-0);
    font-size: .9rem;
    font-weight: 600;
}

/* Its lore line, under the summary (in the popup) */
.sf-kind-lore { margin: -8px 0 16px; text-align: center; color: var(--kind-muted); }

/* ---- Item cards: the Traits' black with a warm olive edge ---- */

.sf-item-card {
    position: relative;
    container: item / inline-size;
    width: 100%;
    padding: 12px;
    background-color: var(--card-bg);
    border: 1px solid var(--sf-olive-600);
    border-radius: 12px;
    box-shadow: 0 4px 10px #00000030;
    font-size: 14px;

    /* Bites scooped out of its corners, so it reads apart from a Trait card
       (corner-shape; browsers without it keep the plain corners) */
    @supports (corner-shape: scoop) {
        border-radius: 6px;
        corner-shape: scoop;
    }

    /* With a count, 10px more on the left, clear of its circle on the
       card's edge; without one, even on both sides */
    &:has(> .sf-item-count) {
        padding-left: 22px;
    }

    /* Its fields in a darker olive to match */
    :is(input:not([type="checkbox"]), select) {
        background-color: var(--sf-olive-900);
    }

    p {
        margin: 0;
    }
}

/* Its chips, and a Cast Action's badges in a Trait card: the fields' dark
   olive with the card's edge and a pale olive text */
:is(.sf-item-card, .sf-card-action-badges) .chip {
    display: inline-block;
    padding: .2rem .5rem;
    background-color: var(--sf-olive-900);
    border: 1px solid var(--sf-olive-600);
    border-radius: 4px;
    color: var(--sf-olive-100);
    font-size: .875rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Its top line: Equip, the name and its badges, the chevron. One line once
   the card has the room for the name at its smallest and the category
   shrunk to 5.5rem (357px); wrapping in narrower cards. */
.equipment-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;

    @container item (width >= 357px) {
        flex-wrap: nowrap;
    }

    select {
        flex: 0 1 auto;
        min-width: 5.5rem;

        @container item (width < 440px) {
            flex-basis: 6rem;
        }
    }
}

.sf-item-card .sf-item-summary {
    flex-wrap: nowrap;
}

/* With badges, the top line is a badge tall (1lh + .4rem + 2px, worked out here so the chevron's own line height
   doesn't change it). Equip, the name and the chevron each take that
   height, so they stay on the name's line when the badges wrap under it,
   instead of centering on the taller card. */
@property --sf-item-line {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
}

.sf-item-card .sf-item-summary:has(.equipment-stat) {
    --sf-item-line: calc(1lh + .4rem + 2px);
    align-items: flex-start;

    > :is(.sf-item-equip, .sf-item-expand) {
        height: var(--sf-item-line);
    }

    .sf-item-main > .equipment-name {
        line-height: var(--sf-item-line);
    }
}

/* The name and its badges between Equip and the chevron: the name takes what
   its line leaves, the badges sit at the right, and they wrap under it one
   at a time as the room runs out, still at the right */
.sf-item-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 6px 8px;

    > .equipment-name {
        flex: 1 1 auto;
    }
}

.equipment-name {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;

    /* The Rank it was made at, in a Trait card's square (.sf-card-rank),
       before the name with a Trait card's gap */
    > .sf-card-rank {
        margin-right: .45em;
        vertical-align: .1em;
    }
}

/* How many (count), in a circle on the card's left edge, a set distance
   down so it stays put when the card opens */
.sf-item-count {
    position: absolute;
    top: 14.15px;
    left: -14px;
    display: grid;
    place-items: center;
    box-sizing: border-box;
    min-width: 26px;
    height: 26px;
    padding: 0 5px;
    background-color: var(--card-bg);
    border: 2px solid var(--sf-olive-600);
    border-radius: 13px;
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1;
}

/* Without Equip, the top line is a name or badge tall (24px) instead of
   Equip's 30px, so the count sits higher to stay centered on it */
.sf-item-card:not(:has(.sf-item-equip)) > .sf-item-count {
    top: 11px;
}

/* Equip (equip): an 18px box in the fields' dark olive, filling pale olive
   with a dark check when it's on. Read-only, it's the same box, disabled. */
.sf-item-equip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    /* Bootstrap's label margin would push it off the name's line */
    margin: 0;
    cursor: pointer;

    input[type="checkbox"] {
        appearance: none;
        flex: none;
        width: 18px;
        height: 18px;
        margin: 0;
        background-color: var(--sf-olive-900);
        border: 1px solid var(--sf-olive-600);
        border-radius: 4px;
        cursor: pointer;
        transition: background-color 150ms, border-color 150ms;

        &:hover:not(:disabled) {
            border-color: var(--sf-olive-400);
        }

        &:focus-visible {
            outline: 2px solid var(--sf-olive-400);
            outline-offset: 2px;
        }

        &:checked {
            background-color: var(--sf-olive-300);
            border-color: var(--sf-olive-300);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%2325241e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
            background-size: 14px;
            background-position: center;
            background-repeat: no-repeat;
        }

        &:disabled {
            opacity: 1;
            cursor: default;
        }
    }

    &:has(input:disabled) {
        cursor: default;
    }

    /* Its label, for screen readers */
    .sf-item-equip-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* The card's icon buttons: faded like the sheet's pens and full strength
   under the pointer or while the card is open */
.sf-item-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    opacity: .4;
    transition: opacity 200ms;

    &:is(:hover, :focus-visible, [aria-expanded="true"]) {
        background: none;
        color: inherit;
        opacity: 1;
    }

    svg {
        width: 14px;
        height: 16px;
        fill: currentColor;
    }
}

/* The chevron (fold), pointing up while open. It's the only place that
   opens and closes the card. */
.sf-item-icon.sf-item-expand {
    svg {
        width: 12px;
        height: 8px;
        fill: none;
        transition: transform 200ms;
    }

    &[aria-expanded="true"] svg {
        transform: rotate(180deg);
    }
}

.sf-item-more {
    display: contents;
}

.sf-item-card.is-closed .sf-item-more {
    display: none;
}

/* Its damage, range, area and resistances as badges. On the top line their
   wrappers step aside, so each badge lays out on its own in .sf-item-main. */
.sf-item-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.sf-item-summary :is(.sf-item-badges, .sf-item-badge-group) {
    display: contents;
}

.sf-item-badge-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

/* One badge holds each value, an icon then its number, 10px apart */
:is(.sf-item-card, .sf-card-action-badges) .chip.equipment-stat {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
}

.equipment-stat-value {
    display: inline-flex;
    align-items: center;
    gap: 4px;

    :is(.icon, .damage-icon) {
        width: 1.1em;
        height: 1.1em;
        margin: 0;
        fill: currentColor;
    }
}

/* A badge's lead: a circle of the checkbox's pale olive with a dark olive
   crosshairs, sword, arc, burst or shield, standing in for the badge's left
   edge. The badge is a pill: both ends rounded to the lead's circle, the
   right one mirroring the left, with room for its number to clear the
   curve. */
:is(.sf-item-card, .sf-card-action-badges) .chip.equipment-stat:has(> .item-stat-lead) {
    flex-wrap: nowrap;
    padding-top: 0;
    padding-right: .75rem;
    padding-bottom: 0;
    padding-left: 0;
    border-radius: calc((1lh + .4rem + 2px) / 2);
}

.item-stat-lead {
    display: grid;
    place-items: center;
    flex: none;
    width: calc(1lh + .4rem + 2px);
    height: calc(1lh + .4rem + 2px);
    margin: -1px -4px -1px -1px;
    background-color: var(--sf-olive-300);
    border-radius: 50%;

    :is(.icon, svg) {
        width: 1rem;
        height: 1rem;
        fill: var(--sf-olive-900);
    }
}

/* "or" between a damage choice's options, inside the badge */
.equipment-stat-or {
    color: var(--sf-olive-400);
    font-weight: 400;
}

/* A chassis (ChassisCard): under its description, a rule, then its
   Physical stats, its Attacks and the Traits it gives, 12px apart. Its HP
   sit on its top line in the MP readout's style (.equipment-mp). The stat
   block keeps its own colors on the card's black; its groups sit 16px
   apart here. */
.sf-chassis {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--sf-olive-600);

    .sf-stats {
        gap: 16px;
    }
}

.sf-chassis-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sf-chassis-label {
    margin: 0;
    color: var(--sf-olive-100);
    font-size: .75rem;
    font-weight: 600;
}

/* An open card's chips the top line leaves out: its category, then its
   value, how it Attacks and the slot it takes */
.equipment-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

/* Edit (edit), and Remove in edit mode: circles half outside the card's
   right edge, in the checkbox's pale olive with a dark olive icon. Edit sits
   on the chips' line under the top line; Remove 8px under it. */
.sf-item-edge {
    position: absolute;
    right: -14px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    background-color: var(--sf-olive-300);
    border: 2px solid var(--sf-olive-600);
    border-radius: 50%;
    color: var(--sf-olive-900);
    cursor: pointer;
    transition: background-color 200ms;

    &:is(:hover, :focus-visible) {
        background-color: var(--sf-olive-100);
        color: var(--sf-olive-900);
    }

    svg {
        width: 11px;
        height: 13px;
        fill: currentColor;
    }
}

.sf-item-edit {
    top: 54.45px;

    &[aria-expanded="true"] {
        background-color: var(--sf-olive-100);
    }

    .pen-icon {
        width: 13px;
        height: 13px;
        opacity: 1;
    }
}

.sf-item-remove {
    top: calc(54.45px + 26px + 8px);
}

/* Edit's fields, clear of the circles at the card's edge */
.sf-item-fields {
    margin-top: 10px;
    padding-right: 12px;
}

.sf-item-name-field {
    flex: 1 1 0;
    min-width: 3rem;
}

/* Note (note): a pen and its label at the card's bottom, faded until
   pointed at or open, opening the notes field at its right */
.sf-item-note-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    font-size: .875rem;
    cursor: pointer;
    opacity: .6;
    transition: opacity 200ms;

    &:is(:hover, :focus-visible, [aria-expanded="true"]) {
        background: none;
        color: inherit;
        opacity: 1;
    }

    svg {
        width: 16px;
        height: 14px;
        fill: currentColor;
    }
}

/* Its description, in italics, then its rules, under its chips */
.sf-item-stock {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
    font-size: .875rem;
}

.sf-item-card .equipment-description {
    margin: 0;
    color: var(--card-text);
    font-size: inherit;
    font-style: italic;
}

.sf-item-card .equipment-effect {
    margin: 0;
    color: var(--card-soft);
    font-size: inherit;
}

/* An enchanted Item's stored MP, on its top line: current over maximum in
   Bebas, the maximum muted */
.equipment-mp {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    font-family: 'bebas_neueregular', sans-serif;
    font-weight: 400;
    line-height: 1;

    .resource-name {
        font-size: 20px;
        font-weight: 400;
    }

    .num {
        font-size: 24px;
    }

    .muted {
        color: var(--card-soft);
    }
}

/* HP or MP with − and + (ItemResource): the name, −, the value over its
   max, +, centered on one line like the sheet's trackers, the buttons the
   smallest round ones */
.equipment-resource {
    align-items: center;
    flex: none;

    .sf-btn {
        flex: none;
    }
}

/* A damage formula's total, muted after it */
.sf-damage-total {
    color: var(--sf-olive-400);
    font-weight: 400;
}
