/* 他的心跳 — cobalt spinel blue scene
   Isolated scene; only active when body has `.hb-active` class. */

:root {
  --hb-cobalt: #3047b5;
  --hb-cobalt-glow: rgba(48, 71, 181, 0.6);
  --hb-cobalt-soft: rgba(48, 71, 181, 0.35);
  --hb-cobalt-bright: rgba(68, 100, 220, 0.9);
  --hb-cobalt-tint: rgba(48, 71, 181, 0.12);
  --hb-transition: 200ms ease-out;
}

.hb-scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 1.2s ease;
  touch-action: none;
  overflow: hidden;
}

.hb-scene[hidden] {
  display: none;
}

.hb-scene.hb-scene--visible {
  opacity: 1;
}

.hb-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Back button (top-left) ─────────────────────────────────── */
.hb-back-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: max(16px, env(safe-area-inset-left, 16px));
  background: transparent;
  border: none;
  color: var(--hb-cobalt);
  font-size: 28px;
  line-height: 1;
  /* 44px min touch target (Apple HIG) */
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--hb-transition), transform 150ms ease;
  filter: drop-shadow(0 0 6px var(--hb-cobalt-soft));
  z-index: 9100;
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.hb-back-btn:active {
  opacity: 1;
  transform: scale(0.92);
}

/* While heartbeat scene is active, hide main chrome to prevent bleed-through */
body.hb-active .chat-header,
body.hb-active .chat-messages,
body.hb-active .chat-input-area,
body.hb-active .chat-bg-moon,
body.hb-active .chat-bg-overlay,
body.hb-active .stars-bg,
body.hb-active .radial-overlay,
body.hb-active .radial-menu,
body.hb-active .utility-bubbles,
body.hb-active .bubble-overlay {
  visibility: hidden;
}

/* ── Persistent companion bar ──────────────────────────────── */
.hb-persist-bar {
  position: fixed;
  top: max(8px, env(safe-area-inset-top, 8px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid var(--hb-cobalt-soft);
  border-radius: 18px;
  color: var(--hb-cobalt);
  font-size: 13px;
  z-index: 8500;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 14px var(--hb-cobalt-soft);
  font-family: 'Noto Sans SC', system-ui, sans-serif;
  touch-action: manipulation;
}

.hb-persist-bar[hidden] {
  display: none;
}

.hb-persist-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--hb-cobalt);
  box-shadow: 0 0 8px var(--hb-cobalt);
  animation: hb-persist-pulse 1.1s ease-in-out infinite;
}

@keyframes hb-persist-pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.35); opacity: 1; }
}

.hb-persist-label {
  letter-spacing: 0.05em;
}

/* ── Bottom control pills ──────────────────────────────────── */
.hb-controls {
  position: fixed;
  bottom: max(32px, env(safe-area-inset-bottom, 32px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 9100;
  /* Stagger fade-in on scene enter */
  animation: hb-controls-in 600ms ease-out both;
}

@keyframes hb-controls-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hb-ctrl-btn {
  /* Glassmorphism pill — consistent with app's dark aesthetic */
  background: rgba(8, 12, 28, 0.55);
  border: 1px solid var(--hb-cobalt-soft);
  color: var(--hb-cobalt);
  /* 44px min touch height (Apple HIG) */
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 22px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    transform 150ms ease,
    background var(--hb-transition),
    box-shadow var(--hb-transition),
    border-color var(--hb-transition),
    color var(--hb-transition);
  font-family: 'Noto Sans SC', system-ui, sans-serif;
  letter-spacing: 0.06em;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  /* Subtle glow on glass surface */
  box-shadow:
    0 0 0 0 transparent,
    inset 0 1px 0 rgba(48, 71, 181, 0.08);
}

/* Press feedback — scale 0.95 (Apple HIG) */
.hb-ctrl-btn:active {
  transform: scale(0.95);
}

/* Active/ON state — prominent glow + brighter text */
.hb-ctrl-btn.hb-ctrl-btn--on {
  background: rgba(48, 71, 181, 0.22);
  border-color: var(--hb-cobalt-bright);
  color: var(--hb-cobalt-bright);
  box-shadow:
    0 0 18px var(--hb-cobalt-soft),
    0 0 40px var(--hb-cobalt-tint),
    inset 0 1px 0 rgba(68, 100, 220, 0.15);
}

/* ── Sleep companion mode ──────────────────────────────────── */
/* Hide everything except pulseline + exit button */
body.hb-sleep .hb-back-btn,
body.hb-sleep .hb-controls {
  display: none !important;
}

/* Exit button — matches fab-btn (Star) position exactly */
.hb-exit-btn {
  position: fixed;
  /* Match .fab-btn position: top = safe-area + 35px, right = 35px */
  top: calc(env(safe-area-inset-top, 0px) + 35px);
  right: 35px;
  background: transparent;
  border: none;
  /* 44px min touch target, centered on the 32px icon */
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hb-cobalt);
  filter: drop-shadow(0 0 8px var(--hb-cobalt-glow));
  opacity: 0.7;
  transition: opacity var(--hb-transition), transform 150ms ease;
  cursor: pointer;
  z-index: 9200;
  line-height: 0;
  /* iOS: prevent text-selection blue boxes and callout menus */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  /* Fade-in when sleep mode activates */
  animation: hb-exit-in 400ms ease-out both;
}

@keyframes hb-exit-in {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 0.7; transform: scale(1); }
}

.hb-exit-btn:active {
  opacity: 1;
  transform: scale(0.92);
}
