/* ═══════════════════════════════════════════════
   Yantrik Companion UI
   Warm organic design — firelight aesthetic
   ═══════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Backgrounds */
  --bg-deep: #0a0a0a;
  --bg-surface: #141210;
  --bg-card: #1a1714;
  --bg-elevated: #221f1a;
  --bg-input: #1a1714;

  /* Amber palette */
  --amber: #d4a574;
  --amber-light: #e8c496;
  --amber-dim: #a07a50;
  --amber-glow: rgba(212, 165, 116, 0.25);
  --amber-glow-strong: rgba(212, 165, 116, 0.5);

  /* Instinct colors */
  --color-pattern: #d4a574;
  --color-reminder: #c48a5a;
  --color-emotional: #c47a7a;
  --color-check-in: #7aa574;
  --color-follow-up: #5aa5a5;
  --color-conflict: #c4695a;

  /* Text */
  --text-primary: #e8e0d8;
  --text-secondary: #8a7e72;
  --text-dim: #5a5248;

  /* Spacing */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --input-height: 56px;

  /* Transitions */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}

button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

textarea {
  font: inherit;
  color: inherit;
  border: none;
  outline: none;
  resize: none;
  background: none;
}

/* ── Screens ── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out);
}

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

/* ════════════════════════════════════════════════
   AI MODE: IDLE — The Breathing Orb
   ════════════════════════════════════════════════ */

#ai-idle {
  justify-content: center;
  align-items: center;
  background: var(--bg-deep);
}

.orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  cursor: pointer;
}

.orb {
  position: relative;
  width: 120px;
  height: 120px;
}

.orb__glow {
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(212, 165, 116, 0.15) 0%,
    rgba(212, 165, 116, 0.05) 40%,
    transparent 70%
  );
  animation: orb-glow 4s ease-in-out infinite;
}

.orb__core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 35%,
    var(--amber-light) 0%,
    var(--amber) 40%,
    var(--amber-dim) 100%
  );
  box-shadow:
    0 0 40px var(--amber-glow),
    0 0 80px rgba(212, 165, 116, 0.1);
  animation: orb-breathe 4s ease-in-out infinite;
}

.orb__ring {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out);
}

/* Proactive state — ring pulses when urges pending */
.orb--proactive .orb__ring {
  opacity: 1;
  border-color: var(--amber);
  animation: orb-ring-pulse 2s ease-in-out infinite;
}

/* Thinking state — faster breathing during LLM call */
.orb--thinking .orb__core {
  animation-duration: 1.5s;
}
.orb--thinking .orb__glow {
  animation-duration: 1.5s;
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes orb-glow {
  0%, 100% {
    opacity: 0.6;
    transform: scale(0.95);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

@keyframes orb-ring-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.8;
  }
}

.orb-label {
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.6;
}

/* Mode switch button */
.mode-switch {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: color 0.2s;
}
.mode-switch:active {
  color: var(--amber);
}

.mode-switch--bottom-right {
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
}

/* ════════════════════════════════════════════════
   AI MODE: CHAT
   ════════════════════════════════════════════════ */

#ai-chat {
  background: var(--bg-deep);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  min-height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.header-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: 12px;
  transition: background 0.15s, color 0.15s;
}
.header-btn:active {
  background: var(--bg-elevated);
  color: var(--amber);
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Messages area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* User message — dark bubble, right-aligned */
.msg--user {
  align-self: flex-end;
  max-width: 80%;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-radius: 18px 18px 4px 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

/* Yantrik message — floating text with amber dot */
.msg--yantrik {
  align-self: flex-start;
  max-width: 85%;
  display: flex;
  gap: 10px;
  font-size: 15px;
  line-height: 1.55;
}

.msg--yantrik::before {
  content: "";
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
}

.msg__text {
  word-break: break-word;
  color: var(--text-primary);
}

/* Typing indicator */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 0 16px 12px;
  gap: 4px;
}

.typing-indicator.visible {
  display: flex;
}

.typing-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber-dim);
  animation: typing-pulse 1.4s ease-in-out infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* ════════════════════════════════════════════════
   INPUT AREA (shared by chat + home)
   ════════════════════════════════════════════════ */

.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid rgba(255,255,255,0.04);
}

.input-area textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 16px;
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.4;
}

.input-area textarea::placeholder {
  color: var(--text-dim);
}

.send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amber);
  color: var(--bg-deep);
  border-radius: 50%;
  transition: transform 0.15s var(--ease-spring), opacity 0.15s;
  opacity: 0.4;
}

.send-btn.active {
  opacity: 1;
}

.send-btn:active {
  transform: scale(0.92);
}

/* ════════════════════════════════════════════════
   GENERIC MODE: HOME
   ════════════════════════════════════════════════ */

#generic-home {
  background: var(--bg-deep);
}

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  min-height: 56px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.5px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg-card);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-check-in);
  animation: status-pulse 3s ease-in-out infinite;
}

.status-dot--offline {
  background: var(--text-dim);
  animation: none;
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Glance cards area */
.glance-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* Individual glance card */
.glance-card {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  border-left: 3px solid var(--amber);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s var(--ease-out);
  min-height: 44px;
}

.glance-card:active {
  background: var(--bg-elevated);
  transform: scale(0.98);
}

/* Instinct color coding via border */
.glance-card[data-instinct="PatternSurfacing"] { border-left-color: var(--color-pattern); }
.glance-card[data-instinct="Reminder"] { border-left-color: var(--color-reminder); }
.glance-card[data-instinct="EmotionalAwareness"] { border-left-color: var(--color-emotional); }
.glance-card[data-instinct="CheckIn"] { border-left-color: var(--color-check-in); }
.glance-card[data-instinct="FollowUp"] { border-left-color: var(--color-follow-up); }
.glance-card[data-instinct="ConflictAlerting"] { border-left-color: var(--color-conflict); }

.glance-card__urgency {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--amber);
}

.glance-card__body {
  flex: 1;
  min-width: 0;
}

.glance-card__reason {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.glance-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.glance-card__instinct-tag {
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  font-size: 11px;
  text-transform: lowercase;
}

/* Empty state */
.glance-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  color: var(--text-dim);
  text-align: center;
}

.glance-empty__orb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--amber-dim), rgba(160, 122, 80, 0.3));
  opacity: 0.4;
  animation: orb-breathe 4s ease-in-out infinite;
}

.glance-empty__text {
  font-size: 14px;
  line-height: 1.5;
}

/* ════════════════════════════════════════════════
   BOOT SEQUENCE: "The Returning Glow"
   ════════════════════════════════════════════════ */

#boot {
  justify-content: center;
  align-items: center;
  background: var(--bg-deep);
}

.boot {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Phase 1: Embers — pulsing coals in darkness */
.boot-embers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ember {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber-glow-strong), 0 0 12px var(--amber-glow);
  opacity: 0;
  animation:
    ember-pulse var(--rate) ease-in-out var(--delay) infinite,
    ember-converge 3s cubic-bezier(0.45, 0.0, 0.15, 1.0) 3s forwards;
}

@keyframes ember-pulse {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.3); }
}

@keyframes ember-converge {
  0% { opacity: 0.6; }
  80% { opacity: 0.4; }
  100% {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
}

/* Phase 2-3: Boot orb + text */
.boot-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 1;
}

.boot-orb {
  position: relative;
  width: 120px;
  height: 120px;
  opacity: 0;
  transform: scale(0.3);
  filter: blur(8px);
  animation: orb-kindle 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 5s forwards;
}

.boot-orb .orb__glow {
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(212, 165, 116, 0.15) 0%,
    rgba(212, 165, 116, 0.05) 40%,
    transparent 70%
  );
  animation: orb-glow 4s ease-in-out infinite;
}

.boot-orb .orb__core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 35%,
    var(--amber-light) 0%,
    var(--amber) 40%,
    var(--amber-dim) 100%
  );
  box-shadow:
    0 0 40px var(--amber-glow),
    0 0 80px rgba(212, 165, 116, 0.1);
  animation: orb-breathe 4s ease-in-out infinite;
}

@keyframes orb-kindle {
  0% { opacity: 0; transform: scale(0.3); filter: blur(8px); }
  50% { opacity: 0.7; filter: blur(2px); }
  100% { opacity: 1; transform: scale(1); filter: blur(0); }
}

.boot-text {
  font-size: 2.2rem;
  color: var(--amber);
  letter-spacing: 0.15em;
  opacity: 0;
  animation: boot-fade-in 1.5s ease-out 5.5s forwards;
}

.boot-status {
  font-size: 0.8rem;
  color: var(--amber-dim);
  letter-spacing: 0.05em;
  opacity: 0;
  animation: boot-status-pulse 2s ease-in-out 6s infinite, boot-fade-in 1s ease-out 6s forwards;
}

@keyframes boot-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes boot-status-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* Fast boot — service already warm */
.boot--fast .ember {
  animation-duration: calc(var(--rate) / 2), 1.5s;
  animation-delay: calc(var(--delay) / 2), 1.5s;
}
.boot--fast .boot-orb { animation-delay: 2.5s; animation-duration: 1s; }
.boot--fast .boot-text { animation-delay: 2.8s; }
.boot--fast .boot-status { animation-delay: 3s, 3s; }

/* Hiding — fade out everything except orb */
.boot--hiding .boot-embers,
.boot--hiding .boot-text,
.boot--hiding .boot-status {
  opacity: 0 !important;
  transition: opacity 0.8s var(--ease-out);
}

/* Personality-driven boot variants */
.boot--warm .ember {
  background: var(--amber-light);
  box-shadow: 0 0 8px rgba(232, 196, 150, 0.6), 0 0 16px var(--amber-glow);
}
.boot--eager .ember {
  animation-duration: calc(var(--rate) / 1.5), 2s;
}
.boot--deep .ember { width: 5px; height: 5px; }

/* ════════════════════════════════════════════════
   SCROLLBAR
   ════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(212, 165, 116, 0.15);
  border-radius: 3px;
}

/* ════════════════════════════════════════════════
   UTILITIES
   ════════════════════════════════════════════════ */

/* ════════════════════════════════════════════════
   MIC BUTTON
   ════════════════════════════════════════════════ */

.mic-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
}

.mic-btn:active {
  color: var(--amber);
}

.mic-btn.recording {
  color: var(--color-emotional);
  background: rgba(196, 122, 122, 0.15);
  animation: mic-pulse 1s ease-in-out infinite;
}

.mic-btn.transcribing {
  color: var(--amber-dim);
  animation: mic-spin 1s linear infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes mic-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Voice status text (shows "Listening..." or "Transcribing...") */
.voice-status {
  display: none;
  align-self: flex-start;
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-dim);
}

.voice-status.visible {
  display: block;
}

.hidden { display: none !important; }
