:root {
  --bg-color: #050505;
  --bg-gradient: radial-gradient(circle at center top, #1a1f25 0%, #000000 100%);
  --panel-bg: rgba(20, 20, 20, 0.98);
  --text-main: #f0f0f0;
  --text-gold: #D4AF37;
  --text-muted: #a0a0a0;
  --string-color: #6a5a4a;
  --btn-gradient: linear-gradient(135deg, #D4AF37 0%, #AA8C2C 100%);
  --btn-text: #000;
  --svg-shadow: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.8));
  --border-color: rgba(255, 255, 255, 0.15);
  --icon-color: #D4AF37;
  --focus-ring: 2px solid #D4AF37;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

body.light-theme {
  --bg-color: #f4f4f0;
  --bg-gradient: radial-gradient(circle at center top, #ffffff 0%, #e6e6e6 100%);
  --panel-bg: rgba(255, 255, 255, 0.98);
  --text-main: #333333;
  --text-gold: #b8860b;
  --text-muted: #555555;
  --string-color: #8c7b6a;
  --btn-gradient: linear-gradient(135deg, #b8860b 0%, #8a6508 100%);
  --btn-text: #fff;
  --svg-shadow: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
  --border-color: rgba(0, 0, 0, 0.1);
  --icon-color: #333;
}

* { box-sizing: border-box; }

*:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

html, body {
  height: 100%; width: 100%; margin: 0; padding: 0;
  overflow: hidden; position: fixed;
  background: var(--bg-color); background-image: var(--bg-gradient);
  color: var(--text-main); font-family: 'Lato', sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background 0.5s ease, color 0.5s ease;
}

.app-container {
  display: flex; flex-direction: column;
  height: 100%; width: 100%; max-width: 600px;
  margin: 0 auto; position: relative;
}

/* --- BARRA SUPERIOR E BOTÕES --- */
.top-bar {
  position: absolute; top: max(15px, var(--safe-top)); left: 0; width: 100%;
  display: flex; justify-content: space-between; padding: 0 15px;
  z-index: 1000; pointer-events: none;
}

.top-bar-group { display: flex; gap: 10px; pointer-events: auto; }

.top-btn {
  background: var(--panel-bg); border: 1px solid var(--border-color);
  color: var(--icon-color); width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; backdrop-filter: blur(10px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, background 0.2s;
}

.top-btn:active { transform: scale(0.92); }
.top-btn svg { width: 22px; height: 22px; stroke-width: 2; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }

/* --- PAINEL DE FONTE FLUTUANTE --- */
.floating-panel {
  position: absolute; top: max(75px, calc(var(--safe-top) + 60px)); right: 15px;
  background: var(--panel-bg); border: 1px solid var(--border-color);
  border-radius: 20px; padding: 10px 15px; display: none; align-items: center; gap: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); z-index: 2000;
  backdrop-filter: blur(15px); animation: modalPop 0.2s ease-out;
}

.circle-btn { width: 45px !important; height: 45px; padding: 0 !important; font-size: 1.2rem !important; display: flex; align-items: center; justify-content: center; }
.font-display { font-family: 'Cinzel', serif; font-size: 1.1rem; font-weight: bold; color: var(--text-gold); min-width: 45px; text-align: center; }
.panel-close { font-size: 28px; cursor: pointer; color: var(--text-muted); line-height: 1; padding: 0 5px; }
.panel-close:hover { color: var(--text-main); }

/* --- MODAIS (JANELAS) --- */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.92); backdrop-filter: blur(15px);
  display: none; align-items: center; justify-content: center; z-index: 3000; padding: 20px;
}

.modal-content {
  background: var(--panel-bg); border: 1px solid var(--text-gold); border-radius: 25px;
  max-width: 400px; width: 100%; padding: 30px; position: relative; text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); animation: modalPop 0.3s ease-out;
  max-height: 90vh; overflow-y: auto;
}

.modal-actions { display: flex; gap: 15px; justify-content: center; width: 100%; margin-top: 10px; }

.modal-btn {
  padding: 12px 20px; border-radius: 50px; cursor: pointer;
  font-family: 'Cinzel', serif; font-size: 0.9rem; font-weight: 600; flex: 1; transition: transform 0.1s;
}

.modal-btn:active { transform: scale(0.95); }
.modal-btn.primary { background: var(--btn-gradient); color: var(--btn-text); border: none; box-shadow: 0 4px 15px rgba(212, 175, 55, 0.2); }
.modal-btn.secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border-color); }
.modal-btn.secondary:hover { border-color: var(--text-gold); color: var(--text-main); }

@keyframes modalPop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-close {
  position: absolute; top: 15px; right: 20px; font-size: 28px; cursor: pointer;
  color: var(--text-muted); line-height: 1; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
}

/* --- GRELHA DE SELEÇÃO E ESTILOS --- */
.selection-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.full-width { grid-column: span 2; }

.select-btn {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-color); color: var(--text-main);
  padding: 18px; border-radius: 12px; cursor: pointer; font-family: 'Cinzel', serif; font-size: 0.9rem;
  transition: all 0.2s; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.select-btn small { font-size: 0.7rem; color: var(--text-muted); font-family: 'Lato', sans-serif; font-weight: 400; }
.select-btn:hover { background: rgba(212, 175, 55, 0.1); border-color: var(--text-gold); }
.select-btn:active { transform: scale(0.98); }
.select-btn.primary { background: var(--btn-gradient); color: var(--btn-text); border: none; font-weight: bold; }

.models-grid { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

.model-option {
  display: flex; align-items: center; gap: 15px; padding: 14px; border: 1px solid var(--border-color);
  border-radius: 12px; cursor: pointer; background: rgba(255, 255, 255, 0.03); transition: background 0.2s;
}
.model-option:hover { background: rgba(255, 255, 255, 0.08); }
.model-preview { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.2); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); }
.model-name { font-family: 'Cinzel', serif; font-size: 0.95rem; color: var(--text-main); }

/* --- ÁREA DO TERÇO VISUAL --- */
.rosary-section {
  flex: 0 0 40%; display: flex; align-items: center; justify-content: center;
  position: relative; padding: calc(75px + var(--safe-top)) 15px 10px 15px; overflow: hidden; transition: flex 0.3s ease;
}

.rosary-svg-container { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; animation: fadeIn 1.5s ease-out; }
svg#rosary-svg { width: 100%; height: 100%; overflow: visible; filter: var(--svg-shadow); transition: filter 0.5s ease; }

.string-line { fill: none; stroke: var(--string-color); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.5s ease; }

/* --- ÁREA DE TEXTO E ORAÇÃO --- */
.text-section {
  flex: 1; min-height: 20%; display: flex; flex-direction: column;
  background-color: var(--panel-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 25px 25px 0 0; padding: 25px 25px 0px 25px; box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.3);
  z-index: 20; overflow: hidden; border-top: 1px solid var(--border-color); position: relative; cursor: pointer;
}
.text-section:active { background-color: rgba(30, 30, 30, 0.95); }
body.light-theme .text-section:active { background-color: rgba(245, 245, 245, 0.95); }

/* Gradiente de sombra no fundo do texto */
.text-section::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 100px;
  background: linear-gradient(to bottom, transparent, var(--panel-bg) 85%);
  pointer-events: none; z-index: 25;
}

.progress-area { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 15px; flex-shrink: 0; }
.progress-bar-container { flex: 1; height: 6px; background: var(--border-color); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--text-gold); width: 0%; transition: width 0.5s ease; }
.progress-text { font-family: 'Cinzel', serif; font-size: 0.85rem; color: var(--text-gold); font-weight: 700; min-width: 45px; text-align: right; }

.header-info { text-align: center; flex-shrink: 0; margin-bottom: 12px; }
.date-badge { font-family: 'Cinzel', serif; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; color: var(--text-gold); margin-bottom: 6px; display: inline-block; border-bottom: 1px solid var(--border-color); padding-bottom: 4px; }
.mystery-title { font-family: 'Cinzel', serif; font-size: 1.2rem; font-weight: 700; color: var(--text-main); margin: 6px 0; line-height: 1.3; }
.bead-label { font-size: 0.9rem; color: var(--text-muted); margin-top: 4px; font-weight: 400; }

.prayer-content {
  flex-grow: 1; overflow-y: auto; min-height: 0; padding-right: 8px; scrollbar-width: thin; scrollbar-color: var(--text-muted) transparent;
  scroll-behavior: smooth; padding-bottom: 120px; 
}
.prayer-content::-webkit-scrollbar { width: 6px; }
.prayer-content::-webkit-scrollbar-track { background: transparent; }
.prayer-content::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; }

.prayer-text { font-size: 1.2rem; line-height: 1.7; white-space: pre-wrap; color: var(--text-main); font-weight: 400; user-select: text; }

.text-fade-in { animation: fadeInText 0.4s ease-out forwards; }
@keyframes fadeInText { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   NOVA ÁREA DE CONTROLOS (PÍLULA FLUTUANTE)
   ========================================= */
.controls-area {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 50px;
  padding: 6px 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 40;
  display: flex;
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
}

.btn-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Botões Modais e Antigos Genéricos */
button.action-btn {
  background: var(--btn-gradient); color: var(--btn-text); border: none; padding: 18px;
  font-family: 'Cinzel', serif; font-size: 1rem; font-weight: 800; border-radius: 50px; cursor: pointer;
  box-shadow: 0 5px 20px rgba(212, 175, 55, 0.3); transition: transform 0.1s, box-shadow 0.2s; outline: none;
  text-transform: uppercase; letter-spacing: 1.5px; -webkit-tap-highlight-color: transparent;
}
button.action-btn:active { transform: scale(0.96); box-shadow: 0 2px 10px rgba(212, 175, 55, 0.2); }

/* Novos Botões de Navegação (Pílula Voltar/Avançar com Ícones) */
.nav-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 24px; font-family: 'Cinzel', serif; font-size: 0.95rem; font-weight: 800;
  border-radius: 40px; cursor: pointer; transition: all 0.2s ease; outline: none;
  text-transform: uppercase; letter-spacing: 1px; -webkit-tap-highlight-color: transparent;
}

.nav-btn:active { transform: scale(0.96); }

.primary-btn {
  background: var(--btn-gradient); color: var(--btn-text); border: none;
  box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.secondary-btn {
  background: transparent; color: var(--text-muted); border: none; padding: 12px 16px;
}

.secondary-btn:hover { color: var(--text-main); }


/* --- ANIMAÇÃO E DESENHO DAS CONTAS --- */
.bead, .cross, .medal-base { cursor: pointer; transform-box: fill-box; transform-origin: center; transition: all 0.5s ease; }
.bead.small { fill: url(#grad-bead-small); }
.bead.large { fill: url(#grad-bead-large); }
.cross, .medal-base { fill: url(#grad-metal); }

.bead.done, .cross.done, .medal-base.done { filter: brightness(0.5) saturate(0.8); transform: scale(0.9); }
.bead.active, .cross.active, .medal-base.active { fill: url(#grad-active) !important; animation: goldenPulse 2.5s infinite ease-in-out; z-index: 100; filter: brightness(1.1); }
.bead.large { r: 10; }
.bead.small { r: 6.5; }

@keyframes goldenPulse { 0%, 100% { transform: scale(1); filter: drop-shadow(0 0 30px var(--text-gold)); } 50% { transform: scale(1.25); filter: drop-shadow(0 0 30px var(--text-gold)) brightness(1.3); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* --- SPINNER DE CARREGAMENTO --- */
.loading-spinner {
  width: 45px; height: 45px; border: 4px solid rgba(212, 175, 55, 0.2); border-top: 4px solid var(--text-gold);
  border-radius: 50%; margin: 0 auto; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- TOAST DE NOTIFICAÇÃO --- */
.toast-notification {
  visibility: hidden; min-width: 250px; background-color: var(--panel-bg); color: var(--text-main);
  text-align: center; border-radius: 25px; padding: 16px; position: fixed; z-index: 4000; left: 50%;
  bottom: max(30px, env(safe-area-inset-bottom, 30px)); 
  transform: translateX(-50%); font-size: 0.95rem; border: 1px solid var(--text-gold);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-family: 'Lato', sans-serif; opacity: 0; transition: opacity 0.3s, bottom 0.3s, visibility 0.3s;
}
.toast-notification.show { visibility: visible; opacity: 1; bottom: max(90px, env(safe-area-inset-bottom, 90px)); } /* Subido para não encostar na pílula */

/* --- RESPONSIVIDADE DESKTOP --- */
@media (min-width: 768px) {
  body { position: relative; padding: 40px; overflow: auto; }
  .app-container {
    flex-direction: row; height: 92vh; border-radius: 30px; overflow: hidden;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3); background: var(--bg-color); border: 1px solid var(--border-color); max-width: 1100px;
  }
  .top-bar { top: 30px; padding: 0 30px; }
  
  .rosary-section {
    flex: 0 0 40%; min-height: auto; max-height: 100%; min-width: 20%; max-width: 80%;
    padding: 85px 10px 10px 10px; align-items: center; justify-content: center;
  }
  .rosary-svg-container { height: 95%; width: 95%; }
  
  .text-section { 
    flex: 1; border-radius: 0; border-left: 1px solid var(--border-color); 
    border-top: none; padding: 90px 40px 0px 40px; cursor: default; 
  }
  
  .text-section:active { background-color: var(--panel-bg); }
  .floating-panel { right: 30px; top: 90px; }
}