/* ------------------------------------------------
   Sojourn Labs — Design Tokens & Theme
   ------------------------------------------------ */

:root {
  --bg: #FAFAF9;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --text-accent: #AAAAAA;
  --mission-color: #111111;
  --divider: #D4D4D4;
  --hover-underline: rgba(0, 0, 0, 0.25);
  --sheet-bg: #FFFFFF;
  --sheet-border: rgba(0, 0, 0, 0.06);
  --sheet-handle: #D4D4D4;
  --btn-bg: #F5F5F4;
  --btn-border: #E5E5E3;
  --btn-hover: #EBEBEA;
  --logo-shape-1: #555555;
  --logo-shape-2: #3A3A3A;
  --logo-shape-3: #1A1A1A;
  --backdrop-start: rgba(250, 250, 249, 0);
  --backdrop-end: rgba(250, 250, 249, 0.7);
  --sheet-btn-bg: rgba(255, 255, 255, 0.6);
  --sheet-btn-border: rgba(0, 0, 0, 0.08);
  --sheet-btn-hover: rgba(255, 255, 255, 0.8);
  --bubble-bg: rgba(32, 153, 253, 0.08);
  --bubble-border: rgba(0, 0, 0, 0.06);
  --footnote-bg: rgba(0, 0, 0, 0.08);
  --footnote-text: #FFFFFF;
  --toast-bg: #1A1A1A;
  --toast-text: #FAFAF9;
}

[data-theme="dark"] {
  --bg: #0C0C0C;
  --text-primary: #E8E8E5;
  --text-secondary: #888888;
  --text-tertiary: #555555;
  --text-accent: #555555;
  --mission-color: #F0F0ED;
  --divider: #2A2A2A;
  --hover-underline: rgba(255, 255, 255, 0.3);
  --sheet-bg: #1A1A1A;
  --sheet-border: rgba(255, 255, 255, 0.06);
  --sheet-handle: #444444;
  --btn-bg: #252525;
  --btn-border: #333333;
  --btn-hover: #2E2E2E;
  --logo-shape-1: #D0D0D0;
  --logo-shape-2: #AAAAAA;
  --logo-shape-3: #888888;
  --backdrop-start: rgba(12, 12, 12, 0);
  --backdrop-end: rgba(12, 12, 12, 0.7);
  --sheet-btn-bg: rgba(255, 255, 255, 0.08);
  --sheet-btn-border: rgba(255, 255, 255, 0.1);
  --sheet-btn-hover: rgba(255, 255, 255, 0.12);
  --bubble-bg: rgba(32, 153, 253, 0.12);
  --bubble-border: rgba(255, 255, 255, 0.06);
  --footnote-bg: rgba(255, 255, 255, 0.12);
  --footnote-text: #0C0C0C;
  --toast-bg: #E8E8E5;
  --toast-text: #0C0C0C;
}

/* ------------------------------------------------
   Base
   ------------------------------------------------ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* ------------------------------------------------
   Page Layout
   ------------------------------------------------ */

.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ------------------------------------------------
   Header
   ------------------------------------------------ */

.header {
  max-width: 728px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 48px 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.shape {
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.4s ease;
}

.shape-1 {
  width: 12px;
  height: 5px;
  border-radius: 3px;
  background: var(--logo-shape-1);
}

.shape-2 {
  width: 20px;
  height: 5px;
  border-radius: 3px;
  background: var(--logo-shape-2);
}

.shape-3 {
  width: 28px;
  height: 9px;
  border-radius: 3px 3px 14px 14px;
  background: var(--logo-shape-3);
}

.logo:hover .shape-1 { transform: translateY(3px); }
.logo:hover .shape-2 { transform: translateY(1px); }
.logo:hover .shape-3 { transform: translateY(-2px); }

.logo-text {
  font-family: 'Overpass', system-ui, sans-serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 24px;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------
   Theme Toggle
   ------------------------------------------------ */

.theme-toggle {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.theme-toggle:hover {
  color: var(--text-primary);
}

.theme-toggle .icon {
  position: absolute;
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

[data-theme="light"] .icon-sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

[data-theme="dark"] .icon-moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

[data-theme="dark"] .icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ------------------------------------------------
   Content & Manifesto
   ------------------------------------------------ */

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px;
}

.manifesto {
  max-width: 680px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.manifesto p {
  font-size: 20px;
  line-height: 170%;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

.manifesto .pivot {
  padding-top: 28px;
}

.manifesto .mission {
  padding-top: 36px;
  font-size: 28px;
  line-height: 145%;
  font-weight: 500;
  color: var(--mission-color);
  transition: color 0.4s ease;
}

.manifesto .closing {
  font-size: 17px;
  line-height: 170%;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

/* ------------------------------------------------
   Prompt Segments (clickable text)
   ------------------------------------------------ */

.prompt-segment {
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 6px;
  margin: 0 -6px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  background: rgba(32, 153, 253, 0);
  box-shadow: 0 0 0 0 rgba(32, 153, 253, 0);
  transition: background-color 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (hover: hover) {
  .prompt-segment:hover,
  .prompt-segment.linked-hover {
    background: rgba(32, 153, 253, 0.10);
    box-shadow: 0 1px 8px -2px rgba(32, 153, 253, 0.18);
  }
}

.prompt-segment.flash {
  animation: segment-flash 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes segment-flash {
  0%   { opacity: 1; }
  40%  { opacity: 0.35; }
  100% { opacity: 1; }
}

.ask-label {
  position: fixed;
  z-index: 50;
  background: #2099FD;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease,
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.ask-label.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (hover: none) {
  .ask-label {
    display: none;
  }
}

/* ------------------------------------------------
   Sign-off
   ------------------------------------------------ */

.sign-off {
  max-width: 680px;
  width: 100%;
}

.divider {
  width: 48px;
  height: 1px;
  border: none;
  background: var(--divider);
  margin: 56px 0;
  transition: background-color 0.4s ease;
}

.signature {
  font-size: 17px;
  color: var(--text-primary);
  margin-bottom: 8px;
  transition: color 0.4s ease;
}

.contact {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-secondary);
  padding: 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.contact:hover {
  color: var(--text-primary);
  text-decoration-color: var(--hover-underline);
}

/* ------------------------------------------------
   Footer
   ------------------------------------------------ */

.footer {
  max-width: 728px;
  width: 100%;
  margin: 0 auto;
  padding: 56px 24px 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.copyright {
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-accent);
  transition: color 0.4s ease;
}

.footer-link {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-accent);
  padding: 0;
  transition: color 0.2s ease;
}

.footer-link:hover {
  color: var(--text-secondary);
}

.footer-icon-link {
  color: var(--text-accent);
  transition: color 0.2s ease;
}

.footer-icon-link:hover {
  color: var(--text-secondary);
}

.for-agents {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-accent);
  text-decoration: none;
  padding: 4px 0;
  transition: color 0.2s ease;
}

.for-agents:hover {
  color: var(--text-secondary);
}

/* ------------------------------------------------
   Action Sheet
   ------------------------------------------------ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 100%, var(--backdrop-end) 0%, var(--backdrop-start) 70%);
  backdrop-filter: blur(20px) saturate(0.3);
  -webkit-backdrop-filter: blur(20px) saturate(0.3);
  transition: opacity 0.35s ease;
}

.sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.action-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 95;
  transform: translate(-50%, 100%);
  width: 420px;
  max-width: calc(100vw - 32px);
  background: none;
  padding: 12px 20px 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.action-sheet.active {
  transform: translate(-50%, 0);
}

.sheet-handle {
  display: none;
}

.sheet-email {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 0;
  transition: color 0.4s ease;
}

.sheet-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  background: var(--sheet-btn-bg);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color 0.15s ease, color 0.4s ease,
              border-color 0.4s ease;
}

.sheet-btn:hover {
  background: var(--sheet-btn-hover);
}

.sheet-btn:active {
  transform: scale(0.985);
}

/* ------------------------------------------------
   Response Overlay
   ------------------------------------------------ */

.response-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 50%, var(--backdrop-end) 0%, var(--backdrop-start) 70%);
  backdrop-filter: blur(20px) saturate(0.3);
  -webkit-backdrop-filter: blur(20px) saturate(0.3);
  transition: opacity 0.45s ease;
}

.response-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.response-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 100px 24px 48px;
  pointer-events: none;
  overflow: hidden;
}

.response-overlay.active {
  overflow-y: auto;
  scrollbar-width: none;
  pointer-events: auto;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 64px,
    black calc(100% - 64px),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 64px,
    black calc(100% - 64px),
    transparent 100%
  );
}

.response-overlay.active .response-bubble,
.response-overlay.active .response-meta,
.response-overlay.active .response-body {
  pointer-events: auto;
}

.response-overlay.active::-webkit-scrollbar {
  display: none;
}

/* Quote bubble — animates from text position via FLIP */
.response-bubble {
  max-width: 600px;
  width: 100%;
  flex-shrink: 0;
  background: var(--bubble-bg);
  border-radius: 16px;
  padding: 20px 24px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: background-color 0.4s ease;
}

.response-bubble.animate {
  opacity: 1;
  transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.2s ease,
              background-color 0.4s ease;
}

.response-quote {
  font-size: 17px;
  line-height: 165%;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

/* Model meta — below bubble */
.response-meta {
  max-width: 600px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 28px;
  padding-left: 4px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: color 0.4s ease;
}

.response-meta.visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease,
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              color 0.4s ease;
}

.response-model-icon {
  width: 16px;
  height: 16px;
  filter: grayscale(1) brightness(0.8);
  opacity: 0.6;
  transition: filter 0.4s ease;
}

[data-theme="dark"] .response-model-icon {
  filter: grayscale(1) brightness(1.8);
  opacity: 0.5;
}

.response-model-name {
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

.response-meta-sep {
  opacity: 0.4;
}

/* Scrollable stream body — below meta */
.response-body {
  max-width: 600px;
  width: 100%;
  flex-shrink: 0;
  margin-top: 10px;
  padding-bottom: 48px;
  opacity: 0;
  pointer-events: none;
  transition: color 0.4s ease;
}

.response-body.visible {
  opacity: 1;
  transition: opacity 0.3s ease, color 0.4s ease;
}

.response-stream {
  font-size: 17px;
  line-height: 180%;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

.response-footnotes {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.4s ease;
}

.response-footnotes.visible {
  opacity: 1;
  transform: translateY(0);
}

.response-footnote {
  font-size: 12px;
  line-height: 160%;
  color: var(--text-tertiary);
  display: flex;
  align-items: baseline;
  gap: 8px;
  transition: color 0.4s ease;
}

.response-footnote-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--footnote-bg);
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-secondary);
  position: relative;
  top: 1px;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* Inline footnote refs in streamed text */
.footnote-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--footnote-bg);
  font-size: 8px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-secondary);
  vertical-align: super;
  margin: 0 1px;
  position: relative;
  top: -1px;
  transition: background-color 0.4s ease, color 0.4s ease;
}

.response-footnote a {
  color: var(--text-tertiary);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.response-footnote a:hover {
  color: var(--text-secondary);
  text-decoration-color: var(--hover-underline);
}

.response-actions {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--divider);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.4s ease;
}

.response-actions.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.response-actions-label {
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  transition: color 0.4s ease;
}

.response-actions-buttons {
  display: flex;
  gap: 8px;
}

.response-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  background: var(--sheet-btn-bg);
  border: none;
  border-radius: 8px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color 0.15s ease, color 0.2s ease;
}

.response-action-btn:hover {
  background: var(--sheet-btn-hover);
  color: var(--text-primary);
}

.response-action-btn:active {
  transform: scale(0.97);
}

.response-action-btn svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.response-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--text-primary);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: cursor-blink 0.7s step-end infinite;
  transition: background-color 0.4s ease;
}

.response-cursor.done {
  animation: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

/* ------------------------------------------------
   Overlay Close Button
   ------------------------------------------------ */

.overlay-close {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 96;
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, color 0.2s ease;
}

.overlay-close.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-close:hover {
  color: var(--text-primary);
}

/* ------------------------------------------------
   Toast
   ------------------------------------------------ */

.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  z-index: 100;
  transform: translate(-50%, 12px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 20px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease,
              transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.4s ease,
              color 0.4s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------
   Entrance Animations
   ------------------------------------------------ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.shape {
  animation: fadeInUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.shape-3 { animation-delay: 0ms; }
.shape-2 { animation-delay: 50ms; }
.shape-1 { animation-delay: 100ms; }

.logo-text {
  animation: fadeInUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) 80ms both;
}

.content,
.footer {
  animation: fadeIn 0.8s ease 200ms both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.theme-toggle {
  animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) 300ms both;
}

/* ------------------------------------------------
   Reduced Motion
   ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------
   Responsive
   ------------------------------------------------ */

@media (max-width: 768px) {
  .header {
    padding: 32px 24px;
  }

  .content {
    padding-top: 24px;
  }

  .manifesto p {
    font-size: 18px;
  }

  .manifesto .mission {
    font-size: 24px;
  }

  .manifesto .closing {
    font-size: 16px;
  }

  .footer {
    padding: 48px 24px 40px;
  }

  .action-sheet {
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
  }
}

@media (max-width: 768px) {
  .response-actions-buttons {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 24px 20px;
  }

  .content {
    padding: 0 20px;
  }

  .manifesto p {
    font-size: 17px;
  }

  .manifesto .mission {
    font-size: 22px;
  }

  .footer {
    padding: 40px 20px 32px;
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }
}
