/* Dialog. Base rules are the quiet look: an own-sized, centred native
   dialog with a plain dimmed backdrop — also what a page without
   JavaScript shows, since showModal() and ::backdrop are both native.
   The element restructures its content into .sg-dialog-scrim (empty until
   a skin mounts Carepa into it) and .sg-dialog-card; both exist in every
   register so the CSS need not care whether JavaScript ran. */

sg-dialog { display: contents; }
sg-dialog dialog {
  box-sizing: border-box;
  max-inline-size: min(34rem, calc(100vw - 2 * var(--sg-space-4)));
  max-block-size: min(85vh, 48rem);
  margin: auto;
  padding: 0;
  border: var(--sg-hairline) solid var(--sg-rule-strong);
  border-radius: var(--sg-radius-2);
  background: var(--sg-surface-raised);
  color: var(--sg-text);
  box-shadow: 0 24px 60px -30px var(--sg-shadow);
}
sg-dialog dialog::backdrop {
  background: var(--sg-scrim, color-mix(in oklab, Canvas 55%, transparent));
}
sg-dialog dialog:not([open]) { display: none; }
sg-dialog .sg-dialog-scrim { display: none; }
sg-dialog .sg-dialog-card {
  padding: var(--sg-space-4);
  display: flow-root;
}
sg-dialog .sg-dialog-card h2, sg-dialog .sg-dialog-card h3 {
  font: 400 1.5rem/1.2 var(--sg-font-display); margin: 0 0 var(--sg-space-2);
}
sg-dialog .sg-dialog-card menu, sg-dialog .sg-dialog-card form menu {
  display: flex; gap: var(--sg-space-2); justify-content: flex-end; margin: var(--sg-space-4) 0 0; padding: 0; list-style: none;
}
sg-dialog .sg-dialog-card button {
  font: 500 0.9375rem/1 var(--sg-font-body); color: var(--sg-text); background: var(--sg-surface);
  border: var(--sg-hairline) solid var(--sg-rule-strong); border-radius: var(--sg-radius-pill); padding: 0.6em 1.1em; cursor: pointer;
}
sg-dialog .sg-dialog-card button[value="ok"], sg-dialog .sg-dialog-card button:last-child {
  background: var(--sg-accent); color: var(--sg-on-accent); border-color: transparent;
}
sg-dialog :focus-visible { outline: var(--sg-focus-width) solid var(--sg-focus); outline-offset: var(--sg-focus-offset); }

/* ── warm and playful: full-bleed, Carepa behind a floating card ───────
   [open] is required on every rule here that sets `display`: a closed
   dialog must stay display:none (the base :not([open]) rule above), or a
   dialog with equal selector specificity later in the file wins by source
   order and a *closed* full-bleed dialog would render fullscreen and eat
   clicks meant for the page under it. Found by dialog.check.mjs. */
sg-dialog[data-skin="warm"] dialog[open],
sg-dialog[data-skin="playful"] dialog[open] {
  inset: 0; margin: 0; padding: 0; border: 0; border-radius: 0;
  max-inline-size: none; max-block-size: none; inline-size: 100%; block-size: 100%;
  background: transparent; box-shadow: none;
  display: grid; place-items: center;
}
sg-dialog[data-skin="warm"] dialog::backdrop,
sg-dialog[data-skin="playful"] dialog::backdrop { background: transparent; }
sg-dialog[data-skin="warm"] .sg-dialog-scrim,
sg-dialog[data-skin="playful"] .sg-dialog-scrim {
  display: block; position: absolute; inset: 0; z-index: 0;
}
sg-dialog[data-skin="warm"] .sg-dialog-card,
sg-dialog[data-skin="playful"] .sg-dialog-card {
  position: relative; z-index: 1;
  inline-size: min(34rem, calc(100vw - 2 * var(--sg-space-4)));
  max-block-size: min(85vh, 48rem); overflow: auto;
  padding: var(--sg-space-4);
  border-radius: var(--sg-radius-2);
  background: color-mix(in oklab, var(--sg-surface-raised) 96%, transparent);
  box-shadow: 0 30px 70px -30px var(--sg-shadow);
}

/* ── entering and leaving: a transition from the first frame ────────────────
   The dialog fades in from @starting-style and, where the browser can hold it
   in the top layer while it goes (the overlay property), fades out again.
   Quiet is 120 ms of opacity and nothing else. Warm adds a short rise on the
   card, playful lets the card rise with a little give on the spring.
   Reduced motion: it is simply there. */
sg-dialog dialog {
  --_dur: 120ms; --_ease: var(--sg-ease-out, ease-out); --_rise: 0px; --_give: 1;
  opacity: 0;
}
sg-dialog dialog[open] { opacity: 1; transition: opacity var(--_dur) var(--_ease); }
sg-dialog dialog::backdrop { opacity: 0; }
sg-dialog dialog[open]::backdrop { opacity: 1; transition: opacity 120ms ease-out; }
@starting-style {
  sg-dialog dialog[open] { opacity: 0; }
  sg-dialog dialog[open]::backdrop { opacity: 0; }
}
@supports (overlay: auto) {
  sg-dialog dialog:not([open]) { transition: opacity var(--_dur) var(--_ease), overlay var(--_dur) allow-discrete, display var(--_dur) allow-discrete; }
  sg-dialog dialog:not([open])::backdrop { transition: opacity 120ms ease-out; }
}
sg-dialog[data-skin="warm"] dialog { --_dur: 180ms; --_rise: 8px; }
sg-dialog[data-skin="playful"] dialog { --_dur: 260ms; --_ease: var(--sg-ease-spring, ease-out); --_rise: 14px; --_give: 0.97; }
sg-dialog:is([data-skin="warm"], [data-skin="playful"]) .sg-dialog-card { translate: 0 var(--_rise); scale: var(--_give); }
sg-dialog:is([data-skin="warm"], [data-skin="playful"]) dialog[open] .sg-dialog-card {
  translate: 0 0; scale: 1;
  transition: translate var(--_dur) var(--_ease), scale var(--_dur) var(--_ease);
}
@starting-style {
  sg-dialog:is([data-skin="warm"], [data-skin="playful"]) dialog[open] .sg-dialog-card { translate: 0 var(--_rise); scale: var(--_give); }
}
@supports (overlay: auto) {
  sg-dialog:is([data-skin="warm"], [data-skin="playful"]) dialog:not([open]) .sg-dialog-card { transition: translate var(--_dur) var(--_ease), scale var(--_dur) var(--_ease); }
}

/* ── the card's buttons, pressed (the touch contract) ───────────────────────
   Down answers in the same frame, with no transition; letting go eases back
   in under 150 ms. Quiet settles 1 px, warm shades the colour toward the ink,
   playful gives a little. The keyboard never moves them, and reduced motion
   keeps the shade and drops the movement. */
sg-dialog .sg-dialog-card button {
  transition: translate 120ms ease-out, scale 120ms var(--sg-ease-out, ease-out), box-shadow 100ms ease-out;
}
sg-dialog .sg-dialog-card button:active { transition: none; translate: 0 1px; box-shadow: inset 0 0 0 100vmax color-mix(in oklab, var(--sg-text, CanvasText) 8%, transparent); }
sg-dialog[data-skin="warm"] .sg-dialog-card button:active { translate: none; box-shadow: inset 0 0 0 100vmax color-mix(in oklab, var(--sg-text) 16%, transparent); }
sg-dialog[data-skin="playful"] .sg-dialog-card button { transition-timing-function: ease-out, var(--sg-ease-spring, ease-out), ease-out; }
sg-dialog[data-skin="playful"] .sg-dialog-card button:active { translate: none; scale: 0.97; box-shadow: inset 0 0 0 100vmax color-mix(in oklab, var(--sg-accent, Highlight) 20%, transparent); }

@media (prefers-reduced-motion: reduce) {
  sg-dialog dialog, sg-dialog dialog::backdrop, sg-dialog .sg-dialog-card { animation: none !important; transition: none !important; }
  sg-dialog .sg-dialog-card button:active { translate: none !important; scale: none !important; box-shadow: inset 0 0 0 100vmax color-mix(in oklab, var(--sg-text) 16%, transparent); }
}
:root[data-sg-input="key"] sg-dialog .sg-dialog-card button:active { translate: none !important; scale: none !important; }
