/* Perkify Widget Styles — scoped inside Shadow DOM */

:host {
  all: initial;
  /* Themes (Dawn family) often hide empty light-DOM elements via
     `div:empty { display: none }`. A shadow host has no light-DOM children, so
     it matches `:empty` and gets hidden — force it visible. */
  display: block !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  color: #333;
}

/* ─── Floating Action Button ─────────────────────────────────── */

.perkify-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6C5CE7 0%, #A855F7 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.45);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.perkify-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(108, 92, 231, 0.55);
}

.perkify-fab:active {
  transform: scale(0.95);
}

/* ─── Point Badge ────────────────────────────────────────────── */

.perkify-point-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #FF6B6B;
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
  box-shadow: 0 2px 6px rgba(255, 107, 107, 0.4);
  animation: perkify-badge-pop 0.3s ease;
}

@keyframes perkify-badge-pop {
  0% {
    transform: scale(0);
  }
  60% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* ─── Expandable Panel ───────────────────────────────────────── */

.perkify-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 320px;
  max-height: 440px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  z-index: 999998;
  overflow: hidden;
  transform: scale(0);
  transform-origin: bottom right;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.2s ease;
  opacity: 0;
}

.perkify-panel.open {
  transform: scale(1);
  opacity: 1;
}

/* ─── Panel Header ───────────────────────────────────────────── */

.perkify-panel-header {
  background: linear-gradient(135deg, #6C5CE7 0%, #A855F7 100%);
  color: #fff;
  padding: 20px 20px 16px;
}

.perkify-panel-header h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.9;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.perkify-panel-header .points {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
}

/* ─── Panel Body ─────────────────────────────────────────────── */

.perkify-panel-body {
  padding: 16px 20px 20px;
}

/* ─── Nudge Message ──────────────────────────────────────────── */

.perkify-nudge {
  background: #F8F7FF;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  color: #555;
  line-height: 1.5;
  border-left: 3px solid #6C5CE7;
}

/* ─── Reward Button ──────────────────────────────────────────── */

.perkify-reward-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #6C5CE7 0%, #A855F7 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.perkify-reward-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.perkify-reward-btn:active:not(:disabled) {
  transform: translateY(0);
}

.perkify-reward-btn:disabled {
  background: #E0E0E0;
  color: #999;
  cursor: default;
}

/* ─── Save Progress Form ─────────────────────────────────────── */

.perkify-save-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.perkify-save-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #E0E0E0;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.perkify-save-form input:focus {
  border-color: #6C5CE7;
}

.perkify-save-form button {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: #6C5CE7;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.perkify-save-form button:hover {
  background: #5A4BD1;
}

/* ─── Discount Result ────────────────────────────────────────── */

.perkify-discount-result {
  background: #E8F5E9;
  border-radius: 10px;
  padding: 16px;
  margin-top: 14px;
  text-align: center;
}

.perkify-discount-result div:first-child {
  font-size: 13px;
  color: #555;
  margin-bottom: 6px;
}

.perkify-discount-code {
  font-size: 22px;
  font-weight: 800;
  color: #2E7D32;
  letter-spacing: 1.5px;
  font-family: monospace;
}

/* ─── Pulse Feed ─────────────────────────────────────────────── */

.perkify-pulse {
  margin-top: 14px;
  padding: 10px 14px;
  background: #FFF8E1;
  border-radius: 10px;
  font-size: 13px;
  color: #F57F17;
  text-align: center;
  font-weight: 500;
  animation: perkify-pulse-fade 0.5s ease;
}

@keyframes perkify-pulse-fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─────────────────────────────────────────────── */

@media (max-width: 480px) {
  .perkify-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
  }

  .perkify-fab {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
}

/* ─── Tootsie demo: mini-Tootsie-Roll launcher ──────────────────────
   Demo-only restyle of Perky's launcher into a little wrapped Tootsie Roll:
   the brown candy body (the brand accent #402021) with red wrapper edges and
   the real twisted wrapper "pull" SVGs on each side.

   The pulls are ::before/::after on .pk-bug ITSELF so they scale and rotate
   WITH the body on hover/pulse. z-index:-1 keeps them behind the body at rest;
   when a transform makes .pk-bug a stacking context the tucked inner edge can
   paint over the body, but the pull SVGs are the same brown (#3c1b0d) as the
   body, so the seam stays invisible. The inner edge tucks ~9px under the body. */
.pk-bug {
  border-radius: 16px !important;
  overflow: visible !important;
  /* The body fill lives in ::after, NOT here, so the pulls (::before) can sit
     beneath it. Transparent own-background + a forced stacking context lock the
     paint order in every state. */
  background: transparent !important;
  isolation: isolate !important;
}
/* ::before = BOTH wrapper pulls (one layer), behind the body (z-index:-2). The
   box spans wider than the bug so a pull pins to each side; their inner edges
   tuck under the body fill above. */
.pk-bug::before {
  content: "";
  position: absolute;
  z-index: -2;
  top: 50%;
  left: -13px;
  right: -13px;
  height: 46px;
  transform: translateY(-50%);
  background-image: url("/perk/tootsie-pull-left.svg"), url("/perk/tootsie-pull-right.svg");
  background-position: left center, right center;
  background-repeat: no-repeat, no-repeat;
  background-size: 24px 46px, 21px 46px;
  pointer-events: none;
}
/* ::after = the candy BODY fill: brown body + red wrapper edges. Sits ABOVE the
   pulls (z-index:-1 > -2) but BELOW the eyes/ring/number (positioned children),
   so the pulls can NEVER paint on top of the body — in any animation state. */
.pk-bug::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: 16px;
  background:
    linear-gradient(
      90deg,
      #e11d3a 0, #e11d3a 6px,
      transparent 6px, transparent calc(100% - 6px),
      #e11d3a calc(100% - 6px), #e11d3a 100%
    ),
    linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #000));
  pointer-events: none;
}

/* ─── Fix: matching-game ("Match & Win") board collapsed ─────────────
   The widget's .pk-mgrid uses `margin: 0 auto` inside a flex-column body. Auto
   margins make a flex item shrink-wrap instead of stretch, so it had no definite
   width and `grid-template-columns: repeat(4, 1fr)` resolved to 0px columns —
   the whole board collapsed to a tiny cluster. Giving it a definite width
   restores the 4 columns. (!important to beat the widget's inline shadow-DOM
   rule, which is injected after this sheet.) */
.pk-mgrid {
  width: min(420px, 100%) !important;
  margin-inline: auto !important;
}

/* ─── Tootsie demo: on-brand widget typography + breathing room ──────
   Use Tootsie's real fonts (loaded via the Adobe kit in the page <head>; @font-face
   from the main document applies inside the shadow DOM): roc-grotesk for body,
   cooper-black-std for the headline moments. !important to beat the widget's inline
   shadow-DOM styles. */
:host,
.perkify-container,
.pk-wrap,
.pk-bub,
.pk-sheet,
.pk-dock {
  font-family: "roc-grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}
.pk-title,
.pk-score strong {
  font-family: "cooper-black-std", Georgia, "Times New Roman", serif !important;
  letter-spacing: -0.01em;
}

/* De-crowd: a little more width + breathing room so it doesn't feel packed. */
.pk-sheet {
  width: 332px !important;
}
.pk-body {
  padding: 16px 16px 14px !important;
}
.pk-section-h {
  margin: 18px 0 9px !important;
}
.pk-row {
  padding: 11px 12px !important;
  margin-bottom: 8px !important;
}
.pk-mcard {
  padding: 12px 13px !important;
  margin-bottom: 9px !important;
}
.pk-msteps {
  gap: 8px !important;
}

/* Small caption under the "Scan a store receipt" button (offline-receipt capture). */
.pk-receipt-note {
  font-size: 11px;
  line-height: 1.45;
  color: var(--mut, #6b6a72);
  text-align: center;
  margin: 8px 4px 2px;
}

/* ─── Receipt scan flow (head-fake OCR processing → success) ───────── */
.pk-rcpt-proc { text-align: center; padding: 10px 4px 4px; }
.pk-rcpt-scan { width: 84px; height: 100px; margin: 4px auto 16px; position: relative; }
.pk-rcpt-doc {
  position: absolute; inset: 0; margin: auto; width: 64px; height: 86px;
  background: #fff; border: 2px solid var(--accent); border-radius: 6px 6px 2px 2px;
  clip-path: polygon(0 0,100% 0,100% 92%,87% 100%,75% 92%,62% 100%,50% 92%,37% 100%,25% 92%,12% 100%,0 92%);
  box-shadow: 0 8px 22px rgba(0,0,0,.12);
}
.pk-rcpt-doc::before {
  content: ""; position: absolute; left: 12px; right: 12px; top: 14px; height: 50px;
  background: repeating-linear-gradient(var(--line) 0 5px, transparent 5px 13px); opacity: .6;
}
.pk-rcpt-laser {
  position: absolute; left: 8px; right: 8px; height: 3px; border-radius: 3px;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
  animation: pkrcptscan 1.5s ease-in-out infinite;
}
@keyframes pkrcptscan { 0%,100% { top: 8px; } 50% { top: 84px; } }
.pk-rcpt-h { font-weight: 800; font-size: 16px; color: var(--ink); }
.pk-rcpt-steps { margin: 14px auto 0; display: flex; flex-direction: column; gap: 8px; max-width: 230px; }
.pk-rcpt-step {
  font-size: 12.5px; color: var(--mut); text-align: left; padding-left: 26px;
  position: relative; opacity: .45; transition: opacity .2s, color .2s;
}
.pk-rcpt-step::before {
  content: ""; position: absolute; left: 0; top: 0; width: 16px; height: 16px;
  border-radius: 50%; border: 2px solid var(--line); box-sizing: border-box;
}
.pk-rcpt-step.on { opacity: 1; color: var(--ink); font-weight: 600; }
.pk-rcpt-step.on::before { border-color: var(--accent); border-top-color: transparent; animation: pkspin .7s linear infinite; }
.pk-rcpt-step.done { opacity: 1; color: var(--ink); }
.pk-rcpt-step.done::before { border-color: var(--accent); background: var(--accent); animation: none; }
.pk-rcpt-step.done::after {
  content: ""; position: absolute; left: 5px; top: 3px; width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(40deg);
}
@keyframes pkspin { to { transform: rotate(360deg); } }
.pk-rcpt-recs { margin-top: 16px; }

.pk-rcpt-done { text-align: center; padding: 12px 6px 4px; }
.pk-rcpt-badge {
  width: 58px; height: 58px; margin: 4px auto 14px; border-radius: 50%; font-size: 28px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
  display: grid; place-items: center; animation: pkpop .45s ease;
}
.pk-rcpt-h2 { font-weight: 800; font-size: 17px; color: var(--ink); }
.pk-rcpt-p { font-size: 13px; color: var(--mut); line-height: 1.5; margin: 9px 6px 0; }
.pk-rcpt-p b { color: var(--ink); }
.pk-rcpt-sub { font-size: 12px; color: var(--mut); margin-top: 9px; }

/* Faux "upload your receipt" drop-zone (the head-fake — no real file picker). */
.pk-rcpt-up { padding: 6px 2px 2px; }
.pk-rcpt-drop {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 26px 18px; border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 16px; background: color-mix(in srgb, var(--accent) 5%, var(--bg));
  color: var(--ink); cursor: pointer; text-align: center;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.pk-rcpt-drop:hover { background: color-mix(in srgb, var(--accent) 9%, var(--bg)); border-color: var(--accent); }
.pk-rcpt-drop:active { transform: scale(.99); }
.pk-rcpt-upic {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.pk-rcpt-uph { font-weight: 800; font-size: 15px; color: var(--ink); }
.pk-rcpt-ups { font-size: 12px; line-height: 1.5; color: var(--mut); max-width: 240px; }
.pk-rcpt-tip { text-align: center; font-size: 11px; color: var(--mut); margin-top: 12px; }
