/* ========================================
   STRANGE FRONTIERS NPC AND MONSTER SHEET
   ========================================
   The short-form sheets, two components drawn alike for now: the NPC
   sheet (php/rpg/components/npc-sheet.php, .sf-npc--npc) and the monster
   sheet (php/rpg/components/monster-sheet.php, .sf-npc--monster). Rules on
   .sf-npc are both's; style one apart with its own class. Each has the
   name and what it is with Movement, the Stats as on a Kind card with live HP, VP,
   SP and MP beside them, then Items and Traits as cards. The full character sheet's sibling (css/sf-sheet.css): the same
   dark panel and grays, cut down to what a GM needs at the table.

   It carries its own colors, so it looks the same in a lore entry, a popup
   or a light section. */

/* Sheets listed one after another, like the encounters in the component
   library, get the same room as a content-stack */
:not(.content-stack, .sf-npc-grid) > .sf-npc + .sf-npc {
	margin-top: 48px;
}

/* Sheets in half-width columns: two across, the same gaps as split-cols
   (css/rpg.css), one column at 959px and below */
.sf-npc-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-items: start;
	gap: 48px 40px;

	@media (max-width: 959px) {
		grid-template-columns: minmax(0, 1fr);
	}
}

.sf-npc {
    --npc-frame: var(--panel-box, var(--sf-gray-600));
    --npc-box: var(--panel, var(--sf-gray-700));
    /* The description's darker box */
    --npc-well: var(--portfolio-black, var(--sf-gray-800));
    --npc-edge: var(--card-border, var(--sf-gray-400));
    --npc-text: var(--panel-text, var(--sf-gray-100));
    --npc-soft: var(--panel-soft, var(--sf-gray-200));
    --npc-rule: rgb(255 255 255 / 18%);
    /* The frame's band and line (see the frame, below) */
    --npc-plate: var(--sf-gray-500);
    --npc-line: var(--sf-gray-300);
    container: npc / inline-size;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 1rem;
    /* ---- The frame, as on the character sheet (css/sf-sheet.css): a 6px
       band in Gray that stops 40px short of the top right corner on both
       edges, then a 2px line in Medium Gray just inside it, with a 24px
       quarter-circle cut out of the top right corner, the line following
       it, and the star in it (::before) ---- */
    border: 1px solid transparent;
    border-radius: 23px 0 23px 23px;
    background:
        linear-gradient(var(--npc-plate), var(--npc-plate)) left top / calc(100% - 40px) 40px no-repeat border-box,
        linear-gradient(var(--npc-plate), var(--npc-plate)) left bottom / 100% calc(100% - 40px) no-repeat border-box;
    color: var(--npc-text);
    font-family: 'Open Sans', sans-serif;

    /* The line and the fill inside it, cut out about the corner: the fill
       out to 25px, the line out to 23px. Drawn first, with everything in the
       sheet positioned (below), so it stays under the content without making
       the sheet a stacking context that would trap its popups. */
    &::before {
        content: "";
        position: absolute;
        inset: 4px;
        border: 2px solid transparent;
        border-radius: 18px 0 18px 18px;
        background:
            url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 15'%3E%3Cpath fill='%23949798' d='M7.5 0L9.15 5.85L15 7.5L9.15 9.15L7.5 15L5.85 9.15L0 7.5L5.85 5.85Z'/%3E%3C/svg%3E") right .5px top .5px / 15px 15px no-repeat border-box,
            radial-gradient(circle at calc(100% - 1px) 1px, transparent 25px, var(--npc-frame) 25.5px) padding-box,
            radial-gradient(circle at calc(100% - 1px) 1px, transparent 23px, var(--npc-line) 23.5px) border-box;
        background-origin: border-box;
        pointer-events: none;
    }

    /* The floating shadow (0 4px 10px at 19% black), following the frame's
       outline: its rounded corners, the 40px at the top right where the
       band stops, and the notch's arc. It's a blurred copy of that outline,
       cut away wherever the sheet is, drawn as a nine-slice border image
       around the sheet (corners kept, edges stretched), so it sits on top
       without covering anything. (A drop-shadow filter would follow the
       notch too, but would make the sheet a stacking context and trap its
       popups; a box-shadow follows the square box, not the notch.) */
    &::after {
        content: "";
        position: absolute;
        inset: -25px;
        border: 64px solid transparent;
        border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='148' height='148' viewBox='0 0 148 148'%3E%3Cdefs%3E%3Cfilter id='b' filterUnits='userSpaceOnUse' x='0' y='0' width='148' height='148'%3E%3CfeGaussianBlur stdDeviation='5'/%3E%3C/filter%3E%3Cmask id='m' maskUnits='userSpaceOnUse' x='0' y='0' width='148' height='148'%3E%3Crect width='148' height='148' fill='white'/%3E%3Cpath d='M47 24H84V64H124V101A23 23 0 0 1 101 124H47A23 23 0 0 1 24 101V47A23 23 0 0 1 47 24ZM47 29H95.02A23 23 0 0 0 119 52.98V101A18 18 0 0 1 101 119H47A18 18 0 0 1 29 101V47A18 18 0 0 1 47 29Z' fill='black'/%3E%3C/mask%3E%3C/defs%3E%3Cg mask='url(%23m)'%3E%3Cpath d='M47 24H84V64H124V101A23 23 0 0 1 101 124H47A23 23 0 0 1 24 101V47A23 23 0 0 1 47 24ZM47 29H95.02A23 23 0 0 0 119 52.98V101A18 18 0 0 1 101 119H47A18 18 0 0 1 29 101V47A18 18 0 0 1 47 29Z' transform='translate(0 4)' fill='black' fill-opacity='.19' filter='url(%23b)'/%3E%3C/g%3E%3C/svg%3E") 64 / 64px;
        pointer-events: none;
    }
}

/* The monster sheet's frame: the band in Monster Frame (teal-900) and the
   line just inside it in Monster Line (teal-800), a blue-leaning teal at
   the old reds' lightness and saturation, with a gold filigree inside
   that (below). Its field is Card Edge too, black
   like a tarot card's, with a filigree and noise in its corners (below),
   and 10px more room around the content for them. Its grays are the cool
   ones, as on the NPC sheet. The star in the corner is the filigree's gold
   (.sf-npc-fil-star, below). */
.sf-npc--monster {
    --npc-plate: var(--sf-teal-900);
    --npc-line: var(--sf-teal-800);
    --npc-frame: var(--sf-gray-900);
    padding: 26px;

    /* The top row's box cut away about the filigree's inner arc in the
       corner (the notch's center is 21px out from the box's corner) */
    .sf-npc-head {
        -webkit-mask: radial-gradient(circle at calc(100% + 21px) -21px, transparent 45px, #000 45.5px);
        mask: radial-gradient(circle at calc(100% + 21px) -21px, transparent 45px, #000 45.5px);
    }

    &::before {
        background:
            radial-gradient(circle at calc(100% - 1px) 1px, transparent 25px, var(--npc-frame) 25.5px) padding-box,
            radial-gradient(circle at calc(100% - 1px) 1px, transparent 23px, var(--npc-line) 23.5px) border-box;
        background-origin: border-box;
    }
}

/* ---- The monster sheet's filigree (php/rpg/components/npc-sheet.php's
   sf_npc_filigree()), after a tarot card's gold border, in Item Accent
   (olive-300): a 3px line inside the frame line, 12px in from the sheet's edge.
   Corner pieces (one SVG, flipped for each corner) cross it with short
   ticks; the top right's piece arcs it around the notch. Straight edges
   join them, so the sheet grows with its content, and a skull breaks it at
   the top's middle. ---- */
.sf-npc-filigree {
    position: absolute;
    inset: 0;
    color: var(--sf-olive-300);
    pointer-events: none;

    svg {
        position: absolute;
        overflow: visible;
        fill: none;
        stroke: currentColor;
        stroke-width: 1;
    }

    /* The line, 3px */
    .sf-npc-fil-outer {
        stroke-width: 3;
    }
}

/* The skull on the top line (the skull from game-icons.net's Burning Skull
   by Lorc, CC BY 3.0, without its flames), in the filigree's gold: 30px tall,
   centered on the line (13.5px in) at the sheet's middle, the line stopping
   about 11px short of it either side, its top past the frame's */
.sf-npc-filigree .sf-npc-fil-skull {
    top: -1.5px;
    left: calc(50% - 12.36px);
    width: 24.73px;
    height: 30px;
    fill: var(--sf-olive-300);
    stroke: none;
}

/* Its backing in the skull's outline, behind the eyes and nose (and a
   boss's skull, cut out of its flames) */
.sf-npc-filigree .sf-npc-fil-skull-back {
    fill: var(--sf-gray-900);
}

/* A boss's skull (.sf-npc--boss, 'boss' => true: the tough one in its
   threat band): the whole Burning Skull, its
   flames too, 52px and set high on the line, the flames rising well past
   the frame's top */
.sf-npc-filigree .sf-npc-fil-skull--flaming {
    top: -20px;
    left: calc(50% - 26px);
    width: 52px;
    height: 52px;
}

/* The star in the frame's notch, the NPC sheet's star in the filigree's
   gold, where the NPC sheet has it (15px, 4.5px in from the top right) */
.sf-npc-filigree .sf-npc-fil-star {
    top: 4.5px;
    right: 4.5px;
    width: 15px;
    height: 15px;
    fill: var(--sf-olive-300);
    stroke: none;
}

.sf-npc-fil-corner {
    width: 40px;
    height: 40px;

    &.sf-npc-fil-corner--tl { top: 0; left: 0; }
    &.sf-npc-fil-corner--bl { bottom: 0; left: 0; transform: scaleY(-1); }
    &.sf-npc-fil-corner--br { right: 0; bottom: 0; transform: scale(-1); }
    &.sf-npc-fil-corner--tr { top: 0; right: 0; width: 56px; height: 56px; transform: scaleX(-1); }
}

/* The edges: the line, 3px (12–15px in), the top one with a gap 20px
   either side of the sheet's middle for the skull (8px off its own center,
   since its right end clears the notch) */
.sf-npc-fil-edge {
    position: absolute;
    background: currentColor;

    &.sf-npc-fil-edge--top,
    &.sf-npc-fil-edge--bottom {
        left: 40px;
        right: 40px;
        height: 3px;
    }

    &.sf-npc-fil-edge--top {
        top: 12px;
        right: 56px;
        --fil-gap: calc(50% + 8px);
        /* Wider for a boss's flaming skull */
        --fil-skull-gap: 23px;
        -webkit-mask: linear-gradient(to right, #000 calc(var(--fil-gap) - var(--fil-skull-gap)), transparent 0 calc(var(--fil-gap) + var(--fil-skull-gap)), #000 0);
        mask: linear-gradient(to right, #000 calc(var(--fil-gap) - var(--fil-skull-gap)), transparent 0 calc(var(--fil-gap) + var(--fil-skull-gap)), #000 0);

        .sf-npc--boss & {
            --fil-skull-gap: 33px;
        }
    }

    &.sf-npc-fil-edge--bottom {
        bottom: 12px;
    }

    &.sf-npc-fil-edge--left,
    &.sf-npc-fil-edge--right {
        top: 40px;
        bottom: 40px;
        width: 3px;
    }

    &.sf-npc-fil-edge--left {
        left: 12px;
    }

    &.sf-npc-fil-edge--right {
        right: 12px;
        top: 56px;
    }
}

/* The monster sheet's wear: the gold filigree line (.sf-npc-filigree--line)
   worn through to the field's black in isolated splotches, as on an old
   printed tarot card. A mask over the line, one SVG tile (2000px): solid
   except for a coarse grain kept only inside a few large (250–500px),
   smooth, low-frequency noise blots, so most of the line stays clean. The
   band, the frame line, the skull and the star aren't worn. Not in print. */
.sf-npc-filigree--line {
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2000' height='2000'%3E%3Cfilter id='w' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.0025' numOctaves='2' seed='7' stitchTiles='stitch' result='b'/%3E%3CfeColorMatrix in='b' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 -4.4' result='blots'/%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.3' numOctaves='2' seed='3' stitchTiles='stitch' result='g'/%3E%3CfeColorMatrix in='g' values='0 0 0 0 .086 0 0 0 0 .094 0 0 0 0 .098 5 0 0 0 -2.2' result='grain'/%3E%3CfeComposite in='grain' in2='blots' operator='in' result='worn'/%3E%3CfeFlood flood-color='%23fff'/%3E%3CfeComposite in2='worn' operator='out'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E") 0 0 / 2000px 2000px;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2000' height='2000'%3E%3Cfilter id='w' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.0025' numOctaves='2' seed='7' stitchTiles='stitch' result='b'/%3E%3CfeColorMatrix in='b' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 -4.4' result='blots'/%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.3' numOctaves='2' seed='3' stitchTiles='stitch' result='g'/%3E%3CfeColorMatrix in='g' values='0 0 0 0 .086 0 0 0 0 .094 0 0 0 0 .098 5 0 0 0 -2.2' result='grain'/%3E%3CfeComposite in='grain' in2='blots' operator='in' result='worn'/%3E%3CfeFlood flood-color='%23fff'/%3E%3CfeComposite in2='worn' operator='out'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E") 0 0 / 2000px 2000px;

    @media print {
        -webkit-mask: none;
        mask: none;
    }
}

/* The noise in the monster sheet's corners, in gold: the night sky's
   sparse grain (css/rpg-night.css), denser and at 240px so each speck is
   a couple of pixels and shows its color, gathered in the
   field's bottom corners and thinning to a trace across the middle (none
   at the top, so the stars show there), as a
   tarot card's speckled black. The grain is a mask over a gold sheen, a
   diagonal of Item Accent (olive-300) and SP yellow (yellow-400), so the
   specks run from pale to bright gold across the sheet. The field inside
   the frame line, with its corners and notch. */
.sf-npc-dust {
    position: absolute;
    inset: 6px;
    border-radius: 16px 0 16px 16px;
    -webkit-mask: radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px);
    mask: radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px);
    pointer-events: none;

    &::before {
        content: "";
        position: absolute;
        inset: 0;
        background: linear-gradient(135deg, var(--sf-olive-300), var(--sf-yellow-400) 25%, var(--sf-olive-400) 50%, var(--sf-yellow-400) 75%, var(--sf-olive-300));
        /* The grain, kept only where the bottom corners (or the faint middle)
           are; none at the top, where the storm's stars show */
        -webkit-mask:
            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 3 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 240px 240px,
            radial-gradient(circle at 0 100%, #000, transparent 280px),
            radial-gradient(circle at 100% 100%, #000, transparent 280px),
            linear-gradient(transparent 20%, rgb(0 0 0 / 15%) 50%);
        -webkit-mask-composite: source-in, source-over, source-over, source-over;
        mask:
            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 3 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 240px 240px,
            radial-gradient(circle at 0 100%, #000, transparent 280px),
            radial-gradient(circle at 100% 100%, #000, transparent 280px),
            linear-gradient(transparent 20%, rgb(0 0 0 / 15%) 50%);
        mask-composite: intersect, add, add, add;
    }
}

/* ---- The storm background ('background' => 'storm', .sf-npc--bg-storm),
   on either sheet ---- */

/* The storm's night, behind its clouds: the field shades from Card
   Edge (gray-900, the darkest a component goes, to meet the clouds' deep
   shadows) at the top to its own Panel Box at the bottom, under a
   starscape (::before): the night sky's sparse grain (css/rpg-night.css,
   the cards' --sf-grain with only its brightest peaks showing), at the
   sky's 200px, fading out down the sheet. It covers the field inside the
   frame line (6px in), with its corners and notch. */
.sf-npc-night {
    position: absolute;
    inset: 6px;
    border-radius: 16px 0 16px 16px;
    background: linear-gradient(var(--sf-gray-900), var(--npc-frame) 75%);
    -webkit-mask: radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px);
    mask: radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px);
    pointer-events: none;

    &::before {
        content: "";
        position: absolute;
        inset: 0;
        background-image: 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 2.6 -1.95'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
        background-size: 200px 200px;
        -webkit-mask: linear-gradient(#000 20%, transparent 70%);
        mask: linear-gradient(#000 20%, transparent 70%);
    }
}

/* The storm's clouds, in the field behind the boxes: four
   cloud images (img/storm_cloud_dark_1–4.webp, on transparency) spread
   down the top of the sheet, two high and two lower, overlapping, over the
   night and its stars (.sf-npc-night). It covers the field inside the frame
   line (6px in), with its corners and notch, and fades out down the sheet.

   After Johan Lagerqvist's CodePen "Color Pop": the clouds tinted, their
   shading running from the field's own black (gray-900) up to #202728 at
   their lightest, so no edge reads darker than the field (baked into the
   images, from the white storm_cloud_1–4.webp), and glitched in short
   bursts (sf-glitch). Dark enough at full opacity to stay behind the
   sheet's content.

   Each cloud drifts sideways on its own slow loop (--sf-drift-1–4, 40px
   either way over 50–80s), stepped four times a second so the clouds
   aren't redrawn every frame; at that speed a step is a fraction of
   a pixel. Lightning lights them up now and then (.sf-npc-lightning).
   Still with reduced motion. */
@property --sf-drift-1 { syntax: "<length>"; inherits: true; initial-value: 0px; }
@property --sf-drift-2 { syntax: "<length>"; inherits: true; initial-value: 0px; }
@property --sf-drift-3 { syntax: "<length>"; inherits: true; initial-value: 0px; }
@property --sf-drift-4 { syntax: "<length>"; inherits: true; initial-value: 0px; }

@keyframes sf-drift-1 { from { --sf-drift-1: -40px; } to { --sf-drift-1: 40px; } }
@keyframes sf-drift-2 { from { --sf-drift-2: 40px; } to { --sf-drift-2: -40px; } }
@keyframes sf-drift-3 { from { --sf-drift-3: -40px; } to { --sf-drift-3: 40px; } }
@keyframes sf-drift-4 { from { --sf-drift-4: 40px; } to { --sf-drift-4: -40px; } }

.sf-npc-sky {
    /* The lightning script (php/javascript-loads.php's CLOUDS) mirrors these
       placements to start its bolts at the clouds' lower edges */
    --sf-npc-clouds:
        url("../img/storm_cloud_dark_3.webp") left calc(-12% + var(--sf-drift-1)) top 30% / 48% auto no-repeat,
        url("../img/storm_cloud_dark_4.webp") right calc(-14% + var(--sf-drift-2)) top 24% / 58% auto no-repeat,
        url("../img/storm_cloud_dark_2.webp") right calc(-10% + var(--sf-drift-3)) top 2% / 55% auto no-repeat,
        url("../img/storm_cloud_dark_1.webp") left calc(-16% + var(--sf-drift-4)) top 0 / 72% auto no-repeat;
    animation:
        sf-drift-1 50s steps(200) -13s infinite alternate,
        sf-drift-2 65s steps(260) -40s infinite alternate,
        sf-drift-3 80s steps(320) -22s infinite alternate,
        sf-drift-4 70s steps(280) -51s infinite alternate;
    position: absolute;
    inset: 6px;
    overflow: hidden;
    border-radius: 16px 0 16px 16px;
    -webkit-mask:
        radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px),
        linear-gradient(#000 35%, transparent 85%);
    -webkit-mask-composite: source-in;
    mask:
        radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px),
        linear-gradient(#000 35%, transparent 85%);
    mask-composite: intersect;
    pointer-events: none;

    /* The clouds, glitching in bursts */
    &::before {
        content: "";
        position: absolute;
        inset: 0;
        background: var(--sf-npc-clouds);
        animation: sf-glitch 40s step-end infinite;
    }
}

/* The glitch's bursts: the turbulence filter (#sf-color-pop, printed once a
   page by npc-sheet.php) on the clouds for 0.4s, then 0.25s 14s later, then
   0.35s 11s after that, on a 40s loop, and no filter between them: any SVG
   filter on the clouds makes the sheet several times costlier to draw. */
@keyframes sf-glitch {
    0% { filter: url(#sf-color-pop); }
    1% { filter: none; }
    35% { filter: url(#sf-color-pop); }
    35.625% { filter: none; }
    62.5% { filter: url(#sf-color-pop); }
    63.375% { filter: none; }
}

/* The color pop's filters, taking no room */
.sf-npc-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .sf-npc-sky {
        animation: none;
    }

    .sf-npc-sky::before {
        animation: none;
    }
}

/* The storm's lightning (after mnald12's CodePen "Lightning
   strike"): now and then a jagged bolt with a few branches drops from the
   clouds, and the clouds flash. Drawn on this canvas by the page's script
   (php/javascript-loads.php), in the field over the clouds and under the
   boxes, with the field's corners and notch, fading out further down the
   sheet than the clouds do. Only while the sheet is on screen, and never
   with reduced motion or in print. */
.sf-npc-lightning {
    position: absolute;
    inset: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    border-radius: 16px 0 16px 16px;
    -webkit-mask:
        radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px),
        linear-gradient(#000 45%, transparent 90%);
    -webkit-mask-composite: source-in;
    mask:
        radial-gradient(circle at calc(100% + 1px) -1px, transparent 25.5px, #000 26px),
        linear-gradient(#000 45%, transparent 90%);
    mask-composite: intersect;
    opacity: 0;
    pointer-events: none;

    @media print {
        display: none;
    }
}

/* The monster sheet's sections (the top row, description, Stats, Items and
   Traits boxes): no background at all, so the content sits straight on the
   field over the storm and noise, with only 8px of padding, since there's
   no box edge to keep the content off. */
.sf-npc--monster :is(.sf-npc-box, .sf-npc-description) {
    padding: 8px;
    background: none;
}

/* Positioned, so the sheet's boxes paint over its frame (::before) */
:where(.sf-npc > *) {
    position: relative;
}

/* The darker boxes, grained like the character sheet's: the strong grain
   (css/sf-cards.css) faded into the box gray over 48px at the sides and top
   and over the bottom half */
.sf-npc-box {
    min-width: 0;
    padding: 14px 16px;
    background-color: var(--npc-box);
    background-image:
        linear-gradient(to right, var(--npc-box), transparent 48px, transparent calc(100% - 48px), var(--npc-box)),
        linear-gradient(to bottom, var(--npc-box), transparent 48px, transparent 45%, var(--npc-box)),
        var(--sf-grain-strong);
    background-size: auto, auto, 200px 200px;
    border-radius: 12px;
}

/* ---- The name and what it is, then its resistances and Movement on the
   right, in a box like the sheet's other sections (.sf-npc-box) ---- */

.sf-npc-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    padding: 12px 16px;
    /* Its top right corner cut away around the frame's notch and star, with
       the same room the frame line keeps from it */
    -webkit-mask: radial-gradient(circle at calc(100% + 17px) -17px, transparent 40px, #000 40.5px);
    mask: radial-gradient(circle at calc(100% + 17px) -17px, transparent 40px, #000 40.5px);
}

/* The level blob, then the name and what it is */
.sf-npc-who {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* The level: the character sheet's blob (css/sf-sheet.css's
   .sf-sheet-level) at 56px, in the site's black, morphing and turning
   while its purple glow pulses, with a tiny "Level" over the number in
   Bebas. A pseudo-element, so the number stays upright; still with
   reduced motion. It overlays the sheet's top left corner, poking a
   little past its top and left edges, so it takes no room in the top
   row. */
.sf-npc-level {
    position: absolute;
    top: -18px;
    left: -18px;
    z-index: 2;
    isolation: isolate;
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    color: var(--npc-text);
    font-family: var(--title, 'bebas_neueregular');
    line-height: 1;

    &::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: -1;
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
        background-color: var(--npc-well);
        box-shadow: 0 0 5px 0 var(--sf-purple-400);
        animation:
            sf-sheet-blob-morph 8s ease-in-out infinite,
            sf-sheet-blob-spin 20s linear infinite,
            sf-sheet-blob-glow 3s ease-in-out infinite alternate;

        @media (prefers-reduced-motion: reduce) {
            animation: none;
        }
    }
}

/* A monster's threat level: in place of the blob, a sharp-cornered
   hexagon on the sheet's dark, turning slowly clockwise, with the Ready
   button's glitch (css/sf-buttons.css's sf-glitch-small-shift and
   sf-glitch-small-glow, the same animations). The glitch sits on its own layer
   (.sf-npc-threat-hex) so it stays level while the hexagon turns inside. */
.sf-npc-threat::before {
    content: none;
}

.sf-npc-threat-hex {
    position: absolute;
    inset: 0;
    z-index: -1;
    animation:
        sf-glitch-small-shift 4s ease-in-out infinite alternate,
        sf-glitch-small-glow 8s ease-in-out infinite alternate;

    /* A regular hexagon, point up, as tall as the blob (56px) */
    &::before {
        content: "";
        position: absolute;
        top: 0;
        left: calc(50% - 24.25px);
        width: 48.5px;
        height: 56px;
        background-color: var(--npc-well);
        clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
        animation: sf-npc-threat-spin 30s linear infinite;
    }

    @media (prefers-reduced-motion: reduce) {
        &,
        &::before {
            animation: none;
        }
    }
}

@keyframes sf-npc-threat-spin {
    to {
        transform: rotate(360deg);
    }
}

.sf-npc-level-label {
    margin-top: 2px;
    font-size: .625rem;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.sf-npc-level-number {
    font-size: 1.625rem;
}

.sf-npc-name {
    margin: 0;
    color: inherit;
    font-family: 'Open Sans', sans-serif;
    font-size: 20px;
    font-weight: 700;
    line-height: 24px;
}

.sf-npc-kind {
    /* A row of its own under the name, resistances and Movement */
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* What it is as keyword badges, styled like an item card's chips
   (css/sf-cards.css) */
.sf-npc-kind .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 resistances' shield badge, then Movement */
.sf-npc-aside {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    /* 32px across, so the resistances and Movement read as two things */
    gap: 8px 32px;
}

/* Its resistances as on the character sheet (css/sf-sheet.css's
   .sf-resistance-list): the shield, in the soft gray, then each damage
   type's icon and its number, bold, along a line */
.sf-npc-resistances {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 1.125rem;

    svg {
        flex: none;
        width: 1.35em;
        height: 1.35em;
        margin: 0;
        fill: currentColor;
    }
}

.sf-npc-resistances-icon {
    display: inline-flex;
    margin-right: -6px;
    color: var(--npc-soft);

    svg {
        width: 1em;
        height: 1em;
    }
}

.sf-npc-resistance {
    display: inline-flex;
    align-items: center;
    gap: 6px;

    > .sf-npc-value {
        font-weight: 700;
    }
}

/* Movement: the character sheet's person-running icon, then the distance */
.sf-npc-move {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 1.125rem;
}

.sf-npc-resource-name--move {
    display: inline-flex;
}

.sf-npc-move-icon {
    width: 1.1rem;
    height: 1.1rem;
    fill: currentColor;
}

.sf-npc-value {
    font-variant-numeric: tabular-nums;
}

/* The description, as the character sheet's description box (css/rpg.css's
   .sf-sheet-description): plain text on the darkest box with round
   corners, no title */
.sf-npc-description {
    padding: 9.6px 12px;
    background-color: var(--npc-well);
    border-radius: 16px;

    p {
        margin: 0;
        color: var(--npc-text);
        font-size: 14.4px;
        line-height: 1.5;
    }

    /* Until it's written */
    &.is-coming-soon p {
        color: var(--npc-soft);
        font-style: italic;
    }
}

/* ---- The Stats as on a Kind card (css/sf-cards.css's .sf-kind-stats),
   each group's resource under it: each group as wide as its tracker, from
   the left, wrapping when there's no room ---- */

.sf-npc-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 16px 32px;
    font-size: 1rem;

    /* With a Special Stat like Magic, four groups: two by two, each as
       wide as its widest column */
    &:has(> .sf-npc-group--magic) {
        display: grid;
        grid-template-columns: repeat(2, max-content);
    }
}

.sf-npc-group {
    --stat-color: var(--sf-neon-500);
    display: flex;
    flex-direction: column;
}

.sf-npc-group--physical { --stat-color: var(--sf-red-500); }
.sf-npc-group--social { --stat-color: var(--sf-purple-500); }
.sf-npc-group--mental { --stat-color: var(--sf-yellow-400); }
.sf-npc-group--magic { --stat-color: var(--sf-blue-400); }

/* The core Stat's name in its color, in Bebas like a Kind card's labels,
   with its number */
.sf-npc-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    color: var(--stat-color);
    font-family: 'bebas_neueregular', sans-serif;
    font-size: 1.125rem;
    letter-spacing: .08em;
    text-transform: uppercase;

    .sf-npc-value {
        color: var(--npc-text);
    }
}

/* Each focus Stat's name and its number, the numbers lined up on the
   right */
.sf-npc-stat {
    display: flex;
    justify-content: space-between;
    gap: 24px;
}

.sf-npc-stat-name {
    color: var(--npc-soft);
    font-family: 'bebas_neueregular', sans-serif;
    letter-spacing: .06em;
}

/* What Magic's points give, where the others list focus Stats */
.sf-npc-note {
    margin: 0;
    color: var(--npc-soft);
    font-size: .875rem;
}

/* Its resource under its focus Stats, live as in Player Tools: the name,
   −, the value over its max, + and restore to full on one line, and a
   meter in the resource's color under them. The page's script
   (php/javascript-loads.php) moves the value. */
.sf-npc-resource {
    display: grid;
    /* The name and restore take equal shares of the spare room at either
       end, so −, the value and + sit centered between them */
    grid-template-columns: 1fr auto auto auto 1fr;
    align-items: center;
    gap: 4px 6px;
    /* At the foot of its column, so the trackers line up even under Magic,
       which has no focus Stats */
    margin-top: auto;
    padding-top: 10px;
    font-size: 1.125rem;

    > .sf-npc-value {
        text-align: center;
        white-space: nowrap;
    }
}

/* A half-width sheet (under 640px, as in .sf-npc-grid): Physical, Social
   and Mental in one row of three equal columns, or two by two when a
   Special Stat like Magic makes a fourth. Each focus Stat's number sits
   closer to its name so a column holds it. */
@container npc (max-width: 640px) {
    .sf-npc-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px 12px;

        &:has(> .sf-npc-group--magic) {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }

    /* Each group measures its own width, for its tracker below */
    .sf-npc-group {
        container: npc-group / inline-size;
    }

    .sf-npc-stat {
        gap: 8px;
    }
}

/* A phone-width sheet, too narrow for three columns: one group per row */
@container npc (max-width: 340px) {
    .sf-npc-stats,
    .sf-npc-stats:has(> .sf-npc-group--magic) {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* A group too narrow for its tracker on one line (under 176px: a third of
   a half-width sheet, or a quarter when two by two): the resource's name
   with − and + centered beside it, restore under the name and the value
   under − and +, then the meter */
@container npc-group (max-width: 175px) {
    .sf-npc-resource {
        grid-template-columns: 1fr auto auto 1fr;
        column-gap: 3px;
        grid-template-areas:
            "name less more ."
            "full value value ."
            "meter meter meter meter";

        > .sf-npc-resource-name { grid-area: name; justify-self: start; }
        > .sf-npc-value { grid-area: value; justify-self: center; white-space: nowrap; }
        > .sf-npc-step:nth-of-type(1) { grid-area: less; }
        > .sf-npc-step:nth-of-type(2) { grid-area: more; }
        > .sf-npc-restore { grid-area: full; justify-self: start; }
        > .sf-npc-meter { grid-area: meter; }
    }
}

.sf-npc-resource--hp { --resource-color: var(--sf-red-500); }
.sf-npc-resource--vp { --resource-color: var(--sf-purple-500); }
.sf-npc-resource--sp { --resource-color: var(--sf-yellow-400); }
.sf-npc-resource--mp { --resource-color: var(--sf-blue-400); }

.sf-npc-resource-name {
    color: var(--resource-color);
}

.sf-npc-max {
    color: var(--npc-soft);
    font-size: .875rem;
}

/* Above its max (a boss given extra), the value takes the resource's color */
.sf-npc-resource.is-over .sf-npc-current {
    color: var(--resource-color);
}

.sf-npc-step-icon {
    width: .75em;
    height: .75em;
    fill: currentColor;
}

/* Restore to full: just its icon at the right end of the line, faded so
   − and + lead, and full strength under the pointer. Disabled at full. */
.sf-npc-restore {
    justify-self: end;
    color: var(--npc-soft);

    &:hover:not(:disabled) {
        color: var(--npc-text);
    }

    &:disabled {
        opacity: .35;
    }
}

.sf-npc-meter {
    grid-column: 1 / -1;
    height: 3px;
    background: rgb(255 255 255 / 12%);

    > span {
        display: block;
        height: 100%;
        background: var(--resource-color, var(--sf-neon-500));
        transition: width 200ms;
    }
}

/* ---- Items (Attacks first) and Traits ---- */

/* A box's title, with a rule running out to the right */
.sf-npc-title {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 0 0 12px;
    color: inherit;
    font-family: 'Open Sans', sans-serif;
    font-size: 1.125rem;
    font-weight: 300;

    &::after {
        content: "";
        flex: 1;
        height: 1px;
        background-color: var(--npc-rule);
    }
}

/* Every box's cards share one grid of columns at least 360px wide: two
   across on a wide sheet, one on a narrow one, so a lone Trait card is as
   wide as an Attack card beside it */
.sf-npc-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr));
    align-items: start;
    /* 24px across, so an Item's count badge, hanging 13px off its card's
       left edge, clears the card beside it */
    gap: 12px 24px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* A scrolling list (the character sheet's .sf-sheet-scroll): room for the
   Item cards' count circles, hanging 13px past their left edge, and for
   Condition cards' headers, which a scrolling list would clip; the margins
   give the room back so nothing moves */
.sf-npc-cards.sf-sheet-scroll,
.sf-npc-scroll.sf-sheet-scroll {
    padding: 2px 14px;
    margin: -2px -14px;
}

/* The Traits: columns as wide as the grid's (at least 360px, 24px apart),
   each running top to bottom, so a short card doesn't leave a gap beside a
   long one. A card stays whole in its column. */
.sf-npc-cards--columns {
    display: block;
    column-width: 360px;
    column-gap: 24px;

    > li {
        break-inside: avoid;
    }

    /* 12px between cards; at the top of a column the break drops it */
    > li + li {
        margin-top: 12px;
    }
}

/* ---- The wide layout ('layout' => 'wide'), for a sheet on a full-width
   row: the name, description and Stats in the first column, the Items and
   Traits in the second, each column its own top to bottom. Each column
   measures itself as the sheet (container npc), so it lays out like a
   half-width sheet. Under 720px, one column again. ---- */
.sf-npc-cols {
    display: grid;
    /* 6 to 4: the name, description and Stats get the wider column */
    grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
    align-items: start;
    gap: 12px 24px;

    @container npc-wide (max-width: 719px) {
        grid-template-columns: minmax(0, 1fr);
    }
}

.sf-npc-col {
    container: npc / inline-size;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

/* The wide sheet also answers to npc-wide, so the rules below can ask how
   wide the whole sheet is from inside a column (which is npc itself) */
.sf-npc--wide {
    container-name: npc npc-wide;
}

/* Side by side, the top row sits clear of the frame's notch, so it keeps
   its whole box; the Items box under the notch takes the cut instead */
@container npc-wide (min-width: 720px) {
    .sf-npc--wide .sf-npc-head {
        -webkit-mask: none;
        mask: none;
    }

    .sf-npc--wide .sf-npc-col + .sf-npc-col > :first-child {
        -webkit-mask: radial-gradient(circle at calc(100% + 17px) -17px, transparent 40px, #000 40.5px);
        mask: radial-gradient(circle at calc(100% + 17px) -17px, transparent 40px, #000 40.5px);
    }

    .sf-npc--monster.sf-npc--wide .sf-npc-col + .sf-npc-col > :first-child {
        -webkit-mask: radial-gradient(circle at calc(100% + 21px) -21px, transparent 45px, #000 45.5px);
        mask: radial-gradient(circle at calc(100% + 21px) -21px, transparent 45px, #000 45.5px);
    }
}

/* Printed, it goes light, with dark text */
@media print {
    .sf-npc-night,
    .sf-npc-sky,
    .sf-npc-dust {
        display: none;
    }

    .sf-npc {
        --npc-frame: var(--sf-gray-50);
        --npc-box: var(--sf-gray-0);
        --npc-well: var(--sf-gray-50);
        --npc-edge: var(--sf-gray-100);
        --npc-text: var(--sf-gray-800);
        --npc-soft: var(--sf-gray-500);
        --npc-rule: rgb(0 0 0 / 15%);
        --npc-plate: var(--sf-gray-100);
        --npc-line: var(--sf-gray-300);
        box-shadow: none;

        &::after {
            display: none;
        }
    }

    .sf-npc-box {
        border: 1px solid var(--npc-edge);
    }

    .sf-npc-level::before,
    .sf-npc-threat-hex,
    .sf-npc-threat-hex::before {
        animation: none;
    }

    /* Printed, just the value, with room left to write it in */
    .sf-npc-step,
    .sf-npc-restore,
    .sf-npc-meter {
        display: none;
    }
}
