/* Bakura mascot: floating launcher and chat panel. Logical properties mirror the
   panel in both reading directions; semantic tokens follow the light/dark theme. */

.bakura-mascot {
  /* Above every storefront layer; the page loader keeps its own extreme value. */
  --bakura-mascot-layer: 9999;
  --bakura-mascot-edge: 16px;
}

/* The fixed mobile buy bar owns the bottom edge while it is visible. */
.has-mobile-buy-bar {
  --bakura-mascot-clearance: calc(94px + env(safe-area-inset-bottom, 0px));
}

.bakura-mascot-launcher,
.bakura-mascot-panel {
  display: none;
}

.bakura-js .bakura-mascot-launcher {
  position: fixed;
  z-index: var(--bakura-mascot-layer);
  inset-inline-end: var(--bakura-mascot-edge);
  inset-block-end: calc(var(--bakura-mascot-edge) + var(--bakura-mascot-clearance, 0px) + env(safe-area-inset-bottom, 0px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 58px;
  block-size: 58px;
  padding: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
  animation: bakura-mascot-enter 320ms ease-out;
  transition: transform 0.2s;
}

.bakura-js .bakura-mascot-launcher:hover {
  transform: translateY(-2px);
}

.bakura-js .bakura-mascot-bird {
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
}

/* Gentle idle ring; it stops after the panel has been opened once. */
.bakura-js .bakura-mascot-launcher::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: bakura-mascot-pulse 2600ms ease-out infinite;
}

.bakura-mascot.is-open .bakura-mascot-launcher::after {
  animation: none;
}

.bakura-js .bakura-mascot-panel {
  position: fixed;
  z-index: var(--bakura-mascot-layer);
  inset-inline-end: var(--bakura-mascot-edge);
  inset-block-end: calc(86px + var(--bakura-mascot-clearance, 0px) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  inline-size: min(372px, calc(100vw - var(--bakura-mascot-edge) * 2));
  block-size: min(560px, 72dvh);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-surface);
  background: var(--surface);
  color: var(--color-text-body);
  box-shadow: var(--shadow-lift);
  animation: bakura-mascot-enter 240ms ease-out;
}

.bakura-mascot-panel[hidden] {
  display: none;
}

.bakura-mascot-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-block-end: 1px solid var(--line);
  background: var(--paper);
}

.bakura-mascot-avatar {
  inline-size: 40px;
  block-size: 40px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
}

.bakura-mascot-heading {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-inline-size: 0;
  margin-inline-end: auto;
}

.bakura-mascot-name {
  color: var(--color-text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.bakura-mascot-status-dot {
  display: inline-block;
  inline-size: 9px;
  block-size: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgb(200 133 55 / 0.22);
}

.bakura-mascot-close {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  inline-size: 40px;
  block-size: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
}

.bakura-mascot-close:hover {
  background: var(--color-wash);
  color: var(--color-text);
}

.bakura-mascot-close .icon {
  inline-size: 20px;
  block-size: 20px;
}

.bakura-mascot-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.bakura-mascot-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-inline-size: 86%;
}

.bakura-mascot-msg.is-user {
  align-self: flex-end;
  align-items: flex-end;
}

.bakura-mascot-msg.is-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.bakura-mascot-bubble {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-surface);
  background: var(--paper-muted);
  color: var(--color-text-body);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.is-assistant .bakura-mascot-bubble {
  border-end-start-radius: 4px;
}

.is-user .bakura-mascot-bubble {
  border-color: var(--button-border);
  border-end-end-radius: 4px;
  background: var(--button-bg);
  color: var(--button-text);
}

.bakura-mascot-typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-block-size: 40px;
}

.bakura-mascot-typing-dot {
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: bakura-mascot-dot 1200ms ease-in-out infinite;
}

.bakura-mascot-typing-dot:nth-of-type(2) {
  animation-delay: 150ms;
}

.bakura-mascot-typing-dot:nth-of-type(3) {
  animation-delay: 300ms;
}

.bakura-mascot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bakura-mascot-chip {
  min-block-size: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--color-text-body);
  font-size: 13px;
  line-height: 1.6;
  transition:
    border-color 0.2s,
    color 0.2s;
}

.bakura-mascot-chip:hover {
  border-color: var(--gold);
  color: var(--gold-dark);
}

.bakura-mascot-products {
  display: flex;
  flex-direction: column;
  gap: 8px;
  inline-size: 100%;
}

.bakura-mascot-products-title {
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.bakura-mascot-product {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--paper);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.bakura-mascot-product:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-soft);
}

.bakura-mascot-product-media {
  display: block;
  flex: none;
  inline-size: 56px;
  block-size: 56px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.bakura-mascot-product-media img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

.bakura-mascot-product-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-inline-size: 0;
}

.bakura-mascot-product-name {
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}

.bakura-mascot-product-price {
  color: var(--gold-dark);
  font-size: 13px;
  line-height: 1.6;
}

.bakura-mascot-form {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-block-start: 1px solid var(--line);
  background: var(--paper);
}

.bakura-mascot-row {
  display: flex;
  gap: 8px;
}

.bakura-mascot-input {
  flex: 1;
  min-width: 0;
  min-block-size: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--color-text);
  font-size: 14px;
}

.bakura-mascot-input::placeholder {
  color: var(--color-text-muted);
}

.bakura-mascot-send {
  flex: none;
  min-block-size: 48px;
  padding: 10px 18px;
  border: 1px solid var(--button-border);
  border-radius: var(--radius-control);
  background: var(--button-bg);
  color: var(--button-text);
  font-size: 14px;
  font-weight: 600;
}

.bakura-mascot-send:hover {
  background: var(--button-bg-hover);
}

.bakura-mascot-send:disabled {
  cursor: default;
  opacity: 0.5;
}

.bakura-mascot-disclaimer {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

@keyframes bakura-mascot-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bakura-mascot-pulse {
  0% {
    opacity: 0.7;
    transform: scale(1);
  }

  70%,
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

@keyframes bakura-mascot-dot {
  0%,
  60%,
  100% {
    opacity: 0.45;
    transform: none;
  }

  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@media (max-width: 640px) {
  .bakura-mascot {
    --bakura-mascot-edge: 14px;
  }

  .bakura-js .bakura-mascot-panel {
    inset-inline: 0;
    inset-block: auto 0;
    inline-size: 100%;
    block-size: min(80dvh, 620px);
    border-inline: 0;
    border-block-end: 0;
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bakura-js .bakura-mascot-launcher,
  .bakura-js .bakura-mascot-launcher::after,
  .bakura-js .bakura-mascot-panel,
  .bakura-mascot-typing-dot {
    animation: none;
  }

  .bakura-js .bakura-mascot-launcher {
    transition: none;
  }

  .bakura-js .bakura-mascot-launcher:hover {
    transform: none;
  }

  .bakura-mascot-chip,
  .bakura-mascot-product {
    transition: none;
  }
}
