/* philKit.sheets: pause, options and result in the game's own materials.
   This file standardises STRUCTURE, TIMING and BEHAVIOUR. It never decides the LOOK: every game sets the skin below
   as custom properties on its sheets host (philKit.sheets({ skin: { '--kit-font': ... } })) or on :root.
   Relative url()s in a custom property resolve against THIS stylesheet, so a skin always uses absolute paths:
   --kit-panel: url(/play/mygame/art/ui-panel.webp);

   SKIN TOKENS (all optional; the fallbacks are materials built from the palette, never the system look)
   Type          --kit-font  --kit-ink  --kit-ink-soft  --kit-title-ink  --kit-title-shadow
   Painted       --kit-panel + --kit-panel-slice + --kit-panel-edge          nine-slice image, border-image style
                 --kit-button, --kit-button-quiet + --kit-button-slice + --kit-button-edge
                 --kit-ribbon + --kit-ribbon-slice ("55 110") + --kit-ribbon-edge ("13px 34px")
                 --kit-switch-off, --kit-switch-on (whole-switch images) + --kit-switch-w + --kit-switch-h
                 --kit-frame + --kit-frame-slice + --kit-frame-edge          hollow picture frame laid over the hero and the pause emblem
                 --kit-star-on, --kit-star-off                                 star sprites (lit / unlit)
   Palette       --kit-paper --kit-paper-hi --kit-paper-lo --kit-edge --kit-edge-deep      panel face and rim
                 --kit-accent --kit-accent-hi --kit-accent-deep --kit-accent-ink           the primary material
                 --kit-quiet --kit-quiet-deep --kit-quiet-ink                              the quiet material
                 --kit-on --kit-off --kit-knob                                             switch
                 --kit-star --kit-star-deep --kit-star-dim                                 drawn stars
   Stage         --kit-veil  --kit-sheet-w  --kit-hero-edge  --kit-hold  --kit-z  --kit-ease
   Without painted images the sheet falls back to gradient + inner highlight + a pressed state that travels. */

.pk-host {
  --kit-font: Georgia, 'Times New Roman', serif;
  --kit-ink: #3b2a1c; --kit-ink-soft: #6b5440; --kit-title-ink: #4a2d10; --kit-title-shadow: rgba(255, 244, 214, .55);
  --kit-paper: #f6e7c8; --kit-paper-hi: #fff4dc; --kit-paper-lo: #ead3a8; --kit-edge: #9a7048; --kit-edge-deep: #5f4128;
  --kit-accent: #e9a43a; --kit-accent-hi: #ffd47a; --kit-accent-deep: #a8651a; --kit-accent-ink: #3a210a;
  --kit-quiet: #d9c6a0; --kit-quiet-deep: #9b8359; --kit-quiet-ink: #4a3a26;
  --kit-on: #4fa6df; --kit-off: #a99273; --kit-knob: #fff4dc;
  --kit-star: #ffc84a; --kit-star-deep: #a8651a; --kit-star-dim: rgba(60, 38, 18, .28);
  --kit-veil: rgba(22, 13, 6, .56); --kit-sheet-w: 336px; --kit-hero-edge: var(--kit-edge-deep);
  --kit-hold: #ffd36a; --kit-z: 30; --kit-ease: cubic-bezier(.23, 1, .32, 1);
  --kit-tap: 44px; --kit-switch-w: 76px; --kit-switch-h: 42px;
  position: absolute; inset: 0; z-index: var(--kit-z); font-family: var(--kit-font); color: var(--kit-ink);
  /* A sheet is modal: it takes every touch, whatever its root does. A game whose stage lets touches through to a canvas
     (pointer-events: none on the root) otherwise gets a sheet nobody can press, with taps landing on the game behind it. */
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; touch-action: manipulation;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.pk-host.pk-kids { --kit-tap: 64px; --kit-switch-h: 48px; --kit-switch-w: 88px; }
.pk-host[hidden] { display: none !important; }
.pk-host *, .pk-host *::before, .pk-host *::after { box-sizing: border-box; }
.pk-veil { position: absolute; inset: 0; background: var(--kit-veil); }
.pk-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 30px 14px 16px; }
.pk-sheet { position: relative; display: flex; flex-direction: column; width: 100%; max-width: var(--kit-sheet-w); max-height: 100%; min-height: 0; outline: none; will-change: transform, opacity; }
/* A sheet on its way out leaves the row, so the one arriving is never squeezed beside it for the length of the fade
   (taps landed on half-width buttons). A flex container keeps an absolute child where it stood: centred. */
.pk-stage > .pk-sheet[inert] { position: absolute; width: calc(100% - 28px); max-height: calc(100% - 46px); }
.pk-host .pk-sheet:focus-visible, .pk-host .pk-sheet:focus { outline: none; }
.pk-host :focus-visible { outline: 3px solid var(--kit-accent-hi); outline-offset: 3px; border-radius: 12px; }
.pk-host button { font: inherit; color: inherit; margin: 0; }

/* ---- panel ---------------------------------------------------------------------------------------------------- */
.pk-panel {
  position: relative; display: flex; flex-direction: column; min-height: 0; max-height: 100%; padding: 0 18px 18px; text-align: center;
  background: linear-gradient(180deg, var(--kit-paper-hi) 0, var(--kit-paper) 42%, var(--kit-paper-lo) 100%);
  border: 7px solid var(--kit-edge); border-radius: 28px;
  box-shadow: 0 8px 0 var(--kit-edge-deep), 0 22px 34px rgba(0, 0, 0, .38), inset 0 0 0 2px rgba(255, 255, 255, .34), inset 0 -18px 26px rgba(80, 50, 20, .1);
}
.pk-has-panel .pk-panel {
  background: none; box-shadow: none; border-radius: 0; border-style: solid; border-color: transparent;
  border-width: var(--kit-panel-edge, 22px);
  border-image: var(--kit-panel) var(--kit-panel-slice, 72) fill / var(--kit-panel-edge, 22px) / 0 stretch;
  padding: 0 8px 12px;
}

/* ---- ribbon: the title plate ---------------------------------------------------------------------------------- */
.pk-ribbon {
  position: relative; z-index: 2; align-self: center; width: max-content; max-width: calc(100% + 28px); min-height: 52px; margin: -30px 0 12px; padding: 7px 28px 9px;
  display: flex; align-items: center; justify-content: center; text-align: center; white-space: nowrap;
  font-size: 27px; line-height: 1.08; font-weight: 700; letter-spacing: .005em; color: var(--kit-title-ink); text-shadow: 0 1px 0 var(--kit-title-shadow);
  background: linear-gradient(180deg, var(--kit-accent-hi), var(--kit-accent)); border-radius: 12px;
  box-shadow: 0 4px 0 var(--kit-accent-deep), 0 10px 14px rgba(0, 0, 0, .25), inset 0 2px 0 rgba(255, 255, 255, .45);
}
.pk-ribbon::before, .pk-ribbon::after {
  content: ''; position: absolute; top: 9px; width: 30px; height: 100%; z-index: -1; background: var(--kit-accent-deep);
}
.pk-ribbon::before { left: -20px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 26% 50%); }
.pk-ribbon::after { right: -20px; clip-path: polygon(0 0, 100% 0, 74% 50%, 100% 100%, 0 100%); }
.pk-has-ribbon .pk-ribbon {
  background: none; box-shadow: none; border-radius: 0; text-shadow: 0 2px 0 var(--kit-title-shadow); padding: 0 6px;
  border-style: solid; border-color: transparent; border-width: var(--kit-ribbon-edge, 13px 34px);
  border-image: var(--kit-ribbon) var(--kit-ribbon-slice, 55 110) fill / var(--kit-ribbon-edge, 13px 34px) / 0 stretch;
}
.pk-has-ribbon .pk-ribbon::before, .pk-has-ribbon .pk-ribbon::after { display: none; }
.pk-lose .pk-ribbon { filter: saturate(.55) brightness(.96); }

/* ---- buttons: materials with weight --------------------------------------------------------------------------- */
.pk-btn {
  position: relative; display: flex; align-items: center; justify-content: center; width: 100%; min-height: calc(var(--kit-tap) + 12px); padding: 0 20px;
  border: 0; cursor: pointer; font-size: 22px; line-height: 1.1; font-weight: 700; letter-spacing: .005em; -webkit-appearance: none; appearance: none;
  transition: transform 150ms var(--kit-ease), box-shadow 150ms var(--kit-ease), filter 150ms var(--kit-ease);
}
.pk-btn:active, .pk-btn.pk-down { transform: translateY(4px); transition-duration: 40ms; }
.pk-btn[aria-disabled='true'] { pointer-events: none; }
.pk-primary {
  color: var(--kit-accent-ink); text-shadow: 0 1px 0 rgba(255, 255, 255, .38);
  background: linear-gradient(180deg, var(--kit-accent-hi), var(--kit-accent) 70%); border-radius: 20px;
  box-shadow: 0 6px 0 var(--kit-accent-deep), 0 11px 16px rgba(0, 0, 0, .26), inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -4px 0 rgba(120, 60, 0, .1);
}
.pk-primary:active, .pk-primary.pk-down { box-shadow: 0 2px 0 var(--kit-accent-deep), 0 3px 6px rgba(0, 0, 0, .2), inset 0 2px 0 rgba(255, 255, 255, .4); }
.pk-quiet {
  min-height: var(--kit-tap); font-size: 18px; color: var(--kit-quiet-ink);
  background: linear-gradient(180deg, color-mix(in srgb, var(--kit-quiet) 78%, #fff), var(--kit-quiet)); border-radius: 16px;
  box-shadow: 0 4px 0 var(--kit-quiet-deep), 0 8px 12px rgba(0, 0, 0, .16), inset 0 2px 0 rgba(255, 255, 255, .45);
}
.pk-quiet:active, .pk-quiet.pk-down { box-shadow: 0 1px 0 var(--kit-quiet-deep), inset 0 2px 0 rgba(255, 255, 255, .3); }
.pk-has-button .pk-primary {
  background: none; box-shadow: none; border-radius: 0; padding: 0 4px; text-shadow: 0 1px 0 rgba(255, 244, 214, .55);
  border-style: solid; border-color: transparent; border-width: var(--kit-button-edge, 18px);
  border-image: var(--kit-button) var(--kit-button-slice, 52) fill / var(--kit-button-edge, 18px) / 0 stretch;
  min-height: calc(var(--kit-tap) + 14px);
}
.pk-has-quiet .pk-quiet {
  background: none; box-shadow: none; border-radius: 0; padding: 0 4px;
  border-style: solid; border-color: transparent; border-width: var(--kit-button-edge, 18px);
  border-image: var(--kit-button-quiet) var(--kit-button-slice, 52) fill / var(--kit-button-edge, 18px) / 0 stretch;
}
.pk-has-button .pk-primary:active, .pk-has-quiet .pk-quiet:active, .pk-has-button .pk-primary.pk-down, .pk-has-quiet .pk-quiet.pk-down { filter: brightness(.93) saturate(1.05); }
.pk-actions { display: grid; gap: 10px; margin-top: 4px; }
.pk-actions .pk-quiet { justify-self: center; width: 78%; }

/* The small gear: the only way from pause to options. */
.pk-gear {
  position: absolute; z-index: 3; top: 10px; right: 10px; display: grid; place-items: center; width: var(--kit-tap); height: var(--kit-tap); padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  color: var(--kit-quiet-ink); background: linear-gradient(180deg, color-mix(in srgb, var(--kit-quiet) 78%, #fff), var(--kit-quiet));
  box-shadow: 0 3px 0 var(--kit-quiet-deep), 0 0 0 2px color-mix(in srgb, var(--kit-quiet-deep) 70%, transparent), inset 0 2px 0 rgba(255, 255, 255, .5);
  transition: transform 150ms var(--kit-ease), box-shadow 150ms var(--kit-ease);
}
.pk-gear:active, .pk-gear.pk-down { transform: translateY(3px); box-shadow: 0 0 0 var(--kit-quiet-deep), inset 0 2px 0 rgba(255, 255, 255, .3); transition-duration: 40ms; }
.pk-gear svg { width: 64%; height: 64%; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform 300ms var(--kit-ease); }
.pk-gear:active svg, .pk-gear.pk-down svg { transform: rotate(40deg); }

/* ---- pause ---------------------------------------------------------------------------------------------------- */
.pk-pause .pk-panel { padding-bottom: 20px; }
.pk-pause .pk-ribbon { max-width: calc(100% - 40px); }
.pk-pause .pk-emblem { flex: none; width: 100%; aspect-ratio: var(--kit-emblem-ratio, 16 / 10); margin: 0 0 12px; position: relative; border-radius: 16px; overflow: hidden; box-shadow: inset 0 0 0 3px var(--kit-hero-edge); background: rgba(0, 0, 0, .1); }
.pk-pause .pk-emblem > * { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

.pk-line { margin: 0 0 12px; font-size: 17px; line-height: 1.25; color: var(--kit-ink-soft); text-wrap: balance; }
.pk-pause .pk-line { margin-top: -2px; }

/* ---- options -------------------------------------------------------------------------------------------------- */
.pk-rows { display: grid; margin: 0 0 14px; padding: 2px 4px; border-radius: 16px; background: rgba(90, 58, 24, .08); box-shadow: inset 0 2px 5px rgba(90, 58, 24, .14), 0 1px 0 rgba(255, 255, 255, .5); }
.pk-row {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: calc(var(--kit-tap) + 12px); padding: 6px 8px; border: 0; background: transparent; cursor: pointer; text-align: left;
  font-size: 20px; line-height: 1.1; color: var(--kit-ink); -webkit-appearance: none; appearance: none;
}
.pk-row + .pk-row { box-shadow: 0 -1px 0 rgba(90, 58, 24, .16), 0 -2px 0 rgba(255, 255, 255, .4); }
.pk-row-ico { flex: none; display: grid; place-items: center; width: 30px; height: 30px; color: var(--kit-edge-deep); opacity: .82; }
.pk-row-ico svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pk-row-label { flex: 1; min-width: 0; }
.pk-switch {
  position: relative; flex: none; width: var(--kit-switch-w); height: var(--kit-switch-h); border-radius: 999px;
  background: var(--kit-off); box-shadow: inset 0 3px 5px rgba(60, 36, 14, .42), 0 2px 0 rgba(255, 255, 255, .55), 0 0 0 3px var(--kit-edge);
  transition: background-color 180ms var(--kit-ease);
}
.pk-switch .pk-knob {
  position: absolute; top: 50%; left: 4px; width: calc(var(--kit-switch-h) - 8px); height: calc(var(--kit-switch-h) - 8px); margin-top: calc((var(--kit-switch-h) - 8px) / -2); border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff, var(--kit-knob) 55%, color-mix(in srgb, var(--kit-knob) 70%, var(--kit-edge)));
  box-shadow: 0 3px 0 rgba(60, 36, 14, .5), 0 5px 7px rgba(0, 0, 0, .22);
  transition: transform 260ms cubic-bezier(.3, 1.45, .5, 1), width 120ms var(--kit-ease);
}
.pk-row[aria-checked='true'] .pk-switch { background: var(--kit-on); }
.pk-row[aria-checked='true'] .pk-knob { transform: translateX(calc(var(--kit-switch-w) - var(--kit-switch-h))); }
.pk-row:active .pk-knob, .pk-row.pk-down .pk-knob { width: calc(var(--kit-switch-h) - 2px); transition-duration: 60ms; }
.pk-row[aria-checked='true']:active .pk-knob, .pk-row[aria-checked='true'].pk-down .pk-knob { transform: translateX(calc(var(--kit-switch-w) - var(--kit-switch-h) - 6px)); }
.pk-row:active .pk-switch, .pk-row.pk-down .pk-switch { transform: translateY(1px); }
/* Painted switch: two whole-switch images; the "on" image is wiped in from the knob's side like water filling a channel. */
.pk-has-switch .pk-switch { background: var(--kit-switch-off) center / 100% 100% no-repeat; box-shadow: none; border-radius: 0; }
.pk-has-switch .pk-switch::before { content: ''; position: absolute; inset: 0; background: var(--kit-switch-on) center / 100% 100% no-repeat; clip-path: inset(0 100% 0 0); transition: clip-path 200ms var(--kit-ease); }
.pk-has-switch .pk-row[aria-checked='true'] .pk-switch::before { clip-path: inset(0 0 0 0); }
.pk-has-switch .pk-row[aria-checked='true'] .pk-switch { background-color: transparent; }
.pk-has-switch .pk-switch .pk-knob { display: none; }
.pk-has-switch .pk-row:active .pk-switch, .pk-has-switch .pk-row.pk-down .pk-switch { transform: translateY(2px) scale(.97); }
.pk-has-switch .pk-switch { transition: transform 150ms var(--kit-ease); }

/* The hold gate in front of grown-ups' options. */
.pk-gate { display: grid; justify-items: center; gap: 14px; padding: 8px 0 18px; }
.pk-gate-btn {
  position: relative; display: grid; place-items: center; width: 96px; height: 96px; padding: 0; border: 0; border-radius: 50%; cursor: pointer; color: var(--kit-quiet-ink);
  background: radial-gradient(circle at 35% 28%, color-mix(in srgb, var(--kit-quiet) 70%, #fff), var(--kit-quiet)); box-shadow: 0 6px 0 var(--kit-quiet-deep), inset 0 2px 0 rgba(255, 255, 255, .5);
  transition: transform 150ms var(--kit-ease), box-shadow 150ms var(--kit-ease); touch-action: none;
}
.pk-gate-btn:active, .pk-gate-btn[data-pk-holding] { transform: translateY(4px); box-shadow: 0 2px 0 var(--kit-quiet-deep), inset 0 2px 0 rgba(255, 255, 255, .4); transition-duration: 40ms; }
.pk-gate-btn svg { width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pk-gate .pk-line { margin: 0; font-size: 16px; }

/* ---- result --------------------------------------------------------------------------------------------------- */
.pk-result { height: 100%; max-height: var(--kit-result-h, 660px); }
.pk-result .pk-panel { flex: 1 1 auto; }
.pk-hero {
  position: relative; flex: 1 1 auto; min-height: var(--kit-hero-min, 132px); margin: 2px 0 8px; border-radius: 16px; overflow: hidden; background: rgba(40, 24, 10, .16);
  box-shadow: 0 0 0 3px var(--kit-hero-edge), 0 4px 0 3px rgba(255, 255, 255, .28);
  transform-origin: 50% 60%;
}
.pk-hero > canvas, .pk-hero > img, .pk-hero > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; }
.pk-hero::after { content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit; box-shadow: inset 0 0 22px rgba(30, 16, 4, .34), inset 0 2px 0 rgba(255, 255, 255, .22); }
.pk-stars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; height: 82px; margin: 0 0 2px; }
.pk-star { position: relative; flex: none; width: 58px; height: 58px; transform: rotate(var(--pk-tilt, 0deg)); }
.pk-star-socket { position: absolute; inset: 3px; border-radius: 50%; background: radial-gradient(circle at 50% 38%, rgba(40, 22, 8, .28), rgba(40, 22, 8, .1) 70%); box-shadow: inset 0 3px 5px rgba(40, 22, 8, .35), 0 2px 0 rgba(255, 255, 255, .45); }
.pk-star svg, .pk-star-img { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.pk-star .pk-star-fill { transform-origin: 50% 54%; }
.pk-star-dim { opacity: 1; }
.pk-star-dim svg path { fill: var(--kit-star-dim); stroke: none; }
.pk-three .pk-star:nth-child(2) { width: 74px; height: 74px; margin-bottom: 7px; --pk-tilt: 0deg; }
.pk-three .pk-star:nth-child(1) { --pk-tilt: -9deg; }
.pk-three .pk-star:nth-child(3) { --pk-tilt: 9deg; }
.pk-has-star .pk-star-on svg, .pk-has-star .pk-star-dim svg, .pk-has-staroff .pk-star-dim svg { display: none; }
.pk-has-star .pk-star-on .pk-star-img { background: var(--kit-star-on) center / contain no-repeat; }
.pk-has-star .pk-star-dim .pk-star-img { background: var(--kit-star-on) center / contain no-repeat; opacity: .55; filter: grayscale(.8) brightness(.8); }
.pk-has-staroff .pk-star-dim .pk-star-img { background: var(--kit-star-off) center / contain no-repeat; opacity: 1; filter: drop-shadow(0 2px 1px rgba(60, 30, 10, .3)); }
.pk-has-star .pk-star-socket { display: none; }
.pk-has-star .pk-star-on .pk-star-img, .pk-has-star .pk-star-dim .pk-star-img { filter: drop-shadow(0 3px 2px rgba(60, 30, 10, .35)); }
.pk-flash { position: absolute; inset: -6px; border-radius: 50%; pointer-events: none; opacity: 0; background: radial-gradient(circle, rgba(255, 240, 180, .95), rgba(255, 214, 90, 0) 66%); }
.pk-result .pk-line { text-align: center; font-size: 18px; margin: 2px 6px 12px; color: var(--kit-ink); }
.pk-result .pk-actions { margin-top: 2px; }
.pk-lose .pk-hero { filter: saturate(.8); }
.pk-has-frame .pk-hero, .pk-has-frame .pk-pause .pk-emblem, .pk-has-frame .pk-emblem { box-shadow: none; border-radius: 12px; }
.pk-has-frame .pk-hero::after { box-shadow: inset 0 0 18px rgba(30, 16, 4, .3); }
.pk-has-frame .pk-hero::before, .pk-has-frame .pk-emblem::before {
  content: ''; position: absolute; inset: -1px; z-index: 2; pointer-events: none; border: solid transparent; border-width: var(--kit-frame-edge, 16px);
  border-image: var(--kit-frame) var(--kit-frame-slice, 46) / var(--kit-frame-edge, 16px) / 0 stretch;
}

.pk-sheet[data-settled='false'] .pk-primary, .pk-sheet[data-settled='false'] .pk-quiet { pointer-events: none; }
.pk-sheet[data-ready='true'] .pk-primary, .pk-sheet[data-ready='true'] .pk-quiet { pointer-events: auto; }

@media (max-height: 600px) { .pk-ribbon { font-size: 24px; min-height: 46px; margin-bottom: 8px; } .pk-stars { height: 62px; } .pk-star { width: 48px; height: 48px; } .pk-three .pk-star:nth-child(2) { width: 60px; height: 60px; } }
@media (max-width: 340px) { .pk-ribbon { font-size: 23px; padding-inline: 20px; } .pk-btn { font-size: 20px; } }
.pk-reduced *, .pk-reduced *::before, .pk-reduced *::after { transition-duration: 0ms !important; animation: none !important; }
.pk-reduced .pk-btn:active, .pk-reduced .pk-gear:active { transition-duration: 0ms !important; }
@media (prefers-reduced-motion: reduce) { .pk-host *, .pk-host *::before, .pk-host *::after { transition-duration: 0ms !important; animation: none !important; } }
