/* ==========================================================================
   Design Tokens & Modern CSS Reset
   ========================================================================== */
:root {
  --bg-main: #07090e;
  --bg-card: rgba(15, 20, 32, 0.75);
  --bg-card-hover: rgba(22, 29, 46, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.14);
  --border-glow: rgba(99, 102, 241, 0.4);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-purple: #a855f7;
  --accent-rose: #f43f5e;
  --accent-emerald: #10b981;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 12px 32px -4px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 40px -10px rgba(99, 102, 241, 0.35);

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Ambient Background Lighting
   ========================================================================== */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
  animation: floatAmbient 18s ease-in-out infinite alternate;
}

.glow-1 {
  top: -15%;
  left: 20%;
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.25) 0%, transparent 70%);
}

.glow-2 {
  bottom: 10%;
  right: 15%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.2) 0%, transparent 70%);
  animation-delay: -6s;
}

.glow-3 {
  top: 40%;
  left: -10%;
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.18) 0%, transparent 70%);
  animation-delay: -12s;
}

@keyframes floatAmbient {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, 40px) scale(1.08); }
  100% { transform: translate(-20px, -30px) scale(0.95); }
}

/* ==========================================================================
   Layout Shell
   ========================================================================== */
.app-layout {
  position: relative;
  z-index: 1;
  max-width: 900px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* ==========================================================================
   Header & Navbar
   ========================================================================== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(15, 20, 32, 0.5);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-full);
  margin-bottom: 2.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(6, 182, 212, 0.2));
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.edge-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  display: inline-block;
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ==========================================================================
   Reusable Buttons & Controls
   ========================================================================== */
.icon-btn, .card-icon-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-normal);
  text-decoration: none;
}

.icon-btn:hover, .card-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: var(--border-highlight);
  transform: translateY(-1px);
}

.card-icon-btn {
  width: 34px;
  height: 34px;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 0.45rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition-normal);
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: var(--border-highlight);
}

.badge {
  background: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  font-weight: 700;
}

/* ==========================================================================
   Category Bar
   ========================================================================== */
.category-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2.25rem;
}

.cat-pill {
  background: rgba(15, 20, 32, 0.6);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 0.55rem 1.15rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.cat-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--border-highlight);
  transform: translateY(-1px);
}

.cat-pill.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(168, 85, 247, 0.22));
  color: #ffffff;
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 20px -3px rgba(99, 102, 241, 0.35);
}

/* ==========================================================================
   Hero Joke Card (Glassmorphism & Depth)
   ========================================================================== */
.joke-stage {
  position: relative;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.joke-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-top: 1px solid var(--border-highlight);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2.5rem;
  box-shadow: var(--shadow-md), var(--shadow-glow);
  display: flex;
  flex-direction: column;
  min-height: 380px;
  justify-content: space-between;
  transition: border-color var(--transition-normal);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.category-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
}

.tag-hash {
  color: var(--accent-primary);
  margin-right: 2px;
}

.source-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

.meta-actions {
  display: flex;
  gap: 0.4rem;
}

/* ==========================================================================
   Card Content & Typography
   ========================================================================== */
.card-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 0;
  position: relative;
}

.joke-content {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.joke-setup {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  opacity: 1;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.punchline-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.punchline-divider {
  width: 40px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.6), transparent);
}

.joke-delivery {
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.5;
  color: #cbd5e1;
  background: linear-gradient(135deg, #e2e8f0 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Fade transitions */
.fade-out {
  opacity: 0 !important;
  transform: translateY(8px);
}

.fade-in {
  opacity: 1 !important;
  transform: translateY(0);
}

/* Loading Pulse */
.loader-container {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  height: 80px;
}

.pulse-bar {
  width: 6px;
  height: 36px;
  border-radius: 3px;
  background: var(--accent-primary);
  animation: pulseHeight 1s ease-in-out infinite alternate;
}

.bar-1 { animation-delay: 0s; }
.bar-2 { animation-delay: 0.2s; background: var(--accent-cyan); }
.bar-3 { animation-delay: 0.4s; background: var(--accent-purple); }

@keyframes pulseHeight {
  from { height: 16px; opacity: 0.3; }
  to { height: 44px; opacity: 1; }
}

/* ==========================================================================
   Card Footer & Actions
   ========================================================================== */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn-group-primary, .btn-group-secondary {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 1.35rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  transition: var(--transition-fast);
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.45);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  box-shadow: 0 6px 22px rgba(99, 102, 241, 0.6);
  transform: translateY(-1px);
}

.key-hint {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  color: #e0e7ff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-ai {
  background: rgba(168, 85, 247, 0.12);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: #d8b4fe;
}

.btn-ai:hover {
  background: rgba(168, 85, 247, 0.22);
  border-color: rgba(168, 85, 247, 0.5);
  color: #ffffff;
  transform: translateY(-1px);
}

.btn-favorite {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-favorite:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-primary);
  border-color: var(--border-highlight);
}

.btn-favorite.active {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.4);
  color: var(--accent-rose);
}

.btn-favorite.active svg {
  fill: var(--accent-rose);
  stroke: var(--accent-rose);
}

/* ==========================================================================
   Footer Shortcuts Hint
   ========================================================================== */
.footer-bar {
  text-align: center;
  margin-top: 2rem;
}

.kbd-shortcuts {
  display: inline-flex;
  gap: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.kbd-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-secondary);
  padding: 0.1rem 0.38rem;
  border-radius: 4px;
}

/* ==========================================================================
   Favorites Slide-Over Drawer
   ========================================================================== */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  transition: visibility var(--transition-normal);
}

.drawer.hidden {
  visibility: hidden;
  pointer-events: none;
}

.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 1;
  transition: opacity var(--transition-normal);
}

.drawer.hidden .drawer-overlay {
  opacity: 0;
}

.drawer-content {
  position: relative;
  width: 100%;
  max-width: 440px;
  height: 100%;
  background: #0d121f;
  border-left: 1px solid var(--border-subtle);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
  transform: translateX(0);
  transition: transform var(--transition-spring);
}

.drawer.hidden .drawer-content {
  transform: translateX(100%);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.drawer-icon {
  color: var(--accent-primary);
}

.drawer-title-group h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.count-pill {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
}

.drawer-actions-bar {
  display: flex;
  gap: 0.65rem;
}

.search-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition-fast);
}

.search-input:focus {
  border-color: var(--accent-primary);
  background: rgba(255, 255, 255, 0.08);
}

.btn-outline-danger {
  background: transparent;
  border: 1px solid rgba(244, 63, 94, 0.25);
  color: #fb7185;
  font-size: 0.8rem;
  padding: 0.45rem 0.85rem;
}

.btn-outline-danger:hover {
  background: rgba(244, 63, 94, 0.15);
  border-color: rgba(244, 63, 94, 0.5);
  color: #ffffff;
}

.favorites-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.25rem;
}

.fav-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: var(--transition-fast);
}

.fav-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

.fav-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.fav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fav-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.fav-actions {
  display: flex;
  gap: 0.35rem;
}

.fav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.fav-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.fav-btn.delete:hover {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.15);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-state svg {
  opacity: 0.35;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border-highlight);
  color: var(--text-primary);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0.75rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast-out {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-8px) scale(0.95); }
}

/* Utility */
.hidden { display: none !important; }

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 640px) {
  .app-layout {
    padding: 1rem 1rem 2rem;
  }

  .joke-card {
    padding: 1.75rem 1.25rem;
    min-height: 350px;
  }

  .joke-setup {
    font-size: 1.2rem;
  }

  .joke-delivery {
    font-size: 1.05rem;
  }

  .card-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-group-primary, .btn-group-secondary {
    width: 100%;
    justify-content: stretch;
  }

  .btn-primary, .btn-ai, .btn-favorite {
    flex: 1;
    justify-content: center;
  }

  .key-hint {
    display: none;
  }

  .drawer-content {
    max-width: 100%;
  }

  .kbd-shortcuts {
    display: none;
  }
}
