/* ==========================================
   NoteX Premium Theme Engine Stylesheet
   Design System: Modern Dark (Cinema)
   Typography: Inter (Google Fonts)
   ========================================== */

/* Google Fonts — Inter */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================
   Theme Tokens (5 themes)
   ========================================== */

:root, .light {
  --background: 210 40% 98%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --primary: 221.2 83.2% 53.3%;
  --primary-foreground: 210 40% 98%;
  --muted: 210 40% 94%;
  --muted-foreground: 215.4 16.3% 42%;
  --border: 214.3 31.8% 84%;
  --accent: 160 84% 39%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 84% 60%;
  --ring: 221.2 83.2% 53.3%;
  --glow-primary: 221.2 83.2% 53.3%;
  --glow-accent: 160 84% 39%;
  --ambient-blob-1: rgba(99, 102, 241, 0.06);
  --ambient-blob-2: rgba(139, 92, 246, 0.04);
  --ambient-blob-3: rgba(5, 150, 105, 0.04);
}

.dark {
  --background: 222 47% 5%;
  --foreground: 213 31% 91%;
  --card: 222 47% 7%;
  --card-foreground: 213 31% 91%;
  --primary: 217.2 91.2% 59.8%;
  --primary-foreground: 222.2 47.4% 11.2%;
  --muted: 217.2 32.6% 15%;
  --muted-foreground: 215 20.2% 65.1%;
  --border: 217.2 32.6% 22%;
  --accent: 160 84% 39%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 72% 51%;
  --ring: 217.2 91.2% 59.8%;
  --glow-primary: 217.2 91.2% 59.8%;
  --glow-accent: 160 84% 39%;
  --ambient-blob-1: rgba(99, 102, 241, 0.08);
  --ambient-blob-2: rgba(139, 92, 246, 0.06);
  --ambient-blob-3: rgba(5, 150, 105, 0.05);
}

.amoled {
  --background: 0 0% 0%;
  --foreground: 0 0% 98%;
  --card: 0 0% 4%;
  --card-foreground: 0 0% 98%;
  --primary: 217.2 91.2% 59.8%;
  --primary-foreground: 0 0% 0%;
  --muted: 0 0% 12%;
  --muted-foreground: 0 0% 60%;
  --border: 0 0% 20%;
  --accent: 160 84% 39%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 72% 51%;
  --ring: 217.2 91.2% 59.8%;
  --glow-primary: 217.2 91.2% 59.8%;
  --glow-accent: 160 84% 39%;
  --ambient-blob-1: rgba(99, 102, 241, 0.04);
  --ambient-blob-2: rgba(139, 92, 246, 0.03);
  --ambient-blob-3: rgba(5, 150, 105, 0.03);
}

.glass {
  --background: 250 40% 10%;
  --foreground: 250 50% 96%;
  --card: 240 40% 12%;
  --card-foreground: 250 50% 96%;
  --primary: 262 83% 58%;
  --primary-foreground: 0 0% 100%;
  --muted: 250 30% 20%;
  --muted-foreground: 250 15% 70%;
  --border: 250 30% 30%;
  --accent: 262 83% 58%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 72% 51%;
  --ring: 262 83% 58%;
  --glow-primary: 262 83% 58%;
  --glow-accent: 262 60% 50%;
  --ambient-blob-1: rgba(168, 85, 247, 0.1);
  --ambient-blob-2: rgba(129, 140, 248, 0.07);
  --ambient-blob-3: rgba(192, 132, 252, 0.06);
}

.minimal {
  --background: 0 0% 100%;
  --foreground: 0 0% 10%;
  --card: 0 0% 97%;
  --card-foreground: 0 0% 10%;
  --primary: 0 0% 15%;
  --primary-foreground: 0 0% 100%;
  --muted: 0 0% 92%;
  --muted-foreground: 0 0% 40%;
  --border: 0 0% 82%;
  --accent: 0 0% 15%;
  --accent-foreground: 0 0% 100%;
  --destructive: 0 72% 51%;
  --ring: 0 0% 15%;
  --glow-primary: 0 0% 15%;
  --glow-accent: 0 0% 15%;
  --ambient-blob-1: rgba(0, 0, 0, 0.02);
  --ambient-blob-2: rgba(0, 0, 0, 0.015);
  --ambient-blob-3: rgba(0, 0, 0, 0.01);
}

/* ==========================================
   Base Styles
   ========================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Safe area padding for notch devices */
body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Monospace code elements */
code, pre, .font-mono {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

/* ==========================================
   Theme Transition Animation
   ========================================== */
html, body,
header, footer, main, nav, section, aside,
div, span, p, a, h1, h2, h3, h4, h5, h6,
input, textarea, select, button, label,
table, tr, td, th, thead, tbody {
  transition: background-color 0.35s ease,
              color 0.35s ease,
              border-color 0.35s ease,
              box-shadow 0.35s ease;
}

/* ==========================================
   Glass theme background override
   ========================================== */
html.glass body {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #090d16 100%);
  background-attachment: fixed;
}

/* ==========================================
   Ambient Light Blobs (Cinema depth)
   ========================================== */
.ambient-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  will-change: transform;
}

.ambient-blob-1 {
  width: 600px;
  height: 600px;
  top: -200px;
  right: -100px;
  background: var(--ambient-blob-1);
  animation: ambientFloat1 25s ease-in-out infinite;
}

.ambient-blob-2 {
  width: 500px;
  height: 500px;
  bottom: -150px;
  left: -100px;
  background: var(--ambient-blob-2);
  animation: ambientFloat2 30s ease-in-out infinite;
}

.ambient-blob-3 {
  width: 400px;
  height: 400px;
  top: 40%;
  left: 50%;
  background: var(--ambient-blob-3);
  animation: ambientFloat3 20s ease-in-out infinite;
}

@keyframes ambientFloat1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -60px) scale(1.08); }
  66% { transform: translate(-30px, 40px) scale(0.95); }
}

@keyframes ambientFloat2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-40px, 30px) scale(1.05); }
  66% { transform: translate(50px, -40px) scale(0.92); }
}

@keyframes ambientFloat3 {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-50%, -30px) scale(1.1); }
}

/* ==========================================
   Scroll Progress Bar
   ========================================== */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg,
    hsl(var(--primary)),
    hsl(var(--accent, var(--primary))),
    hsl(var(--primary)));
  z-index: 9999;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* ==========================================
   Entrance Animations
   ========================================== */

/* Fade In (basic) */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Stagger Entrance (scroll-triggered) */
@keyframes staggerIn {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.stagger-item {
  opacity: 0;
}

.stagger-item.animate-in {
  animation: staggerIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Slide In from Left */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-24px); }
  to { opacity: 1; transform: translateX(0); }
}

.animate-slide-left {
  animation: slideInLeft 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Slide In from Right */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

.animate-slide-right {
  animation: slideInRight 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Scale In (for modals) */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.animate-scale-in {
  animation: scaleIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Pulse Glow (for badges) */
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 hsl(var(--primary) / 0.4); }
  50% { box-shadow: 0 0 0 8px hsl(var(--primary) / 0); }
}

.animate-pulse-glow {
  animation: pulseGlow 2s ease-in-out infinite;
}

/* Heartbeat (for donate) */
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.15); }
  28% { transform: scale(1); }
  42% { transform: scale(1.1); }
  56% { transform: scale(1); }
}

.animate-heartbeat {
  animation: heartbeat 2s ease-in-out infinite;
}

/* Number Count Up (for metrics) */
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-count-up {
  animation: countUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ==========================================
   Shimmer Skeleton Loading
   ========================================== */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-shimmer,
.animate-pulse {
  background: linear-gradient(
    90deg,
    hsl(var(--muted)) 0%,
    hsl(var(--muted) / 0.5) 40%,
    hsl(var(--muted)) 80%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: 12px;
}

/* ==========================================
   Interactive Elements
   ========================================== */

/* Button Press Effect */
button,
a[role="button"],
.interactive,
.btn {
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.2s ease,
              opacity 0.2s ease,
              background-color 0.2s ease,
              border-color 0.2s ease;
}

button:active:not(:disabled),
a[role="button"]:active,
.interactive:active,
.btn:active {
  transform: scale(0.97);
}

/* Focus Ring (keyboard navigation) */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: 8px;
}

/* Primary CTA Glow */
.btn-primary-glow {
  position: relative;
  overflow: hidden;
}

.btn-primary-glow::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(90deg,
    hsl(var(--primary) / 0.5),
    hsl(var(--accent, var(--primary)) / 0.3),
    hsl(var(--primary) / 0.5));
  border-radius: inherit;
  z-index: -1;
  opacity: 0;
  filter: blur(12px);
  transition: opacity 0.3s ease;
}

.btn-primary-glow:hover::before {
  opacity: 1;
}

/* Card Hover Effect (Glassmorphism accent) */
.card-hover {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.3s ease,
              border-color 0.3s ease;
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px hsl(var(--primary) / 0.08),
              0 4px 16px hsl(var(--primary) / 0.05);
  border-color: hsl(var(--primary) / 0.25);
}

/* Template / Feature Card Hover */
.template-card {
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.template-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px hsl(var(--primary) / 0.12);
  border-color: hsl(var(--primary) / 0.4);
}

/* Icon hover bounce */
.icon-hover:hover {
  animation: iconBounce 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes iconBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ==========================================
   Header / Navbar Enhancements
   ========================================== */

/* Header scroll hide/show */
.header-hidden {
  transform: translateY(-100%);
}

header {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.35s ease,
              border-color 0.35s ease,
              box-shadow 0.35s ease;
}

/* Active nav indicator */
.nav-active-indicator {
  position: relative;
}

.nav-active-indicator::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: hsl(var(--primary));
  border-radius: 2px;
  transition: width 0.3s ease;
}

.nav-active-indicator:hover::after {
  width: 100%;
}

/* ==========================================
   Drag & Drop Zone Highlight
   ========================================== */
.drag-over {
  border: 2px dashed hsl(var(--primary)) !important;
  background-color: hsl(var(--primary) / 0.08) !important;
  transition: all 0.2s ease;
}

/* ==========================================
   Syntax Highlighting
   ========================================== */
.hljs {
  background: hsl(var(--muted)) !important;
  color: hsl(var(--foreground)) !important;
  border-radius: 12px;
  padding: 16px !important;
  font-size: 13px;
  line-height: 1.6;
  font-family: 'JetBrains Mono', monospace;
}

/* ==========================================
   Prose / Content Styling
   ========================================== */
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.prose code:not(pre code) {
  background: hsl(var(--muted));
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', monospace;
}

.prose pre {
  border-radius: 12px;
  border: 1px solid hsl(var(--border));
}

.prose blockquote {
  border-left: 3px solid hsl(var(--primary));
  padding-left: 16px;
  color: hsl(var(--muted-foreground));
  font-style: italic;
}

.prose a {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.2s ease;
}

.prose a:hover {
  color: hsl(var(--primary) / 0.8);
}

/* ==========================================
   Custom Scrollbar
   ========================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: hsl(var(--muted-foreground) / 0.25);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.45);
}

/* ==========================================
   Social Share Button Styles
   ========================================== */
.social-btn {
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              filter 0.2s ease,
              box-shadow 0.2s ease;
}

.social-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

/* ==========================================
   Badge Styles
   ========================================== */
.badge-pulse {
  animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ==========================================
   Input Focus Ring
   ========================================== */
input:focus,
textarea:focus,
select:focus {
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
  border-color: hsl(var(--ring) / 0.5);
}

/* ==========================================
   Comment Avatar Placeholder
   ========================================== */
.avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, hsl(var(--primary) / 0.2), hsl(var(--primary) / 0.1));
  border: 1px solid hsl(var(--primary) / 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: hsl(var(--primary));
  flex-shrink: 0;
}

/* ==========================================
   Metric Card Counter Animation
   ========================================== */
.metric-card {
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.metric-card:hover::before {
  opacity: 1;
}

.metric-card:nth-child(1)::before { background: linear-gradient(135deg, hsl(217 91% 60% / 0.05), transparent); }
.metric-card:nth-child(2)::before { background: linear-gradient(135deg, hsl(160 84% 39% / 0.05), transparent); }
.metric-card:nth-child(3)::before { background: linear-gradient(135deg, hsl(270 70% 60% / 0.05), transparent); }
.metric-card:nth-child(4)::before { background: linear-gradient(135deg, hsl(40 95% 55% / 0.05), transparent); }

/* ==========================================
   Tooltip
   ========================================== */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  padding: 4px 10px;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  font-size: 11px;
  font-weight: 500;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ==========================================
   Responsive / Cross-Device
   ========================================== */

/* Touch Target Optimization */
@media (max-width: 767px), (pointer: coarse) {
  button, a, input[type="submit"], select, .touch-target {
    min-height: 44px;
    touch-action: manipulation;
  }

  /* Prevent text zoom on input focus in iOS Safari */
  input[type="text"],
  input[type="password"],
  input[type="email"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Horizontal scrollable toolbar on small screens */
  .editor-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }
}

/* ==========================================
   Reduced Motion (Accessibility)
   ========================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .ambient-blob,
  .ambient-blob-1,
  .ambient-blob-2,
  .ambient-blob-3 {
    animation: none !important;
  }

  .stagger-item {
    opacity: 1 !important;
  }
}

/* ==========================================
   Print Adaptation
   ========================================== */
@media print {
  /* Hide non-essential UI elements */
  #header-mount,
  footer,
  button,
  .no-print,
  #comment-form,
  .social-btn,
  #password-modal,
  #global-qr-modal,
  .ambient-container,
  .scroll-progress {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt;
    line-height: 1.5;
    padding: 0 !important;
    margin: 0 !important;
  }

  .p-6, .p-8, .rounded-3xl, .rounded-2xl {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
  }

  /* Expand hidden contents for print */
  #note-rendered-body {
    display: block !important;
    color: #000000 !important;
  }

  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 90%;
    color: #555;
  }
}

/* ==========================================
   Line Clamp & Long Text Truncation Helpers
   ========================================== */
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
}
