/* =========================================================
   TOKENS
   ========================================================= */
:root {
  --bg-void: #030712;
  --bg-void-2: #090d16;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --text-primary: #f1f5f9;
  --text-muted: #8b95a7;

  /* Neutral / Nova + Euler accent */
  --accent: #38bdf8;
  --accent-2: #f8fafc;
  --accent-soft: rgba(56, 189, 248, 0.35);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;

  /* Shared premium easing curves */
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-persona: 750ms var(--ease-smooth);
}

/* Registering these as typed custom properties lets the browser
   smoothly interpolate every gradient, border, and shadow that
   references them whenever the persona theme changes — instead
   of the flat colors just snapping instantly. */
@property --accent {
  syntax: '<color>';
  inherits: true;
  initial-value: #38bdf8;
}
@property --accent-2 {
  syntax: '<color>';
  inherits: true;
  initial-value: #f8fafc;
}
@property --accent-soft {
  syntax: '<color>';
  inherits: true;
  initial-value: rgba(56, 189, 248, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-void-2) 0%, var(--bg-void) 60%);
  color: var(--text-primary);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: --accent 850ms ease, --accent-2 850ms ease, --accent-soft 850ms ease;
}

::selection { background: var(--accent-soft); }

/* =========================================================
   BACKGROUND LAYERS
   ========================================================= */
#particle-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  display: block;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(circle at 50% 20%, transparent 0%, rgba(3, 7, 18, 0.55) 100%);
}

/* =========================================================
   GLASS BASE
   ========================================================= */
.glass {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
}

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell {
  position: relative;
  z-index: 2;
  height: 100vh;
  max-width: 880px;
  margin: 0 auto;
  padding: 22px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* =========================================================
   HEADER
   ========================================================= */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  transition: box-shadow 850ms ease;
  box-shadow: 0 8px 32px -12px var(--accent-soft);
}

.header-spacer { flex: 1; }

/* ---- Hamburger menu button ---- */
.menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.2s var(--ease-pop);
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--accent-soft);
}

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

.menu-bar {
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: var(--text-primary);
  transition: transform 0.35s var(--ease-spring), opacity 0.25s ease, width 0.3s ease;
}

.menu-btn[aria-expanded="true"] .menu-bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.menu-btn[aria-expanded="true"] .menu-bar:nth-child(2) {
  opacity: 0;
  width: 0;
}
.menu-btn[aria-expanded="true"] .menu-bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.persona-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pfp-ring {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  padding: 2px;
  flex-shrink: 0;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
  transition: background var(--transition-persona);
  animation: ring-spin 6s linear infinite;
}

@keyframes ring-spin {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(0deg); }
}

.pfp-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  background: var(--bg-void);
  object-fit: cover;
  transition: opacity 0.3s ease;
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid var(--bg-void-2);
  box-shadow: 0 0 8px #34d399;
}

.persona-text { min-width: 0; }

.persona-text h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  transition: color var(--transition-persona);
}

.status-line {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   SIDE DRAWER
   ========================================================= */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms var(--ease-smooth);
  z-index: 40;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 86vw);
  z-index: 50;
  display: flex;
  flex-direction: column;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  border-left: none;
  transform: translateX(-104%);
  transition: transform 480ms var(--ease-spring);
  box-shadow: 30px 0 80px -30px rgba(0, 0, 0, 0.7);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 14px;
  flex-shrink: 0;
}

.drawer-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.drawer-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s var(--ease-pop);
}

.drawer-close-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-primary); }
.drawer-close-btn:active { transform: scale(0.9) rotate(90deg); }

.persona-list {
  list-style: none;
  margin: 0;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}

.persona-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  border: 1px solid transparent;
  opacity: 0;
  transform: translateX(-14px);
  animation: item-in 450ms var(--ease-spring) forwards;
  animation-delay: calc(var(--i) * 60ms + 80ms);
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
}

@keyframes item-in {
  to { opacity: 1; transform: translateX(0); }
}

.persona-item:hover {
  background: rgba(255, 255, 255, 0.045);
  transform: translateX(2px);
}

.persona-item.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: var(--accent-soft);
  box-shadow: 0 0 24px -10px var(--accent-soft);
}

.persona-item img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-void);
  flex-shrink: 0;
  object-fit: cover;
  transition: box-shadow 0.3s ease;
}

.persona-item.active img {
  box-shadow: 0 0 0 2px var(--accent-soft), 0 0 16px -2px var(--accent-soft);
}

.persona-item-text { min-width: 0; flex: 1; }

.persona-item-text strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
}

.persona-item-text span {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.persona-item-check {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.3s var(--ease-pop), transform 0.3s var(--ease-pop);
  flex-shrink: 0;
}

.persona-item.active .persona-item-check {
  opacity: 1;
  transform: scale(1);
}

/* ---- Drawer footer: user profile + dev link ---- */
.drawer-footer {
  flex-shrink: 0;
  padding: 14px 16px 18px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-pfp-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  transition: border-color 0.25s ease, transform 0.2s var(--ease-pop);
}

.user-pfp-btn:hover { border-color: var(--accent-soft); transform: scale(1.05); }

.user-pfp-btn.has-photo { border-style: solid; border-color: var(--accent-soft); }

.user-pfp-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.username-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.username-input::placeholder { color: var(--text-muted); }

.username-input:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.dev-info-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 999px;
  transition: color 0.25s ease, background 0.25s ease, gap 0.2s ease;
}

.dev-info-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  gap: 9px;
}

.dev-info-link svg { transition: transform 0.25s var(--ease-pop); }
.dev-info-link:hover svg { transform: translate(2px, -2px); }

/* =========================================================
   CHAT CONTAINER
   ========================================================= */
.chat-container {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: box-shadow 850ms ease;
  box-shadow: 0 20px 60px -25px var(--accent-soft);
}

/* Subtle top-edge glass sheen for extra depth */
.chat-container::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  z-index: 3;
  pointer-events: none;
}

.ambient-glow {
  position: absolute;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(95px);
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
  transition: background 850ms ease;
}

.ambient-glow-a {
  top: -90px;
  right: -60px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
}

.ambient-glow-b {
  bottom: -110px;
  left: -90px;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, var(--accent-2), transparent 70%);
}

.chat-scroll, .typing-indicator, .composer { position: relative; z-index: 1; }

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Neon scrollbar */
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(var(--accent), transparent);
  border-radius: 10px;
}
.chat-scroll { scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }

.day-divider {
  text-align: center;
  margin-bottom: 4px;
}
.day-divider span {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 12px;
  border-radius: 999px;
}

/* ---- Messages ---- */
.message {
  display: flex;
  gap: 10px;
  max-width: 82%;
  animation: msg-in 420ms var(--ease-spring);
}

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

.message.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--bg-void);
  object-fit: cover;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  line-height: 1.55;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.035);
  word-wrap: break-word;
  white-space: pre-wrap;
  transition: background 0.5s ease, border-color 0.5s ease;
}

.message.incoming .msg-bubble {
  border-bottom-left-radius: 4px;
}

.message.outgoing .msg-bubble {
  border-bottom-right-radius: 4px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, transparent), color-mix(in srgb, var(--accent) 5%, transparent));
  border-color: var(--accent-soft);
}

.message.no-avatar .msg-bubble { margin: 0; }

.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 8px; }
.msg-bubble code {
  background: rgba(0,0,0,0.35);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 13px;
}
.msg-bubble pre {
  background: rgba(0,0,0,0.4);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0 0;
}

.msg-bubble.error-bubble {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
}

/* Typing indicator */
/* Typing indicator visibility is driven entirely by the [hidden]
   attribute via these two rules — this avoids a cascade quirk where
   an unconditional `display: flex` on .typing-indicator would win
   over the browser's default [hidden] styling and leave the dots
   visible at all times. */
.typing-indicator[hidden] { display: none; }
.typing-indicator:not([hidden]) {
  display: flex;
  gap: 10px;
  padding: 0 22px 12px;
  align-items: center;
  animation: msg-in 300ms var(--ease-spring);
}
.typing-bubble {
  display: flex;
  gap: 4px;
  padding: 13px 16px;
}
.typing-bubble .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-bubble .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* =========================================================
   COMPOSER
   ========================================================= */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  transition: box-shadow 0.3s ease, border-color 850ms ease;
}

.composer:focus-within {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.composer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  max-height: 140px;
  padding: 9px 2px;
}

.composer-input::placeholder { color: var(--text-muted); }

.composer-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s var(--ease-pop);
  flex-shrink: 0;
}
.composer-icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}
.composer-icon-btn:active { transform: scale(0.9); }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  flex-shrink: 0;
  cursor: pointer;
  color: var(--bg-void);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-pop), box-shadow 850ms ease, background 850ms ease;
  box-shadow: 0 0 22px -4px var(--accent-soft);
}

.send-btn:hover { transform: scale(1.08) rotate(4deg); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.footnote {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  opacity: 0.7;
}

/* =========================================================
   PERSONA THEME OVERRIDES
   ========================================================= */
body.theme-alisa {
  --accent: #f43f5e;
  --accent-2: #fda4af;
  --accent-soft: rgba(244, 63, 94, 0.35);
}

body.theme-klingshot {
  --accent: #22c55e;
  --accent-2: #a855f7;
  --accent-soft: rgba(34, 197, 94, 0.35);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 640px) {
  .app-shell { padding: 14px 10px 10px; gap: 12px; }
  .persona-text h1 { font-size: 14.5px; }
  .status-line { font-size: 11.5px; }
  .message { max-width: 92%; }
  .chat-scroll { padding: 16px; }
  .drawer { width: 88vw; }
}

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

/* Focus visibility for accessibility */
button:focus-visible,
textarea:focus-visible,
input:focus-visible,
li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
