/* ==========================================================================
   NithanYai.com (นิทานยาย) - Design System & Modern Theme Variables
   Warm, Magical, Friendly, Premium & Accessible Design Tokens
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Anuphan:wght@300;400;500;600;700&family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&family=Kanit:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Noto+Sans+Thai:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* Core Color Palette - Warm Magical Library Concept */
  --bg-primary: #FFFDF7;
  --bg-secondary: #F7F1E5;
  --bg-tertiary: #EFE6D5;
  --bg-card: #FFFFFF;
  --bg-glass: rgba(255, 253, 247, 0.85);

  --text-primary: #2C221E;
  --text-secondary: #5D524A;
  --text-muted: #8C7E74;
  --text-light: #FBF8F3;

  /* Accent Colors */
  --accent-orange: #E86A33;
  --accent-orange-hover: #D45822;
  --accent-orange-light: #FFF0E8;

  --accent-amber: #F2994A;
  --accent-amber-light: #FFF8EE;

  --accent-purple: #6B4E71;
  --accent-purple-light: #F4EFF6;

  --accent-green: #3A7D44;
  --accent-green-light: #EBF5ED;

  --accent-blue: #3F72AF;
  --accent-blue-light: #EBF2FA;

  /* Border & Shadows */
  --border-color: #E6DCCE;
  --border-focus: #E86A33;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgba(44, 34, 30, 0.04);
  --shadow-md: 0 8px 24px rgba(44, 34, 30, 0.08);
  --shadow-lg: 0 16px 36px rgba(44, 34, 30, 0.12);
  --shadow-glow: 0 0 20px rgba(232, 106, 51, 0.25);

  /* Typography Families */
  --font-heading: 'Kanit', 'IBM Plex Sans Thai', sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Noto Sans Thai', sans-serif;
  --font-serif: 'Sarabun', Georgia, serif;
  --font-reader: 'IBM Plex Sans Thai', sans-serif;

  /* Spacing */
  --header-height: 96px;
  --container-max: 1280px;

  /* Transitions */
  --transition-fast: 0.18s ease;
  --transition-normal: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dark Mode Theme Overrides */
[data-theme="dark"] {
  --bg-primary: #18151E;
  --bg-secondary: #221D2A;
  --bg-tertiary: #2C2638;
  --bg-card: #231E2D;
  --bg-glass: rgba(24, 21, 30, 0.88);

  --text-primary: #F3EFEA;
  --text-secondary: #C8BFB5;
  --text-muted: #8E8394;
  --text-light: #FFFFFF;

  --accent-orange: #FF7B47;
  --accent-orange-hover: #E86A33;
  --accent-orange-light: rgba(255, 123, 71, 0.15);

  --accent-purple: #9D72A6;
  --accent-purple-light: rgba(157, 114, 166, 0.15);

  --accent-green: #52B788;
  --accent-green-light: rgba(82, 183, 136, 0.15);

  --border-color: #383044;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(255, 123, 71, 0.3);
}

/* Sepia Mode Theme (for Reader) */
[data-theme="sepia"] {
  --bg-primary: #F4ECD8;
  --bg-secondary: #E8DFC8;
  --bg-card: #FAF4E6;
  --text-primary: #423228;
  --text-secondary: #6B5546;
  --border-color: #DCD0B9;
}

/* Universal Reset & Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  /* Prevent a single wide child from making the whole page draggable sideways. */
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  min-height: 100vh;
}

/* Keep media and form controls inside their containing column on narrow screens. */
img, picture, video, canvas, svg {
  max-width: 100%;
}

img, picture, video, canvas {
  height: auto;
}

input, select, textarea, button {
  max-width: 100%;
}

/* Accessibility: Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 1rem;
  background: var(--accent-orange);
  color: white;
  padding: 0.5rem 1rem;
  z-index: 9999;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 1rem;
}

/* Typography Hierarchy */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

a {
  color: var(--accent-orange);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Layout Utilities */
.container {
  width: 100%;
  min-width: 0;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Grid/flex items otherwise default to min-width:auto and can overflow on mobile. */
.container > *, main, section, article, aside, form {
  min-width: 0;
}

@media (max-width: 640px) {
  .container {
    padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
  }
}

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

/* Global Magic Animations */
@keyframes floatParticle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-12px) rotate(4deg); }
}

@keyframes pulseGlow {
  0%, 100% { opacity: 0.6; filter: drop-shadow(0 0 5px rgba(232, 106, 51, 0.4)); }
  50% { opacity: 1; filter: drop-shadow(0 0 15px rgba(232, 106, 51, 0.8)); }
}

@keyframes spinWheel {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(1440deg); }
}

.animated-float {
  animation: floatParticle 6s ease-in-out infinite;
}

.animated-glow {
  animation: pulseGlow 3s ease-in-out infinite;
}

/* Reduce 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;
  }
}
