/* index.css — Samantha Web Client */

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "SF Pro Text", -apple-system, system-ui, sans-serif;
  background: var(--s1-void);
  color: var(--s1-ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── Auth Screen ────────────────────────────────────── */

.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--s1-void);
  z-index: 100;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.auth-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* Auth orb — reuse main orb but larger */
.auth-orb {
  position: relative;
  width: 100px;
  height: 100px;
}

.auth-orb-glow {
  position: absolute;
  inset: -55%;
  border-radius: 50%;
  background: rgba(217, 119, 87, 0.18);
  filter: blur(40px);
  animation: auth-glow 5s ease-in-out infinite;
}

@keyframes auth-glow {
  0%, 100% { transform: scale(0.9); opacity: 0.5; }
  50% { transform: scale(1.1); opacity: 0.7; }
}

.auth-orb-sphere {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%,
    rgba(255, 255, 255, 0.9),
    #d97757 72%,
    rgba(217, 119, 87, 0.6));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 10px 32px rgba(217, 119, 87, 0.34),
    inset 0 -4px 12px rgba(0, 0, 0, 0.1);
  animation: auth-sphere-breathe 3s ease-in-out infinite;
}

@keyframes auth-sphere-breathe {
  0%, 100% { transform: scale(0.97); }
  50% { transform: scale(1.0); }
}

.auth-title {
  font-size: 22px;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--s1-ink);
}

.auth-input {
  width: 260px;
  padding: 12px 18px;
  border: 1px solid var(--s1-border);
  border-radius: 12px;
  background: var(--s1-surface);
  color: var(--s1-ink);
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  outline: none;
  transition: border-color 0.25s;
}

.auth-input:focus { border-color: var(--s1-accent); }
.auth-input::placeholder { color: var(--s1-muted); }

.auth-btn {
  padding: 11px 56px;
  border: none;
  border-radius: 10px;
  background: var(--s1-accent);
  color: var(--s1-on-accent);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}

.auth-btn:hover { filter: brightness(1.1); }
.auth-btn:active { transform: scale(0.97); }

.auth-error {
  font-size: 13px;
  color: var(--s1-danger);
  min-height: 18px;
}

/* ── App Shell ──────────────────────────────────────── */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  overflow: hidden;
}

.app[hidden] { display: none; }

/* ── Header ─────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 48px;
  background: var(--s1-surface);
  border-bottom: 1px solid var(--s1-border-subtle);
  flex-shrink: 0;
}

.app-brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}

.app-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-text {
  font-size: 12px;
  color: var(--s1-muted);
  text-transform: capitalize;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--s1-muted);
  transition: all 0.3s;
}

.status-dot.listening {
  background: var(--s1-success);
  box-shadow: 0 0 6px var(--s1-success);
}

.status-dot.thinking {
  background: var(--s1-accent);
  box-shadow: 0 0 6px var(--s1-accent);
  animation: dot-pulse 0.8s ease-in-out infinite;
}

.status-dot.speaking {
  background: #ba613d;
  box-shadow: 0 0 6px #ba613d;
}

.status-dot.connecting {
  background: var(--s1-accent-deep);
  animation: dot-pulse 0.6s ease-in-out infinite;
}

.status-dot.connected {
  background: var(--s1-accent);
  box-shadow: 0 0 6px var(--s1-accent);
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── Body — conversation + canvas split ─────────────── */

.app-body {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  transition: grid-template-columns 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-body.canvas-open {
  grid-template-columns: 1fr 1fr;
}

/* ── Conversation Panel ─────────────────────────────── */

.conversation-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ══════════════════════════════════════════════════════
   Orb — matches iOS OrbView.swift
   6 states: idle, connecting, connected, listening, thinking, speaking
   ══════════════════════════════════════════════════════ */

.orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 0 12px;
  flex-shrink: 0;
}

.orb {
  --orb-color: #d97757;
  --orb-highlight: rgba(255, 255, 255, 0.9);
  --orb-pulse: 3s;
  --orb-scale-min: 0.97;
  --orb-scale-max: 1.0;

  position: relative;
  width: 100px;
  height: 100px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Ambient glow — 2.1x size, blurred */
.orb-glow {
  position: absolute;
  inset: -55%;
  border-radius: 50%;
  background: var(--orb-color);
  opacity: 0.18;
  filter: blur(54px);
  animation: orb-glow var(--orb-pulse) ease-in-out infinite;
  animation-duration: calc(var(--orb-pulse) * 1.2);
}

@keyframes orb-glow {
  0%, 100% { transform: scale(0.85); opacity: 0.12; }
  50% { transform: scale(1.15); opacity: 0.22; }
}

/* Speaking ripples — 2 expanding circles */
.orb-ripple {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--orb-color);
  opacity: 0;
  pointer-events: none;
}

/* Sphere — radial gradient for 3D look */
.orb-sphere {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%,
    var(--orb-highlight),
    var(--orb-color) 72%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 10px 32px color-mix(in srgb, var(--orb-color) 34%, transparent),
    inset 0 -4px 12px rgba(0, 0, 0, 0.08);
  animation: orb-pulse var(--orb-pulse) ease-in-out infinite;
}

@keyframes orb-pulse {
  0%, 100% { transform: scale(var(--orb-scale-min)); }
  50% { transform: scale(var(--orb-scale-max)); }
}

/* ── Orb state: idle ────────────────────────────────── */
.orb.idle {
  --orb-color: #d97757;
  --orb-pulse: 3s;
  --orb-scale-min: 0.97;
  --orb-scale-max: 1.0;
}

.orb.idle .orb-sphere {
  opacity: 0.92;
}

/* ── Orb state: connecting ──────────────────────────── */
.orb.connecting {
  --orb-color: #c6613f;
  --orb-pulse: 0.6s;
  --orb-scale-min: 0.92;
  --orb-scale-max: 1.04;
}

/* ── Orb state: connected ───────────────────────────── */
.orb.connected {
  --orb-color: #d97757;
  --orb-pulse: 1.5s;
  --orb-scale-min: 0.95;
  --orb-scale-max: 1.02;
}

/* ── Orb state: listening ───────────────────────────── */
.orb.listening {
  --orb-color: #d97757;
  --orb-pulse: 2s;
  --orb-scale-min: 0.95;
  --orb-scale-max: 1.05;
}

/* ── Orb state: thinking ────────────────────────────── */
.orb.thinking {
  --orb-color: #d17d47;
  --orb-highlight: rgba(255, 212, 171, 1.0);
  --orb-pulse: 0.8s;
  --orb-scale-min: 0.90;
  --orb-scale-max: 1.10;
}

/* ── Orb state: speaking ────────────────────────────── */
.orb.speaking {
  --orb-color: #ba613d;
  --orb-highlight: rgba(250, 202, 168, 1.0);
  --orb-pulse: 0.5s;
  --orb-scale-min: 0.97;
  --orb-scale-max: 1.05;
}

.orb.speaking .orb-ripple:nth-child(2) {
  animation: orb-ripple-out 1.2s ease-out infinite;
}

.orb.speaking .orb-ripple:nth-child(3) {
  animation: orb-ripple-out 1.2s ease-out infinite 0.4s;
}

@keyframes orb-ripple-out {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Orb label */
.orb-label {
  margin-top: 10px;
  font-size: 12px;
  color: var(--s1-muted);
  letter-spacing: 0.04em;
  text-transform: capitalize;
  transition: color 0.3s;
}

/* ── Thread ─────────────────────────────────────────── */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.thread:empty::after {
  content: "Tap the orb to start a voice conversation";
  color: var(--s1-muted);
  font-size: 14px;
  text-align: center;
  margin-top: 3rem;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: msg-in 0.25s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: var(--s1-accent);
  color: var(--s1-on-accent);
  border-bottom-right-radius: 6px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--s1-surface-raised);
  border: 1px solid var(--s1-border-subtle);
  border-bottom-left-radius: 6px;
}

.msg.system {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--s1-border);
  color: var(--s1-muted);
  font-size: 13px;
  max-width: 90%;
}

.msg.interim {
  align-self: flex-end;
  background: transparent;
  border: 1px solid var(--s1-border);
  color: var(--s1-secondary);
  font-style: italic;
  border-bottom-right-radius: 6px;
}

.msg.thinking-placeholder {
  align-self: flex-start;
  background: var(--s1-surface-raised);
  border: 1px solid var(--s1-border-subtle);
  border-bottom-left-radius: 6px;
  color: var(--s1-muted);
  animation: msg-in 0.25s ease-out, dot-pulse 1.2s ease-in-out infinite;
}

.msg-time {
  font-size: 11px;
  color: var(--s1-muted);
  margin-top: 4px;
  opacity: 0.65;
}

.msg.user .msg-time {
  color: rgba(255, 255, 255, 0.55);
  text-align: right;
}

/* Canvas trigger button inside message */
.msg-canvas-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 5px 12px;
  border: 1px solid var(--s1-border);
  border-radius: 8px;
  background: var(--s1-surface-dim);
  color: var(--s1-accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.msg-canvas-btn:hover {
  border-color: var(--s1-accent);
  background: var(--s1-accent-bg);
}

.msg-canvas-icon {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}

/* ── Input Bar ──────────────────────────────────────── */

.input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--s1-surface);
  border-top: 1px solid var(--s1-border-subtle);
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--s1-border);
  border-radius: 22px;
  background: var(--s1-surface-dim);
  color: var(--s1-ink);
  font-size: 16px; /* >= 16px prevents iOS zoom */
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.message-input:focus { border-color: var(--s1-accent); }
.message-input::placeholder { color: var(--s1-muted); }

.mic-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--s1-accent);
  color: var(--s1-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.mic-btn:hover { filter: brightness(1.1); }
.mic-btn:active { transform: scale(0.92); }

.mic-btn.active {
  background: var(--s1-danger);
  animation: mic-glow 2s ease-in-out infinite;
}

@keyframes mic-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(213, 85, 85, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(213, 85, 85, 0); }
}

/* ── Canvas Panel ───────────────────────────────────── */

.canvas-panel {
  display: flex;
  flex-direction: column;
  background: var(--s1-surface);
  border-left: 1px solid var(--s1-border-subtle);
  overflow: hidden;
  animation: canvas-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes canvas-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 48px;
  border-bottom: 1px solid var(--s1-border-subtle);
  flex-shrink: 0;
}

.canvas-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--s1-secondary);
  letter-spacing: 0.01em;
}

.canvas-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--s1-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}

.canvas-close:hover {
  background: var(--s1-surface-dim);
  color: var(--s1-ink);
}

.canvas-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
}

.canvas-body h1, .canvas-body h2, .canvas-body h3 {
  color: var(--s1-ink);
  margin-bottom: 8px;
}

.canvas-body h1 { font-size: 18px; }
.canvas-body h2 { font-size: 16px; }
.canvas-body h3 { font-size: 15px; font-weight: 600; }
.canvas-body h3 + h3 { margin-top: 24px; }

.canvas-body p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--s1-secondary);
  margin: 8px 0;
}

.canvas-body ul, .canvas-body ol {
  padding-left: 18px;
  margin: 8px 0;
}

.canvas-body li {
  margin: 6px 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--s1-secondary);
}

.canvas-body li strong {
  color: var(--s1-ink);
}

.canvas-body code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--s1-surface-dim);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 13px;
}

.canvas-body pre {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--s1-surface-dim);
  overflow-x: auto;
  margin: 12px 0;
}

.canvas-body pre code {
  padding: 0;
  background: none;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 840px) {
  .app-body.canvas-open {
    grid-template-columns: 1fr;
  }

  .canvas-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 50;
    border-left: none;
    animation: canvas-up 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes canvas-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

@media (min-width: 1200px) {
  .app-body.canvas-open {
    grid-template-columns: 2fr 3fr;
  }
}
