/* =================================================================
   Font Loading - Must be first
   ================================================================= */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

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

/* =================================================================
   CSS Custom Properties - Light Mode (Default)
   ================================================================= */
:root {
  color-scheme: light;

  /* Canvas backgrounds - refined warm cream with subtle depth */
  --canvas: 40 25% 97%;
  --canvas-subtle: 40 20% 94%;
  --canvas-muted: 40 15% 89%;
  --canvas-elevated: 40 25% 99%;
  --canvas-sunken: 40 15% 92%;

  /* Text colors - ink with warmth */
  --ink: 25 15% 12%;
  --ink-muted: 25 10% 42%;
  --ink-subtle: 25 8% 58%;
  --ink-inverted: 40 25% 97%;

  /* Accent - deep warm terracotta with sophistication */
  --accent: 17 55% 42%;
  --accent-hover: 17 60% 37%;
  --accent-active: 17 65% 32%;
  --accent-subtle: 17 45% 94%;
  --accent-soft: 17 35% 96%;
  --accent-muted: 17 30% 88%;

  /* Semantic states */
  --success: 145 45% 38%;
  --success-hover: 145 50% 33%;
  --success-subtle: 145 35% 94%;
  --success-soft: 145 30% 96%;
  --warning: 38 80% 50%;
  --warning-hover: 38 85% 45%;
  --warning-subtle: 38 60% 94%;
  --error: 0 60% 52%;
  --error-hover: 0 65% 47%;
  --error-subtle: 0 50% 96%;
  --error-soft: 0 40% 98%;

  /* Info state */
  --info: 210 60% 50%;
  --info-subtle: 210 50% 94%;

  /* Borders - refined neutrals with depth */
  --border: 30 12% 86%;
  --border-subtle: 35 15% 92%;
  --border-strong: 25 10% 78%;
  --border-focus: 17 55% 42%;

  /* Shadows - refined depth system */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.02);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.04), 0 1px 2px -1px rgb(0 0 0 / 0.04);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.06), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.04);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.12);
  --shadow-glow: 0 0 20px hsl(17 55% 42% / 0.15);

  /* Gradients - refined and sophisticated */
  --gradient-subtle: linear-gradient(
    180deg,
    hsl(40 25% 97%) 0%,
    hsl(40 20% 94%) 100%
  );

  --gradient-hero: radial-gradient(
    80% 50% at 50% -10%,
    hsl(17 45% 88% / 0.35) 0%,
    transparent 55%
  );

  --gradient-card: linear-gradient(
    145deg,
    hsl(40 25% 98%) 0%,
    hsl(40 20% 96%) 100%
  );

  --gradient-ink: linear-gradient(
    145deg,
    hsl(25 15% 15%) 0%,
    hsl(25 15% 10%) 100%
  );

  /* Spacing scale - 8px base */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Animation timing */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
  --duration-slower: 600ms;
}

/* =================================================================
   CSS Custom Properties - Dark Mode
   ================================================================= */
:root.dark {
  color-scheme: dark;

  /* Canvas backgrounds - deep warm charcoal with depth */
  --canvas: 25 10% 9%;
  --canvas-subtle: 25 9% 13%;
  --canvas-muted: 25 8% 19%;
  --canvas-elevated: 25 10% 11%;
  --canvas-sunken: 25 8% 7%;

  /* Text colors - warm off-white */
  --ink: 40 20% 95%;
  --ink-muted: 35 12% 68%;
  --ink-subtle: 30 10% 52%;
  --ink-inverted: 25 10% 9%;

  /* Accent - muted warm coral */
  --accent: 17 55% 58%;
  --accent-hover: 17 60% 63%;
  --accent-active: 17 65% 68%;
  --accent-subtle: 17 25% 18%;
  --accent-soft: 17 20% 14%;
  --accent-muted: 17 30% 25%;

  /* Semantic states */
  --success: 145 40% 55%;
  --success-hover: 145 45% 60%;
  --success-subtle: 145 25% 16%;
  --success-soft: 145 20% 12%;
  --warning: 38 75% 58%;
  --warning-hover: 38 80% 63%;
  --warning-subtle: 38 40% 16%;
  --error: 0 55% 62%;
  --error-hover: 0 60% 67%;
  --error-subtle: 0 25% 18%;
  --error-soft: 0 20% 12%;

  /* Info state */
  --info: 210 55% 60%;
  --info-subtle: 210 30% 18%;

  /* Borders - refined for dark mode */
  --border: 25 10% 22%;
  --border-subtle: 25 9% 16%;
  --border-strong: 25 12% 30%;
  --border-focus: 17 55% 58%;

  /* Shadows - adapted for dark mode */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.6), 0 8px 10px -6px rgb(0 0 0 / 0.3);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.7);
  --shadow-glow: 0 0 30px hsl(17 55% 58% / 0.2);

  /* Gradients - dark mode adaptations */
  --gradient-subtle: linear-gradient(
    180deg,
    hsl(25 10% 9%) 0%,
    hsl(25 9% 11%) 100%
  );

  --gradient-hero: radial-gradient(
    80% 50% at 50% -10%,
    hsl(17 35% 28% / 0.4) 0%,
    transparent 55%
  );

  --gradient-card: linear-gradient(
    145deg,
    hsl(25 10% 11%) 0%,
    hsl(25 9% 13%) 100%
  );

  --gradient-ink: linear-gradient(
    145deg,
    hsl(25 15% 20%) 0%,
    hsl(25 15% 12%) 100%
  );

  /* Spacing scale - inherited from light */

  /* Animation timing - inherited from light */
}

/* =================================================================
   Base Styles
   ================================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: "Newsreader", Georgia, ui-serif, serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  font-feature-settings: "liga" 1, "calt" 1;
}

html,
body {
  min-height: 100vh;
}

body {
  background: var(--gradient-subtle);
  color: hsl(var(--ink));
  transition: background-color 0.3s ease, color 0.3s ease;
  font-size: 16px;
  line-height: 1.6;
}

/* Smooth theme transitions for all elements */
*,
*::before,
*::after {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-duration: 0.2s;
  transition-timing-function: ease;
}

/* Override for transform/opacity animations */
[class*="animate-"] {
  transition-property: transform, opacity;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Typography refinements */
h1, h2, h3, h4, h5, h6 {
  font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h1 { font-size: clamp(2rem, 4vw + 0.5rem, 3rem); }
h2 { font-size: clamp(1.5rem, 3vw + 0.5rem, 2.25rem); }
h3 { font-size: clamp(1.25rem, 2vw + 0.5rem, 1.75rem); }
h4 { font-size: clamp(1.1rem, 1.5vw + 0.5rem, 1.4rem); }

p {
  line-height: 1.7;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid hsl(var(--accent));
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: hsl(var(--accent) / 0.22);
  color: hsl(var(--ink));
}

/* =================================================================
   Scrollbar
   ================================================================= */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: hsl(var(--ink-muted) / 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--ink-muted) / 0.5);
}

/* =================================================================
   Component Utilities
   ================================================================= */
@layer components {
  .surface-card {
    background: var(--gradient-card);
    backdrop-filter: blur(16px);
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
  }

  .surface-elevated {
    background: hsl(var(--canvas));
    border: 1px solid hsl(var(--border));
    box-shadow:
      0 1px 3px 0 rgb(0 0 0 / 0.04),
      0 12px 48px -12px rgb(0 0 0 / 0.1);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
  }

  .surface-elevated:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-2px);
  }

  .surface-glass {
    background: hsl(var(--canvas) / 0.8);
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid hsl(var(--border) / 0.5);
  }

  .text-gradient {
    background: linear-gradient(
      135deg,
      hsl(var(--ink)) 0%,
      hsl(var(--accent)) 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: hsl(var(--ink));
    color: hsl(var(--canvas));
    border: 1.5px solid hsl(var(--ink));
    border-radius: 0.75rem;
    padding: 0.875rem 1.75rem;
    font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
  }

  .btn-primary:hover {
    background: hsl(var(--accent-hover));
    border-color: hsl(var(--accent-hover));
    transform: translateY(-1px);
  }

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

  .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: transparent;
    color: hsl(var(--ink));
    border: 1.5px solid hsl(var(--border-strong));
    border-radius: 0.75rem;
    padding: 0.875rem 1.75rem;
    font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
  }

  .btn-secondary:hover {
    background: hsl(var(--canvas-subtle));
    border-color: hsl(var(--border));
  }

  .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: transparent;
    color: hsl(var(--ink-muted));
    border: none;
    border-radius: 0.75rem;
    padding: 0.75rem 1.25rem;
    font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
    font-weight: 500;
    font-size: 0.9375rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
  }

  .btn-ghost:hover {
    color: hsl(var(--ink));
    background: hsl(var(--canvas-subtle));
  }

  .input-field {
    width: 100%;
    background: hsl(var(--canvas));
    border: 1.5px solid hsl(var(--border));
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    color: hsl(var(--ink));
    transition: all 0.2s ease;
  }

  .input-field:hover {
    border-color: hsl(var(--border-strong));
  }

  .input-field:focus {
    outline: none;
    border-color: hsl(var(--accent));
    box-shadow: 0 0 0 3px hsl(var(--accent) / 0.1);
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.875rem;
    font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    border-radius: 9999px;
    background: hsl(var(--accent-subtle));
    color: hsl(var(--accent));
  }

  .rounded-card {
    border-radius: 1rem;
  }

  .rounded-panel {
    border-radius: 1.25rem;
  }

  /* Dashboard typography override - sans-serif for data density */
  .font-dashboard {
    font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
    font-feature-settings: "ss01" 1, "ss02" 1;
    letter-spacing: -0.01em;
  }

  .section-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
  }

  @media (min-width: 640px) {
    .section-container {
      padding: 0 2rem;
    }
  }

  @media (min-width: 1024px) {
    .section-container {
      padding: 0 3rem;
    }
  }

  /* Character float animation */
  @keyframes float {
    0%, 100% {
      transform: translateY(0) rotate(0deg);
    }
    25% {
      transform: translateY(-6px) rotate(1deg);
    }
    50% {
      transform: translateY(-3px) rotate(0deg);
    }
    75% {
      transform: translateY(-8px) rotate(-1deg);
    }
  }

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

  /* Gentle pulse for attention */
  @keyframes gentle-pulse {
    0%, 100% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.03);
    }
  }

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

  /* Character hover lift effect */
  .character-hover {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .character-hover:hover {
    transform: translateY(-8px) scale(1.05);
  }

  .bookra-location-map .leaflet-container,
  .bookra-location-map .leaflet-pane,
  .bookra-location-map .leaflet-top,
  .bookra-location-map .leaflet-bottom {
    font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  }

  .bookra-location-map .leaflet-control-attribution {
    background: hsl(var(--canvas) / 0.82);
    color: hsl(var(--ink-muted));
    font-size: 0.625rem;
    backdrop-filter: blur(10px);
  }

  .bookra-location-map .leaflet-control-zoom {
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }

  .bookra-location-map .leaflet-control-zoom a {
    background: hsl(var(--canvas));
    color: hsl(var(--ink));
    border-color: hsl(var(--border));
  }

  .bookra-location-map .leaflet-popup-content-wrapper {
    border-radius: 0.75rem;
    background: hsl(var(--canvas));
    color: hsl(var(--ink));
    border: 1px solid hsl(var(--border));
    box-shadow: var(--shadow-lg);
  }

  .bookra-location-map .leaflet-popup-tip {
    background: hsl(var(--canvas));
  }

  .bookra-map-tiles-warm {
    filter: saturate(0.78) sepia(0.08) contrast(0.96) brightness(1.02);
  }

  .bookra-map-marker span {
    position: relative;
    display: block;
    width: 2rem;
    height: 2rem;
    border: 3px solid hsl(var(--canvas));
    border-radius: 9999px;
    background: var(--bookra-marker-color, hsl(var(--accent)));
    box-shadow: 0 12px 26px rgb(0 0 0 / 0.22);
  }

  .bookra-map-marker span::after {
    content: "";
    position: absolute;
    inset: 0.45rem;
    border-radius: inherit;
    background: hsl(var(--canvas) / 0.9);
  }

  /* Animated list keyframes */
  @keyframes list-scale-in {
    from { opacity: 0; transform: translateY(-16px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  @keyframes list-slide-in {
    from { opacity: 0; transform: translateY(-24px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  @keyframes list-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
  @keyframes list-bounce-in {
    0%   { opacity: 0; transform: translateY(-16px) scale(0.85); }
    60%  { opacity: 1; transform: translateY(4px) scale(1.02); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
  }

  .animate-list-scale {
    animation: list-scale-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .animate-list-slide {
    animation: list-slide-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .animate-list-fade {
    animation: list-fade-in 0.35s ease-out both;
  }
  .animate-list-bounce {
    animation: list-bounce-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }
}
