@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    /* ── Core palette: warm white × near-black × orange ── */
    --background: 40 20% 98%;          /* #FAFAF8 */
    --foreground: 20 14% 5%;           /* #0F0D0B */
    --card: 0 0% 100%;                 /* #FFFFFF */
    --card-foreground: 20 14% 5%;
    --popover: 0 0% 100%;
    --popover-foreground: 20 14% 5%;
    --primary: 22 95% 48%;             /* #EA5504 — Claude orange */
    --primary-foreground: 0 0% 100%;
    --secondary: 30 8% 93%;            /* #EDE9E4 */
    --secondary-foreground: 20 14% 5%;
    --muted: 30 10% 96%;               /* #F5F3F0 */
    --muted-foreground: 25 6% 47%;     /* #7A746E */
    --accent: 24 100% 96%;             /* #FFF4EB — very light orange wash */
    --accent-foreground: 22 95% 32%;   /* dark orange text */
    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 100%;
    --border: 30 8% 88%;               /* #E4E0DB */
    --input: 30 8% 88%;
    --ring: 22 95% 48%;

    --radius: 0.5rem;

    --sidebar-width: 256px;
    --sidebar-collapsed-width: 64px;
    --header-height: 56px;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  html {
    @apply scroll-smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  body {
    @apply bg-background text-foreground;
    font-feature-settings: "rlig" 1, "calt" 1;
  }

  h1, h2, h3, h4, h5, h6 {
    @apply font-semibold tracking-tight;
  }

  ::-webkit-scrollbar {
    @apply w-1.5 h-1.5;
  }

  ::-webkit-scrollbar-track {
    @apply bg-transparent;
  }

  ::-webkit-scrollbar-thumb {
    @apply rounded-full bg-stone-300;
  }

  ::-webkit-scrollbar-thumb:hover {
    @apply bg-stone-400;
  }

  :focus-visible {
    @apply outline-none ring-2 ring-ring ring-offset-2 ring-offset-background;
  }

  ::selection {
    background: hsl(22 95% 48% / 0.15);
    color: hsl(var(--foreground));
  }
}

@layer components {
  /* ── Cards ── */
  .card-base {
    @apply bg-white border border-border rounded-xl shadow-sm;
  }

  .card-elevated {
    @apply bg-white border border-border rounded-xl;
    box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  }

  /* ── Glass (used in onboarding / overlays) ── */
  .glass-card {
    @apply bg-white/90 backdrop-blur-xl border border-border;
    box-shadow: 0 4px 24px -4px rgba(0,0,0,.08), 0 0 0 1px rgba(255,255,255,.6);
  }

  /* ── Gradient text ── */
  .gradient-text {
    @apply bg-clip-text text-transparent;
    background-image: linear-gradient(135deg, #EA5504 0%, #C23F00 100%);
  }

  .gradient-text-warm {
    @apply bg-clip-text text-transparent;
    background-image: linear-gradient(135deg, #F97316 0%, #EA5504 60%, #C23F00 100%);
  }

  /* ── Orange glow ── */
  .glow-orange {
    box-shadow: 0 0 20px rgba(234, 85, 4, 0.25), 0 0 60px rgba(234, 85, 4, 0.08);
  }

  /* ── Progress bar ── */
  .progress-bar {
    @apply h-1.5 rounded-full bg-stone-100 overflow-hidden;
  }

  .progress-fill {
    @apply h-full rounded-full transition-all duration-500;
    background: linear-gradient(90deg, #EA5504 0%, #F97316 100%);
  }

  /* ── Orange gradient border ── */
  .gradient-border {
    position: relative;
    background: white;
    border-radius: calc(var(--radius) + 2px);
  }

  .gradient-border::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: linear-gradient(135deg, #EA5504, #F97316, #FBBF24);
    z-index: -1;
  }

  /* ── Skeleton shimmer ── */
  .skeleton {
    @apply relative overflow-hidden bg-stone-100;
  }

  .skeleton::after {
    content: '';
    @apply absolute inset-0;
    background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,0.7) 50%, transparent 75%);
    background-size: 200% 100%;
    animation: shimmer 1.8s infinite linear;
  }

  /* ── XP bar ── */
  .xp-bar {
    @apply relative h-1.5 rounded-full overflow-hidden bg-stone-200;
  }

  .xp-fill {
    @apply absolute inset-y-0 left-0 rounded-full;
    background: linear-gradient(90deg, #EA5504, #F97316);
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  /* ── Achievement badge ── */
  .badge-achievement {
    @apply inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border;
  }

  /* ── Interactive hover ── */
  .hover-lift {
    @apply transition-all duration-200 hover:-translate-y-0.5;
    &:hover {
      box-shadow: 0 4px 16px rgba(0,0,0,.08);
    }
  }

  /* ── Question type chip ── */
  .question-type-chip {
    @apply inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md text-xs font-medium bg-orange-50 text-orange-700 border border-orange-200;
  }

  /* ── Sidebar dark vars ── */
  .sidebar-dark {
    background-color: #111110;
    color: #E7E5E4;
  }

  /* ── Dot grid overlays ── */
  .bg-dot-grid {
    background-image: radial-gradient(circle at 1px 1px, white 1px, transparent 0);
    background-size: 32px 32px;
  }

  .bg-dot-grid-light {
    background-image: radial-gradient(circle at 1px 1px, rgb(0 0 0 / 0.07) 1px, transparent 0);
    background-size: 32px 32px;
  }

  /* ── Mesh bg (light, subtle) ── */
  .bg-mesh {
    background-color: hsl(var(--background));
    background-image:
      radial-gradient(at 40% 20%, rgba(234, 85, 4, 0.04) 0px, transparent 50%),
      radial-gradient(at 80% 0%, rgba(251, 146, 60, 0.03) 0px, transparent 50%),
      radial-gradient(at 0% 80%, rgba(234, 85, 4, 0.03) 0px, transparent 50%);
  }
}

@layer utilities {

  .no-scrollbar::-webkit-scrollbar { display: none; }
  .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

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

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

/* ── Keyframes ── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes question-enter {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes question-exit {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(-16px); }
}

.question-enter { animation: question-enter 0.25s ease-out forwards; }
.question-exit  { animation: question-exit  0.2s  ease-in  forwards; }

@keyframes pulse-success {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.3); }
  50%       { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

.pulse-success { animation: pulse-success 1.5s ease-in-out 3; }

/* ── Monaco editor ── */
.monaco-editor .margin { background-color: transparent !important; }

/* ── Recharts ── */
.recharts-tooltip-wrapper { @apply !outline-none; }
.recharts-default-tooltip {
  @apply !bg-white !border-border !rounded-xl !shadow-lg;
  box-shadow: 0 4px 16px rgba(0,0,0,.08) !important;
}

/* ── Toaster overrides ── */
[data-sonner-toast] {
  --normal-bg: #ffffff !important;
  --normal-border: hsl(var(--border)) !important;
  --normal-text: hsl(var(--foreground)) !important;
}
