:root {
  --bg-base: #232428;
  --bg-topbar: rgba(30, 31, 36, 0.92);
  --bg-surface: rgba(34, 35, 41, 0.9);
  --bg-elevated: #2b2d34;
  --card-grad: linear-gradient(180deg, #1f1137 0%, #140b24 58%, #10091c 100%);
  --card-border: rgba(168, 85, 247, 0.42);
  --card-border-hover: rgba(192, 132, 252, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --text-primary: #f4f4f8;
  --text-secondary: #b8bccb;
  --text-muted: #84899c;
  --title-pink: #e879f9;
  --title-lavender: #d8b4fe;
  --gold-border: rgba(234, 179, 8, 0.42);
  --gold-text: #fcd34d;
  --accent: #9333ea;
  --accent-soft: rgba(147, 51, 234, 0.22);
  --accent-action: #c4b5fd;
  --emerald: #10b981;
  --danger: #ef4444;
  --discord: #5865f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.48);
  --font-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.glass-panel {
  background: var(--bg-topbar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-color: var(--border-subtle);
}

.glass-card {
  background: var(--bg-surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Top Navbar */
.top-header {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 440px) 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.4rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.header-center {
  width: 100%;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.25);
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #ec4899, #22d3ee);
  display: grid;
  place-items: center;
  color: #fff;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.primary-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-tab {
  padding: 0.42rem 0.78rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: 600 0.88rem var(--font-sans);
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

/* Global Ctrl+K Search */
.global-search {
  position: relative;
  display: flex;
  align-items: center;
}

.global-search .search-icon {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  pointer-events: none;
}

.global-search input {
  width: 100%;
  padding: 0.54rem 4.2rem 0.54rem 2.35rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font: 500 0.86rem var(--font-sans);
  outline: none;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.global-search input:focus {
  border-color: rgba(192, 132, 252, 0.65);
  background: rgba(255, 255, 255, 0.08);
}

.kbd-hint {
  position: absolute;
  right: 0.55rem;
  padding: 0.16rem 0.42rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-muted);
  font: 600 0.7rem var(--font-mono);
  pointer-events: none;
}

.telemetry-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.36rem 0.72rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.75);
}

/* Theme Switcher in Masthead */
.theme-switcher-deck {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
  user-select: none;
}

.theme-toggle-btn:hover {
  color: var(--text-primary);
}

.theme-toggle-btn.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.theme-indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.theme-toggle-btn.active .theme-indicator-dot {
  opacity: 1;
}

/* Voice Audition Box in Character Dialog */
.audition-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.voice-audition-player {
  flex: 1;
  height: 32px;
  outline: none;
}

/* Buttons */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon.sm {
  width: 15px;
  height: 15px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  padding: 0.5rem 0.95rem;
  border-radius: 9px;
  border: 1px solid transparent;
  font: 600 0.85rem var(--font-sans);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.35rem 0.68rem;
  font-size: 0.76rem;
  border-radius: 7px;
}

.btn-icon {
  padding: 0.42rem;
  width: 34px;
  height: 34px;
}

.btn-primary {
  background: linear-gradient(135deg, #9333ea, #7c3aed);
  color: #fff;
  box-shadow: 0 4px 16px rgba(147, 51, 234, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.12);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.13);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.btn-discord {
  background: var(--discord);
  color: #fff;
}

.btn-success {
  background: var(--emerald);
  color: #042f2e;
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.13);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.28);
}

.btn-danger-text:hover:not(:disabled) {
  color: #fca5a5;
}

/* Workspace Layout */
.workspace-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Sidebar only visible when in chat view (or mobile drawer) */
.sessions-sidebar {
  width: 276px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  display: none;
  flex-direction: column;
  min-height: 0;
}

.app-shell.in-chat .sessions-sidebar {
  display: flex;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.55rem 0.55rem 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.52rem 0.62rem;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.session-item.active {
  background: var(--accent-soft);
  border-color: rgba(168, 85, 247, 0.4);
}

.session-item-meta {
  flex: 1;
  min-width: 0;
}

.session-item-title {
  font-size: 0.83rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-preview {
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 5px;
}

.session-item:hover .session-item-del {
  opacity: 1;
}

.session-item-del:hover {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}

.sidebar-empty {
  padding: 1.5rem 0.75rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.sidebar-backdrop {
  display: none;
}

/* Main Stage */
.main-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-pane {
  display: none;
  flex: 1;
  min-height: 0;
}

.view-pane.active {
  display: flex;
  flex-direction: column;
}

/* =========================================================================
   EXPLORE VIEW (JanitorAI-Inspired Charcoal + Editorial Serif + Tall Cards)
   ========================================================================= */

#viewExplore {
  overflow-y: auto;
  padding: 0 0 2.5rem;
}

.announcement-bar {
  text-align: center;
  padding: 0.55rem 1rem;
  background: #1b1c20;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.announcement-bar strong {
  color: #fff;
}

/* Horizontal Emoji Tag Rail */
.tag-rail-wrap {
  max-width: 1280px;
  width: 100%;
  margin: 1.25rem auto 0;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tag-rail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  padding: 0.15rem 0;
}

.tag-rail::-webkit-scrollbar {
  display: none;
}

.tag-rail-pill {
  flex-shrink: 0;
  padding: 0.42rem 0.88rem;
  border-radius: 8px;
  border: 1px solid var(--gold-border);
  background: rgba(28, 29, 34, 0.9);
  color: var(--gold-text);
  font: 600 0.82rem var(--font-sans);
  cursor: pointer;
  transition: all 0.16s ease;
}

.tag-rail-pill:hover {
  background: rgba(234, 179, 8, 0.12);
  border-color: rgba(250, 204, 21, 0.7);
}

.tag-rail-pill.active {
  background: rgba(234, 179, 8, 0.22);
  border-color: #facc15;
  color: #fef08a;
  box-shadow: 0 0 12px rgba(234, 179, 8, 0.22);
}

.rail-scroll-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #2f3138;
  color: var(--text-primary);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Editorial Serif Hero */
.editorial-hero {
  max-width: 960px;
  margin: 2.2rem auto 2rem;
  padding: 0 1.5rem;
  text-align: center;
}

.serif-hero-title {
  margin: 0 0 0.65rem;
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 5.4vw, 4.3rem);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.hero-subtitle {
  margin: 0;
  font-size: 0.98rem;
  color: var(--text-secondary);
}

/* Segmented Feed Bar */
.feed-bar {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto 1.25rem;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.feed-tabs {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  padding: 0.3rem;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.feed-tabs::-webkit-scrollbar {
  display: none;
}

.feed-tab {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0.46rem 0.95rem;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: 600 0.84rem var(--font-sans);
  cursor: pointer;
  transition: all 0.16s ease;
}

.feed-tab:hover {
  color: #fff;
}

.feed-tab.active {
  background: linear-gradient(135deg, #8b5cf6, #9333ea);
  color: #fff;
  box-shadow: 0 4px 14px rgba(147, 51, 234, 0.35);
}

.char-count-pill {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: #2c2d34;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
}

.feed-section-heading {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto 0.9rem;
  padding: 0 1.5rem;
}

.feed-eyebrow {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.feed-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
}

/* Portrait-First Character Grid */
.character-grid {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 1.05rem;
}

/* Tall Violet JanitorAI-Style Card */
.char-card {
  display: flex;
  flex-direction: column;
  border-radius: 13px;
  background: var(--card-grad);
  border: 1px solid var(--card-border);
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.char-card:hover {
  transform: translateY(-4px);
  border-color: var(--card-border-hover);
  box-shadow: 0 14px 36px rgba(88, 28, 135, 0.32);
}

.char-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.62rem 0.8rem;
  background: rgba(168, 85, 247, 0.08);
  border-bottom: 1px solid rgba(168, 85, 247, 0.18);
}

.char-card-name {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--title-pink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.char-card-header-btns {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

.card-mini-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.18rem 0.42rem;
  font: 600 0.68rem var(--font-sans);
  cursor: pointer;
}

.card-mini-btn:hover {
  color: #fff;
  border-color: var(--card-border-hover);
}

/* Full-Bleed Portrait Artwork */
.char-card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at 30% 25%, #4c1d95, #1e1b4b 65%, #0f0a1e 100%);
  overflow: hidden;
  cursor: pointer;
}

.char-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.28s ease;
}

.char-card:hover .char-card-media img {
  transform: scale(1.03);
}

.char-media-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 4rem;
  font-weight: 700;
  color: rgba(233, 213, 255, 0.85);
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

.media-stats-ribbon {
  position: absolute;
  top: 0.55rem;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.26rem 0.6rem;
  border-top-left-radius: 7px;
  border-bottom-left-radius: 7px;
  background: rgba(109, 40, 217, 0.92);
  color: #f5f3ff;
  font: 700 0.72rem var(--font-sans);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.media-discord-pill {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  padding: 0.22rem 0.52rem;
  border-radius: 6px;
  font: 700 0.68rem var(--font-sans);
  background: rgba(88, 101, 242, 0.92);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.media-discord-pill.live {
  background: rgba(16, 185, 129, 0.92);
  color: #022c22;
}

.media-hover-cta {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0.55rem;
  background: linear-gradient(transparent, rgba(12, 7, 24, 0.92));
  display: flex;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.char-card:hover .media-hover-cta {
  opacity: 1;
}

/* Card Body */
.char-card-body {
  padding: 0.75rem 0.82rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
}

.char-creator-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #a78bfa;
}

.verified-dot {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #6366f1;
  color: #fff;
  font-size: 0.62rem;
}

.char-card-tagline {
  margin: 0;
  font-size: 0.81rem;
  color: #d4d7e6;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 3.4em;
}

/* Signature Sparkle Divider */
.sparkle-divider {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0.25rem 0 0.1rem;
}

.sparkle-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(168, 85, 247, 0.2), rgba(192, 132, 252, 0.85));
}

.sparkle-star {
  color: #d8b4fe;
  font-size: 0.95rem;
  line-height: 1;
  text-shadow: 0 0 10px rgba(216, 180, 254, 0.95);
}

/* Multi-Tag Cloud */
.char-tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32rem;
  margin-top: 0.15rem;
}

.card-tag-pill {
  font-size: 0.69rem;
  font-weight: 600;
  padding: 0.17rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e5e7f3;
}

.card-tag-pill.hashtag {
  background: rgba(147, 51, 234, 0.15);
  border-color: rgba(192, 132, 252, 0.45);
  color: #e9d5ff;
}

.card-tag-pill.discord-pill {
  background: rgba(88, 101, 242, 0.24);
  border-color: rgba(129, 140, 248, 0.5);
  color: #c7d2fe;
}

/* Token Footer */
.char-card-footer {
  margin-top: auto;
  padding: 0.5rem 0.8rem 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.token-footer-label {
  font: 600 0.72rem var(--font-mono);
  color: var(--text-muted);
}

.explore-footer {
  max-width: 1280px;
  margin: 2.5rem auto 0;
  padding: 1.25rem 1.5rem 0;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Avatars */
.avatar {
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #9333ea);
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 0.82rem;
  border-radius: 8px;
}

.avatar-md {
  width: 44px;
  height: 44px;
  font-size: 1.05rem;
}

.avatar-lg {
  width: 76px;
  height: 76px;
  font-size: 1.7rem;
  border-radius: 14px;
}

/* Empty States */
.empty-state, .chat-empty-placeholder {
  max-width: 440px;
  margin: 2rem auto;
  padding: 2.25rem 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

.empty-state[hidden], .chat-empty-placeholder[hidden], .chat-room[hidden] {
  display: none !important;
}

.empty-badge {
  font-size: 2.2rem;
}

.empty-state h3, .chat-empty-placeholder h3 {
  margin: 0;
}

.empty-state p, .chat-empty-placeholder p {
  margin: 0 0 0.4rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
}

/* =========================================================================
   DEDICATED CHAT ROOM
   ========================================================================= */

.chat-room {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.72rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chat-char-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.chat-char-text {
  min-width: 0;
}

.chat-char-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-char-name-row h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.discord-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.16rem 0.52rem;
  border-radius: 999px;
  background: rgba(88, 101, 242, 0.25);
  color: #c7d2fe;
}

.discord-badge.running {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
}

.chat-char-tagline {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

.chat-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.msg-row {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.msg-row.user {
  flex-direction: row-reverse;
}

.msg-bubble-wrap {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.msg-row.user .msg-bubble-wrap {
  align-items: flex-end;
}

.msg-sender {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

.msg-bubble {
  padding: 0.85rem 1.05rem;
  border-radius: 15px;
  line-height: 1.58;
  font-size: 0.93rem;
  word-break: break-word;
  border: 1px solid var(--border-subtle);
}

.msg-row.assistant .msg-bubble {
  background: #1c172b;
  border-color: rgba(168, 85, 247, 0.24);
  border-top-left-radius: 4px;
}

.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.34), rgba(99, 102, 241, 0.32));
  border-color: rgba(168, 85, 247, 0.4);
  border-top-right-radius: 4px;
}

.msg-bubble em.rp-action {
  color: var(--accent-action);
  font-style: italic;
}

.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.12rem 0.35rem;
  border-radius: 5px;
}

.msg-bubble pre {
  margin: 0.55rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: #111216;
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.msg-bubble pre code {
  background: transparent;
  padding: 0;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.msg-row:hover .msg-actions,
.msg-row:focus-within .msg-actions {
  opacity: 1;
}

.msg-action-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font: 600 0.72rem var(--font-sans);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}

.msg-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.msg-action-btn.delete:hover {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.typing-cursor::after {
  content: "▋";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent-action);
  animation: blink 0.85s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Composer */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  max-width: 860px;
  width: calc(100% - 2rem);
  margin: 0 auto 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: 14px;
  border: 1px solid var(--border-medium, var(--border-subtle));
  flex-shrink: 0;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font: 500 0.94rem var(--font-sans);
  line-height: 1.45;
  max-height: 160px;
  outline: none;
  padding: 0.35rem 0.25rem;
}

.btn-send {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  flex-shrink: 0;
}

/* Native <dialog> Modals */
dialog.native-dialog {
  width: min(680px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2.5rem);
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
  overflow: hidden;
}

dialog.native-dialog.dialog-sm {
  width: min(500px, calc(100vw - 2rem));
}

dialog.native-dialog::backdrop {
  background: rgba(8, 8, 12, 0.74);
  backdrop-filter: blur(6px);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2.5rem);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.dialog-body {
  padding: 1.2rem 1.35rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.35rem;
  border-top: 1px solid var(--border-subtle);
}

.dialog-footer-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.form-row-avatar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.flex-1 {
  flex: 1;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.span-2 {
  grid-column: span 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.token-live-badge {
  font: 600 0.72rem var(--font-mono);
  color: #d8b4fe;
  background: rgba(147, 51, 234, 0.18);
  padding: 0.12rem 0.48rem;
  border-radius: 999px;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  padding: 0.56rem 0.75rem;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font: 500 0.87rem var(--font-sans);
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--card-border-hover);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  padding-top: 1.25rem;
  cursor: pointer;
}

.form-accordion {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  padding: 0.7rem 0.9rem;
}

.form-accordion summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.accordion-content {
  margin-top: 0.85rem;
}

/* Discord Manager */
.discord-status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
}

.status-card-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.status-card-value {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: capitalize;
}

.discord-control-btns {
  display: flex;
  gap: 0.45rem;
}

.invite-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.invite-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.invite-row {
  display: flex;
  gap: 0.45rem;
}

.invite-row input {
  flex: 1;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-secondary);
  font: 500 0.78rem var(--font-mono);
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
}

.toast {
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: #221a36;
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.55);
  color: #fecaca;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.55);
  color: #a7f3d0;
}

.mobile-only {
  display: none;
}

@media (max-width: 900px) {
  .mobile-only {
    display: inline-flex;
  }

  .top-header {
    grid-template-columns: auto 1fr auto;
    padding: 0.6rem 0.85rem;
  }

  .primary-nav, .telemetry-pill, .kbd-hint {
    display: none;
  }

  .app-shell.in-chat .sessions-sidebar,
  .sessions-sidebar {
    display: flex;
    position: fixed;
    top: 57px;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    background: var(--bg-sidebar);
  }

  .sessions-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 57px 0 0 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 40;
  }

  .character-grid {
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    padding: 0 1rem;
  }

  .chat-topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.55rem;
    flex-wrap: nowrap;
  }

  .msg-bubble-wrap {
    max-width: 90%;
  }

  .form-row-avatar {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }
}

/* =========================================================================
   CHARACTER PROFILE VIEW (JanitorAI 2-Column Split)
   ========================================================================= */

#viewProfile {
  overflow-y: auto;
  padding: 1.5rem 1.5rem 3rem;
}

.profile-shell {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 470px) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.profile-card {
  border-radius: 16px;
  background: var(--card-grad);
  border: 1px solid rgba(168, 85, 247, 0.55);
  box-shadow: 0 18px 48px rgba(109, 40, 217, 0.25);
  padding: 1.15rem 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.profile-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.profile-top-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.profile-char-name {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 800;
  color: var(--title-pink);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.profile-portrait-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle at 30% 25%, #4c1d95, #1e1b4b 65%, #0f0a1e 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.profile-portrait {
  width: 100%;
  height: 100%;
}

.profile-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-creator-badge {
  align-self: flex-start;
  padding: 0.36rem 0.85rem;
  border-radius: 9px;
  border: 1px solid var(--gold-border);
  background: rgba(20, 14, 34, 0.85);
  color: #c4b5fd;
  font-size: 0.84rem;
  font-weight: 700;
}

.profile-bio-box {
  background: rgba(12, 8, 24, 0.58);
  border: 1px solid rgba(168, 85, 247, 0.22);
  border-radius: 12px;
  padding: 1rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.profile-tagline {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 600;
  color: #f3f4fa;
  line-height: 1.5;
}

.profile-bio-body {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.58;
  white-space: pre-wrap;
}

.profile-lore-details {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.65rem;
}

.profile-lore-details summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--title-lavender);
}

.profile-lore-content {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
}

.profile-dates-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.meta-date-pill {
  font-size: 0.72rem;
  color: var(--text-secondary);
  padding: 0.28rem 0.65rem;
  border-radius: 8px;
  background: rgba(8, 8, 16, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.meta-date-pill strong {
  color: #fff;
  font-style: italic;
}

.profile-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.profile-capability-line {
  text-align: center;
  font: 600 0.84rem var(--font-mono);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.profile-cta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  padding-top: 0.2rem;
}

.profile-chat-cta {
  min-width: 210px;
  padding: 0.68rem 1.25rem;
  font-size: 0.92rem;
}

/* Right Column: Saved Chats & Comments */
.profile-community-col {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-width: 0;
}

.profile-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.profile-block-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.profile-block-title h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.count-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.profile-carousel-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.carousel-arrow {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #2c2d34;
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
}

.profile-sessions-track {
  display: flex;
  gap: 0.85rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  scrollbar-width: thin;
}

.profile-session-card {
  flex: 0 0 270px;
  padding: 0.95rem 1rem;
  border-radius: 12px;
  background: #2b2c32;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.profile-session-card:hover {
  border-color: var(--card-border-hover);
  transform: translateY(-2px);
}

.profile-session-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-session-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}

.profile-session-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* Comments Feed */
.profile-comments-block {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.comments-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.comments-prompt-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.comment-composer {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.comment-composer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.comment-composer-top input[type="text"] {
  flex: 1;
  max-width: 240px;
  padding: 0.46rem 0.72rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #2b2c32;
  color: var(--text-primary);
  font: 500 0.83rem var(--font-sans);
  outline: none;
}

.pin-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.comment-composer textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: #2b2c32;
  color: var(--text-primary);
  font: 500 0.88rem var(--font-sans);
  resize: vertical;
  outline: none;
}

.comment-composer textarea:focus {
  border-color: var(--card-border-hover);
}

.btn-comment-submit {
  width: 100%;
  background: #7c749e;
  color: #16151c;
  font-weight: 700;
  padding: 0.62rem;
  border-radius: 9px;
}

.btn-comment-submit:hover:not(:disabled) {
  background: #988ec2;
}

.comments-sort-row select {
  padding: 0.42rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #2b2c32;
  color: var(--text-primary);
  font: 600 0.82rem var(--font-sans);
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.comment-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid transparent;
}

.comment-item.pinned {
  border-color: rgba(168, 85, 247, 0.65);
  background: rgba(147, 51, 234, 0.08);
}

.comment-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.comment-author-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.comment-author {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
}

.comment-pinned-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: #c4b5fd;
}

.comment-text {
  margin: 0;
  font-size: 0.88rem;
  color: #e4e6f0;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-meta-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.comment-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: 600 0.76rem var(--font-sans);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 5px;
}

.comment-action-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.comment-action-btn.delete:hover {
  color: #fca5a5;
}

@media (max-width: 960px) {
  .profile-shell {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
 * Auth Controls, Phase 1 Polish & Phase 2 RP / Settings UI (RELAKE + DESK)
 * Uses strictly theme tokens so both RELAKE (dark) and DESK (light) stay crisp.
 * ============================================================================ */
.user-account-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.user-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 36px;
  padding: 0 0.78rem 0 0.34rem;
  border-radius: 999px;
  border: 1px solid var(--border-medium);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}

.user-pill-btn:hover {
  border-color: var(--border-focus);
  background: var(--accent-soft);
}

.user-pill-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
}

.user-pill-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-pill-name {
  max-width: 112px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-author-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Favorite button on cards & profile */
.card-fav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.18rem 0.48rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.card-fav-btn:hover,
.card-fav-btn.favorited {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Settings Dialog & Tabs */
.settings-dialog {
  max-width: 640px;
  width: min(94vw, 640px);
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.15rem 1.4rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.settings-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.42rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.settings-tab:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.settings-tab.active {
  color: var(--badge-text);
  background: var(--badge-bg);
  border-color: var(--badge-border);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.settings-panel[hidden] {
  display: none;
}

.settings-panel-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.35rem;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Daily Usage Summary Card */
.usage-summary-card {
  padding: 0.95rem 1.05rem;
  border-radius: 12px;
  border: 1px solid var(--border-medium);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.usage-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.usage-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.usage-tier-pill {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--badge-border);
}

.usage-meters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.usage-meter {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.usage-meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.usage-meter-row strong {
  color: var(--text-primary);
  font-weight: 700;
}

.usage-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border-subtle);
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* Personas Manager */
.personas-list,
.memories-list,
.sessions-manage-list,
.lorebook-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 250px;
  overflow-y: auto;
}

.persona-item-card,
.memory-fact-row,
.session-manage-row,
.lorebook-entry-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.persona-item-meta,
.memory-fact-meta,
.session-manage-meta,
.lorebook-entry-meta {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 0;
  flex: 1;
}

.persona-item-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.persona-default-pill,
.lore-keyword-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.48rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--badge-border);
}

.persona-item-bio {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.persona-item-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.persona-create-card,
.lorebook-add-box {
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-medium);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.persona-create-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.persona-create-footer,
.lorebook-add-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Account Identity Card */
.account-identity-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-medium);
  background: var(--bg-elevated);
}

.account-identity-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.account-identity-meta strong {
  color: var(--text-primary);
}

.memory-fact-char {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--badge-text);
}

.memory-fact-cat {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.memory-fact-text {
  font-size: 0.84rem;
  color: var(--text-primary);
  word-break: break-word;
}

/* Chat Room Phase 2 Controls: Stop Stream, Inline Edit, Export Box */
.btn-stop-stream {
  flex-shrink: 0;
  padding: 0 0.9rem;
  height: 38px;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.msg-bubble-wrap:has(.msg-inline-editor) {
  flex: 1 1 auto;
  width: min(100%, 680px);
  max-width: 100%;
}

.msg-inline-editor {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
  min-width: min(100%, 440px);
  margin-top: 0.35rem;
}

.msg-inline-editor textarea {
  width: 100%;
  min-height: 120px;
  max-height: 380px;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border-focus);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.55;
  resize: vertical;
}

.msg-inline-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.chat-export-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.chat-export-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

@media (max-width: 640px) {
  .usage-meters {
    grid-template-columns: 1fr;
  }
  .user-pill-name {
    display: none;
  }
  .user-pill-btn {
    padding: 0.25rem;
  }
}

/* ============================================================================
 * Navbar Overflow, [hidden] Override & Responsive Polish
 * ============================================================================ */
[hidden] {
  display: none !important;
}

.top-header {
  gap: 0.75rem;
}

.header-left,
.header-right {
  flex-shrink: 0;
  gap: 0.5rem;
}

.header-center {
  flex: 1 1 220px;
  min-width: 140px;
  max-width: 420px;
}

.primary-nav {
  flex-shrink: 0;
}

.nav-tab {
  white-space: nowrap;
  flex-shrink: 0;
}

.header-right .btn,
.header-right .telemetry-pill {
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 1180px) {
  .top-header .telemetry-pill {
    display: none;
  }
}

@media (max-width: 960px) {
  .top-header .theme-switcher-deck {
    display: none;
  }
}

/* ============================================================================
 * UI Polish v2: Native Color Scheme, Custom Thin Scrollbars,
 * Single Segmented Theme Switcher, Immersive Chat Room & Mobile Layout
 * ============================================================================ */
:root[data-theme="relake"],
[data-theme="relake"] {
  color-scheme: dark;
}

:root[data-theme="desk"],
[data-theme="desk"] {
  color-scheme: light;
}

select,
select option {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
}

/* Sleek Custom Scrollbars Everywhere (No Generic White Windows Bars) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-button,
*::-webkit-scrollbar-corner {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
}

/* Single Segmented Theme Switcher inside Settings */
.settings-theme-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.25rem;
  border-radius: 10px;
  border: 1px solid var(--border-medium);
  background: var(--bg-base);
}

.seg-theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 34px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.seg-theme-btn:hover {
  color: var(--text-primary);
}

.seg-theme-btn.active {
  background: var(--badge-bg);
  color: var(--badge-text);
  border-color: var(--badge-border);
}

.seg-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--border-medium);
}

.seg-swatch.relake {
  background: linear-gradient(135deg, #171821 40%, #9333ea 100%);
}

.seg-swatch.desk {
  background: linear-gradient(135deg, #eae8e3 40%, #456b54 100%);
}

/* Immersive Full-Height Chat Room & Collapsible Sidebar */
.app-shell.in-chat .top-header {
  display: none !important;
}

.app-shell.in-chat .workspace-body {
  height: 100dvh;
}

.app-shell.in-chat.sidebar-collapsed .sessions-sidebar {
  display: none;
}

.chat-char-info {
  min-width: 0;
  flex: 1;
}

.chat-char-text {
  min-width: 0;
  overflow: hidden;
}

.chat-topbar {
  gap: 0.65rem;
  padding: 0.62rem 1rem;
}

.chat-char-tagline {
  max-width: clamp(120px, 24vw, 320px);
}

.chat-topbar-actions {
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 0.35rem;
}

.chat-topbar-actions .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Mobile Chat & Drawer Responsiveness */
@media (max-width: 900px) {
  .app-shell.in-chat .sessions-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(82vw, 300px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }

  .app-shell.in-chat .sessions-sidebar.open {
    transform: translateX(0);
    display: flex;
  }
}

@media (max-width: 680px) {
  .chat-topbar {
    padding: 0.5rem 0.65rem;
    gap: 0.45rem;
  }

  .chat-char-info {
    gap: 0.45rem;
  }

  .chat-topbar .btn-icon {
    width: 32px;
    height: 32px;
    padding: 0.35rem;
  }

  .chat-char-name-row h2 {
    font-size: 0.96rem;
  }

  .chat-char-tagline {
    display: none;
  }

  .chat-messages {
    padding: 0.85rem 0.65rem;
  }

  .chat-composer {
    margin: 0.45rem 0.55rem 0.65rem;
  }
}

.explore-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.footer-legal-links {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-legal-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.footer-legal-links a:hover {
  color: var(--text-primary);
  text-decoration: underline;
}


/* Chat Swipes (< 1 / N >) & Voice Playback Controls */
.msg-swipe-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  margin-right: 0.25rem;
}

.msg-swipe-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.12rem 0.3rem;
  border-radius: 5px;
  cursor: pointer;
}

.msg-swipe-btn:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--accent-soft);
}

.msg-swipe-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.msg-swipe-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 2.2rem;
  text-align: center;
}

.msg-action-btn.active {
  color: var(--accent-action);
  border-color: var(--border-focus);
}


/* =========================================================================
   PART 1: THEME-AGNOSTIC CHAT CONTROLS, TAP-TO-SHOW ACTIONS & SPRING MOTION
   Works uniformly across relake, desk, abyssal, glacier, and twilight.
   ========================================================================= */
:root {
  --spring-ease: cubic-bezier(0.28, 1.32, 0.42, 1);
  --spring-pop: cubic-bezier(0.34, 1.62, 0.55, 1);
  --spring-dur: 420ms;
  --spring-fast: 240ms;
}

.btn,
.tag-rail-pill,
.feed-tab,
.msg-action-btn,
.user-pill-btn,
.carousel-arrow {
  transition:
    transform var(--spring-fast) var(--spring-pop),
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

.btn:active:not(:disabled),
.tag-rail-pill:active,
.feed-tab:active,
.msg-action-btn:active,
.user-pill-btn:active,
.carousel-arrow:active {
  transform: scale(0.94);
}

/* Bouncy Message Bubbles & Tap-to-Reveal Action Strip */
.msg-bubble {
  cursor: pointer;
  transition:
    transform var(--spring-fast) var(--spring-pop),
    box-shadow 0.22s ease,
    border-color 0.22s ease;
}

.msg-bubble:active {
  transform: scale(0.985);
}

.msg-row.held .msg-bubble {
  transform: scale(1.012);
  border-color: var(--border-focus);
  box-shadow: var(--shadow-md);
}

.msg-row .msg-actions {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
  margin-top: 0;
  transition: opacity 0.2s ease, max-height 0.24s ease, margin-top 0.2s ease;
}

@media (hover: hover) {
  .msg-row:hover .msg-actions {
    opacity: 1;
    max-height: 44px;
    pointer-events: auto;
    margin-top: 0.35rem;
  }
}

.msg-row.held .msg-actions,
.msg-row:focus-within .msg-actions {
  opacity: 1;
  max-height: 44px;
  pointer-events: auto;
  margin-top: 0.35rem;
  animation: actionStripPop var(--spring-dur) var(--spring-pop) both;
}

@keyframes actionStripPop {
  from { opacity: 0; transform: translate3d(0, -6px, 0) scale(0.92); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

/* Theme-Agnostic Typing Indicator Pill */
.chat-typing-row {
  display: none;
  align-items: center;
  gap: 0.38rem;
  padding: 0.38rem 0.85rem;
  margin: 0 1.25rem 0.5rem;
  width: fit-content;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.chat-typing-row.active {
  display: inline-flex;
  animation: actionStripPop var(--spring-dur) var(--spring-pop) both;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: chatTypingBounce 1s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes chatTypingBounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Fluid Dynamic Island Floating Status Pill (Token-Driven) */
.relake-island {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translate3d(-50%, -22px, 0) scale(0.84);
  opacity: 0;
  pointer-events: none;
  z-index: 99998;
  height: 36px;
  min-width: 140px;
  max-width: min(320px, 90vw);
  padding: 0 14px;
  border-radius: 999px;
  background: var(--bg-surface);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  transition:
    transform var(--spring-dur) var(--spring-pop),
    opacity 0.22s ease,
    min-width var(--spring-dur) var(--spring-pop);
}

.relake-island[data-state="streaming"],
.relake-island[data-state="success"],
.relake-island[data-state="info"],
.relake-island[data-state="error"] {
  opacity: 1;
  transform: translate3d(-50%, 0, 0) scale(1);
}

.relake-island[data-state="streaming"] {
  min-width: 210px;
}

.relake-island-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  flex-shrink: 0;
}

.relake-island[data-state="success"] .relake-island-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald-soft);
}

.relake-island[data-state="error"] .relake-island-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger-soft);
}

.relake-island-text {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.relake-island-waves {
  display: none;
  align-items: center;
  gap: 2.5px;
  height: 14px;
}

.relake-island[data-state="streaming"] .relake-island-waves {
  display: inline-flex;
}

.relake-island-waves span {
  width: 2.5px;
  height: 5px;
  border-radius: 99px;
  background: var(--accent);
  animation: islandWave 0.85s ease-in-out infinite;
}

.relake-island-waves span:nth-child(2) { animation-delay: 0.14s; background: var(--title-accent-1); }
.relake-island-waves span:nth-child(3) { animation-delay: 0.28s; background: var(--emerald); }
.relake-island-waves span:nth-child(4) { animation-delay: 0.42s; background: var(--title-accent-2); }

@keyframes islandWave {
  0%, 100% { height: 4px; opacity: 0.55; }
  50% { height: 14px; opacity: 1; }
}

.relake-island-check {
  width: 14px;
  height: 14px;
  color: var(--emerald);
  display: none;
  flex-shrink: 0;
}

.relake-island[data-state="success"] .relake-island-check {
  display: inline-block;
}

/* Staggered Card Spring Reveal & Hover Specular Sheen */
.char-card.spring-reveal {
  animation: cardSpringIn var(--spring-dur) var(--spring-pop) both;
}

@keyframes cardSpringIn {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.95); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@media (hover: hover) {
  .char-card { position: relative; }
  .char-card::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, 0.1), transparent 65%);
    opacity: 0;
    transition: opacity 0.24s ease;
    z-index: 3;
  }
  .char-card:hover::after { opacity: 1; }
}

.native-dialog[open] {
  animation: dialogSpringIn var(--spring-dur) var(--spring-pop) both;
}

@keyframes dialogSpringIn {
  from { opacity: 0; transform: translate3d(0, 16px, 0) scale(0.94); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* Companion Chat Topbar Overflow Button & Unified Chat Menu */
.icon.xs {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.chat-topbar {
  position: relative;
}

.chat-topbar-actions .chat-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  padding: 0.36rem 0.64rem;
  border-radius: 9px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

.chat-more-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-medium, rgba(255, 255, 255, 0.14));
  background: var(--bg-elevated, rgba(255, 255, 255, 0.06));
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.14s ease;
}

.chat-more-btn:hover,
.chat-more-btn[aria-expanded="true"] {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--accent-soft, rgba(147, 51, 234, 0.16));
}

.chat-more-btn:active {
  transform: scale(0.93);
}

@media (max-width: 1200px) {
  .chat-more-btn {
    display: inline-flex;
  }

  .chat-topbar-actions {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 216px;
    max-width: calc(100vw - 1.5rem);
    padding: 0.42rem;
    border-radius: 14px;
    background: color-mix(in srgb, var(--bg-surface) 95%, #0f1117 5%);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--border-medium, rgba(255, 255, 255, 0.14));
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
    z-index: 75;
  }

  .chat-topbar-actions.open {
    display: flex;
    animation: appleActionPop 260ms var(--spring-pop, cubic-bezier(0.22, 1, 0.36, 1)) both;
  }

  .chat-topbar-actions .chat-menu-btn,
  .chat-topbar-actions .btn {
    width: 100%;
    min-height: 38px;
    justify-content: flex-start;
    gap: 0.62rem;
    padding: 0.54rem 0.72rem;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: none;
    text-decoration: none;
  }

  .chat-topbar-actions .chat-menu-btn:hover,
  .chat-topbar-actions .btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
  }

  .chat-topbar-actions #btnChatInviteDiscord {
    background: rgba(88, 101, 242, 0.16);
    color: #c7d2fe;
  }

  .chat-topbar-actions #btnChatInviteDiscord:hover {
    background: rgba(88, 101, 242, 0.28);
    color: #ffffff;
  }

  .chat-topbar-actions .chat-menu-danger {
    margin-top: 0.22rem;
    padding-top: 0.62rem;
    color: #f87171;
    box-shadow: inset 0 1px 0 var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 0 0 9px 9px;
  }

  .chat-topbar-actions .chat-menu-danger:hover {
    background: rgba(239, 68, 68, 0.14);
    color: #fca5a5;
  }

  [data-theme="glacier"] .chat-topbar-actions.open {
    background: rgba(255, 255, 255, 0.97);
    border-color: rgba(15, 23, 42, 0.12);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
  }

  [data-theme="glacier"] .chat-topbar-actions .chat-menu-btn:hover,
  [data-theme="glacier"] .chat-topbar-actions .btn:hover {
    background: rgba(15, 23, 42, 0.06);
  }

  [data-theme="glacier"] .chat-topbar-actions #btnChatInviteDiscord {
    background: rgba(88, 101, 242, 0.12);
    color: #4338ca;
  }

  [data-theme="glacier"] .chat-topbar-actions .chat-menu-danger {
    color: #dc2626;
    box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.09);
  }

  [data-theme="glacier"] .chat-topbar-actions .chat-menu-danger:hover {
    background: rgba(220, 38, 38, 0.09);
    color: #b91c1c;
  }
}


/* =========================================================================
   STANDOUT PART 1: DYNAMIC CHARACTER AURA & SMOOTH SSE TOKEN FADE
   ========================================================================= */
#viewChat {
  --char-aura-rgb: 14, 165, 233;
  position: relative;
}

#viewChat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 280px;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    ellipse 80% 70% at 22% 0%,
    rgba(var(--char-aura-rgb), 0.18),
    transparent 72%
  );
  transition: background 0.65s ease;
}

[data-theme="glacier"] #viewChat::before,
[data-theme="desk"] #viewChat::before {
  background: radial-gradient(
    ellipse 80% 70% at 22% 0%,
    rgba(var(--char-aura-rgb), 0.12),
    transparent 70%
  );
}

#viewChat .chat-topbar {
  position: relative;
  z-index: 25;
  border-bottom: 1px solid rgba(var(--char-aura-rgb), 0.24);
  box-shadow: 0 8px 28px -18px rgba(var(--char-aura-rgb), 0.55);
  transition: border-color 0.5s ease, box-shadow 0.5s ease;
}

#viewChat .chat-messages,
#viewChat .chat-composer {
  position: relative;
  z-index: 1;
}

#viewChat .chat-composer:focus-within {
  border-color: rgba(var(--char-aura-rgb), 0.55);
  box-shadow: 0 0 0 3px rgba(var(--char-aura-rgb), 0.14);
}

/* Smooth SSE Token Fade-In (zero mobile DOM thrash) */
.sse-token-in {
  display: inline;
  animation: sseTokenFadeIn 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes sseTokenFadeIn {
  from {
    opacity: 0;
    filter: blur(1.5px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}


/* =========================================================================
   STANDOUT PART 2: LIVE BOND METER & LIVE DISCORD PRESENCE RING
   ========================================================================= */
.bond-meter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--badge-border);
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  max-width: 175px;
}

.bond-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.bond-pill-track {
  width: 32px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-medium);
  overflow: hidden;
  flex-shrink: 0;
}

.bond-pill-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--emerald));
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Pulsing Live Discord Presence Ring */
.avatar-discord-live {
  position: relative;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--emerald);
  animation: discordPresencePulse 2.4s ease-in-out infinite;
}

.avatar-discord-live::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--emerald);
  border: 2px solid var(--bg-surface);
  z-index: 4;
}

@keyframes discordPresencePulse {
  0%, 100% {
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px rgba(16, 185, 129, 0.85);
  }
  50% {
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 7px rgba(88, 101, 242, 0.35);
  }
}

.char-card.discord-live-card {
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.4), var(--shadow-md);
}


/* =========================================================================
   STANDOUT PART 3: CHARACTER CARD V2 DROPZONE & AVATAR UPLOAD PICKER
   ========================================================================= */
.card-v2-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.85rem;
  border-radius: 12px;
  border: 1.5px dashed var(--border-medium);
  background: var(--bg-elevated);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.card-v2-dropzone:hover,
.card-v2-dropzone.dragover {
  border-color: var(--border-focus);
  background: var(--accent-soft);
}

.card-v2-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-v2-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.avatar-upload-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.avatar-upload-row input[type="url"] {
  flex: 1;
  min-width: 0;
}


/* =========================================================================
   PRODUCTION PACK: BILLING UPGRADE CARD & ACCOUNT DANGER ZONE
   ========================================================================= */
.billing-upgrade-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--badge-border);
}

.billing-upgrade-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.billing-upgrade-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.account-danger-zone {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.account-danger-zone p {
  margin: 0.2rem 0 0;
}


/* =========================================================================
   CREATOR PROFILES (/u/{handle}) & WEEKLY TRENDING
   ========================================================================= */
.creator-profile-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.15rem;
  border-radius: 16px;
}

.creator-banner-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.creator-banner-meta {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.creator-banner-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.creator-banner-title-row h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text-primary);
}

.creator-banner-stats {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.creator-banner-actions {
  display: flex;
  gap: 0.5rem;
}

.creator-handle-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--badge-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.creator-handle-link:hover {
  text-decoration: underline;
}

.badge-pill.pro-pill {
  background: var(--accent-btn);
  color: #ffffff;
  border-color: transparent;
}

.badge-pill.live-pill {
  background: var(--emerald-soft);
  color: var(--emerald);
  border-color: var(--emerald);
}

/* =============================================================================
   App Shell & Persistent Navigation Rail + Mobile PWA Bottom Bar
   ============================================================================= */

:root {
  --nav-rail-w: 68px;
}

.app-shell.rail-expanded {
  --nav-rail-w: 220px;
}

.app-nav-rail {
  width: var(--nav-rail-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.75rem 0.55rem;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-sidebar, var(--bg-topbar));
  transition: width 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 25;
  overflow: visible;
}

.rail-nav-group,
.rail-footer-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rail-footer-group {
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
}

.rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.72rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.rail-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.rail-item.active {
  background: var(--accent-soft);
  color: var(--accent-action, var(--text-primary));
  border-color: var(--card-border, var(--border-subtle));
}

.rail-item-accent {
  color: var(--accent-action, var(--text-primary));
}

.rail-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.rail-label {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.14s ease, max-width 0.18s ease;
}

.app-shell.rail-expanded .rail-label {
  opacity: 1;
  max-width: 140px;
}

.rail-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.app-shell.rail-expanded .rail-badge {
  position: static;
  margin-left: auto;
}

.rail-chevron {
  transition: transform 0.2s ease;
}

.app-shell.rail-expanded .rail-chevron {
  transform: rotate(180deg);
}

/* Tooltips only when rail is collapsed */
.app-shell:not(.rail-expanded) .rail-item[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  padding: 0.36rem 0.65rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
  z-index: 60;
}

.app-shell:not(.rail-expanded) .rail-item[data-tooltip]:hover::after,
.app-shell:not(.rail-expanded) .rail-item[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Mobile PWA Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 900px) {
  .app-nav-rail {
    display: none;
  }

  .feed-bar {
    padding: 0 1rem;
  }

  .feed-tabs {
    width: 100%;
  }

  .feed-tab {
    padding: 0.42rem 0.78rem;
    font-size: 0.8rem;
  }

  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: center;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    padding: 0.38rem 0.45rem calc(0.42rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-topbar);
  }

  .app-shell.in-chat.has-active-chat .mobile-bottom-nav {
    display: none;
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.35rem 0.25rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.16s ease, background 0.16s ease;
  }

  .mobile-nav-btn.active {
    color: var(--accent-action, var(--accent));
    background: var(--accent-soft);
  }

  .app-shell:not(.in-chat) .main-stage {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
}


/* =============================================================================
   App Shell & Feed-Tabs Motion Polish
   ============================================================================= */

.feed-tabs {
  position: relative;
}

.feed-tab {
  position: relative;
  z-index: 1;
}

.feed-tabs.has-indicator .feed-tab.active {
  background: transparent;
  box-shadow: none;
}

.feed-tabs-indicator {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 9px;
  background: var(--accent-btn, linear-gradient(135deg, #8b5cf6, #9333ea));
  box-shadow: 0 4px 14px rgba(147, 51, 234, 0.32);
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition:
    transform var(--spring-fast) var(--spring-pop),
    width var(--spring-fast) var(--spring-pop),
    height var(--spring-fast) var(--spring-pop),
    opacity 0.16s ease;
}

.rail-nav-group {
  position: relative;
}

.rail-item {
  z-index: 1;
}

.rail-nav-group.has-indicator .rail-item.active {
  background: transparent;
  border-color: transparent;
}

.rail-active-indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--card-border, var(--border-subtle));
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition:
    transform var(--spring-fast) var(--spring-pop),
    height var(--spring-fast) var(--spring-pop),
    opacity 0.16s ease;
}

/* Micro-spring tactility on rail & mobile bottom nav */
.rail-item,
.mobile-nav-btn {
  transition:
    transform var(--spring-fast) var(--spring-pop),
    background 0.16s ease,
    color 0.16s ease,
    border-color 0.16s ease;
}

.rail-item:active,
.mobile-nav-btn:active {
  transform: scale(0.93);
}

.rail-item .rail-icon,
.mobile-nav-btn svg {
  transition: transform var(--spring-fast) var(--spring-pop);
}

.rail-item.active .rail-icon,
.mobile-nav-btn.active svg {
  transform: translateY(-1px) scale(1.08);
}

/* View entrance & staggered rail-label choreography */
@keyframes viewFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-pane.active {
  animation: viewFadeIn 190ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.app-shell.rail-expanded .rail-label {
  transition-delay: 45ms;
}

@media (prefers-reduced-motion: reduce) {
  .feed-tabs-indicator,
  .rail-active-indicator,
  .rail-item,
  .mobile-nav-btn,
  .rail-item .rail-icon,
  .mobile-nav-btn svg,
  .view-pane.active {
    animation: none !important;
    transition: none !important;
  }
}


/* =============================================================================
   6-in-1 Motion Suite: Card Parallax, Swipe Slide, Composer Halo, Jump Pill,
   Tag Rail Fade, Theme Cross-Fade & Bond Pulse
   ============================================================================= */

/* 1. Card Portrait Hover Parallax */
.char-card .char-portrait img {
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.char-card:hover .char-portrait img {
  transform: scale(1.045);
}

/* 2. Swipe Horizontal Slide & New Message Entrance */
@keyframes msgSwipeFromRight {
  from {
    opacity: 0.35;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes msgSwipeFromLeft {
  from {
    opacity: 0.35;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.msg-row.msg-swipe-next .msg-bubble-wrap {
  animation: msgSwipeFromRight 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.msg-row.msg-swipe-prev .msg-bubble-wrap {
  animation: msgSwipeFromLeft 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* 3. Composer Focus Halo & Send Button Pop */
.chat-composer {
  transition:
    border-color 0.18s ease,
    box-shadow 0.2s ease;
}

.chat-composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-composer #btnSendMessage {
  transform: scale(0.92);
  opacity: 0.74;
  transition:
    transform var(--spring-fast) var(--spring-pop),
    opacity 0.16s ease,
    background 0.18s ease;
}

.chat-composer.has-text #btnSendMessage,
.chat-composer:focus-within #btnSendMessage {
  transform: scale(1);
  opacity: 1;
}

/* 4. Floating Jump to Latest Pill */
.chat-stage {
  position: relative;
}

.chat-jump-latest {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border-medium, var(--border-subtle));
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  animation: viewFadeIn 180ms cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: transform var(--spring-fast) var(--spring-pop), border-color 0.16s ease;
}

.chat-jump-latest:hover {
  border-color: var(--accent);
  transform: translateX(-50%) translateY(-2px);
}

/* 5. Tag Rail Edge Fade & Smart Scroll Arrow */
.tag-rail-wrap.can-scroll-right .tag-rail {
  -webkit-mask-image: linear-gradient(to right, #000 0%, #000 calc(100% - 34px), transparent 100%);
  mask-image: linear-gradient(to right, #000 0%, #000 calc(100% - 34px), transparent 100%);
}

.rail-scroll-btn {
  transition: opacity 0.18s ease, transform var(--spring-fast) var(--spring-pop);
}

.tag-rail-wrap:not(.can-scroll-right) .rail-scroll-btn {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* 6. Theme Cross-Fade & Bond Level-Up Pulse */
html.theme-transitioning,
html.theme-transitioning body,
html.theme-transitioning .app-shell,
html.theme-transitioning .glass-panel,
html.theme-transitioning .app-nav-rail,
html.theme-transitioning .char-card {
  transition:
    background-color 180ms ease,
    color 180ms ease,
    border-color 180ms ease !important;
}

@keyframes bondLevelPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 var(--accent-glow, rgba(168, 85, 247, 0.45));
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 transparent;
  }
}

.chat-bond-pill.bond-level-up {
  animation: bondLevelPulse 520ms cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  .char-card .char-portrait img,
  .msg-row.msg-swipe-next .msg-bubble-wrap,
  .msg-row.msg-swipe-prev .msg-bubble-wrap,
  .chat-composer,
  .chat-composer #btnSendMessage,
  .chat-jump-latest,
  .rail-scroll-btn,
  .chat-bond-pill.bond-level-up,
  html.theme-transitioning,
  html.theme-transitioning * {
    animation: none !important;
    transition: none !important;
  }
}


/* =============================================================================
   Mobile Chats Picker List & Creator Storefront (/u/{handle})
   ============================================================================= */

.chat-empty-sessions {
  width: min(520px, 100%);
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.chat-empty-sessions-heading {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.chat-empty-session-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.16s ease, transform var(--spring-fast) var(--spring-pop);
}

.chat-empty-session-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.chat-empty-session-meta {
  flex: 1;
  min-width: 0;
}

.chat-empty-session-title {
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-empty-session-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-creator-link,
.profile-creator-badge.is-link {
  cursor: pointer;
  transition: color 0.15s ease;
}

.char-creator-link:hover,
.profile-creator-badge.is-link:hover {
  color: var(--accent-action, var(--accent));
  text-decoration: underline;
}

.creator-pane {
  overflow-y: auto;
  padding-bottom: 2.5rem;
}

.creator-pane .profile-topbar {
  flex-shrink: 0;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.5rem 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.creator-hero {
  flex-shrink: 0;
  max-width: 1280px;
  width: calc(100% - 3rem);
  margin: 0.5rem auto 1.4rem;
  padding: 1.35rem 1.5rem;
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.creator-hero-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--card-border, var(--border-subtle));
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
}

.creator-hero-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.creator-hero-meta {
  flex: 1;
  min-width: 200px;
}

.creator-hero-title-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.creator-hero-name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
}

.creator-hero-handle {
  margin-top: 0.15rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.creator-tier-badge {
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: var(--accent-soft);
  color: var(--accent-action, var(--accent));
  border: 1px solid var(--card-border, var(--border-subtle));
}

.creator-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.creator-stat-pill {
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

@media (max-width: 900px) {
  .creator-pane .profile-topbar {
    padding: 0.85rem 1rem 0.2rem;
  }

  .creator-hero {
    width: calc(100% - 2rem);
    padding: 1rem;
  }
}


/* =============================================================================
   Premium Polish Pack: Heart Burst, Scroll Elevation, Message Clustering & Day
   Dividers, Greeting Peek, Ambient Aura Headers
   ============================================================================= */

/* 1. Scroll-linked Topbar Elevation */
.top-header {
  transition: box-shadow 0.2s ease, backdrop-filter 0.2s ease, background-color 0.2s ease;
}

.top-header.is-scrolled {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}

/* 2. Multi-Layer Heart Celebration FX (Elastic Heart + Shockwave + 6 Radial Sparks) */
@keyframes heartBurstPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25) rotate(-14deg);
  }
  24% {
    opacity: 1;
    transform: translate(-50%, -54%) scale(1.36) rotate(6deg);
  }
  44% {
    opacity: 1;
    transform: translate(-50%, -56%) scale(0.94) rotate(-3deg);
  }
  64% {
    opacity: 0.95;
    transform: translate(-50%, -62%) scale(1.12) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -82%) scale(1.28) rotate(0deg);
  }
}

@keyframes heartShockwave {
  0% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.25);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.45);
  }
}

@keyframes heartSparkFly {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4) rotate(0deg);
  }
  55% {
    opacity: 1;
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.15) rotate(var(--rot, 90deg));
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--tx) * 1.25), calc(-50% + var(--ty) * 1.25)) scale(0.2) rotate(calc(var(--rot, 90deg) * 1.5));
  }
}

@keyframes favBtnElastic {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.42) rotate(-8deg);
  }
  58% {
    transform: scale(0.88) rotate(4deg);
  }
  80% {
    transform: scale(1.12) rotate(0deg);
  }
  100% {
    transform: scale(1);
  }
}

.heart-burst-fx {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 15;
}

.heart-burst {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 3.2rem;
  line-height: 1;
  background: linear-gradient(135deg, #fda4af 0%, #fb7185 45%, #ec4899 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 22px rgba(244, 63, 94, 0.72));
  pointer-events: none;
  animation: heartBurstPop 740ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.heart-shockwave {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2.5px solid rgba(251, 113, 133, 0.85);
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.45), inset 0 0 12px rgba(251, 113, 133, 0.3);
  pointer-events: none;
  animation: heartShockwave 540ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.heart-spark {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.78rem;
  line-height: 1;
  color: var(--spark-color, #fda4af);
  text-shadow: 0 0 10px currentColor;
  pointer-events: none;
  animation: heartSparkFly 620ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.card-fav-btn.is-popping,
.btn-fav-pop.is-popping {
  animation: favBtnElastic 480ms cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.45);
}

/* 3. Message Group Clustering & Sticky Day Dividers */
.chat-day-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.95rem 0 0.55rem;
  position: sticky;
  top: 6px;
  z-index: 5;
  pointer-events: none;
}

.chat-day-divider span {
  padding: 0.22rem 0.72rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
}

.msg-row.msg-grouped {
  margin-top: -0.55rem;
}

.msg-row.msg-grouped > .avatar {
  visibility: hidden;
}

.msg-row.msg-grouped .msg-sender {
  display: none;
}

.msg-row.msg-grouped.assistant .msg-bubble {
  border-top-left-radius: 8px;
}

.msg-row.msg-grouped.user .msg-bubble {
  border-top-right-radius: 8px;
}

/* 4. Character Card First-Line Greeting Peek & Lorebook Badge */
.media-lore-pill {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  padding: 0.18rem 0.52rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  font-size: 0.68rem;
  font-weight: 700;
  backdrop-filter: blur(8px);
  z-index: 3;
}

.media-greeting-peek {
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: 3.15rem;
  padding: 0.42rem 0.62rem;
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f1f5f9;
  font-size: 0.74rem;
  line-height: 1.35;
  max-height: calc(0.74rem * 1.35 * 2 + 0.84rem);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.char-card:hover .media-greeting-peek,
.char-card:focus-within .media-greeting-peek {
  opacity: 1;
  transform: translateY(0);
}

/* 5. Ambient Aura Header on #viewCreator & #viewProfile */
.creator-hero,
.profile-card {
  position: relative;
  overflow: hidden;
}

.creator-hero::before,
.profile-card::before {
  content: "";
  position: absolute;
  inset: -45% -15% auto -15%;
  height: 220px;
  background: radial-gradient(
    ellipse at 30% 35%,
    rgba(var(--aura-rgb, 147, 51, 234), 0.24) 0%,
    rgba(var(--aura-rgb, 147, 51, 234), 0.08) 45%,
    transparent 74%
  );
  filter: blur(26px);
  pointer-events: none;
  z-index: 0;
}

.creator-hero > *,
.profile-card > * {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .heart-burst,
  .heart-shockwave,
  .heart-spark,
  .card-fav-btn.is-popping,
  .media-greeting-peek,
  .top-header {
    animation: none !important;
    transition: none !important;
  }
}


/* Supernova Canvas Overlay & Card Neon Flash */
.relake-fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

@keyframes cardSupernovaFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.78), 0 0 28px rgba(236, 72, 153, 0.55);
    border-color: #fb7185;
  }
  55% {
    box-shadow: 0 0 0 6px rgba(244, 63, 94, 0), 0 0 20px rgba(168, 85, 247, 0.35);
    border-color: #f472b6;
  }
  100% {
    box-shadow: 0 0 0 12px rgba(244, 63, 94, 0);
  }
}

.char-card.fav-supernova-flash {
  animation: cardSupernovaFlash 680ms cubic-bezier(0.16, 1, 0.3, 1);
}

.heart-supernova-pop {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  font-size: 2.8rem;
  line-height: 1;
  background: linear-gradient(135deg, #fde047 0%, #fb7185 45%, #ec4899 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(244, 63, 94, 0.85));
  animation: heartBurstPop 760ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}


/* Hide duplicate recent-chats list on desktop (sidebar already visible) & prevent empty-chat clipping */
.chat-empty-placeholder {
  overflow-y: auto;
  justify-content: safe center;
}

.chat-empty-sessions {
  display: none;
}

@media (max-width: 900px) {
  .chat-empty-sessions {
    display: flex;
    padding-bottom: 1.5rem;
  }

  .chat-empty-placeholder {
    justify-content: flex-start;
    padding-top: 1.75rem;
  }
}


/* Chat Color Palette Live Preview & Swatch Cards */
.chat-palette-dialog { width: min(460px, calc(100vw - 1.5rem)); }
.palette-field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 0.82rem; font-weight: 600; }
.palette-active-badge { font-size: 0.72rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--badge-bg); color: var(--badge-text); border: 1px solid var(--badge-border); }

.palette-live-preview {
  --p-bg: #1a1a1a; --p-top: #202020; --p-border: #333333; --p-ai: #282828;
  --p-user: #382525; --p-text: #ffffff; --p-muted: #999999; --p-accent: #e85d5d;
  border-radius: 14px; overflow: hidden; border: 1px solid var(--p-border);
  background: var(--p-bg); color: var(--p-text); margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); transition: background 0.25s ease, border-color 0.25s ease;
}
.palette-live-preview[data-preview-palette="sage"] { --p-bg: #2b332b; --p-top: #252e25; --p-border: #424e42; --p-ai: #343e34; --p-user: #3d4a3d; --p-text: #f4f8f4; --p-accent: #8a9a8a; }
.palette-live-preview[data-preview-palette="blueprint"] { --p-bg: #0c1e36; --p-top: #0e2440; --p-border: #1d3d66; --p-ai: #142f54; --p-user: #173d6d; --p-text: #f0f7ff; --p-accent: #38bdf8; }
.palette-live-preview[data-preview-palette="clay"] { --p-bg: #2a201c; --p-top: #261d19; --p-border: #4a3b34; --p-ai: #382c26; --p-user: #4a362d; --p-text: #faf6f3; --p-accent: #b87a54; }
.palette-live-preview[data-preview-palette="emerald"] { --p-bg: #16271e; --p-top: #14241b; --p-border: #2c4d3c; --p-ai: #1f382b; --p-user: #264a38; --p-text: #f2faf5; --p-accent: #2e8b57; }
.palette-live-preview[data-preview-palette="rose"] { --p-bg: #2b181b; --p-top: #261517; --p-border: #4d2d32; --p-ai: #3b2226; --p-user: #4d272d; --p-text: #fff2f4; --p-accent: #e06c75; }
.palette-live-preview[data-preview-palette="ocean"] { --p-bg: #132433; --p-top: #10202e; --p-border: #274763; --p-ai: #1d364c; --p-user: #22476b; --p-text: #f2f8fc; --p-accent: #3a7bd5; }
.palette-live-preview[data-preview-palette="amber"] { --p-bg: #2b2516; --p-top: #241f12; --p-border: #4d4329; --p-ai: #3d3520; --p-user: #4f4221; --p-text: #fcf9f0; --p-accent: #d4a017; }

.plp-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--p-top); border-bottom: 1px solid var(--p-border); font-size: 12px; font-weight: 700; }
.plp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--p-accent); }
.plp-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.plp-bubble { max-width: 82%; padding: 8px 11px; border-radius: 10px; font-size: 12px; line-height: 1.4; }
.plp-bubble.ai { align-self: flex-start; background: var(--p-ai); border: 1px solid var(--p-border); border-top-left-radius: 3px; }
.plp-bubble.user { align-self: flex-end; background: var(--p-user); border-top-right-radius: 3px; }
.plp-composer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; background: var(--p-top); border-top: 1px solid var(--p-border); }
.plp-input { font-size: 11px; color: var(--p-muted); }
.plp-send { font-size: 10px; font-weight: 800; padding: 4px 10px; border-radius: 6px; background: var(--p-accent); color: #ffffff; }

.palette-cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 440px) { .palette-cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.palette-card-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 6px;
  border-radius: 10px; border: 1.5px solid var(--border-subtle); background: var(--bg-surface);
  color: var(--text-primary); font-size: 11px; font-weight: 600; cursor: pointer;
  transition: transform 240ms cubic-bezier(0.34, 1.62, 0.55, 1), border-color 0.18s ease, box-shadow 0.18s ease;
}
.palette-card-btn:active { transform: scale(0.92); }
.palette-card-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pcard-swatch { width: 30px; height: 30px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28); }


/* =========================================================================
   ROTATING ARTWORK SHOWCASE WIDGET & CLICKABLE SORT HEADING
   ========================================================================= */
.hero-widget-wrap {
  max-width: 1280px;
  width: 100%;
  margin: 0.9rem auto 0;
  padding: 0 1.5rem;
}

.hero-widget-carousel {
  position: relative;
  width: 100%;
  height: 320px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  background: var(--bg-surface);
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
}

@media (max-width: 680px) {
  .hero-widget-wrap {
    padding: 0 0.75rem;
    margin-top: 0.7rem;
  }
  .hero-widget-carousel {
    height: 250px;
    border-radius: 16px;
  }
}

.hero-widget-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(1.06);
  transition: opacity 720ms cubic-bezier(0.22, 1, 0.36, 1), transform 1100ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.hero-widget-slide.active {
  opacity: 1;
  transform: scale(1);
  z-index: 1;
}

.hero-widget-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 28%;
  display: block;
}

.hero-widget-scrim {
  position: absolute;
  inset: auto 0 0 0;
  height: 58px;
  background: linear-gradient(to top, rgba(8, 10, 16, 0.45), transparent);
  z-index: 2;
  pointer-events: none;
}

.hero-widget-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(12, 14, 20, 0.46);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.hero-widget-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  border: none;
  padding: 0;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: width 360ms cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}

.hero-widget-dot.active {
  width: 22px;
  background: #ffffff;
}


/* =============================================================================
   Micro-Interactions & Fixed Shimmer Skeletons (Cherry-Picked & Fixed from Ryl)
   ============================================================================= */

@keyframes relakeShimmer {
  100% {
    transform: translateX(100%);
  }
}

.char-skeleton {
  border-radius: 16px;
  height: 270px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}

.char-skeleton::after,
.inline-shimmer-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.11), transparent);
  transform: translateX(-100%);
  animation: relakeShimmer 1.05s ease-in-out infinite;
}

.inline-shimmer-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0;
}

.inline-shimmer-bar {
  height: 44px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
}

/* Tactile Bubble Press & Hold Lift */
.msg-bubble {
  transition:
    transform var(--spring-fast) var(--spring-pop),
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.msg-bubble:active {
  transform: scale(0.97);
}

.msg-row.held .msg-bubble {
  transform: scale(1.02);
}

/* Send Button Pop & New Message Spring Entrance */
@keyframes sendPopBounce {
  0% { transform: scale(0.86); }
  55% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.btn-send.sent-pop,
#btnSendMessage.sent-pop {
  animation: sendPopBounce 340ms var(--spring-pop);
}

@keyframes msgBubbleSpring {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-row.msg-spring-in {
  animation: msgBubbleSpring 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .char-skeleton::after,
  .inline-shimmer-bar::after,
  .btn-send.sent-pop,
  #btnSendMessage.sent-pop,
  .msg-row.msg-spring-in,
  .msg-bubble {
    animation: none !important;
    transition: none !important;
  }
}


/* =============================================================================
   Checkpoint Audit Fixes: Cross-Theme Chat Palette & Chat Topbar Spacing
   ============================================================================= */

:root[data-desk-palette="dark"] {
  --studio-main-bg: #1a1a1a; --studio-card-border: #333333;
  --studio-text-primary: #ffffff; --studio-text-secondary: #aaaaaa;
  --studio-accent: #e85d5d; --studio-accent-soft: rgba(232, 93, 93, 0.2);
  --studio-chat-top-bg: #202020; --studio-bubble-ai: #282828; --studio-bubble-user: #382525; --studio-composer-bg: #1e1e1e;
}
:root[data-desk-palette="sage"] {
  --studio-main-bg: #2b332b; --studio-card-border: #424e42;
  --studio-text-primary: #f4f8f4; --studio-text-secondary: #c2cec2;
  --studio-accent: #8a9a8a; --studio-accent-soft: rgba(138, 154, 138, 0.22);
  --studio-chat-top-bg: #252e25; --studio-bubble-ai: #343e34; --studio-bubble-user: #3d4a3d; --studio-composer-bg: #242c24;
}
:root[data-desk-palette="blueprint"] {
  --studio-main-bg: #0c1e36; --studio-card-border: #1d3d66;
  --studio-text-primary: #f0f7ff; --studio-text-secondary: #b5d5f5;
  --studio-accent: #38bdf8; --studio-accent-soft: rgba(56, 189, 248, 0.22);
  --studio-chat-top-bg: #0e2440; --studio-bubble-ai: #142f54; --studio-bubble-user: #173d6d; --studio-composer-bg: #0e2440;
}
:root[data-desk-palette="clay"] {
  --studio-main-bg: #2a201c; --studio-card-border: #4a3b34;
  --studio-text-primary: #faf6f3; --studio-text-secondary: #d6c6bd;
  --studio-accent: #b87a54; --studio-accent-soft: rgba(184, 122, 84, 0.22);
  --studio-chat-top-bg: #261d19; --studio-bubble-ai: #382c26; --studio-bubble-user: #4a362d; --studio-composer-bg: #261d19;
}
:root[data-desk-palette="emerald"] {
  --studio-main-bg: #16271e; --studio-card-border: #2c4d3c;
  --studio-text-primary: #f2faf5; --studio-text-secondary: #bce0cb;
  --studio-accent: #2e8b57; --studio-accent-soft: rgba(46, 139, 87, 0.22);
  --studio-chat-top-bg: #14241b; --studio-bubble-ai: #1f382b; --studio-bubble-user: #264a38; --studio-composer-bg: #14241b;
}
:root[data-desk-palette="rose"] {
  --studio-main-bg: #2b181b; --studio-card-border: #4d2d32;
  --studio-text-primary: #fff2f4; --studio-text-secondary: #e6c5ca;
  --studio-accent: #e06c75; --studio-accent-soft: rgba(224, 108, 117, 0.22);
  --studio-chat-top-bg: #261517; --studio-bubble-ai: #3b2226; --studio-bubble-user: #4d272d; --studio-composer-bg: #261517;
}
:root[data-desk-palette="ocean"] {
  --studio-main-bg: #132433; --studio-card-border: #274763;
  --studio-text-primary: #f2f8fc; --studio-text-secondary: #bcd4e6;
  --studio-accent: #3a7bd5; --studio-accent-soft: rgba(58, 123, 213, 0.22);
  --studio-chat-top-bg: #10202e; --studio-bubble-ai: #1d364c; --studio-bubble-user: #22476b; --studio-composer-bg: #10202e;
}
:root[data-desk-palette="amber"] {
  --studio-main-bg: #2b2516; --studio-card-border: #4d4329;
  --studio-text-primary: #fcf9f0; --studio-text-secondary: #e0d5ba;
  --studio-accent: #d4a017; --studio-accent-soft: rgba(212, 160, 23, 0.22);
  --studio-chat-top-bg: #241f12; --studio-bubble-ai: #3d3520; --studio-bubble-user: #4f4221; --studio-composer-bg: #241f12;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-messages {
  background: var(--studio-main-bg) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar {
  background: var(--studio-chat-top-bg) !important;
  border-bottom-color: var(--studio-card-border) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-icon,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .chat-more-btn {
  color: var(--studio-text-primary) !important;
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .chat-more-btn[aria-expanded="true"] {
  border-color: var(--studio-accent) !important;
  background: var(--studio-accent-soft) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar-actions .btn {
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar-actions.open {
  background: var(--studio-chat-top-bg) !important;
  border-color: var(--studio-card-border) !important;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar-actions.open .chat-menu-danger {
  color: #f87171 !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) #chatCharTagline {
  color: var(--studio-text-secondary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .msg-row.assistant .msg-bubble {
  background: var(--studio-bubble-ai) !important;
  border-color: var(--studio-card-border) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .msg-row.user .msg-bubble {
  background: var(--studio-bubble-user) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-composer {
  background: var(--studio-chat-top-bg) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) #btnSendMessage {
  background: var(--studio-accent) !important;
  color: #ffffff !important;
}

/* Fix .chat-topbar crowding & #chatBondPill clipping */
.chat-char-info {
  flex: 1 1 auto;
  min-width: 0;
}

.chat-char-name-row {
  flex-wrap: nowrap;
  min-width: 0;
}

.chat-char-name-row h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-bond-pill {
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-topbar-actions {
  flex-shrink: 0;
  gap: 0.35rem;
}


/* =============================================================================
   Patch A: Profile Editing, Creator Bio & Explore Load More Pagination
   ============================================================================= */

.settings-avatar-editor {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated, rgba(255, 255, 255, 0.02));
  margin-bottom: 0.85rem;
}

.settings-avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border-strong, var(--border-subtle));
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.settings-avatar-controls {
  flex: 1;
  min-width: 0;
}

.settings-avatar-controls .field {
  margin-bottom: 0;
}

.settings-avatar-url-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.settings-avatar-url-row input[type="url"] {
  flex: 1 1 170px;
  min-width: 0;
}

.input-prefix-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm, 10px);
  background: var(--bg-input, var(--bg-elevated));
  overflow: hidden;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.input-prefix-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.input-prefix-at {
  padding: 0 0.55rem 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  user-select: none;
}

.input-prefix-wrap input {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding-left: 0 !important;
  flex: 1;
  min-width: 0;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.field-char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.settings-panel-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.creator-hero-bio {
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-secondary, var(--text-muted));
  max-width: 62ch;
  white-space: pre-wrap;
  word-break: break-word;
}

.explore-load-more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.35rem auto 0.6rem;
  padding: 0.25rem 0;
}

.explore-load-more-wrap[hidden] {
  display: none !important;
}

.explore-pagination-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

#btnLoadMoreChars {
  min-width: 210px;
}

@media (max-width: 640px) {
  .settings-avatar-editor {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-avatar-preview {
    align-self: flex-start;
  }

  .settings-panel-actions-split {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .settings-panel-actions-split .btn {
    width: 100%;
    justify-content: center;
  }

  #btnLoadMoreChars {
    width: 100%;
    max-width: 320px;
  }
}


/* =============================================================================
   Patch B: Recent Chats Filter, Inline Session Rename & Message Rewind
   ============================================================================= */

.sidebar-search-wrap {
  padding: 0 0.75rem 0.6rem;
}

.sidebar-search-input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input, var(--bg-elevated));
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.sidebar-search-input::placeholder {
  color: var(--text-muted);
}

.sidebar-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.session-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}

.session-item-rename {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  transition: opacity 0.14s ease, color 0.14s ease, background 0.14s ease;
}

.session-item:hover .session-item-rename,
.session-item:focus-within .session-item-rename,
.session-item.active .session-item-rename {
  opacity: 1;
}

.session-item-rename:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
}

.session-rename-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
}

.session-rename-input {
  flex: 1;
  min-width: 0;
  padding: 0.22rem 0.45rem;
  font-size: 0.82rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--bg-input, var(--bg-elevated));
  color: var(--text-primary);
  outline: none;
}

.session-rename-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.session-rename-btn.save {
  border-color: var(--accent);
  color: var(--accent-action, var(--accent));
}

.msg-action-btn.rewind:hover {
  color: var(--accent-action, var(--accent));
  border-color: var(--accent);
}

@media (hover: none), (max-width: 900px) {
  .session-item-rename {
    opacity: 0.78;
  }
}


/* =============================================================================
   Patch 05: Mobile Chats Tab, Drawer Bounds, Navbar Fit & Card Header Polish
   ============================================================================= */

.sidebar-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.sidebar-mobile-close {
  display: none;
}

.chat-empty-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

@media (max-width: 900px) {
  .chat-empty-placeholder.has-sessions .chat-empty-hero {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    width: min(560px, 100%);
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
  }

  .chat-empty-placeholder.has-sessions .chat-empty-hero .empty-badge,
  .chat-empty-placeholder.has-sessions .chat-empty-hero p {
    display: none;
  }

  .chat-empty-placeholder.has-sessions .chat-empty-hero h3 {
    margin: 0;
    font-size: 1.05rem;
  }

  .chat-empty-placeholder.has-sessions .chat-empty-hero #btnGoExplore {
    padding: 0.42rem 0.78rem;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
}

.chat-empty-sessions-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.chat-empty-session-card {
  justify-content: space-between;
}

.chat-empty-session-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.chat-empty-session-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

.chat-empty-session-actions .session-item-rename,
.chat-empty-session-actions .session-item-del {
  opacity: 0.85;
}

@media (hover: none), (max-width: 900px) {
  .session-item-del,
  .session-item-rename {
    opacity: 0.85 !important;
  }

  .sidebar-mobile-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
  }

  /* Full-height slide-over drawer cleanly covers topbar & bottom nav */
  .app-shell .sessions-sidebar,
  .app-shell.in-chat .sessions-sidebar {
    top: 0 !important;
    bottom: 0 !important;
    z-index: 65 !important;
    width: min(84vw, 310px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .sidebar-backdrop.open {
    inset: 0 !important;
    z-index: 55 !important;
  }

  /* Keep top header accessible on mobile Chats tab until a chat room is open */
  .app-shell.in-chat:not(.has-active-chat) .top-header {
    display: grid !important;
  }

  .app-shell.in-chat:not(.has-active-chat) .workspace-body {
    height: calc(100dvh - 57px);
  }

  .app-shell.in-chat:not(.has-active-chat) .main-stage {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .chat-empty-placeholder {
    padding: 1rem 0.9rem 1.5rem;
  }
}

@media (max-width: 640px) {
  .top-header {
    padding: 0.5rem 0.65rem;
    gap: 0.45rem;
  }

  .header-left,
  .header-right {
    gap: 0.38rem;
  }

  .header-center {
    min-width: 0;
  }

  .global-search {
    padding: 0.38rem 0.6rem;
    min-width: 0;
  }

  .global-search input {
    min-width: 0;
    font-size: 0.84rem;
  }

  #btnOpenCreateChar {
    padding: 0.42rem 0.68rem;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .user-pill-btn {
    padding: 0.18rem;
  }

  .user-pill-name {
    display: none;
  }
}

@media (max-width: 480px) {
  .brand-name {
    display: none;
  }

  .char-card-header {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .char-card-name {
    flex: 1 1 100%;
  }

  .char-card-header-btns {
    margin-left: auto;
  }
}


/* =============================================================================
   Patch 06: Desktop Chats Empty State, Studio/Favorites Focus & Above-the-Fold
   ============================================================================= */

/* Keep top header visible on desktop & mobile when in Chats view without an open chat room */
.app-shell.in-chat:not(.has-active-chat) .top-header {
  display: grid !important;
}

.app-shell.in-chat:not(.has-active-chat) .workspace-body {
  height: calc(100dvh - 57px);
}

/* Center desktop empty-state placeholder cleanly inside #viewChat */
@media (min-width: 901px) {
  .chat-empty-placeholder {
    height: 100%;
    max-width: 460px;
    margin: 0 auto;
    justify-content: center;
  }

  /* Don't reserve width for hidden rename/delete buttons until hovered or active */
  .session-item .session-item-actions {
    max-width: 0;
    overflow: hidden;
    transition: max-width 0.16s ease;
  }

  .session-item:hover .session-item-actions,
  .session-item:focus-within .session-item-actions,
  .session-item.active .session-item-actions {
    max-width: 60px;
  }
}

/* Compact Explore hero & announcement bar so feed tabs + cards surface above the fold */
.announcement-bar {
  max-width: 1280px;
  margin: 0.65rem auto 0;
  width: calc(100% - 3rem);
  border-radius: 12px;
}

@media (min-width: 681px) {
  .hero-widget-carousel {
    height: 215px;
  }

  .editorial-hero {
    padding: 1.1rem 1.5rem 0.9rem;
  }

  .serif-hero-title {
    font-size: clamp(2rem, 3.6vw, 2.85rem);
  }
}

/* Center tag rail when pills fit horizontally */
.tag-rail {
  justify-content: safe center;
}

/* Keep feed-tabs + count pill cohesive without giant stranded gap */
.feed-bar {
  justify-content: flex-start;
  gap: 0.75rem;
}

/* Prevent double gradient fill on active feed tab when sliding indicator is active */
.feed-tabs.has-indicator .feed-tab.active {
  background: transparent !important;
  box-shadow: none !important;
}

/* Dedicated Studio (My Characters) & Favorites workspace mode: hide Explore marketing hero */
#viewExplore.is-personal-feed .announcement-bar,
#viewExplore.is-personal-feed .hero-widget-wrap,
#viewExplore.is-personal-feed .editorial-hero {
  display: none !important;
}

#viewExplore.is-personal-feed .tag-rail-wrap {
  margin-top: 0.85rem;
}

@media (max-width: 680px) {
  .announcement-bar {
    width: calc(100% - 1.5rem);
    margin: 0.5rem auto 0;
  }
}


/* =============================================================================
   Patch 07: Dark Chat Palette Full Contrast Parity + Pin / Follow / Blocks UI
   ============================================================================= */

/* Fix ALL contrast issues when a dark Chat Palette is active on a light outer theme (Glacier/Desk) */
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-ghost,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-icon {
  color: var(--studio-text-secondary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-ghost:hover,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-icon:hover {
  color: var(--studio-text-primary) !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-secondary {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .btn-secondary:hover {
  filter: brightness(1.12);
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-topbar .chat-char-tagline,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .msg-sender {
  color: var(--studio-text-secondary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .bond-meter-pill {
  background: var(--studio-accent-soft) !important;
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .bond-pill-track {
  background: rgba(255, 255, 255, 0.18) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .chat-day-divider span {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-secondary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .msg-bubble em.rp-action {
  color: var(--studio-accent) !important;
  filter: brightness(1.25);
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .msg-action-btn {
  background: var(--studio-chat-top-bg) !important;
  color: var(--studio-text-secondary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .msg-action-btn:hover {
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-accent) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .chat-composer textarea {
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .chat-composer textarea::placeholder {
  color: var(--studio-text-secondary) !important;
  opacity: 0.72;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-room .chat-jump-latest {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-card-border) !important;
}

/* Session Pin Button */
.session-item-pin {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  transition: opacity 0.14s ease, color 0.14s ease, background 0.14s ease;
}

.session-item:hover .session-item-pin,
.session-item:focus-within .session-item-pin,
.session-item.active .session-item-pin,
.session-item-pin.pinned {
  opacity: 1;
}

.session-item-pin.pinned {
  color: var(--accent-action, var(--accent));
}

.session-item-pin:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
}

@media (min-width: 901px) {
  .session-item.is-pinned .session-item-actions,
  .session-item:hover .session-item-actions,
  .session-item:focus-within .session-item-actions,
  .session-item.active .session-item-actions {
    max-width: 84px;
  }
}

@media (hover: none), (max-width: 900px) {
  .session-item-pin {
    opacity: 0.85 !important;
  }
}

/* Creator Follow Button & Blocks Manager */
.creator-follow-btn.following {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-medium, var(--border-subtle));
  box-shadow: none;
}

.settings-blocks-section {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.blocks-manage-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}

.block-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 0.82rem;
}

.block-item-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-right: 0.4rem;
}

.chat-danger-box {
  border-color: rgba(239, 68, 68, 0.25);
}


/* =============================================================================
   Patch 08: Immersive Chat Palette Rail/Sidebar, In-Chat Search, RP Toolbar,
   Reading Progress Bar, Breathing Stream Glow & Relative Timestamps
   ============================================================================= */

/* 1. Seamless Immersive Left Rail & Sidebar when a Chat Palette is active inside a chat room */
.app-nav-rail,
.sessions-sidebar {
  transition: background-color 0.22s ease, border-color 0.22s ease, color 0.22s ease;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .app-nav-rail,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .sessions-sidebar {
  background: var(--studio-chat-top-bg) !important;
  border-right-color: var(--studio-card-border) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-footer-group,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .sidebar-header {
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-item {
  color: var(--studio-text-secondary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-item:hover {
  background: rgba(255, 255, 255, 0.07) !important;
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-item.active,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-item-accent {
  color: var(--studio-accent) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-active-indicator {
  background: var(--studio-accent-soft) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .rail-badge {
  background: var(--studio-accent) !important;
  color: #ffffff !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .sidebar-title,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .sidebar-group-label,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .session-item-preview {
  color: var(--studio-text-secondary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .session-item-title {
  color: var(--studio-text-primary) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .session-item.active {
  background: var(--studio-accent-soft) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat .sidebar-search-input,
:root[data-desk-palette]:not([data-desk-palette="default"]) .app-shell.in-chat.has-active-chat #btnSidebarNewChat {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-card-border) !important;
}

/* 2. Reading Scroll Progress Hairline at Bottom of .chat-topbar */
.chat-scroll-progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--emerald, var(--accent)));
  opacity: 0;
  pointer-events: none;
  transition: width 120ms linear, opacity 0.2s ease;
  z-index: 4;
}

.chat-scroll-progress.visible {
  opacity: 0.9;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-scroll-progress {
  background: var(--studio-accent) !important;
}

/* 3. Collapsible In-Chat Search Bar & Highlighted Hits */
.chat-in-search-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.48rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-topbar);
  flex-shrink: 0;
  animation: viewFadeIn 160ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-in-search-bar[hidden] {
  display: none !important;
}

.chat-in-search-input {
  flex: 1;
  min-width: 0;
  padding: 0.38rem 0.68rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.84rem;
  outline: none;
}

.chat-in-search-input:focus {
  border-color: var(--accent);
}

.chat-in-search-count {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.msg-row.search-match-active .msg-bubble {
  box-shadow: 0 0 0 2px var(--accent), 0 8px 24px rgba(0, 0, 0, 0.22) !important;
}

mark.chat-search-hit {
  background: rgba(250, 204, 21, 0.44);
  color: inherit;
  padding: 0;
  border-radius: 2px;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-in-search-bar {
  background: var(--studio-chat-top-bg) !important;
  border-bottom-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-in-search-input {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-in-search-count,
:root[data-desk-palette]:not([data-desk-palette="default"]) .chat-in-search-bar .btn-ghost {
  color: var(--studio-text-secondary) !important;
}

/* 4. RP Formatting Quick-Insert Toolbar & Live Composer Counter */
.composer-rp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  max-width: 860px;
  width: calc(100% - 2rem);
  margin: 0 auto 0.32rem;
  padding: 0 0.2rem;
  flex-shrink: 0;
}

.composer-rp-chips {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  flex-wrap: wrap;
}

.rp-chip-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.16rem 0.56rem;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: transform var(--spring-fast) var(--spring-pop), border-color 0.15s ease, color 0.15s ease;
}

.rp-chip-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.rp-chip-btn:active {
  transform: scale(0.92);
}

.rp-chip-hint {
  width: 22px;
  padding: 0.16rem 0;
  text-align: center;
}

.composer-stats {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.18s ease;
  white-space: nowrap;
}

.composer-stats.visible {
  opacity: 0.85;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .rp-chip-btn {
  background: var(--studio-bubble-ai) !important;
  color: var(--studio-text-secondary) !important;
  border-color: var(--studio-card-border) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .rp-chip-btn:hover {
  color: var(--studio-text-primary) !important;
  border-color: var(--studio-accent) !important;
}

:root[data-desk-palette]:not([data-desk-palette="default"]) .composer-stats {
  color: var(--studio-text-secondary) !important;
}

/* 5. Streaming Composer Breathing Glow, Copy Confirmation & Relative Timestamps */
@keyframes composerStreamPulse {
  0%, 100% {
    box-shadow: 0 0 0 1px var(--accent-soft, rgba(168, 85, 247, 0.28));
  }
  50% {
    box-shadow: 0 0 0 3px var(--accent-glow, rgba(168, 85, 247, 0.35)), 0 0 18px var(--accent-soft, rgba(168, 85, 247, 0.22));
  }
}

.chat-composer.is-streaming {
  animation: composerStreamPulse 1.8s ease-in-out infinite;
}

.msg-action-btn.copied {
  color: var(--emerald, #10b981) !important;
  border-color: var(--emerald, #10b981) !important;
}

.msg-time-meta {
  font-weight: 500;
  font-size: 0.68rem;
  opacity: 0.68;
  margin-left: 0.4rem;
}

/* 6. Keyboard Shortcuts Dialog Grid */
.shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.48rem 0.65rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.84rem;
}

.shortcut-row kbd {
  padding: 0.16rem 0.48rem;
  border-radius: 6px;
  border: 1px solid var(--border-medium, var(--border-subtle));
  background: var(--bg-surface);
  font: 700 0.74rem var(--font-mono);
  color: var(--text-primary);
  white-space: nowrap;
}

@media (max-width: 680px) {
  .composer-rp-toolbar {
    width: calc(100% - 1.1rem);
  }
}


/* =============================================================================
   Patch 09: Mobile Chat Layout Fixes + Ryl's Apple-Style Spring Animations
   ============================================================================= */

/* 1. Never wrap Discord badge onto 2 lines */
.discord-badge {
  white-space: nowrap;
  flex-shrink: 0;
}

/* 2. Keep day dividers in normal flow so they never float over scrolled RP text */
.chat-day-divider {
  position: static;
}

/* 3. Mobile Chat Topbar single-row fix, full bubble width & clean composer */
@media (max-width: 900px) {
  .chat-topbar {
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 0.45rem !important;
  }

  .app-shell .sessions-sidebar,
  .app-shell.in-chat .sessions-sidebar {
    transition: transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  }
}

@media (max-width: 680px) {
  .chat-topbar {
    padding: 0.48rem 0.6rem !important;
  }

  #chatDiscordBadge {
    display: none !important;
  }

  .chat-char-info {
    gap: 0.45rem !important;
  }

  .chat-char-name-row {
    gap: 0.35rem !important;
  }

  .bond-meter-pill {
    max-width: 112px;
    padding: 0.14rem 0.42rem;
  }

  .bond-pill-track {
    display: none;
  }

  /* Reclaim left avatar gutter on narrow screens so long RP bubbles breathe */
  .msg-row {
    gap: 0;
  }

  .msg-row > .avatar {
    display: none;
  }

  .msg-bubble-wrap {
    max-width: 96% !important;
    width: 100%;
  }

  .msg-row.user .msg-bubble-wrap {
    max-width: 88% !important;
    width: auto;
  }

  .chat-composer {
    width: calc(100% - 1rem);
    margin: 0.3rem auto 0.55rem;
    padding: 0.45rem 0.55rem;
  }

  .chat-composer textarea {
    min-height: 24px;
    padding: 0.28rem 0.25rem;
    font-size: 0.9rem;
    overflow-y: hidden;
  }

  #btnOpenShortcuts {
    display: none;
  }
}

/* 4. Adapted Ryl Apple-Style Spring Physics Animations */
@keyframes appleCardBounce {
  0% { opacity: 0; transform: translate3d(0, 22px, 0) scale(0.90); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes appleMsgBounce {
  0% { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.91); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes appleActionPop {
  0% { opacity: 0; transform: translate3d(0, -10px, 0) scale(0.84); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes appleDialogBounce {
  0% { opacity: 0; transform: translate3d(0, 24px, 0) scale(0.90); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

.char-card {
  will-change: transform;
}

.char-card:active {
  transform: scale(0.96);
}

.char-card.spring-reveal {
  animation: appleCardBounce var(--spring-dur) var(--spring-pop) both;
}

.msg-row.msg-spring-in {
  animation: appleMsgBounce var(--spring-dur) var(--spring-pop) both;
}

.msg-row.held .msg-actions,
.chat-topbar-actions.open {
  animation: appleActionPop 340ms var(--spring-pop) both;
}

.native-dialog[open] {
  animation: appleDialogBounce var(--spring-dur) var(--spring-pop) both;
}

.sessions-sidebar .session-item {
  transition:
    transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
    background 0.16s ease,
    border-color 0.16s ease;
}

.sessions-sidebar .session-item:active {
  transform: scale(0.96);
}

@media (prefers-reduced-motion: reduce) {
  .char-card.spring-reveal,
  .msg-row.msg-spring-in,
  .msg-row.held .msg-actions,
  .chat-topbar-actions.open,
  .native-dialog[open],
  .sessions-sidebar .session-item {
    animation: none !important;
    transition: none !important;
  }
}


/* =============================================================================
   Patch 12: Zero-Flash Pre-Paint Boot Routing & Chat Boot Loader
   ============================================================================= */

.chat-boot-loader {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.chat-boot-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--border-subtle);
  border-top-color: var(--accent);
  animation: bootSpin 0.75s linear infinite;
}

@keyframes bootSpin {
  to { transform: rotate(360deg); }
}

/* Hide Explore before JS runs when booting directly into /chat/{id}, /chats, /c/{id}, or /u/{handle} */
html[data-boot-route="chat-room"] #viewExplore,
html[data-boot-route="chats"] #viewExplore,
html[data-boot-route="profile"] #viewExplore,
html[data-boot-route="creator"] #viewExplore {
  display: none !important;
}

html[data-boot-route="chat-room"] #viewChat,
html[data-boot-route="chats"] #viewChat {
  display: flex !important;
  flex-direction: column;
}

html[data-boot-route="chat-room"] .top-header,
html[data-boot-route="chat-room"] #mobileBottomNav {
  display: none !important;
}

html[data-boot-route="chat-room"] .workspace-body {
  height: 100dvh;
}

html[data-boot-route="chat-room"] #chatEmptyPlaceholder {
  display: none !important;
}

html[data-boot-route="chat-room"] .chat-boot-loader {
  display: flex;
}

html[data-boot-route="chat-room"][data-desk-palette]:not([data-desk-palette="default"]) #viewChat {
  background: var(--studio-main-bg) !important;
  color: var(--studio-text-primary) !important;
}

html[data-boot-route="chat-room"][data-desk-palette]:not([data-desk-palette="default"]) .app-nav-rail,
html[data-boot-route="chat-room"][data-desk-palette]:not([data-desk-palette="default"]) .sessions-sidebar {
  background: var(--studio-chat-top-bg) !important;
  border-right-color: var(--studio-card-border) !important;
}

html[data-boot-route="chat-room"][data-desk-palette]:not([data-desk-palette="default"]) .chat-boot-loader {
  color: var(--studio-text-secondary) !important;
}

html[data-boot-route="chat-room"][data-desk-palette]:not([data-desk-palette="default"]) .chat-boot-spinner {
  border-top-color: var(--studio-accent) !important;
}

html[data-boot-route="personal"] #viewExplore .announcement-bar,
html[data-boot-route="personal"] #viewExplore .hero-widget-wrap,
html[data-boot-route="personal"] #viewExplore .editorial-hero {
  display: none !important;
}

@media (min-width: 901px) {
  html[data-boot-route="chat-room"] .sessions-sidebar,
  html[data-boot-route="chats"] .sessions-sidebar {
    display: flex;
  }
}


/* =============================================================================
   Patch 14: Context Budget Inspector & Rolling Auto-Summary Controls
   ============================================================================= */
.context-budget-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface-2, rgba(255, 255, 255, 0.03));
}
.context-budget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
}
.context-budget-bar {
  display: flex;
  height: 8px;
  width: 100%;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-surface, rgba(128, 128, 128, 0.16));
}
.cb-seg {
  display: block;
  height: 100%;
  transition: width 0.25s ease;
}
.cb-sys { background: #7c5cff; }
.cb-lore { background: #00b8d9; }
.cb-mem { background: #f59e0b; }
.cb-hist { background: #22c55e; }
.context-budget-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.85rem;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.context-budget-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.context-budget-legend b {
  color: var(--text-primary);
  font-weight: 600;
}
.cb-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.field-label-split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.rolling-summary-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.inline-check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}
.inline-check-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}
.rolling-summary-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.rolling-summary-box .field-hint,
.context-budget-card .field-hint {
  font-size: 0.76rem;
  color: var(--text-secondary);
}


/* =============================================================================
   Patch 16: Multi-Tag Include/Exclude, Rating & Timeframe Filters, Blocked Tags
   ============================================================================= */
.tag-rail-pill.excluded {
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
  text-decoration: line-through;
}
.explore-filter-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.explore-filter-select,
.explore-filter-pill {
  height: 32px;
  padding: 0 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-surface-2, var(--bg-surface));
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.explore-filter-pill:hover,
.explore-filter-select:hover {
  border-color: var(--accent);
}
.explore-filter-pill.is-exclude-active {
  border-color: rgba(239, 68, 68, 0.65);
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
}
.explore-filter-clear {
  color: var(--text-secondary);
}
.blocked-tags-input-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.blocked-tags-input-row input {
  flex: 1;
  min-width: 0;
}
.blocked-tags-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}
.blocked-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(239, 68, 68, 0.13);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #f87171;
}
.blocked-tag-chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}


/* =============================================================================
   Patch 17: Full-Page Chat Settings & Story Memory Studio
   ============================================================================= */
dialog.native-dialog.chat-settings-fullscreen {
  width: min(1240px, 96vw);
  max-width: 96vw;
  height: min(92dvh, 920px);
  max-height: 94dvh;
}
dialog.native-dialog.chat-settings-fullscreen .dialog-form {
  height: 100%;
  max-height: 100%;
}
dialog.native-dialog.chat-settings-fullscreen .chat-settings-body {
  flex: 1;
  min-height: 0;
  padding: 1.25rem 1.5rem;
}
.chat-settings-grid {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 1.5rem;
  height: 100%;
  min-height: 0;
  align-items: start;
}
.chat-settings-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}
.chat-settings-col-memory {
  height: 100%;
  min-height: 0;
}
.memory-editor-pane {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.memory-editor-primary {
  flex: 1.35;
}
.memory-editor-secondary {
  flex: 1;
}
.memory-editor-pane textarea {
  flex: 1;
  min-height: 220px;
  line-height: 1.55;
  font-size: 0.9rem;
  resize: vertical;
}
.memory-editor-secondary textarea {
  min-height: 155px;
}
@media (max-width: 900px) {
  dialog.native-dialog.chat-settings-fullscreen {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: none;
  }
  dialog.native-dialog.chat-settings-fullscreen .chat-settings-body {
    padding: 1rem;
  }
  .chat-settings-grid {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-settings-col-memory {
    height: auto;
  }
  .memory-editor-pane textarea {
    min-height: 210px;
  }
  .memory-editor-secondary textarea {
    min-height: 140px;
  }
}


/* =============================================================================
   Patch 18: Continue / Write for Me Chips & In-Chat RPG Status Blocks / Tables
   ============================================================================= */
.rp-chip-action {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  color: var(--text-primary);
}
.rp-chip-action:disabled {
  opacity: 0.55;
  cursor: wait;
}
.rp-status-details {
  margin: 0.55rem 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-surface, #161822) 72%, transparent);
  overflow: hidden;
}
.rp-status-details > summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  font-size: 0.84rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  user-select: none;
}
.rp-status-details > summary::-webkit-details-marker {
  display: none;
}
.rp-status-details > summary::before {
  content: "▸";
  display: inline-block;
  font-size: 0.78rem;
  opacity: 0.8;
  transition: transform 0.18s ease;
}
.rp-status-details[open] > summary::before {
  transform: rotate(90deg);
}
.rp-status-details-body {
  padding: 0.55rem 0.75rem 0.7rem;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
  line-height: 1.5;
}
.rp-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 0.55rem 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.rp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  line-height: 1.4;
}
.rp-table th,
.rp-table td {
  padding: 0.42rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.rp-table th {
  font-weight: 700;
  background: rgba(128, 128, 128, 0.1);
}
.rp-table tr:last-child td {
  border-bottom: none;
}


/* Patch 19: Dual-mode Send / Continue button */
.btn-send .icon-send-continue {
  display: none;
}
.btn-send.is-continue-mode .icon-send-plane {
  display: none;
}
.btn-send.is-continue-mode .icon-send-continue {
  display: block;
}
.btn-send.is-continue-mode {
  opacity: 0.92;
}


/* =============================================================================
   Patch 20: Hydrogen Audit Polish Pack
   (Compact Above-the-Fold Hero, Unified Sans Hierarchy, Tighter 4:3 Cards,
    Zero Top-Edge Clipping, Collapsed Rail Micro-Labels, Scoped Search Pill,
    and Discord Exclusive Highlight)
   ============================================================================= */
.hero-widget-wrap {
  margin-top: 0.55rem;
}
.hero-widget-carousel {
  height: 155px;
  border-radius: 16px;
}
.editorial-hero {
  margin: 0.85rem auto 0.75rem;
}
.serif-hero-title {
  font-family: var(--font-sans, "Plus Jakarta Sans", system-ui, sans-serif);
  font-size: clamp(1.65rem, 3.1vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}
.hero-subtitle {
  font-size: 0.9rem;
}
.feed-title {
  font-family: var(--font-sans, "Plus Jakarta Sans", system-ui, sans-serif);
  letter-spacing: -0.02em;
}
.feed-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.feed-heading-left {
  display: flex;
  flex-direction: column;
}
.active-search-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.72rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-surface));
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.active-search-pill[hidden] {
  display: none;
}
.active-search-x {
  font-size: 1rem;
  line-height: 1;
  opacity: 0.8;
}

/* Tighter 4:3 Card Aspect Ratio + Zero Top-Edge Scroll Clipping */
.character-grid {
  padding-top: 0.45rem;
}
.char-card-media {
  aspect-ratio: 4 / 3;
}
.char-card-body {
  padding: 0.68rem 0.78rem 0.75rem;
  gap: 0.35rem;
}

/* Collapsed Left Rail Persistent Micro-Labels */
.app-shell:not(.rail-expanded) .app-nav-rail {
  width: 74px;
  padding: 0.65rem 0.35rem;
}
.app-shell:not(.rail-expanded) .rail-item {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.2rem;
  padding: 0.42rem 0.2rem;
  min-height: 52px;
}
.app-shell:not(.rail-expanded) .rail-label {
  opacity: 0.84;
  max-width: 66px;
  font-size: 0.64rem;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.app-shell:not(.rail-expanded) .rail-item.active .rail-label {
  opacity: 1;
}
.app-shell:not(.rail-expanded) .rail-toggle-btn .rail-label {
  display: none;
}

/* Discord Bot Connectivity Prominence */
.discord-highlight-accordion {
  border-color: rgba(88, 101, 242, 0.48);
  background: rgba(88, 101, 242, 0.06);
}
.discord-highlight-accordion > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.discord-feature-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  background: rgba(88, 101, 242, 0.2);
  border: 1px solid rgba(88, 101, 242, 0.45);
  color: #a5b4fc;
}

@media (max-width: 680px) {
  .hero-widget-carousel {
    height: 130px;
  }
  .editorial-hero {
    margin: 0.65rem auto 0.6rem;
  }
}

/* =============================================================================
   Ryl Relake v33 UI Polish: Full-Width Chats & Frosted Glassmorphism Profile
   (Fixes Chats Tab Conversation List Clipping & Profile Saved Chats / Comments)
   ============================================================================= */
.app-shell.in-chat:not(.has-active-chat) #viewChat {
  background: var(--bg-base) !important;
  color: var(--text-primary) !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}
[data-theme="desk"] .app-shell.in-chat:not(.has-active-chat) #viewChat,
[data-theme="glacier"] .app-shell.in-chat:not(.has-active-chat) #viewChat {
  background: transparent !important;
  color: #1e242d !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}

.chat-empty-placeholder {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  padding: 1rem 0.9rem calc(84px + env(safe-area-inset-bottom, 0px)) !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  background: transparent !important;
}

.chat-empty-placeholder .chat-empty-hero,
.chat-empty-placeholder .chat-empty-sessions {
  width: 100% !important;
  max-width: 640px !important;
  min-width: 0 !important;
  margin-left: auto !important;
  margin-right: auto !important;
  box-sizing: border-box !important;
}

.chat-empty-placeholder h3 {
  color: var(--text-primary) !important;
}
[data-theme="desk"] .chat-empty-placeholder h3,
[data-theme="glacier"] .chat-empty-placeholder h3 {
  color: #1e242d !important;
}

.chat-empty-placeholder .chat-empty-sessions-label {
  color: var(--text-muted) !important;
}

.chat-empty-session-card {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  background: var(--card-bg) !important;
  border: 1px solid var(--border-subtle) !important;
  color: var(--text-primary) !important;
}

/* Glassmorphism for Profile Saved Chats, Carousel Cards, Arrows, Comments & Sort Select */
#viewProfile .profile-sessions-block,
#viewProfile .profile-comments-block {
  background: rgba(24, 26, 36, 0.48) !important;
  backdrop-filter: blur(20px) saturate(165%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(165%) !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24) !important;
}

#viewProfile .profile-session-card,
#viewProfile .comment-card,
#viewProfile .carousel-arrow,
#viewProfile #commentContentInput,
#viewProfile #commentsSortSelect {
  background: rgba(255, 255, 255, 0.08) !important;
  backdrop-filter: blur(14px) saturate(150%) !important;
  -webkit-backdrop-filter: blur(14px) saturate(150%) !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  color: var(--text-primary) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18) !important;
}

/* Light themes (Desk & Glacier): crisp frosted Apple glass letting dual PFP gradient shine through */
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-sessions-block,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-comments-block {
  background: rgba(255, 255, 255, 0.44) !important;
  backdrop-filter: blur(20px) saturate(170%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(170%) !important;
  border: 1px solid rgba(255, 255, 255, 0.68) !important;
  box-shadow: 0 10px 32px -6px rgba(15, 23, 42, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.75) !important;
}

:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-session-card,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .comment-card,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .carousel-arrow,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile #commentContentInput,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile #commentsSortSelect {
  background: rgba(255, 255, 255, 0.56) !important;
  backdrop-filter: blur(14px) saturate(160%) !important;
  -webkit-backdrop-filter: blur(14px) saturate(160%) !important;
  border: 1px solid rgba(255, 255, 255, 0.75) !important;
  color: #14181f !important;
  box-shadow: 0 4px 14px -2px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8) !important;
}

:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-session-title,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .comment-author {
  color: #0f172a !important;
}

:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-session-preview,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .profile-session-meta,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .comment-body,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile .comment-time,
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile #commentContentInput::placeholder {
  color: #475569 !important;
}

:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile #btnPostComment {
  background: rgba(20, 24, 31, 0.78) !important;
  backdrop-filter: blur(12px) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
}

/* Monochrome Chat Palette (Pure Matte Ink & Crisp Silver-White) */
:root[data-desk-palette="monochrome"] {
  --studio-main-bg: #111112;
  --studio-card-bg: #1c1c1e;
  --studio-card-border: #2e2e32;
  --studio-text-primary: #f5f5f7;
  --studio-text-secondary: #a1a1aa;
  --studio-text-muted: #71717a;
  --studio-accent: #e4e4e7;
  --studio-accent-soft: rgba(228, 228, 231, 0.16);
  --studio-chat-top-bg: #161618;
  --studio-bubble-ai: #1e1e21;
  --studio-bubble-user: #2d2d32;
  --studio-composer-bg: #18181b;
}

:root[data-desk-palette="monochrome"] #btnSendMessage,
:root[data-desk-palette="monochrome"] .btn-send {
  background: #f4f4f5 !important;
  color: #111112 !important;
}

.palette-live-preview[data-preview-palette="monochrome"] {
  --p-bg: #111112; --p-top: #161618; --p-border: #2e2e32; --p-ai: #1e1e21;
  --p-user: #2d2d32; --p-text: #f5f5f7; --p-muted: #8a8a93; --p-accent: #d4d4d8;
}
.palette-live-preview[data-preview-palette="monochrome"] .plp-send {
  background: #f4f4f5;
  color: #111112;
}

/* =============================================================================
   Merged from Relake-Ryl: Dual-Color PFP Ambient Gradient, Profile Overflow & Spring Thumb
   ============================================================================= */
.profile-card-col, .profile-card { max-width: 100% !important; min-width: 0 !important; overflow: hidden !important; }
.profile-card-top { flex-wrap: wrap !important; gap: 6px !important; }
.profile-top-actions { display: flex !important; flex-wrap: wrap !important; gap: 4px !important; justify-content: flex-end !important; max-width: 100% !important; }

/* Full-Height Dual-Dominant Color Gradient (Top -> Bottom) */
#viewProfile.has-pfp-theme {
  background:
    radial-gradient(120% 55% at 25% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.30) 0%, transparent 72%),
    radial-gradient(120% 60% at 75% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.32) 0%, transparent 75%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.14) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.18) 100%),
    var(--bg-base) !important;
}
.profile-card.has-pfp-theme {
  background:
    radial-gradient(115% 52% at 20% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.28) 0%, transparent 72%),
    radial-gradient(115% 58% at 80% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.30) 0%, transparent 74%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.14) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.16) 100%),
    var(--card-bg) !important;
  border-color: rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.42) !important;
}
.char-card.has-pfp-theme {
  background:
    radial-gradient(120% 60% at 25% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.26) 0%, transparent 72%),
    radial-gradient(120% 65% at 75% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.28) 0%, transparent 74%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.12) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.15) 100%),
    var(--card-bg) !important;
  border-color: rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.38) !important;
}
:is([data-theme="desk"], [data-theme="glacier"]) #viewProfile.has-pfp-theme {
  background:
    radial-gradient(115% 52% at 20% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.26) 0%, transparent 72%),
    radial-gradient(115% 58% at 80% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.28) 0%, transparent 74%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.14) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.17) 100%),
    var(--bg-base) !important;
}
:is([data-theme="desk"], [data-theme="glacier"]) .profile-card.has-pfp-theme {
  background:
    radial-gradient(115% 48% at 20% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.22) 0%, transparent 72%),
    radial-gradient(115% 54% at 80% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.24) 0%, transparent 74%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.11) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.14) 100%),
    #ffffff !important;
}
:is([data-theme="desk"], [data-theme="glacier"]) .char-card.has-pfp-theme {
  background:
    radial-gradient(120% 56% at 25% 0%, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.20) 0%, transparent 72%),
    radial-gradient(120% 60% at 75% 100%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.22) 0%, transparent 74%),
    linear-gradient(180deg, rgba(var(--pfp-rgb-top, var(--pfp-rgb)), 0.09) 0%, rgba(var(--pfp-rgb-bottom, var(--pfp-rgb)), 0.12) 100%),
    #ffffff !important;
}

/* Sliding spring thumb inside #feedTabs */
.feed-tabs { position: relative !important; }
.feed-spring-thumb {
  position: absolute; top: 4px; bottom: 4px; left: 0; border-radius: 9px;
  background: var(--bg-elevated, rgba(255, 255, 255, 0.14));
  border: 1px solid var(--border-medium, rgba(255, 255, 255, 0.16));
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
  pointer-events: none; z-index: 0; opacity: 0;
  transition: transform 460ms cubic-bezier(0.34, 1.56, 0.64, 1), width 460ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.feed-spring-thumb.ready { opacity: 1; }
.feed-tabs.has-spring-thumb .feed-tab.active { background: transparent !important; box-shadow: none !important; }

/* === Ryl Port: Sort Dropdown & URL Importer === */
.sort-heading-wrap { position: relative; display: inline-flex; align-items: center; }
.feed-title-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  cursor: pointer;
}
.feed-title-btn:active { transform: scale(0.95); }
.feed-title-chevron {
  font-size: 0.95rem;
  color: var(--text-muted);
  transition: transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.feed-title-btn[aria-expanded="true"] .feed-title-chevron { transform: rotate(180deg); }
.sort-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  padding: 6px;
  border-radius: 12px;
  background: var(--bg-elevated, var(--bg-surface));
  border: 1px solid var(--border-medium);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}
.sort-dropdown-menu.open { display: flex; }
.sort-option-btn {
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.sort-option-btn:hover { background: var(--bg-surface); color: var(--text-primary); }
.sort-option-btn.active { background: var(--badge-bg); color: var(--badge-text); font-weight: 700; }
.url-import-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.url-import-row input { flex: 1; min-width: 0; }
