:root {
  --primary: #1a4f8b;
  --primary-dark: #0f325d;
  --primary-light: #e8f0fe;
  --secondary: #d4a373;
  --accent: #2b7a78;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --verse-bg: #f0f7ff;
  --verse-border: #3b82f6;
  --quote-bg: #fdfbf7;
  --quote-border: #d4a373;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Merriweather", Georgia, Cambria, "Times New Roman", Times, serif;
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #334155;
  --verse-bg: #1e293b;
  --verse-border: #60a5fa;
  --quote-bg: #1e293b;
  --quote-border: #fbbf24;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  width: 100%;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #ffffff;
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.logo-icon {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-text p {
  font-size: 0.8rem;
  color: #cbd5e1;
}

.header-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.header-search input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.5rem;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 0.9rem;
  outline: none;
  transition: all 0.2s;
}

.header-search input::placeholder {
  color: #cbd5e1;
}

.header-search input:focus {
  background: #ffffff;
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: #cbd5e1;
  pointer-events: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-nav-slide {
  text-decoration: none;
  padding: 0.45rem 1rem;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.btn-nav-slide:hover {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Category Tabs */
.category-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.category-tabs {
  display: flex;
  gap: 0.5rem;
}

.cat-tab {
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.cat-tab:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.cat-tab.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(59, 130, 246, 0.2);
}

.badge-count {
  background: var(--primary);
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
}

.cat-tab:not(.active) .badge-count {
  background: var(--text-light);
}

/* Step Filter Pills */
.step-filter-bar {
  width: 100%;
  max-width: 1400px;
  margin: 1rem auto 0;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  box-sizing: border-box;
}

.step-filter-bar::-webkit-scrollbar {
  height: 4px;
}

.step-filter-bar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.filter-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  margin-right: 0.25rem;
}

.step-pill {
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.step-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.step-pill.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Main Layout */
.main-content {
  max-width: 1400px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
}

/* Card Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.lesson-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.step-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary);
  text-transform: uppercase;
}

.card-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
}

.card-title-vi {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.card-title-ko {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.feature-tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-weight: 600;
}

.tag-full {
  background: #e0f2fe;
  color: #0369a1;
}

.tag-sum {
  background: #fef3c7;
  color: #92400e;
}

.tag-img {
  background: #f3e8ff;
  color: #6b21a8;
}

.tag-slide {
  background: #ecfdf5;
  color: #065f46;
}

.card-actions-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-read {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}

.btn-slide-card {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0d9488;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s;
}

.btn-slide-card:hover {
  background: #0d9488;
  color: #ffffff;
  border-color: #0d9488;
  transform: translateY(-1px);
}

.modal-body.slide-mode {
  padding: 0 !important;
  overflow: hidden !important;
  display: flex;
  flex-direction: column;
}

.modal-slide-iframe {
  width: 100%;
  height: 100%;
  border: none;
  flex: 1;
  min-height: 550px;
}

/* Reader Modal View */
.reader-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.reader-modal.active {
  display: flex;
}

.modal-dialog {
  background: var(--bg-card);
  width: 100%;
  max-width: 1000px;
  height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.modal-title-area {
  flex: 1;
  min-width: 0;
}

.modal-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.modal-h2 {
  font-size: 1.25rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal Control Tabs (Full, Summary, Diagram) */
.reader-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.reader-tabs {
  display: flex;
  gap: 0.5rem;
}

.reader-tab-btn {
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.reader-tab-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.reader-tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.reader-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tool-btn {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* Reader Body */
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.5rem;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-main);
}

/* Article Styling inside Reader */
.modal-body h2 {
  font-family: var(--font-sans);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 1rem;
  line-height: 1.3;
}

.modal-body h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
  border-left: 4px solid var(--primary);
  padding-left: 0.75rem;
}

.modal-body h4 {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.modal-body p {
  margin-bottom: 1.1rem;
}

.modal-body .verse {
  background: var(--verse-bg);
  border-left: 4px solid var(--verse-border);
  padding: 0.85rem 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1.25rem 0;
  font-style: italic;
  font-size: 1rem;
  color: var(--text-main);
}

.modal-body blockquote {
  background: var(--quote-bg);
  border-left: 4px solid var(--quote-border);
  padding: 0.85rem 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.modal-body cite {
  display: block;
  font-weight: 700;
  font-style: normal;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: #b45309;
  margin-bottom: 0.5rem;
}

.modal-body .picture {
  text-align: center;
  margin: 1.5rem 0;
}

.modal-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.2s;
}

.modal-body img:hover {
  transform: scale(1.01);
}

.diagram-container {
  text-align: center;
  padding: 1rem 0;
}

.diagram-img {
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

/* Audio Player */
.audio-bar {
  background: var(--bg-hover);
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.audio-bar audio {
  flex: 1;
  height: 36px;
}

/* Modal Footer */
.modal-footer {
  padding: 0.85rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
}

.nav-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Image Zoom Modal */
.image-zoom-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  cursor: zoom-out;
}

.image-zoom-modal.active {
  display: flex;
}

.image-zoom-modal img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

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

/* Responsive for Millions of Screen Sizes */
@media (max-width: 900px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
  }
}

@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .header-actions {
    justify-content: space-between;
    width: 100%;
  }
  .header-search {
    max-width: 100%;
  }
  .category-nav {
    padding: 0.5rem 1rem;
  }
  .category-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }
  .cat-tab {
    white-space: nowrap;
    padding: 0.5rem 1rem;
    font-size: 0.88rem;
    flex-shrink: 0;
  }
  .step-filter-bar {
    padding: 0 1rem;
    margin-top: 0.5rem;
  }
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0 1rem;
  }
  .reader-modal {
    padding: 0;
  }
  .modal-dialog {
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    width: 100vw;
    border-radius: 0;
    border: none;
  }
  .modal-header {
    padding: 0.75rem 1rem;
  }
  .modal-h2 {
    font-size: 1.05rem;
  }
  .reader-tabs-bar {
    padding: 0.4rem 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .reader-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 0.4rem;
  }
  .reader-tab-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .reader-tools {
    justify-content: flex-end;
    gap: 0.35rem;
  }
  .tool-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
  .modal-body {
    padding: 1.25rem 1rem;
    font-size: 0.98rem;
  }
  .modal-footer {
    padding: 0.6rem 1rem;
  }
  .modal-footer span {
    display: none;
  }
  .nav-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
  }
}

@media (max-width: 480px) {
  .logo-text h1 {
    font-size: 1.05rem;
  }
  .logo-text p {
    font-size: 0.75rem;
  }
  .btn-nav-slide {
    font-size: 0.78rem;
    padding: 0.35rem 0.75rem;
  }
  .lesson-card {
    padding: 1rem;
  }
  .card-title-vi {
    font-size: 0.98rem;
  }
}
