/* 🪐 UNIVERSE AI Mini App — dark space, Gen Z, mobile-first (360–430px) */
:root {
  --bg-0: #05070f;
  --bg-1: #0a1020;
  --bg-panel: rgba(14, 20, 36, 0.78);
  --bg-elevated: rgba(22, 32, 52, 0.88);
  --stroke: rgba(148, 210, 255, 0.12);
  --stroke-strong: rgba(45, 212, 191, 0.35);
  --text: #eef4ff;
  --text-dim: #9aacc8;
  --text-faint: #6b7f9e;
  --accent: #2dd4bf;
  --accent-2: #22d3ee;
  --accent-deep: #0f766e;
  --danger: #fb7185;
  --user-a: #0d9488;
  --user-b: #0891b2;
  --ai-bubble: rgba(255, 255, 255, 0.06);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --dock-h: 0px;
  --top-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

textarea {
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  width: 100%;
  color: var(--text);
}

/* Atmosphere */
.cosmos {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, #142038 0%, transparent 55%),
    radial-gradient(80% 50% at 100% 100%, rgba(8, 145, 178, 0.18) 0%, transparent 50%),
    radial-gradient(70% 45% at 0% 80%, rgba(13, 148, 136, 0.16) 0%, transparent 45%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
}

.cosmos__mesh {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, rgba(34, 211, 238, 0.08), transparent 28%),
    radial-gradient(circle at 75% 20%, rgba(45, 212, 191, 0.1), transparent 32%),
    radial-gradient(circle at 60% 75%, rgba(14, 165, 233, 0.07), transparent 30%);
  animation: mesh-drift 18s ease-in-out infinite alternate;
}

.cosmos__stars {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 18%, rgba(255,255,255,0.75), transparent),
    radial-gradient(1px 1px at 28% 62%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.4px 1.4px at 48% 24%, rgba(170,240,255,0.8), transparent),
    radial-gradient(1px 1px at 66% 72%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.2px 1.2px at 82% 36%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 91% 81%, rgba(190,245,255,0.55), transparent),
    radial-gradient(1px 1px at 8% 88%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.3px 1.3px at 55% 48%, rgba(255,255,255,0.65), transparent);
  animation: stars-twinkle 6s ease-in-out infinite;
}

.cosmos__glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.45;
}

.cosmos__glow--a {
  width: 220px;
  height: 220px;
  left: -40px;
  top: 18%;
  background: rgba(34, 211, 238, 0.22);
  animation: glow-float 12s ease-in-out infinite;
}

.cosmos__glow--b {
  width: 260px;
  height: 260px;
  right: -60px;
  bottom: 12%;
  background: rgba(45, 212, 191, 0.18);
  animation: glow-float 14s ease-in-out infinite reverse;
}

.cosmos__noise {
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes mesh-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(2%, 2%, 0) scale(1.05); }
}

@keyframes stars-twinkle {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.7; }
}

@keyframes glow-float {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(18px, -24px, 0); }
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none !important;
}

.screen--center {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(24px + var(--safe-t)) 28px calc(28px + var(--safe-b));
  gap: 10px;
}

.screen--main {
  padding-top: var(--safe-t);
}

/* Brand */
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
}

.brand-mark--hero {
  width: 88px;
  height: 88px;
  margin-bottom: 6px;
}

.brand-mark--sm {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-mark__core {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(0 0 18px rgba(45, 212, 191, 0.45));
  animation: core-pulse 2.8s ease-in-out infinite;
}

.brand-mark--sm .brand-mark__core {
  font-size: 22px;
}

.brand-mark__orbit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(45, 212, 191, 0.35);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.15);
  animation: orbit-spin 10s linear infinite;
}

.brand-mark__orbit::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px var(--accent-2);
}

@keyframes orbit-spin {
  to { transform: rotate(360deg); }
}

@keyframes core-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.brand-title {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.15rem;
  letter-spacing: 0.08em;
  background: linear-gradient(120deg, #f0fdff 10%, var(--accent) 55%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tag {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 280px;
}

.boot-status {
  margin: 18px 0 0;
  color: var(--text-faint);
  font-size: 0.88rem;
}

.pulse-loader {
  display: flex;
  gap: 7px;
  margin-top: 22px;
}

.pulse-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.1s ease-in-out infinite;
}

.pulse-loader span:nth-child(2) { animation-delay: 0.15s; background: var(--accent-2); }
.pulse-loader span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse-dot {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  50% { transform: translateY(-5px); opacity: 1; }
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--top-h);
  padding: 10px 14px 8px;
  backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(5, 7, 15, 0.82), rgba(5, 7, 15, 0.35) 80%, transparent);
  z-index: 5;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  line-height: 1.1;
}

.topbar__sub {
  color: var(--text-dim);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.1);
  border: 1px solid rgba(45, 212, 191, 0.28);
  color: #b7fff4;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: core-pulse 2s ease-in-out infinite;
}

.chip--warn {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.35);
  color: #fecdd3;
}

.chip--warn .chip__dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  transition: transform 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  background: rgba(45, 212, 191, 0.1);
  outline: none;
}

.icon-btn--sm {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

/* Messages */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 14px 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
  width: 0;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
  max-width: 92%;
  animation: msg-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg--user {
  align-self: flex-end;
  margin-left: auto;
}

.msg--assistant {
  align-self: flex-start;
}

.msg__bubble {
  padding: 11px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.msg--user .msg__bubble {
  background: linear-gradient(145deg, var(--user-a), var(--user-b));
  color: #f0fdff;
  border-bottom-right-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.msg--assistant .msg__bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--stroke);
  border-bottom-left-radius: 6px;
  backdrop-filter: blur(10px);
  color: var(--text);
}

.msg__meta {
  font-size: 0.7rem;
  color: var(--text-faint);
  padding: 0 6px;
}

.msg--user .msg__meta {
  text-align: right;
}

.msg__media {
  display: block;
  max-width: 220px;
  max-height: 180px;
  border-radius: 12px;
  margin-bottom: 8px;
  object-fit: cover;
}

.msg__file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.86rem;
}

.msg--system {
  align-self: center;
  max-width: 100%;
  margin: 4px 0 14px;
}

.msg--system .msg__bubble {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.86rem;
  padding: 8px 10px;
}

.welcome-card {
  margin: 8px 0 18px;
  padding: 18px 16px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(160deg, rgba(45, 212, 191, 0.12), rgba(8, 145, 178, 0.05) 55%, rgba(255, 255, 255, 0.03)),
    var(--bg-panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  animation: msg-in 0.45s ease both;
}

.welcome-card h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.welcome-card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.suggestion {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.suggestion:active {
  transform: scale(0.96);
}

.suggestion:hover,
.suggestion:focus-visible {
  border-color: var(--stroke-strong);
  background: rgba(45, 212, 191, 0.12);
  outline: none;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 4px 2px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  opacity: 0.5;
  animation: pulse-dot 1s ease-in-out infinite;
}

.typing i:nth-child(2) { animation-delay: 0.12s; }
.typing i:nth-child(3) { animation-delay: 0.24s; }

/* Attachment preview */
.attach-preview {
  padding: 0 14px 8px;
}

.attach-preview__inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--stroke-strong);
  animation: msg-in 0.25s ease both;
}

.attach-preview__thumb {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: rgba(45, 212, 191, 0.12);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 1.2rem;
}

.attach-preview__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attach-preview__name {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.attach-preview__kind {
  color: var(--text-faint);
  font-size: 0.75rem;
}

.attach-preview__meta {
  flex: 1;
  min-width: 0;
}

/* Composer dock */
.composer-dock {
  flex-shrink: 0;
  padding: 6px 12px calc(10px + var(--safe-b));
  background: linear-gradient(0deg, rgba(5, 7, 15, 0.96) 40%, rgba(5, 7, 15, 0.55) 85%, transparent);
  backdrop-filter: blur(16px);
  z-index: 6;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 6px 4px;
  border-radius: 12px;
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color 0.18s ease, background 0.18s ease, transform 0.15s ease;
}

.mode-tab svg {
  opacity: 0.75;
}

.mode-tab.is-active {
  color: #d7fffa;
  background: linear-gradient(160deg, rgba(45, 212, 191, 0.28), rgba(8, 145, 178, 0.18));
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.28);
}

.mode-tab.is-active svg {
  opacity: 1;
  color: var(--accent);
}

.mode-tab:active {
  transform: scale(0.96);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border-radius: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.composer__field {
  flex: 1;
  min-width: 0;
  padding: 8px 2px;
}

.composer__field textarea {
  max-height: 110px;
  min-height: 24px;
  line-height: 1.35;
  font-size: 0.98rem;
}

.composer__field textarea::placeholder {
  color: var(--text-faint);
}

.send-btn {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #041016;
  box-shadow: 0 8px 22px rgba(34, 211, 238, 0.28);
  transition: transform 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

.send-btn:disabled {
  opacity: 0.38;
  filter: grayscale(0.3);
  box-shadow: none;
  cursor: not-allowed;
}

.send-btn:not(:disabled):active {
  transform: scale(0.9);
}

.send-btn.is-loading .send-btn__icon {
  display: none;
}

.send-btn.is-loading .send-btn__spin {
  display: block !important;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(4, 16, 22, 0.25);
  border-top-color: #041016;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.composer__mic.is-recording {
  color: #fff;
  background: rgba(251, 113, 133, 0.25);
  border-color: rgba(251, 113, 133, 0.5);
  animation: rec-pulse 1s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(251, 113, 133, 0); }
}

/* Error + buttons */
.error-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 10px 0 0;
}

.error-detail {
  color: var(--text-dim);
  max-width: 300px;
  margin: 4px 0 18px;
}

.btn-primary {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #041016;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 28px rgba(45, 212, 191, 0.28);
  transition: transform 0.15s ease;
}

.btn-primary:active {
  transform: scale(0.96);
}

/* Recording bar state in composer */
body.is-recording .send-btn {
  background: linear-gradient(145deg, #fb7185, #f43f5e);
  color: #fff;
  box-shadow: 0 8px 22px rgba(244, 63, 94, 0.3);
}

/* Narrow screens */
@media (max-width: 360px) {
  .mode-tab span {
    font-size: 0.62rem;
  }
  .brand-title {
    font-size: 1.9rem;
  }
  .topbar__sub {
    max-width: 110px;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
