/*
 * Web Extension Experience — first-party bar + reader overlay styles.
 *
 * The website-owned bar that demonstrates the Chrome extension's bottom-bar
 * loop on opted-in public Gist pages. Light-DOM CSS, scoped by a single
 * .gist-web-ext-* prefix so it cannot leak into surrounding layout.
 *
 * Visual contract mirrors packages/chrome-plugin/extension/content/overlay/
 * unified-bar-styles.js: 64px bar, 44px circular bolt button, sunrise
 * gradient on the bolt, slide-up entry, light/dark via prefers-color-scheme.
 *
 * The reader assets ship their own CSS (unified-reader.generated.css plus
 * unified-reader-share.generated.css); this file only owns the bar and the
 * overlay shell.
 */

/* ---------- design tokens ---------- */

:root {
  --gist-web-ext-bar-bg: #ffffff;
  --gist-web-ext-bar-border: rgba(28, 28, 36, 0.12);
  --gist-web-ext-bar-text: #1c1c24;
  --gist-web-ext-bar-text-secondary: rgba(28, 28, 36, 0.68);
  --gist-web-ext-bar-hover-bg: rgba(28, 28, 36, 0.06);
  --gist-web-ext-bar-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06), 0 -16px 32px rgba(0, 0, 0, 0.08);
  --gist-web-ext-overlay-bg: #faf6ee;
  --gist-web-ext-icon-on-gradient: #000000;
  --gist-web-ext-gradient: linear-gradient(135deg, #ff6b6b 0%, #ffd93d 50%, #ff8e53 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --gist-web-ext-bar-bg: #1c1c24;
    --gist-web-ext-bar-border: #2a2a2f;
    --gist-web-ext-bar-text: #ffffff;
    --gist-web-ext-bar-text-secondary: rgba(255, 255, 255, 0.68);
    --gist-web-ext-bar-hover-bg: rgba(255, 255, 255, 0.06);
    --gist-web-ext-bar-shadow: 0 -2px 12px rgba(0, 0, 0, 0.35), 0 -16px 32px rgba(0, 0, 0, 0.45);
    --gist-web-ext-overlay-bg: #0e0e12;
  }
}

/* ---------- page spacer (mirrors extension gist-bottom-spacer) ---------- */

/**
 * Appended to document.body while the bar is visible so fixed-position
 * footer chrome is not covered by the 64px control bar.
 */
.gist-web-ext-page-spacer {
  height: 64px;
  pointer-events: none;
  flex-shrink: 0;
}

/* ---------- bar ---------- */

.gist-web-ext-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  z-index: 2147483646;
  background: var(--gist-web-ext-bar-bg);
  border-top: 1px solid var(--gist-web-ext-bar-border);
  box-shadow: var(--gist-web-ext-bar-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  color: var(--gist-web-ext-bar-text);
  transform: translateY(100%);
  transition: transform 250ms ease;
  pointer-events: auto;
}

.gist-web-ext-bar[data-visible="true"] {
  transform: translateY(0);
}

.gist-web-ext-bar[data-state="loading"] {
  pointer-events: none;
}

.gist-web-ext-bar-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  height: 100%;
}

/* ---------- bolt button ---------- */

.gist-web-ext-bolt-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gist-web-ext-gradient);
  color: var(--gist-web-ext-icon-on-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  position: relative;
  font: inherit;
  transition: transform 200ms ease, filter 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.gist-web-ext-bolt-btn:hover {
  filter: brightness(1.05);
}

.gist-web-ext-bolt-btn:active {
  transform: scale(0.96);
}

.gist-web-ext-bolt-btn:focus-visible {
  outline: 2px solid var(--gist-web-ext-bar-text);
  outline-offset: 2px;
}

/*
 * Loading-state breathing animation. Plan 222 locks the cycle duration
 * to the Chrome extension's BarTiming.BREATHING_CYCLE_MS = 3500 ms (see
 * packages/chrome-plugin/extension/content/overlay/unified-bar-constants.js:100).
 * If the extension changes that constant, update this duration to match
 * — the web bar's UX mirrors the extension bar's UX exactly.
 */
.gist-web-ext-bolt-btn[data-breathing="true"] {
  animation: gist-web-ext-bolt-breathe 3500ms ease-in-out infinite;
}

@keyframes gist-web-ext-bolt-breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.gist-web-ext-bolt-btn svg {
  width: 26px;
  height: 26px;
}

.gist-web-ext-bolt-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--gist-web-ext-bar-text);
  color: var(--gist-web-ext-bar-bg);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
  z-index: 1;
}

.gist-web-ext-bolt-tooltip:empty {
  display: none;
}

.gist-web-ext-bar[data-visible="true"] .gist-web-ext-bolt-btn[data-initial-highlight="true"] .gist-web-ext-bolt-tooltip,
.gist-web-ext-bar[data-visible="true"] .gist-web-ext-bolt-btn:hover .gist-web-ext-bolt-tooltip {
  opacity: 1;
}

.gist-web-ext-bar[data-visible="true"] .gist-web-ext-bolt-btn[data-initial-highlight="true"]:hover .gist-web-ext-bolt-tooltip {
  opacity: 0;
}

/* ---------- dismiss (ghost X) ---------- */

.gist-web-ext-dismiss-btn {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--gist-web-ext-bar-border);
  background: var(--gist-web-ext-bar-bg);
  color: var(--gist-web-ext-bar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, background 150ms ease, border-color 150ms ease;
}

.gist-web-ext-bar:hover .gist-web-ext-dismiss-btn {
  opacity: 0.35;
  pointer-events: auto;
}

.gist-web-ext-dismiss-btn:hover {
  opacity: 1;
  background: var(--gist-web-ext-bar-hover-bg);
  border-color: var(--gist-web-ext-bar-text-secondary);
}

.gist-web-ext-dismiss-btn svg {
  width: 18px;
  height: 18px;
}

.gist-web-ext-bar[data-state="loading"] .gist-web-ext-dismiss-btn {
  display: none;
}

/* ---------- overlay shell ---------- */

.gist-web-ext-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483645;
  background: var(--gist-web-ext-overlay-bg);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.gist-web-ext-overlay[data-visible="true"] {
  display: flex;
}

.gist-web-ext-overlay-close {
  appearance: none;
  -webkit-appearance: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--gist-web-ext-bar-border);
  background: var(--gist-web-ext-bar-bg);
  color: var(--gist-web-ext-bar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 2147483647;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: background 150ms ease, border-color 150ms ease, transform 200ms ease;
}

.gist-web-ext-overlay-close:hover {
  background: var(--gist-web-ext-bar-hover-bg);
  border-color: var(--gist-web-ext-bar-text-secondary);
}

.gist-web-ext-overlay-close:active {
  transform: scale(0.96);
}

.gist-web-ext-overlay-close svg {
  width: 18px;
  height: 18px;
}

.gist-web-ext-reader-root {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.gist-web-ext-reader-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--gist-web-ext-overlay-bg);
}
