/* ════════════════════════════════════════════════════════════════════════
   CODE BUDDY (js/code-buddy.js, inc/code-buddy.php)
   A logo-pink blob tucked into the bottom-left corner: it peeks out
   (mostly off-screen, clear of the product cards) and pops fully out on
   hover/focus, when its bubble is open, or when it has news. Bottom-left
   on every screen size; on mobile the basket is the matching floating
   button bottom-right.
   ════════════════════════════════════════════════════════════════════════ */
.tomo-buddy {
  --buddy-pink: #FF4B9F;
  --buddy-feat: #2a2a38;
  --buddy-size: 60px;
  position: fixed; left: 4px; bottom: 12px;
  z-index: 9997;            /* under the nav (9999) and mobile basket (9998) */
  font-family: 'Fredoka', sans-serif;
}
.tomo-buddy-btn {
  position: relative; display: block;
  width: var(--buddy-size); height: var(--buddy-size);
  padding: 0; border: 0; background: none; cursor: pointer;
  transform: translate(-48%, 30%);   /* peeking from the corner, clear of the cards */
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
  -webkit-tap-highlight-color: transparent;
}
.tomo-buddy-btn:hover,
.tomo-buddy-btn:focus-visible,
.tomo-buddy.is-open .tomo-buddy-btn,
.tomo-buddy.is-news .tomo-buddy-btn { transform: translate(10px, 0); }
/* The tilt while peeking is on the face only (the separate `rotate`
   property, so it doesn't fight the bob animation's transform), which
   keeps the count badge upright: a tilted 1 read as a 7. */
.tomo-buddy-btn:hover .tomo-buddy-body,
.tomo-buddy-btn:focus-visible .tomo-buddy-body,
.tomo-buddy.is-open .tomo-buddy-body,
.tomo-buddy.is-news .tomo-buddy-body { rotate: 0deg; }
.tomo-buddy-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 50%; }
.tomo-buddy-body {
  display: block; width: 100%; height: 100%;
  animation: tomo-buddy-bob 3.2s ease-in-out infinite;
  filter: var(--tomo-drop);
  rotate: 24deg;
  transition: rotate 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
.tomo-buddy-face { display: block; width: 100%; height: 100%; overflow: visible; }

/* Shared face parts (corner buddy + card faces) */
.tomo-buddy-head  { fill: var(--buddy-pink, #FF4B9F); }
.tomo-buddy-eyes  { fill: var(--buddy-feat, #2a2a38); transform-box: fill-box; transform-origin: center; transition: transform 0.08s; }
.tomo-buddy-smile { fill: none; stroke: var(--buddy-feat, #2a2a38); stroke-width: 2.6; stroke-linecap: round; }
.tomo-buddy-grin  { fill: var(--buddy-feat, #2a2a38); stroke: var(--buddy-feat, #2a2a38); stroke-width: 1.6; stroke-linejoin: round; display: none; }
.tomo-buddy.is-blinking .tomo-buddy-eyes { transform: scaleY(0.12); }
/* Big grin when it's open or has news */
.tomo-buddy.is-open .tomo-buddy-smile,
.tomo-buddy.is-news .tomo-buddy-smile,
.tomo-buddy-btn:hover .tomo-buddy-smile { display: none; }
.tomo-buddy.is-open .tomo-buddy-grin,
.tomo-buddy.is-news .tomo-buddy-grin,
.tomo-buddy-btn:hover .tomo-buddy-grin { display: inline; }

/* Code count, like the basket's */
.tomo-buddy-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box;
  border-radius: 100px; border: 2px solid #fff;
  background: var(--ink); color: #fff;
  font-size: 0.72rem; font-weight: 700; line-height: 16px; text-align: center;
}
.tomo-buddy-badge[hidden] { display: none; }
[data-theme="dark"] .tomo-buddy-badge { color: #1a1a22; border-color: #1a1a22; }

.tomo-buddy.is-news .tomo-buddy-body { animation: tomo-buddy-hop 0.6s cubic-bezier(0.34,1.56,0.64,1) 2; }
@keyframes tomo-buddy-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes tomo-buddy-hop {
  0% { transform: translateY(0) scale(1, 1); }
  20% { transform: translateY(0) scale(1.12, 0.86); }
  50% { transform: translateY(-16px) scale(0.92, 1.1); }
  80% { transform: translateY(0) scale(1.08, 0.92); }
  100% { transform: translateY(0) scale(1, 1); }
}

/* ── Speech bubble ─────────────────────────────────────────────────── */
.tomo-buddy-bubble {
  position: absolute; left: 0; bottom: calc(var(--buddy-size) + 14px);
  width: min(300px, calc(100vw - 28px)); box-sizing: border-box;
  max-height: min(60vh, 440px); overflow-y: auto;
  padding: 14px 16px 16px;
  background: #fff; color: var(--ink);
  border: 2.5px solid var(--ink); border-radius: 20px;
  box-shadow: var(--tomo-shadow);
  transform-origin: 24px 100%;
  animation: tomo-buddy-pop 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
.tomo-buddy-bubble[hidden] { display: none; }
[data-theme="dark"] .tomo-buddy-bubble { background: #23232e; box-shadow: var(--tomo-shadow); }
@keyframes tomo-buddy-pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }

.tomo-buddy-close {
  position: absolute; top: 6px; right: 8px;
  width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: none; color: var(--muted); cursor: pointer;
  font-size: 1.3rem; line-height: 1;
}
.tomo-buddy-close:hover { color: var(--ink); background: var(--border-soft); }
.tomo-buddy-title { margin: 0 30px 6px 0; font-size: 1.08rem; font-weight: 700; line-height: 1.2; }
.tomo-buddy-text  { margin: 0 0 10px; font-size: 0.9rem; font-weight: 500; line-height: 1.35; color: var(--ink); }
.tomo-buddy-text:last-child { margin-bottom: 0; }

.tomo-buddy-codes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tomo-buddy-code {
  display: flex; flex-direction: column; gap: 3px;
  padding: 9px 11px;
  border: 2px dashed var(--border); border-radius: 14px;
}
.tomo-buddy-code.is-news { border: 2px solid #FF4B9F; background: rgba(255,75,159,0.08); }
.tomo-buddy-code-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tomo-buddy-code-name { font-weight: 700; font-size: 0.98rem; letter-spacing: 0.06em; }
.tomo-buddy-code-ok { font-size: 0.78rem; font-weight: 700; color: #e0408a; white-space: nowrap; }
[data-theme="dark"] .tomo-buddy-code-ok { color: #FF4B9F; }
.tomo-buddy-code-label { font-size: 0.84rem; font-weight: 500; line-height: 1.3; }
.tomo-buddy-code-src { color: var(--muted); }
.tomo-buddy-code-hint { font-size: 0.76rem; font-weight: 500; line-height: 1.3; color: var(--muted); }
.tomo-buddy-code.is-paused { opacity: 0.85; }
.tomo-buddy-use {
  flex-shrink: 0; padding: 4px 14px; border-radius: 100px; cursor: pointer;
  border: 2px solid var(--ink); background: var(--ink); color: #fff;
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.8rem;
}
.tomo-buddy-use:disabled { opacity: 0.5; cursor: progress; }
[data-theme="dark"] .tomo-buddy-use { color: #1a1a22; }

/* ── Pink face on product cards a held code applies to ─────────────── */
.tomo-buddy-card {
  position: absolute; right: 10px; bottom: -18px; z-index: 7;   /* above the card's stretched link */
  width: 42px; height: 42px; padding: 0;
  border: 0; background: none; cursor: pointer;
  --buddy-pink: #FF4B9F; --buddy-feat: #2a2a38;
  filter: var(--tomo-drop);
  animation: tomo-buddy-wiggle 4s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}
.tomo-buddy-card-face { display: block; width: 100%; height: 100%; overflow: visible; }
.tomo-buddy-card .tomo-buddy-smile { display: none; }
.tomo-buddy-card .tomo-buddy-grin  { display: inline; }
.tomo-buddy-card-tip {
  position: absolute; right: -4px; bottom: calc(100% + 6px);
  padding: 4px 10px; border-radius: 100px; white-space: nowrap;
  background: #FF4B9F; color: #fff;
  font-family: 'Fredoka', sans-serif; font-size: 0.78rem; font-weight: 700;
  opacity: 0; transform: translateY(4px) scale(0.9); pointer-events: none;
  transition: opacity 0.15s, transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
.tomo-buddy-card:hover .tomo-buddy-card-tip,
.tomo-buddy-card:focus-visible .tomo-buddy-card-tip { opacity: 1; transform: translateY(0) scale(1); }
.tomo-buddy-card:hover { animation-play-state: paused; }
.tomo-buddy-card:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 50%; }
/* A little wiggle every few seconds, to catch the eye */
@keyframes tomo-buddy-wiggle {
  0%, 82%, 100% { transform: rotate(0) scale(1); }
  86% { transform: rotate(-14deg) scale(1.08); }
  90% { transform: rotate(12deg) scale(1.08); }
  94% { transform: rotate(-6deg) scale(1.04); }
}

/* ── Pink face next to discounted basket/checkout items ────────────── */
.tomo-buddy-mark {
  display: inline-block; width: 1.15em; height: 1.15em;
  margin-left: 4px; vertical-align: -0.22em;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath fill='%23FF4B9F' d='M20 1.2C30.6 1 39 9.6 38.9 20.2 38.8 30.7 30.4 39 19.9 38.9 9.4 38.8 1 30.3 1.1 19.8 1.2 9.4 9.6 1.3 20 1.2Z'/%3E%3Ccircle cx='13.3' cy='15.8' r='3' fill='%232a2a38'/%3E%3Ccircle cx='25.9' cy='16.7' r='2.4' fill='%232a2a38'/%3E%3Cpath d='M15.2 23.6Q20 22.4 24.8 24Q23.8 30.2 19.8 30Q16 29.6 15.2 23.6Z' fill='%232a2a38' stroke='%232a2a38' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ── Mobile: same corner, a touch smaller ──────────────────────────── */
@media (max-width: 780px) {
  .tomo-buddy { --buddy-size: 54px; left: 2px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  /* Peek out sideways only: anything pushed below the screen edge gets
     sliced off by iPhone Safari's toolbar area. */
  .tomo-buddy-btn { transform: translate(-40%, 0); }
  .tomo-buddy-card { width: 36px; height: 36px; bottom: -14px; right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .tomo-buddy-body, .tomo-buddy-card, .tomo-buddy-bubble, .tomo-buddy.is-news .tomo-buddy-body { animation: none; }
  .tomo-buddy-btn, .tomo-buddy-body { transition: none; }
}
@media print { .tomo-buddy, .tomo-buddy-card { display: none !important; } }

/* ── Unlocked secret products in the bubble ────────────────────────── */
.tomo-buddy-sub { margin-top: 4px; }
.tomo-buddy-secrets { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tomo-buddy-secret a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px 7px 7px; border-radius: 14px;
  background: var(--ink); color: #fff; text-decoration: none;
  transition: transform 0.15s;
}
.tomo-buddy-secret a:hover { transform: translateX(3px); }
.tomo-buddy-secret.is-news a { box-shadow: 0 0 0 3px #FF4B9F; }
.tomo-buddy-secret img, .tomo-buddy-secret-noimg {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 10px;
  object-fit: contain; background: rgba(255,255,255,0.18);
}
.tomo-buddy-secret-text { display: flex; flex-direction: column; min-width: 0; }
.tomo-buddy-secret-name { font-weight: 700; font-size: 0.9rem; line-height: 1.2; }
.tomo-buddy-secret-go { font-size: 0.78rem; font-weight: 600; opacity: 0.85; }
[data-theme="dark"] .tomo-buddy-secret a { color: #1a1a22; }
[data-theme="dark"] .tomo-buddy-secret img, [data-theme="dark"] .tomo-buddy-secret-noimg { background: rgba(26,26,34,0.15); }

/* ── Secret faces: [tomo_secret_face] (inc/secrets.php) ────────────── */
.tomo-secret-face {
  display: inline-block; vertical-align: -0.15em;
  width: var(--sf-size, 1em); height: var(--sf-size, 1em);
  padding: 0; margin: 0 0.05em; border: 0; background: none;
  color: inherit; line-height: 0; cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), color 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tomo-secret-face svg { display: block; width: 100%; height: 100%; overflow: visible; }
.tomo-secret-face.is-faint { opacity: 0.35; }
.tomo-secret-face.is-pink  { color: #FF4B9F; }
.tomo-secret-face.is-blue  { color: var(--ink); }
.tomo-secret-face:hover { transform: rotate(-12deg) scale(1.2); opacity: 1; }
.tomo-secret-face:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 50%; }
.tomo-secret-face.is-busy { cursor: progress; }
.tomo-secret-face.is-found { color: #FF4B9F; opacity: 1; animation: tomo-sf-found 0.6s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes tomo-sf-found { 0% { transform: scale(1); } 40% { transform: scale(1.8) rotate(15deg); } 100% { transform: scale(1); } }
.tomo-secret-face-note { font-size: 0.8em; color: var(--tomo-pink-text, #e0408a); border: 1px dashed currentColor; border-radius: 4px; padding: 0 4px; }
@media (prefers-reduced-motion: reduce) { .tomo-secret-face, .tomo-secret-face.is-found { transition: none; animation: none; } }

/* Pink-face confetti on a secret product's page (secretConfetti in js/code-buddy.js) */
.tomo-confetti { position: fixed; inset: 0; z-index: 10003; pointer-events: none; }
