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

:root {
  /* Dynamic font scale (will be changed by JS) */
  --base-font-size: 18px;
  
  /* Light Mode Palette (Default) */
  --bg-primary: #FAF9F6;      /* Warm white, softer on senior eyes than pure white */
  --bg-secondary: #F0EDE4;    /* Light warm grey */
  --bg-card: #FFFFFF;
  --text-primary: #1C1E21;    /* Deep off-black for high legibility */
  --text-secondary: #4A5056;
  --text-muted: #6B7280;
  --accent-primary: #005a36;  /* High contrast vibrant dark green */
  --accent-hover: #004026;
  --accent-light: #e6f2ec;
  --border-color: #D2CAB8;    /* Softer border color, warm tone */
  --table-border: #C8BFAD;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(67, 56, 30, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

[data-theme="dark"] {
  /* Dark Mode Palette */
  --bg-primary: #0F1012;      /* Deep soft black */
  --bg-secondary: #17191C;    /* Dark charcoal */
  --bg-card: #1F2226;
  --text-primary: #F3F4F6;    /* Bright text for high contrast on dark bg */
  --text-secondary: #D1D5DB;
  --text-muted: #9CA3AF;
  --accent-primary: #34d399;  /* Bright neonish green */
  --accent-hover: #10b981;
  --accent-light: #064e3b;
  --border-color: #2D3139;
  --table-border: #3D424F;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

body {
  font-family: 'Sarabun', 'Outfit', system-ui, -apple-system, sans-serif;
  font-size: var(--base-font-size);
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 12px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 6px;
  border: 3px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Header & Sticky Elements */
.site-header {
  background: var(--bg-card);
  border-bottom: 2px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 100;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

@media (min-width: 768px) {
  .header-container {
    flex-direction: row;
    justify-content: space-between;
  }
}

.site-title-area {
  text-align: center;
}

@media (min-width: 768px) {
  .site-title-area {
    text-align: left;
  }
}

.site-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-primary);
  letter-spacing: -0.02em;
}

.site-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
  font-weight: 500;
}

/* Top Navigation Panel - Extra large buttons for seniors */
.nav-panel {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

@media (min-width: 768px) {
  .nav-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 0.8rem;
  }
}

.nav-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.8rem 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

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

.nav-btn.active {
  background: var(--accent-primary);
  color: #FFFFFF !important;
  border-color: var(--accent-primary);
}

.nav-btn .sub-text {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.85;
}

/* Floating Actions & Utility Controls */
.control-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.6rem 1rem;
}

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

.btn-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.control-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.font-btn {
  font-size: 1.2rem;
  font-weight: 800;
  padding: 0.3rem 0.9rem;
  min-width: 44px;
  height: 40px;
  justify-content: center;
}

.font-indicator {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0 0.4rem;
}

/* Main Container Layout */
.main-content {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  padding-bottom: 8rem; /* Make room for floating home button */
}

/* SPA Sections */
.app-section {
  display: none;
  animation: fadeIn 0.3s ease-out forwards;
}

.app-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Cover Page (Home) Layout */
.cover-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

@media (min-width: 768px) {
  .cover-card {
    padding: 3rem;
  }
}

.cover-header {
  text-align: center;
  margin-bottom: 2.5rem;
  border-bottom: 3px double var(--border-color);
  padding-bottom: 2rem;
}

.cover-title {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent-primary);
  margin-bottom: 0.5rem;
}

.cover-subtitle {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
}

.cover-date {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.section-heading {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent-primary);
  margin: 2.5rem 0 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-left: 5px solid var(--accent-primary);
  padding-left: 0.8rem;
}

/* Time Table & Sharing Table Styling */
.table-container {
  overflow-x: auto;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 2px solid var(--table-border);
  margin: 1.5rem 0;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  min-width: 600px;
}

th, td {
  padding: 1.2rem 1rem;
  border-bottom: 1px solid var(--table-border);
  vertical-align: middle;
}

th {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 3px solid var(--table-border);
}

tr:last-child td {
  border-bottom: none;
}

/* Zebra striping & hover highlights */
tr:nth-child(even) td {
  background-color: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] tr:nth-child(even) td {
  background-color: rgba(255, 255, 255, 0.015);
}

tr:hover td {
  background-color: var(--accent-light) !important;
}

.highlight-round {
  font-weight: 700;
  color: var(--accent-primary);
}

.timetable-table th, .timetable-table td {
  white-space: nowrap;
}

.church-tag {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  display: inline-block;
  margin: 0.2rem;
}

/* Key Messages Styling */
.key-messages-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.2rem;
  margin: 1.5rem 0;
}

@media (min-width: 768px) {
  .key-messages-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.key-message-card {
  background: var(--bg-secondary);
  border-left: 6px solid var(--accent-primary);
  padding: 1.5rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.key-message-icon {
  background: var(--accent-primary);
  color: #FFFFFF;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}

.key-message-text {
  font-weight: 500;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Outline & Content Pages layout */
.content-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-color);
  padding: 1.5rem 1rem;
  box-shadow: var(--shadow-md);
  margin-top: 1.5rem;
}

@media (min-width: 768px) {
  .content-card {
    padding: 2.5rem 2rem;
  }
}

.part-header {
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
}

.part-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent-primary);
}

.part-subtitle {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-top: 0.4rem;
  line-height: 1.5;
}

/* Sub-tabs layout: Outline (โครงร่าง) vs Transcript (ถอดเทป) */
.subtabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 3px solid var(--border-color);
  margin-bottom: 1.8rem;
  padding-bottom: 1px;
}

.subtab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.8rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.subtab-btn:hover {
  color: var(--accent-primary);
}

.subtab-btn.active {
  color: var(--accent-primary);
}

.subtab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 5px;
  background-color: var(--accent-primary);
  border-radius: 4px;
}

/* Outline Indentation Styles based on ilvl */
.outline-p {
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: flex-start;
}

.outline-p.lvl-0 {
  margin-left: 0;
  font-weight: 800;
  color: var(--text-primary);
  font-size: 1.15em;
  margin-top: 1.8rem;
  border-top: 1px dashed var(--border-color);
  padding-top: 1.5rem;
}

.outline-p.lvl-0:first-of-type {
  border-top: none;
  padding-top: 0;
}

.outline-p.lvl-1 {
  margin-left: 1.8rem;
  font-weight: normal;
  color: var(--text-primary);
  font-size: 1.08em;
  margin-top: 1.2rem;
}

.outline-p.lvl-2 {
  margin-left: 3.6rem;
  font-weight: normal;
  color: var(--text-secondary);
}

.outline-p.lvl-3 {
  margin-left: 5.4rem;
  color: var(--text-secondary);
}

.outline-p.lvl-4 {
  margin-left: 7.2rem;
  color: var(--text-muted);
}

.outline-p.lvl-5 {
  margin-left: 9rem;
  color: var(--text-muted);
}

.p-prefix {
  font-weight: inherit;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.transcript-outline-p, .transcript-outline-p * {
  font-weight: bold !important;
}

.transcript-bold-p, .transcript-bold-p * {
  font-weight: bold !important;
}

.p-text {
  flex-grow: 1;
}

/* Bible Verse Paragraph */
.bible-verses-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
  font-weight: 500;
}

.bible-title {
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 0.4rem;
  font-size: 1.05em;
}

/* Transcript content layouts */
.transcript-p {
  margin-bottom: 1.5rem;
  text-indent: 2rem;
  line-height: 1.8;
  text-align: left;
}

/* Empty or Missing State */
.missing-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-color);
  color: var(--text-secondary);
}

.missing-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

.missing-state-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.missing-state-text {
  font-size: 1rem;
}

/* Back to Top Floating Button */
.floating-home-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 70px;
  height: 70px;
  background-color: var(--accent-primary);
  color: #FFFFFF;
  border-radius: 50%;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  gap: 2px;
  z-index: 99;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-home-btn:hover {
  transform: scale(1.1) translateY(-5px);
  background-color: var(--accent-hover);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.floating-home-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Responsive UI Tweaks */
@media (max-width: 576px) {
  .site-title {
    font-size: 1.5rem;
  }
  
  .nav-btn {
    padding: 0.6rem 0.3rem;
    font-size: 1rem;
    border-radius: var(--radius-sm);
  }
  
  .floating-home-btn {
    bottom: 1.5rem;
    right: 1.5rem;
    width: 60px;
    height: 60px;
    font-size: 0.75rem;
  }
  
  .floating-home-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Reduce indentations on thin mobile displays */
  .outline-p.lvl-1 { margin-left: 0.8rem; }
  .outline-p.lvl-2 { margin-left: 1.6rem; }
  .outline-p.lvl-3 { margin-left: 2.4rem; }
  .outline-p.lvl-4 { margin-left: 3.2rem; }
  .outline-p.lvl-5 { margin-left: 4.0rem; }
}
