/* ═══════════════════════════════════════════════════════════
   TalkStory v1 — voice Q&A FAB + modal
   Scoped to .hg-ts-* so nothing leaks into page content.
   ═══════════════════════════════════════════════════════════ */

:root {
  /* Brand greens — canonical Kauai green from the site palette so the
     pill reads as native Hawaii Guide chrome rather than a bolted-on widget.
     (Variable kept named --hg-ts-ocean so the rest of the file stays untouched
     during the recolor; rename in a follow-up cleanup if it bothers anyone.) */
  --hg-ts-ocean: #1D9771;
  --hg-ts-ocean-dark: #156d52;
  --hg-ts-ocean-light: #3eb293;
  --hg-ts-accent: #F27A24;
  --hg-ts-ink: #1a1d21;
  --hg-ts-muted: #67707a;
  --hg-ts-panel: #ffffff;
  --hg-ts-panel-soft: #f4f6f9;
  --hg-ts-border: #dde3ea;
}

/* ── FAB launcher (right-side, sits where the Shaka FAB used to live —
   the Shaka FAB has been bumped up to 230px to make room) ───────────── */
.hg-ts-fab {
  position: fixed;
  bottom: 160px;
  right: 16px;
  z-index: 9992;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  min-height: 52px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--hg-ts-ocean) 0%, var(--hg-ts-ocean-dark) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.hg-ts-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(0,0,0,0.32);
}
.hg-ts-fab:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}
.hg-ts-fab-icon {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  flex: 0 0 auto;
}
.hg-ts-fab-icon svg { width: 14px; height: 14px; fill: #fff; }
.hg-ts-fab-label { white-space: nowrap; }

/* Subtle breathing pulse so the button draws the eye without being annoying. */
.hg-ts-fab::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  border: 2px solid rgba(29, 151, 113, 0.5);
  opacity: 0;
  pointer-events: none;
  animation: hg-ts-breathe 3s ease-in-out infinite;
}
@keyframes hg-ts-breathe {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}
.hg-ts-fab.is-open::before { animation: none; }

/* ── Backdrop ─────────────────────────────────────────────────────── */
.hg-ts-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 28, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 9998;
}
.hg-ts-backdrop.is-active { opacity: 1; pointer-events: auto; }

/* ── Modal ────────────────────────────────────────────────────────── */
/* Centered both axes so it reads as a focused tool rather than an
   ad-adjacent popup. Mobile media query below pins it to the bottom
   sheet pattern, which is the right native behavior on small screens. */
.hg-ts-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-50% + 20px));
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  background: var(--hg-ts-panel);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
  /* Bumped from 16 → 17 px for older readers — site CLAUDE.md target is
     17-19px body text. Headings and bubbles bumped proportionally below. */
  font-size: 17px;
  color: var(--hg-ts-ink);
  line-height: 1.5;
}
.hg-ts-modal.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

/* ── Header ───────────────────────────────────────────────────────── */
/* Two-row layout: top row pairs the parent-brand HawaiiGuide logo on the
   left with the modal controls (voice toggle, hands-free, close) on the
   right. Title + sub get their own breathing room below, so the product
   name "Talk Story" is the visual focal point of the modal header. */
.hg-ts-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 14px;
  background: linear-gradient(135deg, var(--hg-ts-ocean) 0%, var(--hg-ts-ocean-dark) 100%);
  color: #fff;
}
.hg-ts-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.hg-ts-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.hg-ts-header-logo {
  flex: 0 0 auto;
  height: 28px;
  width: auto;
  display: block;
}
@media (max-width: 480px) {
  .hg-ts-header-logo { height: 24px; }
}
.hg-ts-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hg-ts-header-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin: 0;
}
.hg-ts-header-sub {
  display: block;
  font-size: 14px;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 1px;
}
.hg-ts-voice-toggle {
  display: inline-flex;
  gap: 4px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 3px;
  margin-right: 4px;
}
.hg-ts-voice-toggle button {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.3px;
}
.hg-ts-voice-toggle button.is-active {
  background: #fff;
  color: var(--hg-ts-ocean-dark);
}
.hg-ts-close {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.hg-ts-close:hover { background: rgba(255,255,255,0.18); }

/* ── Hands-free toggle ───────────────────────────────────────────── */
/* Sits between the voice toggle and the close X. Off by default. When on,
   the modal auto-restarts the mic 1.5s after each answer finishes playing
   (with a visible countdown the user can cancel). */
.hg-ts-handsfree-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.14);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  padding: 0;
}
.hg-ts-handsfree-btn:hover { background: rgba(255,255,255,0.26); }
.hg-ts-handsfree-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
  opacity: 0.85;
}
.hg-ts-handsfree-btn[aria-pressed="true"] {
  background: #fff;
}
.hg-ts-handsfree-btn[aria-pressed="true"] svg {
  fill: var(--hg-ts-ocean-dark);
  opacity: 1;
}
/* Pulse the active state subtly so users notice it's on. */
.hg-ts-handsfree-btn[aria-pressed="true"]::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  animation: hg-ts-hf-pulse 2s ease-in-out infinite;
  pointer-events: none;
}
.hg-ts-handsfree-btn { position: relative; }
@keyframes hg-ts-hf-pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50%      { transform: scale(1.18); opacity: 0; }
}

/* ── Transcript (scrolling chat area) ─────────────────────────────── */
.hg-ts-transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  background: var(--hg-ts-panel-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 50vh;
}
.hg-ts-transcript:empty::before {
  content: attr(data-empty-hint);
  display: block;
  text-align: center;
  color: var(--hg-ts-muted);
  font-size: 16px;
  padding: 24px 12px;
  margin: auto;
}
.hg-ts-bubble {
  max-width: 92%;
  padding: 12px 15px;
  border-radius: 14px;
  font-size: 17px;
  line-height: 1.55;
  word-wrap: break-word;
}
.hg-ts-bubble.is-user {
  align-self: flex-end;
  background: var(--hg-ts-ocean);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.hg-ts-bubble.is-assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--hg-ts-ink);
  border: 1px solid var(--hg-ts-border);
  border-bottom-left-radius: 4px;
}
.hg-ts-bubble.is-error {
  background: #fff5f5;
  border-color: #f7c9c9;
  color: #8a1f1f;
}
.hg-ts-bubble-audio {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--hg-ts-border);
}
.hg-ts-bubble-audio audio {
  width: 100%;
  height: 32px;
}
.hg-ts-citations {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}
.hg-ts-citation {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--hg-ts-panel-soft);
  border: 1px solid var(--hg-ts-border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--hg-ts-ink);
  font-size: 14px;
  transition: border-color 0.15s;
}
.hg-ts-citation:hover { border-color: var(--hg-ts-ocean-light); }
.hg-ts-citation-title {
  flex: 1 1 auto;
  font-weight: 600;
  line-height: 1.3;
}
.hg-ts-citation-meta {
  font-size: 11px;
  color: var(--hg-ts-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.hg-ts-citation-badge {
  background: var(--hg-ts-ocean);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

/* ── Status row (the always-visible progress indicator) ───────────── */
.hg-ts-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--hg-ts-border);
  background: #fff;
  font-size: 15px;
  color: var(--hg-ts-muted);
  min-height: 44px;
}
.hg-ts-status-indicator {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.hg-ts-status-text { line-height: 1.3; }

/* ── Animation — LISTENING (pulse rings around mic) ───────────────── */
.hg-ts-state-listening .hg-ts-status { color: var(--hg-ts-ocean-dark); font-weight: 600; }
.hg-ts-state-listening .hg-ts-status-indicator::before,
.hg-ts-state-listening .hg-ts-status-indicator::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--hg-ts-ocean);
  animation: hg-ts-listen-ring 1.2s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.hg-ts-state-listening .hg-ts-status-indicator::after { animation-delay: 0.4s; }
.hg-ts-state-listening .hg-ts-status-indicator {
  background: radial-gradient(circle, var(--hg-ts-ocean) 0%, var(--hg-ts-ocean) 40%, transparent 50%);
}
@keyframes hg-ts-listen-ring {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ── Animation — THINKING / TRANSCRIBING (conic-gradient spinner) ─── */
.hg-ts-state-thinking .hg-ts-status,
.hg-ts-state-transcribing .hg-ts-status { color: var(--hg-ts-ocean-dark); font-weight: 600; }
.hg-ts-state-thinking .hg-ts-status-indicator,
.hg-ts-state-transcribing .hg-ts-status-indicator {
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, var(--hg-ts-ocean) 280deg, transparent 360deg);
  animation: hg-ts-spin 0.9s linear infinite;
  mask: radial-gradient(closest-side, transparent 60%, #000 62%);
  -webkit-mask: radial-gradient(closest-side, transparent 60%, #000 62%);
}
@keyframes hg-ts-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ── Animation — SPEAKING (audio equalizer bars) ──────────────────── */
.hg-ts-state-speaking .hg-ts-status { color: var(--hg-ts-accent); font-weight: 600; }
.hg-ts-state-speaking .hg-ts-status-indicator {
  display: inline-flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2px;
  width: 22px;
  height: 18px;
}
.hg-ts-state-speaking .hg-ts-status-indicator::before,
.hg-ts-state-speaking .hg-ts-status-indicator::after,
.hg-ts-state-speaking .hg-ts-status-indicator .hg-ts-bar {
  content: '';
  flex: 1 1 auto;
  background: var(--hg-ts-accent);
  border-radius: 2px;
  animation: hg-ts-eq 0.9s ease-in-out infinite;
}
.hg-ts-state-speaking .hg-ts-status-indicator::after { animation-delay: 0.3s; }
.hg-ts-state-speaking .hg-ts-status-indicator .hg-ts-bar { animation-delay: 0.15s; }
@keyframes hg-ts-eq {
  0%, 100% { height: 25%; }
  50% { height: 100%; }
}

/* ── Animation — ERROR (static dot) ───────────────────────────────── */
.hg-ts-state-error .hg-ts-status { color: #b22020; font-weight: 600; }
.hg-ts-state-error .hg-ts-status-indicator {
  border-radius: 50%;
  background: #b22020;
  width: 10px;
  height: 10px;
}

/* Idle / done — hide the indicator entirely. */
.hg-ts-state-idle .hg-ts-status-indicator,
.hg-ts-state-done .hg-ts-status-indicator { display: none; }
.hg-ts-state-idle .hg-ts-status { color: var(--hg-ts-muted); }

/* ── Input row ────────────────────────────────────────────────────── */
.hg-ts-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  background: #fff;
}
.hg-ts-mic-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--hg-ts-ocean);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.hg-ts-mic-btn:hover { background: var(--hg-ts-ocean-dark); }
.hg-ts-mic-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.hg-ts-mic-btn.is-recording {
  background: #b22020;
  animation: hg-ts-mic-pulse 1s ease-in-out infinite;
}
@keyframes hg-ts-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(178, 32, 32, 0.5); }
  50%      { box-shadow: 0 0 0 10px rgba(178, 32, 32, 0); }
}
.hg-ts-mic-btn svg { width: 18px; height: 18px; fill: #fff; }

.hg-ts-text-input {
  flex: 1 1 auto;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 14px;
  border: 1px solid var(--hg-ts-border);
  border-radius: 22px;
  background: var(--hg-ts-panel-soft);
  font-family: inherit;
  font-size: 17px;
  line-height: 1.45;
  color: var(--hg-ts-ink);
  outline: none;
}
.hg-ts-text-input:focus {
  border-color: var(--hg-ts-ocean-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(24,102,180,0.15);
}
.hg-ts-send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--hg-ts-accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.hg-ts-send-btn:hover:not(:disabled) { background: #d46b1c; }
.hg-ts-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.hg-ts-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Footer disclaimer ────────────────────────────────────────────── */
.hg-ts-footer-note {
  padding: 0 16px 12px;
  font-size: 13px;
  color: var(--hg-ts-muted);
  text-align: center;
  line-height: 1.4;
  background: #fff;
}

/* ── Mobile refinements ───────────────────────────────────────────── */
@media (max-width: 560px) {
  .hg-ts-fab {
    /* Mobile: drop the pill closer to the bottom edge so it doesn't
       crowd the Shaka FAB stacked above it. Standard mobile sticky ads
       max out around 90px tall, so 110px keeps a 20px gap above any ad
       while opening up ~80px of clear space between this pill and Shaka
       (which sits at bottom: 250px on mobile). */
    bottom: 110px;
    padding: 10px 14px 10px 12px;
    font-size: 15px;
  }
  .hg-ts-modal {
    width: 100vw;
    max-width: 100vw;
    bottom: 0;
    border-radius: 18px 18px 0 0;
    max-height: 85vh;
  }
  .hg-ts-modal.is-active { transform: translate(-50%, 0); }
  .hg-ts-transcript { max-height: none; }
}

/* Print + no-JS: hide entirely. */
@media print {
  .hg-ts-fab, .hg-ts-modal, .hg-ts-backdrop { display: none !important; }
}
