/* ==========================================================================
   NP E-Book — Core Design System & Global Styles
   โรงเรียนหนองไผ่ (nongphai.ac.th)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Prompt:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* School Primary Brand */
  --np-green-dark: #1b5e20;
  --np-green-primary: #2e7d32;
  --np-green-light: #4caf50;
  --np-gold: #e6a100;
  --np-gold-light: #ffc107;
  --np-pink: #ec4899;
  --np-pink-dark: #db2777;
  --np-blue: #0284c7;
  --np-blue-dark: #0369a1;
  
  /* Modern Warm Paper UI Palette */
  --bg-dark-app: #f7f5ef;
  --bg-surface-1: #ffffff;
  --bg-surface-2: #f1ede4;
  --bg-surface-3: #e8e3d8;
  --bg-glass: rgba(255, 255, 255, 0.94);
  --border-glass: rgba(0, 0, 0, 0.09);
  --border-glass-active: rgba(236, 72, 153, 0.4);
  
  /* Text */
  --text-primary: #0f2744;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-gold: #b45309;
  
  /* Accents */
  --accent-cyan: #0284c7;
  --accent-purple: #8b5cf6;
  --accent-red: #ef4444;
  
  /* Typography */
  --font-display: 'Prompt', 'Outfit', sans-serif;
  --font-body: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, monospace;
  
  /* Dimensions & Transitions */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 30px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 39, 68, 0.1);
  --shadow-lg: 0 16px 40px rgba(15, 39, 68, 0.16);
  --shadow-glow-gold: 0 0 25px rgba(230, 161, 0, 0.25);
  --shadow-glow-pink: 0 0 25px rgba(236, 72, 153, 0.3);
  
  --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Optional Dark Theme Variables */
[data-theme="dark"] {
  --bg-dark-app: #0c1017;
  --bg-surface-1: #131924;
  --bg-surface-2: #1a2232;
  --bg-surface-3: #222d42;
  --bg-glass: rgba(19, 25, 36, 0.85);
  --border-glass: rgba(255, 255, 255, 0.1);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
}

/* Global Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-dark-app);
  background-image: radial-gradient(#e4ded3 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  font-family: var(--font-display);
  cursor: pointer;
  border: none;
  background: none;
  transition: var(--transition-fast);
}

/* App Header & Navigation */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  transition: var(--transition-normal);
}

.header-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-logo-img {
  height: 52px;
  width: auto;
  object-fit: contain;
  display: block;
  transition: transform var(--transition-fast, 0.2s ease);
}

.brand-logo-img:hover {
  transform: scale(1.03);
}

@media (max-width: 640px) {
  .brand-logo-img {
    height: 42px;
  }
}

.school-emblem {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--np-green-primary), var(--np-gold));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 14px rgba(46, 125, 50, 0.25);
  position: relative;
  overflow: hidden;
}

.school-emblem::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.25), transparent);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #0f2744;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-text h1 span.np-badge {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(230, 161, 0, 0.15);
  color: #b45309;
  border: 1px solid rgba(230, 161, 0, 0.35);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand-text p {
  font-size: 0.82rem;
  color: #1e3a8a;
  font-weight: 500;
}

/* Header Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border-glass);
  background: var(--bg-surface-1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.btn-nav:hover {
  color: var(--text-primary);
  background: var(--bg-surface-2);
  border-color: rgba(0, 0, 0, 0.15);
}

/* ปุ่ม "ชั้นหนังสือทั้งหมด" เปลี่ยนเป็นสีชมพู */
.btn-nav.active {
  color: #ffffff;
  background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
  border-color: #f472b6;
  box-shadow: 0 4px 14px rgba(236, 72, 153, 0.4);
}

.btn-nav.active:hover {
  background: linear-gradient(135deg, #f472b6 0%, #ec4899 100%);
  color: #ffffff;
  transform: translateY(-1px);
}

/* ปุ่ม "Admin" เปลี่ยนเป็นสีฟ้า */
.btn-admin {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.15rem;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.btn-admin:hover {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.45);
}

/* Main Hero & Search Banner */
.portal-hero {
  position: relative;
  padding: 3rem 1.5rem 2.2rem;
  max-width: 1360px;
  margin: 0 auto;
}

.hero-content {
  text-align: center;
  max-width: 780px;
  margin: 0 auto;
}

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(46, 125, 50, 0.15);
  border: 1px solid rgba(76, 175, 80, 0.35);
  color: #81c784;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.9rem);
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 0.85rem;
  background: linear-gradient(135deg, #ffffff 40%, #c8e6c9 80%, #ffd54f 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.6;
}

/* Search Bar Container */
.search-box-wrapper {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

.search-box {
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  padding: 0.45rem 0.6rem 0.45rem 1.4rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  transition: var(--transition-normal);
}

.search-box:focus-within {
  border-color: #ec4899;
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.2);
  background: #ffffff;
}

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #0f2744;
  font-family: var(--font-body);
  font-size: 1rem;
}

.search-box input::placeholder {
  color: #94a3b8;
}

/* ปุ่มค้นหา เปลี่ยนจากสีเขียว เป็นสีชมพู */
.search-btn {
  background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
  color: #ffffff;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(236, 72, 153, 0.35);
  transition: var(--transition-fast);
}

.search-btn:hover {
  background: linear-gradient(135deg, #f472b6 0%, #ec4899 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(236, 72, 153, 0.45);
}

/* Theme Switcher Bar */
.theme-selector-bar {
  max-width: 1360px;
  margin: 1.5rem auto 2.5rem;
  padding: 0 1.5rem;
}

.theme-pill-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--bg-surface-1);
  padding: 0.75rem 1.2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
}

.theme-pill-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.theme-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-glass);
}

.theme-pill:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.theme-pill.active {
  background: var(--bg-surface-3);
  color: var(--np-gold-light);
  border-color: var(--np-gold);
  box-shadow: 0 0 16px rgba(230, 161, 0, 0.25);
}

/* Category Filter Tabs */
.category-filter-area {
  max-width: 1360px;
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-filter-area::-webkit-scrollbar {
  display: none;
}

.cat-btn {
  white-space: nowrap;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-glass);
}

.cat-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-3);
}

.cat-btn.active {
  background: var(--text-primary);
  color: var(--bg-dark-app);
  font-weight: 700;
  border-color: var(--text-primary);
}

/* Portal Main Container */
.portal-main-wrapper {
  max-width: 1360px;
  margin: 0 auto 4rem;
  padding: 0 1.5rem;
}

/* Bookcard 3D Structure */
.book-card-item {
  position: relative;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  perspective: 1000px;
  transition: transform var(--transition-normal);
}

.book-card-item:hover {
  transform: translateY(-10px);
}

.book-cover-3d {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.414; /* A4 aspect */
  border-radius: 0 10px 10px 0; /* มุมซ้ายบน-ล่างเป็นฉากสันปก มุมขวามน */
  box-shadow: 
    2px 0 0 #f8fafc,
    4px 0 0 #e2e8f0,
    6px 0 0 #cbd5e1,
    12px 16px 30px rgba(0, 0, 0, 0.7),
    -4px 4px 14px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem 0.9rem;
  transition: all var(--transition-normal);
}

.book-card-item:hover .book-cover-3d {
  transform: translateY(-4px);
  box-shadow: 
    3px 0 0 #f8fafc,
    5px 0 0 #e2e8f0,
    8px 0 0 #cbd5e1,
    16px 22px 40px rgba(0, 0, 0, 0.85),
    -6px 6px 18px rgba(0, 0, 0, 0.65);
}

/* Spine effect: สันหนังสือด้านซ้าย */
.book-cover-3d::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(0,0,0,0.6) 0%, rgba(255,255,255,0.22) 25%, rgba(0,0,0,0.25) 60%, transparent 100%);
  border-right: 1px solid rgba(0,0,0,0.18);
  box-shadow: inset -1px 0 2px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 5;
}

.book-badge-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 0.2rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 2;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.badge-featured {
  background: #ff9800;
  color: #fff;
}

.badge-popular {
  background: #e91e63;
  color: #fff;
}

.book-cover-header {
  z-index: 1;
}

.book-category-pill {
  font-size: 0.65rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 0.4rem;
}

.book-cover-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.35;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-cover-footer {
  z-index: 1;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 0.5rem;
}

.book-cover-author {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-cover-meta {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  justify-content: space-between;
  margin-top: 0.2rem;
}

/* Info under the book shelf */
.book-shelf-info {
  margin-top: 0.75rem;
  text-align: center;
}

.book-shelf-title {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.book-shelf-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Modal Quick View / Book Details */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  max-width: 680px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}

.modal-backdrop.active .modal-dialog {
  transform: translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-close-modal {
  font-size: 1.3rem;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close-modal:hover {
  background: var(--bg-surface-3);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
}

.modal-cover-preview {
  aspect-ratio: 1 / 1.414;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: -4px 6px 18px rgba(0,0,0,0.5);
}

.modal-meta-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.modal-meta-item {
  display: flex;
  gap: 0.5rem;
}

.modal-meta-item strong {
  min-width: 90px;
  color: var(--text-secondary);
}

.modal-desc-box {
  background: var(--bg-surface-2);
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 0.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: var(--bg-surface-2);
  border-top: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn-open-reader {
  background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
  color: #ffffff;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px rgba(236, 72, 153, 0.4);
  border: 1px solid #f472b6;
}

.btn-open-reader:hover {
  background: linear-gradient(135deg, #f472b6 0%, #ec4899 100%);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(236, 72, 153, 0.55);
}

.btn-copy-embed {
  background: var(--bg-surface-3);
  color: var(--text-primary);
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid var(--border-glass);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-copy-embed:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Toast notifications */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-surface-3);
  color: #fff;
  padding: 0.85rem 1.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass-active);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  z-index: 3000;
  transform: translateY(100px);
  opacity: 0;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.toast-msg.show {
  transform: translateY(0);
  opacity: 1;
}

/* Footer */
.app-footer {
  background: var(--bg-surface-1);
  border-top: 1px solid var(--border-glass);
  padding: 2.5rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.app-footer a {
  color: var(--np-gold-light);
}

/* Responsive */
@media (max-width: 768px) {
  .header-container {
    flex-wrap: wrap;
  }
  .modal-body {
    grid-template-columns: 1fr;
  }
  .modal-cover-preview {
    max-width: 180px;
    margin: 0 auto;
  }
  .theme-pill-container {
    justify-content: flex-start;
  }
}
