/* === CATHOLIC COMEDY DESIGN SYSTEM & APP STYLES === */
:root {
  --lit-green: #004d25;
  --lit-gold: #b8860b;
  --lit-red: #9d0208;
  --lit-purple: #5a189a;
  --lit-rose: #d63384;
  --header-bg: var(--lit-green);
  --header-text: #ffffff;
  --brand-color: #ffd700;
  
  --bg-body: #f4f6f8;
  --surface-card: #ffffff;
  --text-main: #1c2024;
  --text-muted: #606f7b;
  --border-color: #e2e8f0;
  --input-bg: #f8fafc;
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"], .dark-theme {
  --bg-body: #0b0f17;
  --surface-card: #151c28;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #243042;
  --input-bg: #101622;
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

[data-theme="retro"], .retro-theme {
  --bg-body: #2b1d0c;
  --surface-card: #3d2b14;
  --text-main: #ffd700;
  --text-muted: #d4af37;
  --border-color: #8b5a2b;
  --input-bg: #221508;
  --header-bg: #8b4513;
}

[data-theme="anime"], .anime-theme {
  --bg-body: #0f172a;
  --surface-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #3b82f6;
  --input-bg: #0b1120;
  --header-bg: #1d4ed8;
}

[data-theme="memento-mori"], .memento-mori-theme {
  --bg-body: #050505;
  --surface-card: #121212;
  --text-main: #e2e8f0;
  --text-muted: #71717a;
  --border-color: #27272a;
  --input-bg: #09090b;
  --header-bg: #27272a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  padding-bottom: 75px;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
  transition: background-color 0.2s, color 0.2s;
  touch-action: manipulation;
}

/* Ensure inputs, selects, and textareas are at least 16px to prevent iOS Safari auto-zoom */
select, input, textarea {
  font-family: inherit;
  font-size: 16px !important;
  max-width: 100%;
  box-sizing: border-box;
}

/* === SPLASH SCREEN === */
#appSplashScreen {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: radial-gradient(circle at center, #005a2b 0%, #002e17 100%);
  z-index: 999999999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
#appSplashScreen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none !important;
  display: none !important;
}
.splash-cross-icon {
  font-size: 3.5rem;
  color: #ffd700;
  filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.6));
  animation: splashPulse 1.5s infinite ease-in-out;
  margin-bottom: 1.2rem;
}
@keyframes splashPulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.1); opacity: 1; filter: drop-shadow(0 0 30px rgba(255, 215, 0, 0.9)); }
}
.splash-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 0 0 0.5rem 0;
  color: #ffffff;
}
.splash-subtitle {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

/* === APP HEADER === */
header {
  background: var(--header-bg);
  color: var(--header-text);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  transition: background 0.3s ease;
}
.header-container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--brand-color);
  object-fit: cover;
}
.brand-title {
  display: flex;
  flex-direction: column;
}
.brand-title span:first-child {
  font-family: 'Playfair Display', serif;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.1;
  color: #ffffff;
}
.brand-subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  color: var(--brand-color);
  font-weight: 600;
}
.header-actions {
  display: flex;
  gap: 0.5rem;
}
.hamburger-btn, .theme-toggle-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
}

/* === MAIN CONTAINER & CARDS === */
.main-container {
  max-width: 900px;
  margin: 1rem auto;
  padding: 0 1rem;
}
.tab-content {
  display: none;
  animation: tabFadeIn 0.2s ease;
}
.tab-content.active {
  display: block;
}
@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.card {
  background: var(--surface-card);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 1rem;
  color: var(--header-bg);
  flex-wrap: wrap;
  gap: 8px;
}
.badge {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  background: var(--header-bg);
  color: #fff;
}

/* === RITE SWITCHER & BUTTONS === */
.rite-switcher {
  display: flex;
  background: var(--input-bg);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 1.2rem;
  gap: 4px;
}
.rite-btn, .rite-tab {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rite-btn.active, .rite-tab.active {
  background: var(--surface-card);
  color: var(--header-bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.btn-primary {
  background: var(--header-bg);
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}
.btn-secondary {
  background: var(--input-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* === READINGS & BIBLE LINKS === */
.readings-container {
  line-height: 1.8;
  font-size: 1.05rem;
}
.bible-link-btn {
  color: var(--header-bg) !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  text-decoration: underline !important;
  padding: 3px 8px !important;
  border-radius: 6px !important;
  background: rgba(0, 77, 37, 0.1) !important;
  display: inline-block !important;
  touch-action: manipulation !important;
}

/* === DEVOTIONS SUBTABS === */
.devotion-subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}
.devotion-subtab-btn {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}
.devotion-subtab-btn.active {
  background: var(--header-bg);
  color: #ffffff;
  border-color: var(--header-bg);
}

/* === ARCADE MINI-GAMES NAV === */
.arcade-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 1.5rem;
  scrollbar-width: thin;
}
.arcade-nav-btn {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  cursor: pointer;
}
.arcade-nav-btn.active {
  background: var(--header-bg);
  color: #ffffff;
  border-color: var(--header-bg);
}

/* === SCRIPTURE MODAL === */
#scripturePopupModal {
  position: fixed !important;
  top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
  width: 100vw !important; height: 100vh !important;
  background: rgba(0, 0, 0, 0.75) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  z-index: 99999999 !important;
  display: none;
  align-items: center !important;
  justify-content: center !important;
  padding: 1rem !important;
}
#scripturePopupModal.active {
  display: flex !important;
}
.scripture-modal-card {
  background: var(--surface-card);
  color: var(--text-main);
  border: 2px solid var(--lit-gold);
  border-radius: 20px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
  overflow: hidden;
}
.scripture-modal-header {
  padding: 1.2rem 1.5rem;
  background: linear-gradient(135deg, rgba(184,134,11,0.12), rgba(0,77,37,0.08));
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.scripture-modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--header-bg);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.scripture-modal-close-btn {
  background: rgba(0,0,0,0.06);
  border: none;
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}
.scripture-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  line-height: 1.8;
  font-size: 1.05rem;
  flex: 1;
}
.scripture-modal-footer {
  padding: 1rem 1.5rem;
  background: var(--input-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* === BOTTOM NAVIGATION === */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 62px;
  background: var(--surface-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 -4px 15px rgba(0,0,0,0.05);
}
.nav-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  gap: 4px;
}
.nav-item i { font-size: 1.2rem; }
.nav-item.active {
  color: var(--header-bg);
  font-weight: 800;
}

/* === DRAWER === */
.drawer-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 2000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; left: 0; width: 300px; height: 100vh;
  background: var(--surface-card);
  z-index: 2001;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 1.5rem;
  box-shadow: 10px 0 30px rgba(0,0,0,0.2);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.drawer-theme-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 1.5rem;
}
.theme-icon-btn {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  padding: 8px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}
.theme-icon-btn.active {
  border-color: var(--header-bg);
  background: rgba(0,77,37,0.1);
}


/* === VISUAL ROSARY BEAD TRACK STYLES === */
.rosary-bead-track {
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto; padding: 0.8rem 0.6rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 12px; margin-bottom: 1.2rem;
  scroll-behavior: smooth;
}
.rosary-bead-track::-webkit-scrollbar { height: 6px; }
.rosary-bead-track::-webkit-scrollbar-thumb { background: var(--header-bg); border-radius: 4px; }

.bead-item {
  flex: 0 0 auto; width: 32px; height: 32px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 800; cursor: pointer; transition: all 0.25s ease;
  user-select: none; background: var(--input-bg);
  border: 2px solid var(--border-color); color: var(--text-muted);
}
.bead-item.large-bead {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, rgba(212,175,55,0.25), rgba(0,77,37,0.15));
  border-color: var(--lit-gold); color: var(--lit-gold); font-size: 0.85rem;
}
.bead-item.crucifix-bead {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--header-bg); color: #fff; border-color: var(--brand-color);
  font-size: 1rem;
}
.bead-item.active {
  transform: scale(1.28);
  border-color: var(--brand-color) !important;
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.95) !important;
  background: var(--header-bg) !important; color: #fff !important;
}


/* === 10 IN-APP MINI-GAMES STYLING === */
.arcade-nav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.8rem;
  margin-bottom: 1.5rem;
  scrollbar-width: thin;
}

.arcade-nav::-webkit-scrollbar {
  height: 6px;
}

.arcade-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.arcade-nav-btn {
  background: var(--input-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.arcade-nav-btn:hover {
  background: var(--border-color);
}

.arcade-nav-btn.active {
  background: var(--header-bg);
  color: #ffffff;
  border-color: var(--header-bg);
  box-shadow: 0 4px 12px rgba(0,77,37,0.25);
}

.game-pane {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

/* Heresy Sweeper */
.heresy-grid {
  display: grid;
  gap: 4px;
  max-width: 420px;
  margin: 1rem auto;
  background: var(--border-color);
  padding: 6px;
  border-radius: 10px;
}

.heresy-cell {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
  transition: background 0.15s;
}

.heresy-cell:hover {
  filter: brightness(0.95);
}

.heresy-cell.revealed {
  background: var(--input-bg);
  border-color: transparent;
}

.heresy-cell.mine {
  background: #dc2626 !important;
  color: #ffffff;
}

.heresy-cell.flagged {
  background: #fef08a;
  color: #854d0e;
}

/* Wordle */
.wordle-grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  max-width: 320px;
  margin: 1.2rem auto;
}

.wordle-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.wordle-cell {
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--surface-card);
  color: var(--text-main);
}

.wordle-cell.correct {
  background: #16a34a !important;
  color: #fff !important;
  border-color: #16a34a !important;
}

.wordle-cell.present {
  background: #ca8a04 !important;
  color: #fff !important;
  border-color: #ca8a04 !important;
}

.wordle-cell.absent {
  background: #4b5563 !important;
  color: #fff !important;
  border-color: #4b5563 !important;
}

/* Solitaire Board */
#klondikeBoard {
  background: #1e5631;
  border-radius: 12px;
  padding: 1rem;
  min-height: 480px;
  color: #ffffff;
  position: relative;
  overflow-x: auto;
}

/* Memory Grid */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 400px;
  margin: 1rem auto;
}

.memory-card {
  aspect-ratio: 1 / 1;
  background: var(--surface-card);
  border: 2px solid var(--lit-gold);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  cursor: pointer;
  transition: transform 0.2s;
}

.memory-card.flipped {
  transform: rotateY(180deg);
  background: var(--input-bg);
}

.memory-card.matched {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22c55e;
}

/* Match 3 Grid */
.match3-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-width: 380px;
  margin: 1rem auto;
  background: var(--border-color);
  padding: 6px;
  border-radius: 12px;
}

.match3-cell {
  aspect-ratio: 1 / 1;
  background: var(--surface-card);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.15s;
}

.match3-cell.selected {
  outline: 3px solid var(--lit-gold);
  transform: scale(1.1);
  z-index: 2;
}

/* Canvas Games */
.daily-reading-row { margin: .65rem 0; line-height: 1.7; }
.bible-link-btn { font: inherit; color: var(--header-bg); background: transparent; border: 0; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: .25rem; text-align: left; }
.reading-source, .reading-calendar-note { font-size: .85rem; line-height: 1.5; margin-top: 1rem; }
.reading-calendar-note { color: var(--text-muted); }
.bible-link-btn:focus-visible { outline: 2px solid var(--header-bg); outline-offset: 3px; }
canvas.game-canvas {
  background: #111827;
  border-radius: 12px;
  display: block;
  margin: 0 auto;
  max-width: 100%;
}


/* === LIBRARY CONTROLS (RESPONSIVE & OVERFLOW-SAFE) === */
.library-controls-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 1.2rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .library-controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

.library-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.75rem 2.2rem 0.75rem 1rem;
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 16px !important;
  line-height: 1.4;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23606f7b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
}

.library-select:focus {
  border-color: var(--header-bg);
  box-shadow: 0 0 0 3px rgba(0, 77, 37, 0.15);
  outline: none;
}

.library-search-container {
  display: flex;
  gap: 10px;
  margin-bottom: 1.2rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.library-search-input {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-main);
  font-size: 16px !important;
  box-sizing: border-box;
  outline: none;
}

.library-search-input:focus {
  border-color: var(--header-bg);
  box-shadow: 0 0 0 3px rgba(0, 77, 37, 0.15);
}

.library-search-btn {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  font-size: 15px !important;
  white-space: nowrap;
}

.library-content-container {
  line-height: 1.85;
  font-size: 1.05rem;
  max-height: 65vh;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-word;
  overflow-wrap: break-word;
  background: var(--input-bg);
  padding: 1.2rem;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  box-sizing: border-box;
  max-width: 100%;
  width: 100%;
}
