@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400&family=Inter+Tight:wght@400;500;600;700&display=swap');

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

:root {
  --bg-sink: #1e1e1c;
  --bg: #2b2b29;
  --bg-dark: #3d3d3b;
  --bg-mid: #5d5d5b;
  --bg-light: #7D7D7B;
  --bg-glass: rgba(30, 30, 28, 0.7);
  --bg-glass-light: rgba(255, 255, 255, 0.04);
  --text: #FFFFFF;
  --text-mid: #dddddd;
  --text-dark: #999999;
  --text-faint: #5d5d5b;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #F44E2A;
  --accent-hover: #FF6342;
  --accent-glow: rgba(244, 78, 42, 0.3);
  --radius-sm: 20px;
  --radius-md: 12px;
  --radius-lg: 24px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter Tight', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Global background gradient */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(244, 78, 42, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(244, 78, 42, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Particle canvas background */
#particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.6;
}

/* Nav */
nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(30,30,28,0.6) 0%, transparent 100%);
}

nav .logo {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--text-mid);
}

nav .auth-status {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

nav .auth-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

nav .auth-status.logged-in .dot {
  background: #4ADE80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

/* Main stage */
main {
  position: relative;
  z-index: 2;
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 32px 32px;
}

/* Hero state — initial question input */
.hero {
  width: 100%;
  max-width: 640px;
  text-align: center;
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}

.hero.hidden {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
  position: absolute;
}

.hero h1 {
  font-weight: 500;
  font-size: 56px;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin-bottom: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #bbbbbb 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero .subtitle {
  font-size: 16px;
  color: var(--text-dark);
  margin-bottom: 48px;
  letter-spacing: -0.01em;
}

.question-box {
  position: relative;
  background: var(--bg-glass-light);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: border-color 0.2s var(--ease), box-shadow 0.3s var(--ease);
}

.question-box:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04), 0 0 40px rgba(244, 78, 42, 0.08);
}

.question-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 18px 20px;
  font-family: 'Inter Tight', sans-serif;
  font-size: 17px;
  color: var(--text);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.question-box input::placeholder {
  color: var(--text-faint);
}

.question-box .mic-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: transparent;
  color: var(--text-dark);
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
  padding: 0;
}

.question-box .mic-icon:hover {
  background: var(--bg-glass-light);
  color: var(--text-mid);
}

.question-box .mic-icon:disabled {
  color: var(--text-faint);
  cursor: not-allowed;
}

.question-box .mic-icon.listening {
  color: var(--accent);
  background: var(--accent-soft, rgba(244, 78, 42, 0.12));
  animation: micPulse 1.4s var(--ease) infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 78, 42, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(244, 78, 42, 0); }
}

.question-box .submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
  padding: 0;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.question-box .submit-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.03);
}

.question-box .submit-btn:disabled {
  background: var(--bg-mid);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.hero .examples {
  margin-top: 32px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.hero .example-chip {
  background: var(--bg-glass-light);
  border: 1px solid var(--border);
  color: var(--text-mid);
  padding: 8px 14px;
  border-radius: 100px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-family: 'Inter Tight', sans-serif;
}

.hero .example-chip:hover {
  background: var(--bg-glass);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Loading overlay — dramatic particle burst */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(ellipse at center, rgba(244, 78, 42, 0.08) 0%, rgba(30, 30, 28, 0.9) 60%, rgba(30, 30, 28, 0.95) 100%);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 48px;
  opacity: 0;
  transition: opacity 0.5s var(--ease);
  overflow: hidden;
}

.loading-overlay.active {
  display: flex;
  opacity: 1;
}

/* Dedicated particle canvas for loading */
.loading-overlay canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.loading-orb {
  width: 200px;
  height: 200px;
  position: relative;
  z-index: 2;
}

.loading-orb .core {
  position: absolute;
  inset: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #FF8860 0%, var(--accent) 40%, #B83718 100%);
  box-shadow:
    0 0 80px var(--accent),
    0 0 160px rgba(244, 78, 42, 0.4),
    inset 0 0 30px rgba(255, 255, 255, 0.2);
  animation: breathe 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.18); filter: brightness(1.25); }
}

.loading-text {
  font-family: 'Inter Tight', sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.02em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out);
  z-index: 2;
  text-align: center;
  max-width: 400px;
}

.loading-text.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Workspace — active state with avatar + diagram */
.workspace {
  width: 100%;
  max-width: 1400px;
  height: calc(100vh - 180px);
  margin-top: 60px;
  display: none;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out);
}

.workspace.active {
  display: grid;
  opacity: 1;
}

/* Artifact panel (big) */
.artifact-panel {
  background: var(--bg-glass-light);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.artifact-panel iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
}

.artifact-loading {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(30, 30, 28, 0.85);
  backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 100px;
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--text-mid);
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 10;
  border: 1px solid var(--border);
}

.artifact-loading.active { display: flex; }

.artifact-loading .orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseGlow 1.2s var(--ease) infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px transparent; transform: scale(1.15); }
}

/* Right column — avatar card */
.avatar-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.avatar-card {
  width: 100%;
  aspect-ratio: 3 / 4;          /* match the widget's natural 240x320 portrait */
  background: var(--bg-glass-light);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

/* Hide portrait once widget is live */
.avatar-card.widget-mode img { display: none; }

/* The Ojin widget has a hardcoded 240x320 inner frame inside its shadow DOM.
   We scale it uniformly via a CSS variable updated in JS so it fills the card. */
.avatar-card widget-embed {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 240px;
  height: 320px;
  transform: translate(-50%, -50%) scale(var(--widget-scale, 1));
  transform-origin: center center;
  display: block;
}

.expert-info {
  background: var(--bg-glass-light);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  flex-shrink: 0;
}

.expert-info .label {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--text-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.expert-info .expert-name {
  font-weight: 500;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-bottom: 10px;
}

.expert-info .topic {
  font-size: 13px;
  color: var(--text-mid);
  line-height: 1.5;
}

/* Question header at top of workspace */
.question-header {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 800px;
  width: calc(100% - 64px);
  display: none;
  align-items: baseline;
  gap: 14px;
  padding: 14px 22px;
  background: rgba(30, 30, 28, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  z-index: 15;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out) 0.3s;
}

.question-header.active {
  display: flex;
  opacity: 1;
}

.question-header .question-label {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--text-dim, #888);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  flex-shrink: 0;
}

.question-header .question-text {
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
  font-weight: 500;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Voice-only hint pill at bottom (kept for future use) */
.voice-hint {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: rgba(30, 30, 28, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px;
  color: var(--text-mid);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out) 0.4s;
  letter-spacing: -0.005em;
}

.voice-hint.active {
  display: flex;
  opacity: 1;
}

.voice-hint svg {
  color: var(--accent);
}

/* Error message */
.error-msg {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #2e1a1a;
  border: 1px solid #4e2a2a;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  color: #ff6666;
  font-size: 13px;
  z-index: 200;
  display: none;
  max-width: 500px;
  backdrop-filter: blur(10px);
}

.error-msg.active { display: block; }

/* Small screens */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .avatar-column {
    flex-direction: row;
    max-height: 200px;
  }
  .avatar-card {
    width: 200px;
    aspect-ratio: 1 / 1;
  }
  .hero h1 { font-size: 36px; }
}

/* Icons */
.icon-arrow { width: 18px; height: 18px; }
.icon-upload { width: 18px; height: 18px; }
