/**
 * CM Storytelling Toolkit - Core Styles
 * Version: 3.0.0
 * 
 * Base styles for all storytelling modules
 * Provides consistent foundation for eReader, Zen Mode, etc.
 */

/* ==========================================================================
   CORE VARIABLES & TYPOGRAPHY
   ========================================================================== */

:root {
  /* Core Colors */
  --cm-primary: #007cba;
  --cm-primary-dark: #005a87;
  --cm-secondary: #666;
  --cm-text: #333;
  --cm-text-light: #666;
  --cm-background: #ffffff;
  --cm-background-dark: #f8f9fa;
  --cm-border: #ddd;
  --cm-shadow: rgba(0, 0, 0, 0.1);
  
  /* Typography */
  --cm-font-family: 'Merriweather', Georgia, serif;
  --cm-font-family-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --cm-font-size-base: 18px;
  --cm-line-height-base: 1.6;
  --cm-font-weight-normal: 400;
  --cm-font-weight-bold: 700;
  
  /* Spacing */
  --cm-spacing-xs: 0.5rem;
  --cm-spacing-sm: 1rem;
  --cm-spacing-md: 1.5rem;
  --cm-spacing-lg: 2rem;
  --cm-spacing-xl: 3rem;
  
  /* Layout */
  --cm-max-width: 800px;
  --cm-border-radius: 0px;
  --cm-transition: all 0.3s ease;
  
  /* Z-Index Layers */
  --cm-z-base: 1;
  --cm-z-navigation: 100;
  --cm-z-overlay: 1000;
  --cm-z-modal: 10000;
  --cm-z-tooltip: 100000;
}

/* ==========================================================================
   CORE BUTTON STYLES
   ========================================================================== */

.cm-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--cm-spacing-xs) var(--cm-spacing-md);
  border: none;
  border-radius: var(--cm-border-radius);
  background: var(--cm-primary);
  color: white;
  font-family: var(--cm-font-family-ui);
  font-size: 16px;
  font-weight: var(--cm-font-weight-normal);
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  transition: var(--cm-transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cm-button:hover,
.cm-button:focus {
  background: var(--cm-primary-dark);
  color: white;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--cm-shadow);
}

.cm-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--cm-shadow);
}

.cm-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Button Variants */
.cm-button--secondary {
  background: var(--cm-secondary);
}

.cm-button--secondary:hover,
.cm-button--secondary:focus {
  background: #555;
}

.cm-button--outline {
  background: transparent;
  color: var(--cm-primary);
  border: 2px solid var(--cm-primary);
}

.cm-button--outline:hover,
.cm-button--outline:focus {
  background: var(--cm-primary);
  color: white;
}

.cm-button--small {
  padding: calc(var(--cm-spacing-xs) * 0.5) var(--cm-spacing-sm);
  font-size: 14px;
}

.cm-button--large {
  padding: var(--cm-spacing-sm) var(--cm-spacing-lg);
  font-size: 18px;
}

/* ==========================================================================
   STORYTELLING CONTENT CONTAINERS
   ========================================================================== */

.cm-storytelling-container {
  max-width: var(--cm-max-width);
  margin: 0 auto;
  padding: var(--cm-spacing-md);
}

.cm-storytelling-content {
  font-family: var(--cm-font-family);
  font-size: var(--cm-font-size-base);
  line-height: var(--cm-line-height-base);
  color: var(--cm-text);
  word-wrap: break-word;
  hyphens: auto;
}

.cm-storytelling-content h1,
.cm-storytelling-content h2,
.cm-storytelling-content h3,
.cm-storytelling-content h4,
.cm-storytelling-content h5,
.cm-storytelling-content h6 {
  font-family: var(--cm-font-family-ui);
  font-weight: var(--cm-font-weight-bold);
  line-height: 1.3;
  margin-top: var(--cm-spacing-lg);
  margin-bottom: var(--cm-spacing-md);
}

.cm-storytelling-content h1 { font-size: 2.2em; }
.cm-storytelling-content h2 { font-size: 1.8em; }
.cm-storytelling-content h3 { font-size: 1.5em; }
.cm-storytelling-content h4 { font-size: 1.3em; }
.cm-storytelling-content h5 { font-size: 1.1em; }
.cm-storytelling-content h6 { font-size: 1em; }

.cm-storytelling-content p {
  margin-bottom: var(--cm-spacing-md);
}

.cm-storytelling-content blockquote {
  border-left: 4px solid var(--cm-primary);
  padding-left: var(--cm-spacing-md);
  margin: var(--cm-spacing-lg) 0;
  font-style: italic;
  color: var(--cm-text-light);
}

/* ==========================================================================
   OVERLAY BASE STYLES
   ========================================================================== */

.cm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--cm-background);
  z-index: var(--cm-z-overlay);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cm-overlay.cm-overlay--active {
  opacity: 1;
  visibility: visible;
}

.cm-overlay.cm-overlay--loading {
  cursor: wait;
}

.cm-overlay__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cm-overlay--active .cm-overlay__backdrop {
  opacity: 1;
}

/* ==========================================================================
   NAVIGATION BASE STYLES
   ========================================================================== */

.cm-navigation {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--cm-background);
  border-top: 1px solid var(--cm-border);
  padding: var(--cm-spacing-sm);
  z-index: var(--cm-z-navigation);
  box-shadow: 0 -2px 10px var(--cm-shadow);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.cm-navigation--visible {
  transform: translateY(0);
}

.cm-navigation__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--cm-max-width);
  margin: 0 auto;
  gap: var(--cm-spacing-sm);
}

.cm-navigation__group {
  display: flex;
  align-items: center;
  gap: var(--cm-spacing-xs);
}

.cm-navigation__button {
  min-width: 44px;
  height: 44px;
  padding: var(--cm-spacing-xs);
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-border-radius);
  background: var(--cm-background);
  color: var(--cm-text);
  font-family: var(--cm-font-family-ui);
  font-size: 14px;
  cursor: pointer;
  transition: var(--cm-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.cm-navigation__button:hover,
.cm-navigation__button:focus {
  background: var(--cm-background-dark);
  border-color: var(--cm-primary);
  color: var(--cm-primary);
}

.cm-navigation__button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cm-navigation__info {
  font-family: var(--cm-font-family-ui);
  font-size: 14px;
  color: var(--cm-text-light);
  text-align: center;
  white-space: nowrap;
}

/* ==========================================================================
   LOADING STATES
   ========================================================================== */

.cm-loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--cm-border);
  border-radius: 50%;
  border-top-color: var(--cm-primary);
  animation: cm-spin 1s linear infinite;
}

@keyframes cm-spin {
  to { transform: rotate(360deg); }
}

.cm-loading-text::after {
  content: '';
  animation: cm-dots 1.5s steps(4, end) infinite;
}

@keyframes cm-dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

.cm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cm-hidden {
  display: none !important;
}

.cm-invisible {
  visibility: hidden !important;
}

.cm-no-scroll {
  overflow: hidden !important;
}

.cm-text-center {
  text-align: center;
}

.cm-text-left {
  text-align: left;
}

.cm-text-right {
  text-align: right;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Mobile First Approach */
@media (max-width: 768px) {
  :root {
    --cm-font-size-base: 16px;
    --cm-spacing-md: 1rem;
    --cm-spacing-lg: 1.5rem;
  }
  
  .cm-storytelling-container {
    padding: var(--cm-spacing-sm);
  }
  
  .cm-navigation {
    padding: var(--cm-spacing-xs) var(--cm-spacing-sm);
    /* Support for iOS safe area */
    padding-bottom: calc(var(--cm-spacing-xs) + env(safe-area-inset-bottom));
  }
  
  .cm-navigation__controls {
    gap: var(--cm-spacing-xs);
  }
  
  .cm-button {
    min-height: 44px; /* Touch target size */
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .cm-storytelling-container {
    padding: var(--cm-spacing-lg);
  }
}

/* Desktop */
@media (min-width: 1025px) {
  .cm-navigation {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    transform: none;
    border-top: none;
    border-bottom: 1px solid var(--cm-border);
    box-shadow: 0 2px 10px var(--cm-shadow);
  }
  
  .cm-navigation--visible {
    transform: none;
  }
}

/* Print Styles */
@media print {
  .cm-navigation,
  .cm-button,
  .cm-overlay {
    display: none !important;
  }
  
  .cm-storytelling-content {
    font-size: 12pt;
    line-height: 1.4;
    color: #000;
  }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .cm-navigation {
    box-shadow: 0 -1px 5px var(--cm-shadow);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}/* CSS Document */

