/* ============================================
   UnAI.se Design System v1.0
   Design Tokens + Theme System + Animations
   ============================================ */

/* ===== CSS VARIABLES ===== */
:root {
  /* Dark Theme (Default) */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #475569;
  
  /* Accent Colors */
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-green: #22c55e;
  --accent-yellow: #eab308;
  --accent-red: #ef4444;
  
  /* Highlights */
  --highlight-red: rgba(239, 68, 68, 0.3);
  --highlight-red-border: #ef4444;
  --highlight-yellow: rgba(234, 179, 8, 0.25);
  --highlight-yellow-border: #eab308;
  
  /* Component Backgrounds */
  --card-bg: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  --input-bg: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  
  /* UI Helpers */
  --scrollbar-track: #1e293b;
  --scrollbar-thumb: #475569;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --overlay-bg: rgba(15, 23, 42, 0.8);
  --celebration-glow: rgba(34, 197, 94, 0.5);
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #cbd5e1;
  --card-bg: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
  --input-bg: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #cbd5e1;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --overlay-bg: rgba(255, 255, 255, 0.8);
  --highlight-red: rgba(239, 68, 68, 0.2);
  --highlight-yellow: rgba(234, 179, 8, 0.15);
  --celebration-glow: rgba(34, 197, 94, 0.3);
}

/* ===== BASE STYLES ===== */
* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  box-sizing: border-box;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* Smooth theme transitions for all elements */
body, body * {
  transition: background-color var(--transition-normal), 
              border-color var(--transition-normal), 
              color var(--transition-normal), 
              box-shadow var(--transition-normal);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== SELECTION ===== */
::selection { background: var(--accent-blue); color: white; }

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 700;
}

p, span, div {
  color: var(--text-secondary);
}

/* ===== CARDS ===== */
.card {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  transition: transform var(--transition-normal), 
              box-shadow var(--transition-normal);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px var(--shadow-color);
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--shadow-color);
}

/* ===== INPUT AREA ===== */
.input-area {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-xl);
  transition: all var(--transition-normal);
}

.input-area:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #2563eb);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(59, 130, 246, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-analyzing {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-blue { background: rgba(59, 130, 246, 0.2); color: var(--accent-blue); }
.badge-red { background: rgba(239, 68, 68, 0.2); color: var(--accent-red); }
.badge-green { background: rgba(34, 197, 94, 0.2); color: var(--accent-green); }
.badge-yellow { background: rgba(234, 179, 8, 0.2); color: var(--accent-yellow); }
.badge-purple { background: rgba(139, 92, 246, 0.2); color: var(--accent-purple); }

/* ===== HIGHLIGHTS ===== */
.highlight-red {
  background: var(--highlight-red);
  border-bottom: 2px solid var(--highlight-red-border);
  padding: 0 2px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.highlight-red:hover {
  background: rgba(239, 68, 68, 0.5);
}

.highlight-yellow {
  background: var(--highlight-yellow);
  border-bottom: 2px solid var(--highlight-yellow-border);
  padding: 0 2px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.highlight-yellow:hover {
  background: rgba(234, 179, 8, 0.4);
}

/* ===== SCORE BAR ===== */
.score-bar {
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1), 
              background 0.3s ease;
}

/* ===== POP ANIMATION ===== */
.pop-anim {
  animation: celebratePulse 0.6s ease;
}

/* ===== PASS POP IN ===== */
.pass-pop-in {
  animation: passPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 30px var(--shadow-color);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9999;
  max-width: 400px;
  display: none;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-left: 4px solid var(--accent-green);
}

.toast.error {
  border-left: 4px solid var(--accent-red);
}

/* ===== REWRITE PANEL ===== */
#rewritePanel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-lg);
  z-index: 9999;
  box-shadow: 0 -8px 40px var(--shadow-color);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 60vh;
  overflow-y: auto;
  visibility: hidden;
}

#rewritePanel.active {
  transform: translateY(0);
  visibility: visible;
}

/* ===== KEYBOARD HINT ===== */
.kbd-hint {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
  z-index: 50;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

/* ===== PULSE DOT ===== */
.pulse-dot {
  animation: pulse 2s ease-in-out infinite;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes celebratePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes passPopIn {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes aiWarningPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

@keyframes confettiFall {
  0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== UTILITIES ===== */
.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

.slide-in {
  animation: slideIn 0.4s ease forwards;
}

.float {
  animation: float 3s ease-in-out infinite;
}

/* ===== HEADER ===== */
header {
  background: var(--bg-primary);
  border-color: var(--border-color);
}

header a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

header a:hover {
  color: var(--accent-blue);
}

header a[href="detector.html"] {
  color: var(--accent-blue);
  font-weight: 600;
}

/* ===== FOOTER ===== */
footer {
  background: var(--bg-primary);
  border-color: var(--border-color);
}

footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

footer a:hover {
  color: var(--accent-blue);
}

/* ===== MEDIA QUERIES ===== */
@media (max-width: 768px) {
  #xpBadge {
    display: none !important;
  }

  .card {
    padding: var(--space-md);
  }
  
  h1 {
    font-size: 1.875rem;
  }
  
  #rewritePanel {
    max-height: 70vh;
  }
}

#method-summary {
  color: var(--text-secondary);
  line-height: 1.75;
}

#method-summary h2 {
  margin-bottom: 1rem;
  color: var(--text-primary);
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  font-weight: 800;
}

#method-summary h3 {
  margin-top: 1.5rem;
  margin-bottom: .4rem;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
}

#method-summary a {
  color: var(--accent-blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}
