/* ============================================================
   COOPCHAT THEMES
   Each theme is selected via data-app-theme="<name>" on <html>.
   Themes define: an accent color, a background gradient, and a
   distinct particle/motion treatment rendered by themes.js into
   the .theme-bg-layer container that's present on both the auth
   screen and the main app shell.
   ============================================================ */

:root {
  --theme-glow: var(--accent);
}

/* Shared container for all theme background effects - sits behind
   everything else via a low z-index, in-flow so it never blocks clicks. */
.theme-bg-layer {
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
}
.theme-bg-layer .theme-gradient { position: absolute; inset: 0; }
.theme-bg-layer .theme-orb { position: absolute; border-radius: 50%; filter: blur(70px); }
.theme-bg-layer .theme-particle { position: absolute; border-radius: 50%; }

/* Everything in the app shell/auth card needs to sit above the bg layer */
#auth-screen, .app-layout, #announcement-banner { position: relative; z-index: 1; }

/* ============================================================
   1. SPACE — deep navy/purple, drifting stars, nebula glow
   ============================================================ */
[data-app-theme="space"] {
  --accent: #5865F2;
  --theme-glow: #7c7ff5;
  --bg: #0a0b14;
  --bg-elevated: #14162380;
  --bg-panel: #14162399;
}
[data-app-theme="space"] .theme-gradient {
  background: radial-gradient(circle at 25% 25%, rgba(88,101,242,0.28), transparent 50%),
              radial-gradient(circle at 75% 70%, rgba(168,85,247,0.2), transparent 50%),
              #0a0b14;
}
[data-app-theme="space"] .theme-orb:nth-child(2) { background: #5865F2; width: 400px; height: 400px; top: 5%; left: 10%; animation: themeFloat1 9s ease-in-out infinite; opacity: 0.5; }
[data-app-theme="space"] .theme-orb:nth-child(3) { background: #a855f7; width: 340px; height: 340px; bottom: 8%; right: 12%; animation: themeFloat2 11s ease-in-out infinite; opacity: 0.45; }
[data-app-theme="space"] .theme-particle { background: white; box-shadow: 0 0 4px rgba(255,255,255,0.9); animation-name: themeStarTwinkle; }

/* ============================================================
   2. PLANT / NATURE — forest green, floating leaves
   ============================================================ */
[data-app-theme="plant"] {
  --accent: #4ade80;
  --theme-glow: #86efac;
  --bg: #0d150f;
  --bg-elevated: #16241a80;
  --bg-panel: #16241a99;
}
[data-app-theme="plant"] .theme-gradient {
  background: radial-gradient(circle at 20% 30%, rgba(74,222,128,0.22), transparent 55%),
              radial-gradient(circle at 80% 75%, rgba(132,204,22,0.16), transparent 50%),
              #0d150f;
}
[data-app-theme="plant"] .theme-orb:nth-child(2) { background: #4ade80; width: 380px; height: 380px; top: 10%; right: 15%; animation: themeFloat1 10s ease-in-out infinite; opacity: 0.35; }
[data-app-theme="plant"] .theme-orb:nth-child(3) { background: #a3e635; width: 300px; height: 300px; bottom: 10%; left: 10%; animation: themeFloat2 12s ease-in-out infinite; opacity: 0.3; }
[data-app-theme="plant"] .theme-particle { background: #86efac; border-radius: 30% 70% 60% 40%; animation-name: themeLeafFall; }

/* ============================================================
   3. OCEAN — deep teal/blue, rising bubbles
   ============================================================ */
[data-app-theme="ocean"] {
  --accent: #22d3ee;
  --theme-glow: #67e8f9;
  --bg: #071a1f;
  --bg-elevated: #0f2a3280;
  --bg-panel: #0f2a3299;
}
[data-app-theme="ocean"] .theme-gradient {
  background: radial-gradient(circle at 30% 20%, rgba(34,211,238,0.22), transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(14,116,144,0.28), transparent 55%),
              #071a1f;
}
[data-app-theme="ocean"] .theme-orb:nth-child(2) { background: #22d3ee; width: 380px; height: 380px; top: 15%; left: 15%; animation: themeFloat1 8s ease-in-out infinite; opacity: 0.4; }
[data-app-theme="ocean"] .theme-orb:nth-child(3) { background: #0891b2; width: 340px; height: 340px; bottom: 5%; right: 10%; animation: themeFloat2 10s ease-in-out infinite; opacity: 0.4; }
[data-app-theme="ocean"] .theme-particle { background: rgba(103,232,249,0.5); border: 1px solid rgba(103,232,249,0.8); animation-name: themeBubbleRise; }

/* ============================================================
   4. TIME — a full day/night cycle every hour, updated every 30s.
   Colors are NOT set here as static values (aside from a sane
   fallback) since themes.js interpolates and applies them live
   based on wall-clock time. This block just defines the elements'
   shapes/positioning/animation, not their colors.
   ============================================================ */
[data-app-theme="time"] {
  --accent: #f59e0b;
  --theme-glow: #fbbf24;
  --bg: #0a0c1c;
  --bg-elevated: #14172b80;
  --bg-panel: #14172b99;
}
[data-app-theme="time"] .theme-gradient {
  /* Fallback shown for an instant before the first JS tick applies real
     colors - avoids a flash of unstyled black. */
  background: linear-gradient(180deg, #6ec4f0 0%, #0a0c1c 100%);
  transition: background 2s ease;
}
.time-sun {
  position: absolute; left: 50%; top: 8%; width: 140px; height: 140px;
  transform: translateX(-50%); border-radius: 50%; transition: top 2s ease, background 2s ease;
  filter: blur(4px);
}
.time-stars {
  position: absolute; inset: 0; opacity: 0; transition: opacity 2s ease;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 15%, white, transparent),
    radial-gradient(1.5px 1.5px at 25% 35%, white, transparent),
    radial-gradient(1px 1px at 40% 10%, white, transparent),
    radial-gradient(1.5px 1.5px at 55% 25%, white, transparent),
    radial-gradient(1px 1px at 70% 40%, white, transparent),
    radial-gradient(1.5px 1.5px at 85% 15%, white, transparent),
    radial-gradient(1px 1px at 95% 30%, white, transparent),
    radial-gradient(1.5px 1.5px at 15% 50%, white, transparent),
    radial-gradient(1px 1px at 32% 55%, white, transparent),
    radial-gradient(1.5px 1.5px at 60% 55%, white, transparent),
    radial-gradient(1px 1px at 78% 52%, white, transparent),
    radial-gradient(1.5px 1.5px at 90% 60%, white, transparent);
}
/* Ambient particles read as birds/motes during the day and stars/fireflies
   at night - kept as simple soft dots that work in both contexts rather
   than swapping shape, since the sky color shift already carries the
   day/night read. */
[data-app-theme="time"] .theme-particle {
  background: rgba(255,255,255,0.6); box-shadow: 0 0 6px rgba(255,255,255,0.5);
}

/* ============================================================
   5. CYBERPUNK — hot pink/cyan, scanning grid, glitch accents
   ============================================================ */
[data-app-theme="cyberpunk"] {
  --accent: #ec4899;
  --theme-glow: #22d3ee;
  --bg: #06050a;
  --bg-elevated: #12101a80;
  --bg-panel: #12101a99;
}
[data-app-theme="cyberpunk"] .theme-gradient {
  background: radial-gradient(circle at 20% 20%, rgba(236,72,153,0.22), transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(34,211,238,0.2), transparent 50%),
              linear-gradient(#06050a, #06050a);
}
[data-app-theme="cyberpunk"] .theme-gradient::after {
  content: ''; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(236,72,153,0.06) 1px, transparent 1px),
                     linear-gradient(90deg, rgba(34,211,238,0.06) 1px, transparent 1px);
  background-size: 40px 40px;
}
[data-app-theme="cyberpunk"] .theme-orb:nth-child(2) { background: #ec4899; width: 360px; height: 360px; top: 10%; left: 15%; animation: themeFloat1 7s ease-in-out infinite; opacity: 0.4; }
[data-app-theme="cyberpunk"] .theme-orb:nth-child(3) { background: #22d3ee; width: 320px; height: 320px; bottom: 10%; right: 10%; animation: themeFloat2 9s ease-in-out infinite; opacity: 0.4; }
[data-app-theme="cyberpunk"] .theme-particle { background: #22d3ee; box-shadow: 0 0 6px currentColor; animation-name: themeGlitchFlicker; }

/* ============================================================
   6. MIDNIGHT SNOW — cool blue-white, falling snow
   ============================================================ */
[data-app-theme="snow"] {
  --accent: #93c5fd;
  --theme-glow: #dbeafe;
  --bg: #0b0f17;
  --bg-elevated: #16202f80;
  --bg-panel: #16202f99;
}
[data-app-theme="snow"] .theme-gradient {
  background: radial-gradient(circle at 30% 20%, rgba(147,197,253,0.16), transparent 55%),
              radial-gradient(circle at 70% 80%, rgba(199,210,254,0.1), transparent 50%),
              #0b0f17;
}
[data-app-theme="snow"] .theme-orb:nth-child(2) { background: #93c5fd; width: 340px; height: 340px; top: 10%; right: 15%; animation: themeFloat1 14s ease-in-out infinite; opacity: 0.25; }
[data-app-theme="snow"] .theme-orb:nth-child(3) { background: #c7d2fe; width: 280px; height: 280px; bottom: 15%; left: 10%; animation: themeFloat2 16s ease-in-out infinite; opacity: 0.2; }
[data-app-theme="snow"] .theme-particle { background: white; box-shadow: 0 0 3px rgba(255,255,255,0.7); animation-name: themeSnowFall; }

/* ============================================================
   Shared keyframes used across themes
   ============================================================ */
@keyframes themeFloat1 { 0%, 100% { transform: translate(0,0) scale(1); } 50% { transform: translate(50px,-40px) scale(1.15); } }
@keyframes themeFloat2 { 0%, 100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-60px,50px) scale(1.1); } }

@keyframes themeStarTwinkle {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.4); }
}
@keyframes themeLeafFall {
  0% { transform: translateY(-10vh) translateX(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.85; }
  90% { opacity: 0.85; }
  100% { transform: translateY(110vh) translateX(40px) rotate(360deg); opacity: 0; }
}
@keyframes themeBubbleRise {
  0% { transform: translateY(10vh) scale(0.8); opacity: 0; }
  10% { opacity: 0.7; }
  90% { opacity: 0.5; }
  100% { transform: translateY(-110vh) scale(1.3); opacity: 0; }
}
@keyframes themeCloudDrift {
  0% { transform: translateX(-10vw); opacity: 0; }
  15% { opacity: 0.6; }
  85% { opacity: 0.6; }
  100% { transform: translateX(10vw); opacity: 0; }
}
@keyframes themeGlitchFlicker {
  0%, 90%, 100% { opacity: 0.8; transform: scale(1); }
  92% { opacity: 0.1; transform: scale(0.7) translateX(3px); }
  94% { opacity: 0.9; transform: scale(1.1) translateX(-2px); }
  96% { opacity: 0.2; }
}
@keyframes themeSnowFall {
  0% { transform: translateY(-10vh) translateX(0); opacity: 0; }
  10% { opacity: 0.9; }
  90% { opacity: 0.9; }
  100% { transform: translateY(110vh) translateX(30px); opacity: 0; }
}

/* ============================================================
   Theme picker UI (Profile & Settings modal)
   ============================================================ */
.app-theme-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px;
}
.app-theme-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); text-align: left;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.app-theme-card:hover { border-color: var(--text-muted); transform: translateY(-1px); }
.app-theme-card-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.app-theme-swatch { width: 100%; height: 36px; border-radius: 6px; display: block; margin-bottom: 2px; }
.app-theme-swatch-space { background: linear-gradient(135deg, #0a0b14, #5865F2 60%, #a855f7); }
.app-theme-swatch-plant { background: linear-gradient(135deg, #0d150f, #4ade80 60%, #a3e635); }
.app-theme-swatch-ocean { background: linear-gradient(135deg, #071a1f, #22d3ee 60%, #0891b2); }
.app-theme-swatch-time { background: linear-gradient(135deg, #0a0c1c, #ff7a5a 40%, #6ec4f0 70%, #ff9d6e); }
.app-theme-swatch-cyberpunk { background: linear-gradient(135deg, #06050a, #ec4899 50%, #22d3ee); }
.app-theme-swatch-snow { background: linear-gradient(135deg, #0b0f17, #93c5fd 60%, #c7d2fe); }
.app-theme-name { font-size: 13px; font-weight: 700; color: var(--text); }
.app-theme-desc { font-size: 11px; color: var(--text-muted); line-height: 1.3; }

/* ============================================================
   Low performance tier: strips expensive blur/backdrop-filter
   effects that tank frame rate on weak/integrated GPUs (budget
   laptops, older Chromebooks, etc). Applied via data-perf-tier
   on <html>, set by perf.js based on hardware detection or a
   manual override in Settings.
   ============================================================ */
[data-perf-tier="low"] .sidebar,
[data-perf-tier="low"] .chat-area,
[data-perf-tier="low"] .online-panel {
  backdrop-filter: none;
  background: var(--bg-panel);
}
[data-perf-tier="low"] .theme-bg-layer .theme-orb {
  filter: none;
  opacity: 0.15;
}
[data-perf-tier="low"] .theme-bg-layer .theme-particles-wrap {
  display: none;
}
[data-perf-tier="low"] .theme-bg-layer .theme-gradient::after {
  display: none;
}
[data-perf-tier="low"] .intro-particles,
[data-perf-tier="low"] .intro-scanline {
  display: none;
}
[data-perf-tier="low"] .intro-orb {
  filter: blur(30px);
  opacity: 0.35;
}
[data-perf-tier="low"] .modal-content,
[data-perf-tier="low"] .admin-modal {
  animation: none;
}
[data-perf-tier="low"] .message-row {
  animation: none;
}

/* --- Lightweight intro (low perf tier) --- */
@keyframes introLiteLogoIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.intro-lite .intro-bg-lite {
  position: absolute; inset: 0;
  background: linear-gradient(160deg, #0a0b14, #14162a 60%, #1a1030);
}
.intro-lite .intro-logo-text-lite {
  font-size: 52px; font-weight: 900; color: var(--accent); margin: 0;
  animation: introLiteLogoIn 0.5s ease-out;
}
.intro-lite .intro-tagline-lite {
  color: rgba(255,255,255,0.6); font-size: 14px; margin: 12px 0 0; letter-spacing: 0.1em;
  animation: introLiteLogoIn 0.5s ease-out 0.15s both;
}
.intro-lite .intro-feature-card-lite { animation: introLiteLogoIn 0.4s ease-out; }
.intro-lite .intro-feature-title-lite { color: white; font-size: 28px; font-weight: 800; margin: 0 0 10px; }

